You are here

public function LanguageSelectorTranslatableTest::testLanguageStringSelector in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/tests/src/Functional/LanguageSelectorTranslatableTest.php \Drupal\Tests\language\Functional\LanguageSelectorTranslatableTest::testLanguageStringSelector()

Tests content translation language selectors are correctly translated.

File

core/modules/language/tests/src/Functional/LanguageSelectorTranslatableTest.php, line 70

Class

LanguageSelectorTranslatableTest
Tests the content translation settings language selector options.

Namespace

Drupal\Tests\language\Functional

Code

public function testLanguageStringSelector() {

  // Add another language.
  $edit = [
    'predefined_langcode' => 'es',
  ];
  $this
    ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

  // Translate the string English in Spanish (Inglés). Override config entity.
  $name_translation = 'Inglés';
  \Drupal::languageManager()
    ->getLanguageConfigOverride('es', 'language.entity.en')
    ->set('label', $name_translation)
    ->save();

  // Check content translation overview selector.
  $path = 'es/admin/config/regional/content-language';
  $this
    ->drupalGet($path);

  // Get en language from selector.
  $elements = $this
    ->xpath('//select[@id=:id]//option[@value=:option]', [
    ':id' => 'edit-settings-user-user-settings-language-langcode',
    ':option' => 'en',
  ]);

  // Check that the language text is translated.
  $this
    ->assertEqual($elements[0]
    ->getText(), $name_translation, 'Checking the option string English is translated to Spanish.');
}