42c2a308bb305924d052310450cfc17c0c20cf83
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / Migrate / d7 / MigrateCommentTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
4
5 use Drupal\comment\CommentInterface;
6 use Drupal\comment\Entity\Comment;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8 use Drupal\node\NodeInterface;
9
10 /**
11  * Tests migration of comments from Drupal 7.
12  *
13  * @group comment
14  */
15 class MigrateCommentTest extends MigrateDrupal7TestBase {
16
17   public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24
25     $this->installConfig(static::$modules);
26     $this->installEntitySchema('node');
27     $this->installEntitySchema('comment');
28
29     $this->executeMigrations([
30       'd7_filter_format',
31       'd7_user_role',
32       'd7_user',
33     ]);
34     $this->executeMigration('d7_node_type');
35     // We only need the test_content_type node migration to run for real, so
36     // mock all the others.
37     $this->prepareMigrations([
38       'd7_node' => [
39         [[0], [0]],
40       ],
41     ]);
42     $this->executeMigrations([
43       'd7_node',
44       'd7_comment_type',
45       'd7_comment',
46     ]);
47   }
48
49   /**
50    * Tests migration of comments from Drupal 7.
51    */
52   public function testCommentMigration() {
53     $comment = Comment::load(1);
54     $this->assertTrue($comment instanceof CommentInterface);
55     /** @var \Drupal\comment\CommentInterface $comment */
56     $this->assertIdentical('A comment', $comment->getSubject());
57     $this->assertIdentical('1421727536', $comment->getCreatedTime());
58     $this->assertIdentical('1421727536', $comment->getChangedTime());
59     $this->assertTrue($comment->getStatus());
60     $this->assertIdentical('admin', $comment->getAuthorName());
61     $this->assertIdentical('admin@local.host', $comment->getAuthorEmail());
62     $this->assertIdentical('This is a comment', $comment->comment_body->value);
63     $this->assertIdentical('filtered_html', $comment->comment_body->format);
64     $this->assertEquals('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
65
66     $node = $comment->getCommentedEntity();
67     $this->assertTrue($node instanceof NodeInterface);
68     $this->assertIdentical('1', $node->id());
69   }
70
71 }