3 namespace Drupal\Tests\migrate_drupal\Kernel\d7;
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
9 * Tests follow-up migrations.
11 * @group migrate_drupal
13 class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
15 use FileMigrationSetupTrait;
20 public static $modules = [
21 'content_translation',
29 // A requirement for translation migrations.
30 'migrate_drupal_multilingual',
40 protected function setUp() {
43 $this->fileMigrationSetup();
45 $this->installEntitySchema('node');
46 $this->installEntitySchema('comment');
47 $this->installEntitySchema('taxonomy_term');
48 $this->installConfig(static::$modules);
49 $this->installSchema('node', ['node_access']);
51 $this->executeMigrations([
56 'd7_language_content_settings',
58 'd7_taxonomy_vocabulary',
62 'd7_node_translation',
69 protected function getFileMigrationInfo() {
71 'path' => 'public://sites/default/files/cube.jpeg',
73 'base_path' => 'public://',
74 'plugin_id' => 'd7_file',
79 * Test entity reference translations.
81 public function testEntityReferenceTranslations() {
82 // Test the entity reference field before the follow-up migrations.
83 $node = Node::load(2);
84 $this->assertSame('5', $node->get('field_reference')->target_id);
85 $this->assertSame('5', $node->get('field_reference_2')->target_id);
86 $translation = $node->getTranslation('is');
87 $this->assertSame('4', $translation->get('field_reference')->target_id);
88 $this->assertSame('4', $translation->get('field_reference_2')->target_id);
90 $node = Node::load(4);
91 $this->assertSame('3', $node->get('field_reference')->target_id);
92 $this->assertSame('3', $node->get('field_reference_2')->target_id);
93 $translation = $node->getTranslation('en');
94 $this->assertSame('2', $translation->get('field_reference')->target_id);
95 $this->assertSame('2', $translation->get('field_reference_2')->target_id);
97 // Run the follow-up migrations.
98 $migration_plugin_manager = $this->container->get('plugin.manager.migration');
99 $migration_plugin_manager->clearCachedDefinitions();
100 $follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation');
101 $this->executeMigrations(array_keys($follow_up_migrations));
103 // Test the entity reference field after the follow-up migrations.
104 $node = Node::load(2);
105 $this->assertSame('4', $node->get('field_reference')->target_id);
106 $this->assertSame('4', $node->get('field_reference_2')->target_id);
107 $translation = $node->getTranslation('is');
108 $this->assertSame('4', $translation->get('field_reference')->target_id);
109 $this->assertSame('4', $translation->get('field_reference_2')->target_id);
111 $node = Node::load(4);
112 $this->assertSame('2', $node->get('field_reference')->target_id);
113 $this->assertSame('2', $node->get('field_reference_2')->target_id);
114 $translation = $node->getTranslation('en');
115 $this->assertSame('2', $translation->get('field_reference')->target_id);
116 $this->assertSame('2', $translation->get('field_reference_2')->target_id);