function MigrateExternalTranslatedTest::testMigrations

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php \Drupal\Tests\migrate\Kernel\MigrateExternalTranslatedTest::testMigrations()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php \Drupal\Tests\migrate\Kernel\MigrateExternalTranslatedTest::testMigrations()
  3. 10 core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php \Drupal\Tests\migrate\Kernel\MigrateExternalTranslatedTest::testMigrations()

Tests importing and rolling back our data.

File

core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php, line 57

Class

MigrateExternalTranslatedTest
Tests migrating non-Drupal translated content.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testMigrations() : void {
    
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('node');
    $this->assertCount(0, $storage->loadMultiple());
    // Run the migrations.
    $migration_ids = [
        'external_translated_test_node',
        'external_translated_test_node_translation',
    ];
    $this->executeMigrations($migration_ids);
    $this->assertCount(3, $storage->loadMultiple());
    $node = $storage->load(1);
    $this->assertEquals('en', $node->language()
        ->getId());
    $this->assertEquals('Cat', $node->title->value);
    $this->assertEquals('Chat', $node->getTranslation('fr')->title->value);
    $this->assertEquals('es - Cat', $node->getTranslation('es')->title->value);
    $node = $storage->load(2);
    $this->assertEquals('en', $node->language()
        ->getId());
    $this->assertEquals('Dog', $node->title->value);
    $this->assertEquals('fr - Dog', $node->getTranslation('fr')->title->value);
    $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 2");
    $node = $storage->load(3);
    $this->assertEquals('en', $node->language()
        ->getId());
    $this->assertEquals('Monkey', $node->title->value);
    $this->assertFalse($node->hasTranslation('fr'), "No french translation for node 3");
    $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 3");
    $this->assertNull($storage->load(4), "No node 4 migrated");
    // Roll back the migrations.
    foreach ($migration_ids as $migration_id) {
        $migration = $this->getMigration($migration_id);
        $executable = new MigrateExecutable($migration, $this);
        $executable->rollback();
    }
    $this->assertCount(0, $storage->loadMultiple());
}

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