beaf5f1955a61e0e34fdeb9733b062c3cd311f64
[yaffs-website] / web / core / modules / views_ui / src / Tests / TranslatedViewTest.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests that translated strings in views UI don't override original strings.
10  *
11  * @group views_ui
12  */
13 class TranslatedViewTest extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = [
21     'config_translation',
22     'views_ui',
23   ];
24
25   /**
26    * Languages to enable.
27    *
28    * @var array
29    */
30   protected $langcodes = [
31     'fr',
32   ];
33
34   /**
35    * Administrator user for tests.
36    *
37    * @var \Drupal\user\UserInterface
38    */
39   protected $adminUser;
40
41   protected function setUp() {
42     parent::setUp();
43
44     $permissions = [
45       'administer site configuration',
46       'administer views',
47       'translate configuration',
48       'translate interface',
49     ];
50
51     // Create and log in user.
52     $this->adminUser = $this->drupalCreateUser($permissions);
53     $this->drupalLogin($this->adminUser);
54
55     // Add languages.
56     foreach ($this->langcodes as $langcode) {
57       ConfigurableLanguage::createFromLangcode($langcode)->save();
58     }
59     $this->resetAll();
60     $this->rebuildContainer();
61   }
62
63   public function testTranslatedStrings() {
64     $translation_url = 'admin/structure/views/view/files/translate/fr/add';
65     $edit_url = 'admin/structure/views/view/files';
66
67     // Check origial string.
68     $this->drupalGet($edit_url);
69     $this->assertTitle('Files (File) | Drupal');
70
71     // Translate the label of the view.
72     $this->drupalGet($translation_url);
73     $edit = [
74       'translation[config_names][views.view.files][label]' => 'Fichiers',
75     ];
76     $this->drupalPostForm(NULL, $edit, t('Save translation'));
77
78     // Check if the label is translated.
79     $this->drupalGet($edit_url, ['language' => \Drupal::languageManager()->getLanguage('fr')]);
80     $this->assertTitle('Files (File) | Drupal');
81     $this->assertNoText('Fichiers');
82   }
83
84 }