function MigrateFieldOptionTranslationTest::testFieldOptionTranslation

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

Tests the Drupal 7 field option translation to Drupal 8 migration.

File

core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php, line 52

Class

MigrateFieldOptionTranslationTest
Migrate field option translations.

Namespace

Drupal\Tests\field\Kernel\Migrate\d7

Code

public function testFieldOptionTranslation() : void {
    $language_manager = $this->container
        ->get('language_manager');
    
    /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_color');
    $allowed_values = [
        0 => [
            'label' => 'Verte',
        ],
        1 => [
            'label' => 'Noire',
        ],
        2 => [
            'label' => 'Blanche',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_color');
    $allowed_values = [
        0 => [
            'label' => 'Grænn',
        ],
        1 => [
            'label' => 'Svartur',
        ],
        2 => [
            'label' => 'Hvítur',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_rating');
    $allowed_values = [
        0 => [
            'label' => 'Haute',
        ],
        1 => [
            'label' => 'Moyenne',
        ],
        2 => [
            'label' => 'Faible',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_rating');
    $allowed_values = [
        0 => [
            'label' => 'Hár',
        ],
        1 => [
            'label' => 'Miðlungs',
        ],
        2 => [
            'label' => 'Lágt',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_boolean');
    $this->assertNull($config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_boolean');
    $allowed_values = [
        0 => [
            0 => 'Off',
            1 => '1',
        ],
        1 => [
            0 => 'Off',
            1 => '1',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.storage.node.field_checkbox');
    $allowed_values = [
        0 => [
            0 => 'Stop',
            1 => 'Go',
        ],
        1 => [
            0 => 'Stop',
            1 => 'Go',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    $config_translation = $language_manager->getLanguageConfigOverride('is', 'field.storage.node.field_checkbox');
    $allowed_values = [
        0 => [
            0 => 'Stop',
            1 => 'Go',
        ],
        1 => [
            0 => 'Stop',
            1 => 'Go',
        ],
    ];
    $this->assertSame($allowed_values, $config_translation->get('settings.allowed_values'));
    // Ensure that the count query works as expected.
    $this->assertCount(20, $this->getMigration('d7_field_option_translation')
        ->getSourcePlugin());
}

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