function MigrateNodeTest::testNodeEntityTranslations

Test node entity translations migration from Drupal 7 to 8.

File

core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php, line 258

Class

MigrateNodeTest
Tests node migration.

Namespace

Drupal\Tests\node\Kernel\Migrate\d7

Code

public function testNodeEntityTranslations() {
  $manager = $this->container
    ->get('content_translation.manager');
  // Get the node and its translations.
  $node = Node::load(1);
  $node_fr = $node->getTranslation('fr');
  $node_is = $node->getTranslation('is');
  // Test that fields translated with Entity Translation are migrated.
  $this->assertSame('An English Node', $node->getTitle());
  $this->assertSame('A French Node', $node_fr->getTitle());
  $this->assertSame('An Icelandic Node', $node_is->getTitle());
  $this->assertSame('5', $node->field_integer->value);
  $this->assertSame('6', $node_fr->field_integer->value);
  $this->assertSame('7', $node_is->field_integer->value);
  // Test that the French translation metadata is correctly migrated.
  $metadata_fr = $manager->getTranslationMetadata($node_fr);
  $this->assertSame('en', $metadata_fr->getSource());
  $this->assertTrue($metadata_fr->isOutdated());
  $this->assertSame('2', $node_fr->getOwnerId());
  $this->assertSame('1529615802', $node_fr->getCreatedTime());
  $this->assertSame('1529615802', $node_fr->getChangedTime());
  $this->assertTrue($node_fr->isPublished());
  // Test that the Icelandic translation metadata is correctly migrated.
  $metadata_is = $manager->getTranslationMetadata($node_is);
  $this->assertSame('en', $metadata_is->getSource());
  $this->assertFalse($metadata_is->isOutdated());
  $this->assertSame('1', $node_is->getOwnerId());
  $this->assertSame('1529615813', $node_is->getCreatedTime());
  $this->assertSame('1529615813', $node_is->getChangedTime());
  $this->assertFalse($node_is->isPublished());
}

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