e040ac0deb05aa807ab12e8573937cf530e96ee7
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d6 / MigrateCommentTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d6;
4
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;
9
10 /**
11  * Tests the migration of comments from Drupal 6.
12  *
13  * @group comment
14  * @group migrate_drupal_6
15  */
16 class MigrateCommentTest extends MigrateDrupal6TestBase {
17
18   use CommentTestTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $modules = [
24     'comment',
25     'content_translation',
26     'language',
27     'menu_ui',
28   ];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp() {
34     parent::setUp();
35
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']);
41
42     // The entity.node.canonical route must exist when the RDF hook is called.
43     $this->container->get('router.builder')->rebuild();
44
45     $this->migrateContent();
46     $this->executeMigrations([
47       'language',
48       'd6_language_content_settings',
49       'd6_node',
50       'd6_node_translation',
51       'd6_comment_type',
52       'd6_comment_field',
53       'd6_comment_field_instance',
54       'd6_comment_entity_display',
55       'd6_comment_entity_form_display',
56       'd6_comment',
57     ]);
58   }
59
60   /**
61    * Tests the migrated comments.
62    */
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());
74
75     $node = $comment->getCommentedEntity();
76     $this->assertInstanceOf(NodeInterface::class, $node);
77     $this->assertSame('1', $node->id());
78
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());
83
84     $node = $comment->getCommentedEntity();
85     $this->assertInstanceOf(NodeInterface::class, $node);
86     $this->assertSame('1', $node->id());
87
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());
92
93     $node = $comment->getCommentedEntity();
94     $this->assertInstanceOf(NodeInterface::class, $node);
95     $this->assertSame('1', $node->id());
96
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());
104
105     $node = $comment->getCommentedEntity();
106     $this->assertInstanceOf(NodeInterface::class, $node);
107     $this->assertSame('21', $node->id());
108
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());
117
118     $node = $comment->getCommentedEntity();
119     $this->assertInstanceOf(NodeInterface::class, $node);
120     $this->assertSame('21', $node->id());
121   }
122
123 }