function MigrateCommentTest::testMigration

Same name in this branch
  1. 10 core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest::testMigration()
Same name in other branches
  1. 9 core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest::testMigration()
  2. 9 core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest::testMigration()
  3. 8.9.x core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest::testMigration()
  4. 8.9.x core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest::testMigration()
  5. 11.x core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest::testMigration()
  6. 11.x core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest::testMigration()

Tests the migrated comments.

File

core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php, line 62

Class

MigrateCommentTest
Tests the migration of comments from Drupal 6.

Namespace

Drupal\Tests\comment\Kernel\Migrate\d6

Code

public function testMigration() : void {
    $comment = Comment::load(1);
    $this->assertSame('The first comment.', $comment->getSubject());
    $this->assertSame('The first comment body.', $comment->comment_body->value);
    $this->assertSame('filtered_html', $comment->comment_body->format);
    $this->assertNull($comment->pid->target_id);
    $this->assertSame('1', $comment->getCommentedEntityId());
    $this->assertSame('node', $comment->getCommentedEntityTypeId());
    $this->assertSame('en', $comment->language()
        ->getId());
    $this->assertSame('comment_node_story', $comment->getTypeId());
    $this->assertSame('203.0.113.1', $comment->getHostname());
    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class, $node);
    $this->assertSame('1', $node->id());
    $comment = Comment::load(2);
    $this->assertSame('The response to the second comment.', $comment->subject->value);
    $this->assertSame('3', $comment->pid->target_id);
    $this->assertSame('203.0.113.2', $comment->getHostname());
    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class, $node);
    $this->assertSame('1', $node->id());
    $comment = Comment::load(3);
    $this->assertSame('The second comment.', $comment->subject->value);
    $this->assertNull($comment->pid->target_id);
    $this->assertSame('203.0.113.3', $comment->getHostname());
    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class, $node);
    $this->assertSame('1', $node->id());
    // Tests that the language of the comment is migrated from the node.
    $comment = Comment::load(7);
    $this->assertSame('Comment to John Smith - EN', $comment->subject->value);
    $this->assertSame('This is an English comment.', $comment->comment_body->value);
    $this->assertSame('21', $comment->getCommentedEntityId());
    $this->assertSame('node', $comment->getCommentedEntityTypeId());
    $this->assertSame('en', $comment->language()
        ->getId());
    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class, $node);
    $this->assertSame('21', $node->id());
    // Tests that the comment language is correct and that the commented entity
    // is correctly migrated when the comment was posted to a node translation.
    $comment = Comment::load(8);
    $this->assertSame('Comment to John Smith - FR', $comment->subject->value);
    $this->assertSame('This is a French comment.', $comment->comment_body->value);
    $this->assertSame('21', $comment->getCommentedEntityId());
    $this->assertSame('node', $comment->getCommentedEntityTypeId());
    $this->assertSame('fr', $comment->language()
        ->getId());
    $node = $comment->getCommentedEntity();
    $this->assertInstanceOf(NodeInterface::class, $node);
    $this->assertSame('21', $node->id());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.