3 namespace Drupal\Tests\migrate\Kernel\Plugin;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\Entity\Node;
7 use Drupal\Tests\migrate\Kernel\MigrateTestBase;
8 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
11 * Tests the EntityRevision destination plugin.
15 class EntityRevisionTest extends MigrateTestBase {
17 use ContentTypeCreationTrait;
22 public static $modules = [
23 'content_translation',
36 protected function setUp() {
38 $this->installConfig('node');
39 $this->installSchema('node', ['node_access']);
40 $this->installEntitySchema('node');
41 $this->installEntitySchema('user');
45 * Tests that EntityRevision correctly handles revision translations.
47 public function testRevisionTranslation() {
48 ConfigurableLanguage::createFromLangcode('fr')->save();
50 /** @var \Drupal\node\NodeInterface $node */
51 $node = Node::create([
52 'type' => $this->createContentType()->id(),
53 'title' => 'Default 1',
55 $node->addTranslation('fr', [
56 'title' => 'French 1',
59 $node->setNewRevision();
60 $node->setTitle('Default 2');
61 $node->getTranslation('fr')->setTitle('French 2');
66 'plugin' => 'embedded_data',
70 'vid' => $node->getRevisionId(),
72 'title' => 'Titre nouveau, tabarnak!',
90 'langcode' => 'langcode',
94 'plugin' => 'entity_revision:node',
95 'translations' => TRUE,
99 /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
100 $migration = $this->container
101 ->get('plugin.manager.migration')
102 ->createStubMigration($migration);
104 $this->executeMigration($migration);
106 // The entity_revision destination uses the revision ID and langcode as its
107 // keys (the langcode is only used if the destination is configured for
108 // translation), so we should be able to look up the source IDs by revision
110 $source_ids = $migration->getIdMap()->lookupSourceID([
111 'vid' => $node->getRevisionId(),
114 $this->assertNotEmpty($source_ids);
115 $this->assertSame($node->id(), $source_ids['nid']);
116 $this->assertSame($node->getRevisionId(), $source_ids['vid']);
117 $this->assertSame('fr', $source_ids['langcode']);
119 // Confirm the french revision was used in the migration, instead of the
121 /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
122 $entity_type_manager = \Drupal::entityTypeManager();
123 $revision = $entity_type_manager->getStorage('node')->loadRevision(1);
124 $this->assertSame('Default 1', $revision->label());
125 $this->assertSame('French 1', $revision->getTranslation('fr')->label());
126 $revision = $entity_type_manager->getStorage('node')->loadRevision(2);
127 $this->assertSame('Default 2', $revision->label());
128 $this->assertSame('Titre nouveau, tabarnak!', $revision->getTranslation('fr')->label());