function FollowUpMigrationsTest::testEntityReferenceTranslations

Same name in this branch
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\FollowUpMigrationsTest::testEntityReferenceTranslations()
Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\FollowUpMigrationsTest::testEntityReferenceTranslations()
  2. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d7\FollowUpMigrationsTest::testEntityReferenceTranslations()
  3. 10 core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\FollowUpMigrationsTest::testEntityReferenceTranslations()
  4. 10 core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d7\FollowUpMigrationsTest::testEntityReferenceTranslations()
  5. 11.x core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\FollowUpMigrationsTest::testEntityReferenceTranslations()
  6. 11.x core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d7\FollowUpMigrationsTest::testEntityReferenceTranslations()

Tests entity reference translations.

@dataProvider providerTestEntityReferenceTranslations

File

core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php, line 73

Class

FollowUpMigrationsTest
Tests follow-up migrations.

Namespace

Drupal\Tests\migrate_drupal\Kernel\d7

Code

public function testEntityReferenceTranslations($node_migrations) {
    $this->executeMigrations($node_migrations);
    // Test the entity reference field before the follow-up migrations.
    $node = Node::load(2);
    $this->assertSame('5', $node->get('field_reference')->target_id);
    $this->assertSame('6', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('is');
    $this->assertSame('4', $translation->get('field_reference')->target_id);
    $this->assertSame('4', $translation->get('field_reference_2')->target_id);
    $node = Node::load(4);
    $this->assertSame('3', $node->get('field_reference')->target_id);
    $this->assertSame('3', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('en');
    $this->assertSame('2', $translation->get('field_reference')->target_id);
    $this->assertSame('2', $translation->get('field_reference_2')->target_id);
    $user = User::load(2);
    $this->assertSame('3', $user->get('field_reference')->target_id);
    // Run the follow-up migrations.
    $migration_plugin_manager = $this->container
        ->get('plugin.manager.migration');
    $migration_plugin_manager->clearCachedDefinitions();
    $follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation');
    $this->executeMigrations(array_keys($follow_up_migrations));
    // Test the entity reference field after the follow-up migrations.
    $node = Node::load(2);
    $this->assertSame('4', $node->get('field_reference')->target_id);
    $this->assertSame('6', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('is');
    $this->assertSame('4', $translation->get('field_reference')->target_id);
    $this->assertSame('4', $translation->get('field_reference_2')->target_id);
    $node = Node::load(4);
    $this->assertSame('2', $node->get('field_reference')->target_id);
    $this->assertSame('2', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('en');
    $this->assertSame('2', $translation->get('field_reference')->target_id);
    $this->assertSame('2', $translation->get('field_reference_2')->target_id);
    $user = User::load(2);
    $this->assertSame('2', $user->get('field_reference')->target_id);
}

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