db backup prior to drupal security update
[yaffs-website] / web / core / modules / language / src / Tests / LanguageSelectorTranslatableTest.php
1 <?php
2
3 namespace Drupal\language\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Tests the content translation settings language selector options.
9  *
10  * @group language
11  */
12 class LanguageSelectorTranslatableTest extends WebTestBase {
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    * The user with administrator privileges.
31    *
32    * @var \Drupal\user\Entity\User;
33    */
34   public $administrator;
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     // Create user and set permissions.
43     $this->administrator = $this->drupalCreateUser($this->getAdministratorPermissions(), 'administrator');
44     $this->drupalLogin($this->administrator);
45   }
46
47   /**
48    * Returns an array of permissions needed for the translator.
49    */
50   protected function getAdministratorPermissions() {
51     return array_filter(
52       ['translate interface',
53         'administer content translation',
54         'create content translations',
55         'update content translations',
56         'delete content translations',
57         'administer languages',
58       ]
59     );
60   }
61
62   /**
63    * Tests content translation language selectors are correctly translated.
64    */
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'));
69
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)
75       ->save();
76
77     // Check content translation overview selector.
78     $path = 'es/admin/config/regional/content-language';
79     $this->drupalGet($path);
80
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']);
83
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.');
86   }
87
88 }