LanguageSelectorTranslatableTest.php in Drupal 8
File
core/modules/language/tests/src/Functional/LanguageSelectorTranslatableTest.php
View source
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Tests\BrowserTestBase;
class LanguageSelectorTranslatableTest extends BrowserTestBase {
public static $modules = [
'language',
'content_translation',
'node',
'comment',
'field_ui',
'entity_test',
'locale',
];
protected $defaultTheme = 'stark';
public $administrator;
protected function setUp() {
parent::setUp();
$this->administrator = $this
->drupalCreateUser($this
->getAdministratorPermissions(), 'administrator');
$this
->drupalLogin($this->administrator);
}
protected function getAdministratorPermissions() {
return array_filter([
'translate interface',
'administer content translation',
'create content translations',
'update content translations',
'delete content translations',
'administer languages',
]);
}
public function testLanguageStringSelector() {
$edit = [
'predefined_langcode' => 'es',
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$name_translation = 'Inglés';
\Drupal::languageManager()
->getLanguageConfigOverride('es', 'language.entity.en')
->set('label', $name_translation)
->save();
$path = 'es/admin/config/regional/content-language';
$this
->drupalGet($path);
$elements = $this
->xpath('//select[@id=:id]//option[@value=:option]', [
':id' => 'edit-settings-user-user-settings-language-langcode',
':option' => 'en',
]);
$this
->assertEqual($elements[0]
->getText(), $name_translation, 'Checking the option string English is translated to Spanish.');
}
}