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 = ['comment', 'menu_ui'];
28 protected function setUp() {
31 $this->installEntitySchema('node');
32 $this->installEntitySchema('comment');
33 $this->installSchema('comment', ['comment_entity_statistics']);
34 $this->installConfig(['comment']);
36 // The entity.node.canonical route must exist when the RDF hook is called.
37 $this->container->get('router.builder')->rebuild();
39 $this->migrateContent();
40 $this->executeMigrations([
44 'd6_comment_field_instance',
45 'd6_comment_entity_display',
46 'd6_comment_entity_form_display',
52 * Tests the migrated comments.
54 public function testMigration() {
55 $comment = Comment::load(1);
56 $this->assertSame('The first comment.', $comment->getSubject());
57 $this->assertSame('The first comment body.', $comment->comment_body->value);
58 $this->assertSame('filtered_html', $comment->comment_body->format);
59 $this->assertSame(NULL, $comment->pid->target_id);
60 $this->assertSame('1', $comment->getCommentedEntityId());
61 $this->assertSame('node', $comment->getCommentedEntityTypeId());
62 $this->assertSame('en', $comment->language()->getId());
63 $this->assertSame('comment_node_story', $comment->getTypeId());
64 $this->assertSame('203.0.113.1', $comment->getHostname());
66 $node = $comment->getCommentedEntity();
67 $this->assertInstanceOf(NodeInterface::class, $node);
68 $this->assertSame('1', $node->id());
70 $comment = Comment::load(2);
71 $this->assertSame('The response to the second comment.', $comment->subject->value);
72 $this->assertSame('3', $comment->pid->target_id);
73 $this->assertSame('203.0.113.2', $comment->getHostname());
75 $node = $comment->getCommentedEntity();
76 $this->assertInstanceOf(NodeInterface::class, $node);
77 $this->assertSame('1', $node->id());
79 $comment = Comment::load(3);
80 $this->assertSame('The second comment.', $comment->subject->value);
81 $this->assertSame(NULL, $comment->pid->target_id);
82 $this->assertSame('203.0.113.3', $comment->getHostname());
84 $node = $comment->getCommentedEntity();
85 $this->assertInstanceOf(NodeInterface::class, $node);
86 $this->assertSame('1', $node->id());