You are here

public function MigrateCommentTest::testMigration in Drupal 8

Same name in this branch
  1. 8 core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d6\MigrateCommentTest::testMigration()
  2. 8 core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php \Drupal\Tests\comment\Kernel\Migrate\d7\MigrateCommentTest::testMigration()
Same name and namespace in other branches
  1. 9 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/d7/MigrateCommentTest.php, line 66

Class

MigrateCommentTest
Tests the migration of comments from Drupal 7.

Namespace

Drupal\Tests\comment\Kernel\Migrate\d7

Code

public function testMigration() {
  $comment = Comment::load(1);
  $this
    ->assertInstanceOf(Comment::class, $comment);
  $this
    ->assertSame('Subject field in English', $comment
    ->getSubject());
  $this
    ->assertSame('1421727536', $comment
    ->getCreatedTime());
  $this
    ->assertSame('1421727536', $comment
    ->getChangedTime());
  $this
    ->assertTrue($comment
    ->isPublished());
  $this
    ->assertSame('admin', $comment
    ->getAuthorName());
  $this
    ->assertSame('admin@local.host', $comment
    ->getAuthorEmail());
  $this
    ->assertSame('This is a comment', $comment->comment_body->value);
  $this
    ->assertSame('filtered_html', $comment->comment_body->format);
  $this
    ->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment
    ->getHostname());
  $this
    ->assertSame('en', $comment
    ->language()
    ->getId());
  $this
    ->assertSame('1000000', $comment->field_integer->value);
  $node = $comment
    ->getCommentedEntity();
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertSame('1', $node
    ->id());

  // Tests that comments that used the Drupal 7 Title module and that have
  // their subject replaced by a real field are correctly migrated.
  $comment = Comment::load(2);
  $this
    ->assertInstanceOf(Comment::class, $comment);
  $this
    ->assertSame('TNG for the win!', $comment
    ->getSubject());
  $this
    ->assertSame('TNG is better than DS9.', $comment->comment_body->value);
  $this
    ->assertSame('en', $comment
    ->language()
    ->getId());

  // Tests that the commented entity is correctly migrated when the comment
  // was posted to a node translation.
  $comment = Comment::load(3);
  $this
    ->assertInstanceOf(Comment::class, $comment);
  $this
    ->assertSame('Comment to IS translation', $comment
    ->getSubject());
  $this
    ->assertSame('This is a comment to an Icelandic translation.', $comment->comment_body->value);
  $this
    ->assertSame('2', $comment
    ->getCommentedEntityId());
  $this
    ->assertSame('node', $comment
    ->getCommentedEntityTypeId());
  $this
    ->assertSame('is', $comment
    ->language()
    ->getId());
  $node = $comment
    ->getCommentedEntity();
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertSame('2', $node
    ->id());

  // Tests a comment migrated from Drupal 6 to Drupal 7 that did not have a
  // language.
  $comment = Comment::load(4);
  $this
    ->assertInstanceOf(Comment::class, $comment);
  $this
    ->assertSame('Comment without language', $comment
    ->getSubject());
  $this
    ->assertSame('1426781880', $comment
    ->getCreatedTime());
  $this
    ->assertSame('1426781880', $comment
    ->getChangedTime());
  $this
    ->assertTrue($comment
    ->isPublished());
  $this
    ->assertSame('Bob', $comment
    ->getAuthorName());
  $this
    ->assertSame('bob@local.host', $comment
    ->getAuthorEmail());
  $this
    ->assertSame('A comment without language (migrated from Drupal 6)', $comment->comment_body->value);
  $this
    ->assertSame('filtered_html', $comment->comment_body->format);
  $this
    ->assertSame('drupal7.local', $comment
    ->getHostname());
  $this
    ->assertSame('und', $comment
    ->language()
    ->getId());
  $this
    ->assertSame('10', $comment->field_integer->value);
  $node = $comment
    ->getCommentedEntity();
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertSame('1', $node
    ->id());
}