1<?php 2 3namespace Drupal\Tests\language\Functional; 4 5use Drupal\Tests\BrowserTestBase; 6 7/** 8 * Tests the content translation settings language selector options. 9 * 10 * @group language 11 */ 12class LanguageSelectorTranslatableTest extends BrowserTestBase { 13 14 /** 15 * Modules to enable. 16 * 17 * @var array 18 */ 19 public static $modules = [ 20 'language', 21 'content_translation', 22 'node', 23 'comment', 24 'field_ui', 25 'entity_test', 26 'locale', 27 ]; 28 29 /** 30 * {@inheritdoc} 31 */ 32 protected $defaultTheme = 'stark'; 33 34 /** 35 * The user with administrator privileges. 36 * 37 * @var \Drupal\user\Entity\User 38 */ 39 public $administrator; 40 41 /** 42 * {@inheritdoc} 43 */ 44 protected function setUp() { 45 parent::setUp(); 46 47 // Create user and set permissions. 48 $this->administrator = $this->drupalCreateUser($this->getAdministratorPermissions(), 'administrator'); 49 $this->drupalLogin($this->administrator); 50 } 51 52 /** 53 * Returns an array of permissions needed for the translator. 54 */ 55 protected function getAdministratorPermissions() { 56 return array_filter( 57 ['translate interface', 58 'administer content translation', 59 'create content translations', 60 'update content translations', 61 'delete content translations', 62 'administer languages', 63 ] 64 ); 65 } 66 67 /** 68 * Tests content translation language selectors are correctly translated. 69 */ 70 public function testLanguageStringSelector() { 71 // Add another language. 72 $edit = ['predefined_langcode' => 'es']; 73 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); 74 75 // Translate the string English in Spanish (Inglés). Override config entity. 76 $name_translation = 'Inglés'; 77 \Drupal::languageManager() 78 ->getLanguageConfigOverride('es', 'language.entity.en') 79 ->set('label', $name_translation) 80 ->save(); 81 82 // Check content translation overview selector. 83 $path = 'es/admin/config/regional/content-language'; 84 $this->drupalGet($path); 85 86 // Get en language from selector. 87 $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en']); 88 89 // Check that the language text is translated. 90 $this->assertEqual($elements[0]->getText(), $name_translation, 'Checking the option string English is translated to Spanish.'); 91 } 92 93} 94