diff --git a/core/modules/views_ui/src/Tests/ViewsUITourTest.php b/core/modules/views_ui/src/Tests/ViewsUITourTest.php index 86533b3..bfb3e07 100644 --- a/core/modules/views_ui/src/Tests/ViewsUITourTest.php +++ b/core/modules/views_ui/src/Tests/ViewsUITourTest.php @@ -8,6 +8,7 @@ namespace Drupal\views_ui\Tests; use Drupal\tour\Tests\TourTestBase; +use Drupal\language\Entity\ConfigurableLanguage; /** * Tests the Views UI tour. @@ -28,11 +29,11 @@ class ViewsUITourTest extends TourTestBase { * * @var array */ - public static $modules = array('views_ui', 'tour'); + public static $modules = array('views_ui', 'tour', 'language', 'locale'); protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour')); + $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour', 'administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->adminUser); } @@ -50,4 +51,77 @@ public function testViewsUiTourTips() { $this->assertTourTips(); } + /** + * Tests views_ui tour tip availability in a different language. + */ + public function testViewsUiTourTipsTranslated() { + $ln = 'nl'; + + // Enable import of translations. By default this is disabled for automated + // tests. + $this->config('locale.settings') + ->set('translation.import_enabled', TRUE) + ->save(); + + // Add Dutch language programmatically. + ConfigurableLanguage::createFromLangcode($ln)->save(); + // Import a .po file. + $this->importPoFile($this->getPoFile(), array( + 'langcode' => $ln, + )); + + // Create a basic view that shows all content, with a page and a block + // display. + $view['label'] = $this->randomMachineName(16); + $view['id'] = strtolower($this->randomMachineName(16)); + $view['page[create]'] = 1; + $view['page[path]'] = $this->randomMachineName(16); + // Load the page in dutch. + $this->drupalPostForm($ln . '/admin/structure/views/add', $view, t('Save and edit')); + $this->assertTourTips(); + } + + /** + * Helper function: import a standalone .po file in a given language. + * + * @param string $contents + * Contents of the .po file to import. + * @param array $options + * (optional) Additional options to pass to the translation import form. + */ + public function importPoFile($contents, array $options = array()) { + $name = tempnam('temporary://', "po_") . '.po'; + file_put_contents($name, $contents); + $options['files[file]'] = $name; + $this->drupalPostForm('admin/config/regional/translate/import', $options, t('Import')); + drupal_unlink($name); + } + + /** + * Helper function that returns a proper .po file. + */ + public function getPoFile() { + return <<< EOF +msgid "" +msgstr "" +"Project-Id-Version: Drupal 8\\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=UTF-8\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\\n" + +msgid "Format" +msgstr "Formaat" + +msgid "Fields" +msgstr "Velden" + +msgid "Sort criteria" +msgstr "Sorteercriteria" + +msgid "Filter criteria" +msgstr "Filtercriteria" +EOF; + } + }