Version 1
[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\Tests\CommentTestTrait;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7
8 /**
9  * Upgrade comments.
10  *
11  * @group migrate_drupal_6
12  */
13 class MigrateCommentTest extends MigrateDrupal6TestBase {
14
15   use CommentTestTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['comment', 'menu_ui'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     $this->installEntitySchema('node');
29     $this->installEntitySchema('comment');
30     $this->installSchema('comment', ['comment_entity_statistics']);
31     $this->installConfig(['comment']);
32
33     // The entity.node.canonical route must exist when the RDF hook is called.
34     $this->container->get('router.builder')->rebuild();
35
36     $this->migrateContent();
37     $this->executeMigrations([
38       'd6_node',
39       'd6_comment_type',
40       'd6_comment_field',
41       'd6_comment_field_instance',
42       'd6_comment_entity_display',
43       'd6_comment_entity_form_display',
44       'd6_comment',
45     ]);
46   }
47
48   /**
49    * Tests the Drupal 6 to Drupal 8 comment migration.
50    */
51   public function testComments() {
52     /** @var \Drupal\Core\Entity\EntityStorageInterface $comment_storage */
53     $comment_storage = $this->container->get('entity.manager')->getStorage('comment');
54     /** @var \Drupal\comment\CommentInterface $comment */
55     $comment = $comment_storage->load(1);
56     $this->assertIdentical('The first comment.', $comment->getSubject());
57     $this->assertIdentical('The first comment body.', $comment->comment_body->value);
58     $this->assertIdentical('filtered_html', $comment->comment_body->format);
59     $this->assertIdentical(NULL, $comment->pid->target_id);
60     $this->assertIdentical('1', $comment->getCommentedEntityId());
61     $this->assertIdentical('node', $comment->getCommentedEntityTypeId());
62     $this->assertIdentical('en', $comment->language()->getId());
63     $this->assertIdentical('comment_no_subject', $comment->getTypeId());
64     $this->assertEquals('203.0.113.1', $comment->getHostname());
65
66     $comment = $comment_storage->load(2);
67     $this->assertIdentical('The response to the second comment.', $comment->subject->value);
68     $this->assertIdentical('3', $comment->pid->target_id);
69     $this->assertEquals('203.0.113.2', $comment->getHostname());
70
71     $comment = $comment_storage->load(3);
72     $this->assertIdentical('The second comment.', $comment->subject->value);
73     $this->assertIdentical(NULL, $comment->pid->target_id);
74     $this->assertEquals('203.0.113.3', $comment->getHostname());
75   }
76
77 }