diff --git a/core/modules/views_ui/src/Tests/ViewsUITourTest.php b/core/modules/views_ui/src/Tests/ViewsUITourTest.php index 7030cac..6945bff 100644 --- a/core/modules/views_ui/src/Tests/ViewsUITourTest.php +++ b/core/modules/views_ui/src/Tests/ViewsUITourTest.php @@ -25,6 +25,13 @@ class ViewsUITourTest extends TourTestBase { protected $adminUser; /** + * String translation storage object. + * + * @var \Drupal\locale\StringStorageInterface + */ + protected $localeStorage; + + /** * Modules to enable. * * @var array @@ -33,7 +40,7 @@ class ViewsUITourTest extends TourTestBase { protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour', 'administer languages', 'translate interface', 'access administration pages')); + $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour')); $this->drupalLogin($this->adminUser); } @@ -57,18 +64,28 @@ public function testViewsUiTourTips() { public function testViewsUiTourTipsTranslated() { $langcode = 'nl'; - // Enable import of translations. By default this is disabled for automated - // tests. - $this->config('locale.settings') - ->set('translation.import_enabled', TRUE) - ->save(); + // Add a default locale storage for this test. + $this->localeStorage = $this->container->get('locale.storage'); // Add Dutch language programmatically. ConfigurableLanguage::createFromLangcode($langcode)->save(); - // Import a .po file. - $this->importPoFile($this->getPoFile(), array( - 'langcode' => $langcode, - )); + + // Handler titles that need translations. + $handler_titles = array( + 'Format', + 'Fields', + 'Sort criteria', + 'Filter criteria', + ); + + foreach ($handler_titles as $handler_title) { + // Create source string. + $source = $this->localeStorage->createString(array( + 'source' => $handler_title + )); + $source->save(); + $this->createTranslation($source, $langcode); + } // Create a basic view that shows all content, with a page and a block // display. @@ -77,51 +94,23 @@ public function testViewsUiTourTipsTranslated() { $view['page[create]'] = 1; $view['page[path]'] = $this->randomMachineName(16); // Load the page in dutch. - $this->drupalPostForm($langcode . '/admin/structure/views/add', $view, t('Save and edit')); + $this->drupalPostForm( + $langcode . '/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. + * Creates single translation for source string. */ - 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; + public function createTranslation($source, $langcode) { + return $this->localeStorage->createTranslation(array( + 'lid' => $source->lid, + 'language' => $langcode, + 'translation' => $this->randomMachineName(100), + ))->save(); } }