- public function testComments() {
- /** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */
- $comment_storage = $this->container->get('entity.manager')->getStorage('comment');
- /** @var \Drupal\comment\CommentInterface $comment */
- $comment = $comment_storage->load(1);
- $this->assertIdentical('The first comment.', $comment->getSubject());
- $this->assertIdentical('The first comment body.', $comment->comment_body->value);
- $this->assertIdentical('filtered_html', $comment->comment_body->format);
- $this->assertIdentical(NULL, $comment->pid->target_id);
- $this->assertIdentical('1', $comment->getCommentedEntityId());
- $this->assertIdentical('node', $comment->getCommentedEntityTypeId());
- $this->assertIdentical('en', $comment->language()->getId());
- $this->assertIdentical('comment_no_subject', $comment->getTypeId());
- $this->assertEquals('203.0.113.1', $comment->getHostname());
-
- $comment = $comment_storage->load(2);
- $this->assertIdentical('The response to the second comment.', $comment->subject->value);
- $this->assertIdentical('3', $comment->pid->target_id);
- $this->assertEquals('203.0.113.2', $comment->getHostname());
-
- $comment = $comment_storage->load(3);
- $this->assertIdentical('The second comment.', $comment->subject->value);
- $this->assertIdentical(NULL, $comment->pid->target_id);
- $this->assertEquals('203.0.113.3', $comment->getHostname());
+ public function testMigration() {
+ $comment = Comment::load(1);
+ $this->assertSame('The first comment.', $comment->getSubject());
+ $this->assertSame('The first comment body.', $comment->comment_body->value);
+ $this->assertSame('filtered_html', $comment->comment_body->format);
+ $this->assertSame(NULL, $comment->pid->target_id);
+ $this->assertSame('1', $comment->getCommentedEntityId());
+ $this->assertSame('node', $comment->getCommentedEntityTypeId());
+ $this->assertSame('en', $comment->language()->getId());
+ $this->assertSame('comment_node_story', $comment->getTypeId());
+ $this->assertSame('203.0.113.1', $comment->getHostname());
+
+ $node = $comment->getCommentedEntity();
+ $this->assertInstanceOf(NodeInterface::class, $node);
+ $this->assertSame('1', $node->id());
+
+ $comment = Comment::load(2);
+ $this->assertSame('The response to the second comment.', $comment->subject->value);
+ $this->assertSame('3', $comment->pid->target_id);
+ $this->assertSame('203.0.113.2', $comment->getHostname());
+
+ $node = $comment->getCommentedEntity();
+ $this->assertInstanceOf(NodeInterface::class, $node);
+ $this->assertSame('1', $node->id());
+
+ $comment = Comment::load(3);
+ $this->assertSame('The second comment.', $comment->subject->value);
+ $this->assertSame(NULL, $comment->pid->target_id);
+ $this->assertSame('203.0.113.3', $comment->getHostname());
+
+ $node = $comment->getCommentedEntity();
+ $this->assertInstanceOf(NodeInterface::class, $node);
+ $this->assertSame('1', $node->id());
+
+ // Tests that the language of the comment is migrated from the node.
+ $comment = Comment::load(7);
+ $this->assertSame('Comment to John Smith - EN', $comment->subject->value);
+ $this->assertSame('This is an English comment.', $comment->comment_body->value);
+ $this->assertSame('21', $comment->getCommentedEntityId());
+ $this->assertSame('node', $comment->getCommentedEntityTypeId());
+ $this->assertSame('en', $comment->language()->getId());
+
+ $node = $comment->getCommentedEntity();
+ $this->assertInstanceOf(NodeInterface::class, $node);
+ $this->assertSame('21', $node->id());
+
+ // Tests that the comment language is correct and that the commented entity
+ // is correctly migrated when the comment was posted to a node translation.
+ $comment = Comment::load(8);
+ $this->assertSame('Comment to John Smith - FR', $comment->subject->value);
+ $this->assertSame('This is a French comment.', $comment->comment_body->value);
+ $this->assertSame('21', $comment->getCommentedEntityId());
+ $this->assertSame('node', $comment->getCommentedEntityTypeId());
+ $this->assertSame('fr', $comment->language()->getId());
+
+ $node = $comment->getCommentedEntity();
+ $this->assertInstanceOf(NodeInterface::class, $node);
+ $this->assertSame('21', $node->id());