Version 1
[yaffs-website] / web / core / modules / views_ui / src / Tests / TranslatedViewTest.php
diff --git a/web/core/modules/views_ui/src/Tests/TranslatedViewTest.php b/web/core/modules/views_ui/src/Tests/TranslatedViewTest.php
new file mode 100644 (file)
index 0000000..beaf5f1
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+namespace Drupal\views_ui\Tests;
+
+use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests that translated strings in views UI don't override original strings.
+ *
+ * @group views_ui
+ */
+class TranslatedViewTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = [
+    'config_translation',
+    'views_ui',
+  ];
+
+  /**
+   * Languages to enable.
+   *
+   * @var array
+   */
+  protected $langcodes = [
+    'fr',
+  ];
+
+  /**
+   * Administrator user for tests.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $adminUser;
+
+  protected function setUp() {
+    parent::setUp();
+
+    $permissions = [
+      'administer site configuration',
+      'administer views',
+      'translate configuration',
+      'translate interface',
+    ];
+
+    // Create and log in user.
+    $this->adminUser = $this->drupalCreateUser($permissions);
+    $this->drupalLogin($this->adminUser);
+
+    // Add languages.
+    foreach ($this->langcodes as $langcode) {
+      ConfigurableLanguage::createFromLangcode($langcode)->save();
+    }
+    $this->resetAll();
+    $this->rebuildContainer();
+  }
+
+  public function testTranslatedStrings() {
+    $translation_url = 'admin/structure/views/view/files/translate/fr/add';
+    $edit_url = 'admin/structure/views/view/files';
+
+    // Check origial string.
+    $this->drupalGet($edit_url);
+    $this->assertTitle('Files (File) | Drupal');
+
+    // Translate the label of the view.
+    $this->drupalGet($translation_url);
+    $edit = [
+      'translation[config_names][views.view.files][label]' => 'Fichiers',
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save translation'));
+
+    // Check if the label is translated.
+    $this->drupalGet($edit_url, ['language' => \Drupal::languageManager()->getLanguage('fr')]);
+    $this->assertTitle('Files (File) | Drupal');
+    $this->assertNoText('Fichiers');
+  }
+
+}