3 namespace Drupal\Tests\comment\Kernel\Migrate\d6;
5 use Drupal\comment\Entity\Comment;
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
8 use Drupal\node\NodeInterface;
11 * Tests the migration of comments from Drupal 6.
14 * @group migrate_drupal_6
16 class MigrateCommentTest extends MigrateDrupal6TestBase {
23 public static $modules = [
25 'content_translation',
33 protected function setUp() {
36 $this->installEntitySchema('node');
37 $this->installEntitySchema('comment');
38 $this->installSchema('comment', ['comment_entity_statistics']);
39 $this->installSchema('node', ['node_access']);
40 $this->installConfig(['comment']);
42 // The entity.node.canonical route must exist when the RDF hook is called.
43 $this->container->get('router.builder')->rebuild();
45 $this->migrateContent();
46 $this->executeMigrations([
48 'd6_language_content_settings',
50 'd6_node_translation',
53 'd6_comment_field_instance',
54 'd6_comment_entity_display',
55 'd6_comment_entity_form_display',
61 * Tests the migrated comments.
63 public function testMigration() {
64 $comment = Comment::load(1);
65 $this->assertSame('The first comment.', $comment->getSubject());
66 $this->assertSame('The first comment body.', $comment->comment_body->value);
67 $this->assertSame('filtered_html', $comment->comment_body->format);
68 $this->assertSame(NULL, $comment->pid->target_id);
69 $this->assertSame('1', $comment->getCommentedEntityId());
70 $this->assertSame('node', $comment->getCommentedEntityTypeId());
71 $this->assertSame('en', $comment->language()->getId());
72 $this->assertSame('comment_node_story', $comment->getTypeId());
73 $this->assertSame('203.0.113.1', $comment->getHostname());
75 $node = $comment->getCommentedEntity();
76 $this->assertInstanceOf(NodeInterface::class, $node);
77 $this->assertSame('1', $node->id());
79 $comment = Comment::load(2);
80 $this->assertSame('The response to the second comment.', $comment->subject->value);
81 $this->assertSame('3', $comment->pid->target_id);
82 $this->assertSame('203.0.113.2', $comment->getHostname());
84 $node = $comment->getCommentedEntity();
85 $this->assertInstanceOf(NodeInterface::class, $node);
86 $this->assertSame('1', $node->id());
88 $comment = Comment::load(3);
89 $this->assertSame('The second comment.', $comment->subject->value);
90 $this->assertSame(NULL, $comment->pid->target_id);
91 $this->assertSame('203.0.113.3', $comment->getHostname());
93 $node = $comment->getCommentedEntity();
94 $this->assertInstanceOf(NodeInterface::class, $node);
95 $this->assertSame('1', $node->id());
97 // Tests that the language of the comment is migrated from the node.
98 $comment = Comment::load(7);
99 $this->assertSame('Comment to John Smith - EN', $comment->subject->value);
100 $this->assertSame('This is an English comment.', $comment->comment_body->value);
101 $this->assertSame('21', $comment->getCommentedEntityId());
102 $this->assertSame('node', $comment->getCommentedEntityTypeId());
103 $this->assertSame('en', $comment->language()->getId());
105 $node = $comment->getCommentedEntity();
106 $this->assertInstanceOf(NodeInterface::class, $node);
107 $this->assertSame('21', $node->id());
109 // Tests that the comment language is correct and that the commented entity
110 // is correctly migrated when the comment was posted to a node translation.
111 $comment = Comment::load(8);
112 $this->assertSame('Comment to John Smith - FR', $comment->subject->value);
113 $this->assertSame('This is a French comment.', $comment->comment_body->value);
114 $this->assertSame('21', $comment->getCommentedEntityId());
115 $this->assertSame('node', $comment->getCommentedEntityTypeId());
116 $this->assertSame('fr', $comment->language()->getId());
118 $node = $comment->getCommentedEntity();
119 $this->assertInstanceOf(NodeInterface::class, $node);
120 $this->assertSame('21', $node->id());