3 namespace Drupal\language\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Tests the content translation settings language selector options.
12 class LanguageSelectorTranslatableTest extends WebTestBase {
19 public static $modules = [
21 'content_translation',
30 * The user with administrator privileges.
32 * @var \Drupal\user\Entity\User;
34 public $administrator;
39 protected function setUp() {
42 // Create user and set permissions.
43 $this->administrator = $this->drupalCreateUser($this->getAdministratorPermissions(), 'administrator');
44 $this->drupalLogin($this->administrator);
48 * Returns an array of permissions needed for the translator.
50 protected function getAdministratorPermissions() {
52 ['translate interface',
53 'administer content translation',
54 'create content translations',
55 'update content translations',
56 'delete content translations',
57 'administer languages',
63 * Tests content translation language selectors are correctly translated.
65 public function testLanguageStringSelector() {
66 // Add another language.
67 $edit = ['predefined_langcode' => 'es'];
68 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
70 // Translate the string English in Spanish (Inglés). Override config entity.
71 $name_translation = 'Inglés';
72 \Drupal::languageManager()
73 ->getLanguageConfigOverride('es', 'language.entity.en')
74 ->set('label', $name_translation)
77 // Check content translation overview selector.
78 $path = 'es/admin/config/regional/content-language';
79 $this->drupalGet($path);
81 // Get en language from selector.
82 $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en']);
84 // Check that the language text is translated.
85 $this->assertEqual((string) $elements[0], $name_translation, 'Checking the option string English is translated to Spanish.');