You are here

public function MigrateMenuTranslationTest::testMenuTranslation in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Migrate/d7/MigrateMenuTranslationTest.php \Drupal\Tests\system\Kernel\Migrate\d7\MigrateMenuTranslationTest::testMenuTranslation()

Tests migration of menu translations.

File

core/modules/system/tests/src/Kernel/Migrate/d7/MigrateMenuTranslationTest.php, line 42

Class

MigrateMenuTranslationTest
Tests menu translation migration.

Namespace

Drupal\Tests\system\Kernel\Migrate\d7

Code

public function testMenuTranslation() {
  $language_manager = \Drupal::service('language_manager');
  $config_translation = $language_manager
    ->getLanguageConfigOverride('is', 'system.menu.main');
  $this
    ->assertSame('is - Main menu', $config_translation
    ->get('label'));
  $this
    ->assertSame('is - Main menu description', $config_translation
    ->get('description'));
  $config_translation = $language_manager
    ->getLanguageConfigOverride('fr', 'system.menu.main');
  $this
    ->assertSame('fr - Main menu', $config_translation
    ->get('label'));
  $this
    ->assertSame('fr - Main menu description', $config_translation
    ->get('description'));

  // Translate and localize menu.
  $config_translation = $language_manager
    ->getLanguageConfigOverride('fr', 'system.menu.menu-test-menu');
  $this
    ->assertSame('fr - Test menu description', $config_translation
    ->get('description'));

  // No translations for fixed language menu.
  $config_translation = $language_manager
    ->getLanguageConfigOverride('fr', 'menu-fixedlang');
  $this
    ->assertNull($config_translation
    ->get('description'));
  $this
    ->assertNull($config_translation
    ->get('label'));
  $config_translation = $language_manager
    ->getLanguageConfigOverride('is', 'menu-fixedlang');
  $this
    ->assertNull($config_translation
    ->get('description'));
  $this
    ->assertNull($config_translation
    ->get('label'));

  // Test rollback.
  $this->migration = $this
    ->getMigration("d7_menu_translation");
  (new MigrateExecutable($this->migration, $this))
    ->rollback();
  $config_translation = $language_manager
    ->getLanguageConfigOverride('is', 'system.menu.main');
  $this
    ->assertNull($config_translation
    ->get('description'));
  $this
    ->assertNull($config_translation
    ->get('label'));
  $config_translation = $language_manager
    ->getLanguageConfigOverride('fr', 'system.menu.main');
  $this
    ->assertNull($config_translation
    ->get('description'));
  $this
    ->assertNull($config_translation
    ->get('label'));

  // Translate and localize menu.
  $config_translation = $language_manager
    ->getLanguageConfigOverride('fr', 'system.menu.menu-test-menu');
  $this
    ->assertNull($config_translation
    ->get('description'));
}