function FollowUpMigrationsTest::testEntityReferenceTranslations

Same name in this branch
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php \Drupal\Tests\migrate_drupal\Kernel\d7\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.

File

core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php, line 40

Class

FollowUpMigrationsTest
Tests follow-up migrations.

Namespace

Drupal\Tests\migrate_drupal\Kernel\d6

Code

public function testEntityReferenceTranslations() {
    // Test the entity reference field before the follow-up migrations.
    $node = Node::load(10);
    $this->assertSame('13', $node->get('field_reference')->target_id);
    $this->assertSame('13', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('fr');
    $this->assertSame('20', $translation->get('field_reference')->target_id);
    $this->assertSame('20', $translation->get('field_reference_2')->target_id);
    $node = Node::load(12)->getTranslation('en');
    $this->assertSame('10', $node->get('field_reference')->target_id);
    $this->assertSame('10', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('fr');
    $this->assertSame('11', $translation->get('field_reference')->target_id);
    $this->assertSame('11', $translation->get('field_reference_2')->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('d6_entity_reference_translation');
    $this->executeMigrations(array_keys($follow_up_migrations));
    // Test the entity reference field after the follow-up migrations.
    $node = Node::load(10);
    $this->assertSame('12', $node->get('field_reference')->target_id);
    $this->assertSame('12', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('fr');
    $this->assertSame('12', $translation->get('field_reference')->target_id);
    $this->assertSame('12', $translation->get('field_reference_2')->target_id);
    $node = Node::load(12)->getTranslation('en');
    $this->assertSame('10', $node->get('field_reference')->target_id);
    $this->assertSame('10', $node->get('field_reference_2')->target_id);
    $translation = $node->getTranslation('fr');
    $this->assertSame('10', $translation->get('field_reference')->target_id);
    $this->assertSame('10', $translation->get('field_reference_2')->target_id);
}

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