3 namespace Drupal\Tests\comment\Kernel\Migrate\d7;
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;
11 * Tests migration of comments from Drupal 7.
15 class MigrateCommentTest extends MigrateDrupal7TestBase {
17 public static $modules = ['filter', 'node', 'comment', 'text', 'menu_ui'];
22 protected function setUp() {
25 $this->installConfig(static::$modules);
26 $this->installEntitySchema('node');
27 $this->installEntitySchema('comment');
29 $this->executeMigrations([
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([
42 $this->executeMigrations([
50 * Tests migration of comments from Drupal 7.
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());
66 $node = $comment->getCommentedEntity();
67 $this->assertTrue($node instanceof NodeInterface);
68 $this->assertIdentical('1', $node->id());