function MigrateCommentTest::testCommentEntityTranslations
Tests the migration of comment entity translations.
File
-
core/
modules/ comment/ tests/ src/ Kernel/ Migrate/ d7/ MigrateCommentTest.php, line 131
Class
- MigrateCommentTest
- Tests the migration of comments from Drupal 7.
Namespace
Drupal\Tests\comment\Kernel\Migrate\d7Code
public function testCommentEntityTranslations() {
$manager = $this->container
->get('content_translation.manager');
// Get the comment and its translations.
$comment = Comment::load(1);
$comment_fr = $comment->getTranslation('fr');
$comment_is = $comment->getTranslation('is');
// Test that fields translated with Entity Translation are migrated.
$this->assertSame('Subject field in English', $comment->getSubject());
$this->assertSame('Subject field in French', $comment_fr->getSubject());
$this->assertSame('Subject field in Icelandic', $comment_is->getSubject());
$this->assertSame('1000000', $comment->field_integer->value);
$this->assertSame('2000000', $comment_fr->field_integer->value);
$this->assertSame('3000000', $comment_is->field_integer->value);
// Test that the French translation metadata is correctly migrated.
$metadata_fr = $manager->getTranslationMetadata($comment_fr);
$this->assertFalse($metadata_fr->isPublished());
$this->assertSame('en', $metadata_fr->getSource());
$this->assertSame('1', $metadata_fr->getAuthor()->uid->value);
$this->assertSame('1531837764', $metadata_fr->getCreatedTime());
$this->assertSame('1531837764', $metadata_fr->getChangedTime());
$this->assertFalse($metadata_fr->isOutdated());
// Test that the Icelandic translation metadata is correctly migrated.
$metadata_is = $manager->getTranslationMetadata($comment_is);
$this->assertTrue($metadata_is->isPublished());
$this->assertSame('en', $metadata_is->getSource());
$this->assertSame('2', $metadata_is->getAuthor()->uid->value);
$this->assertSame('1531838064', $metadata_is->getCreatedTime());
$this->assertSame('1531838064', $metadata_is->getChangedTime());
$this->assertTrue($metadata_is->isOutdated());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.