X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftoolbar%2Ftests%2Fsrc%2FFunctional%2FToolbarMenuTranslationTest.php;fp=web%2Fcore%2Fmodules%2Ftoolbar%2Ftests%2Fsrc%2FFunctional%2FToolbarMenuTranslationTest.php;h=995d49ee386991a9ced937ac1cf64e007c679e07;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/toolbar/tests/src/Functional/ToolbarMenuTranslationTest.php b/web/core/modules/toolbar/tests/src/Functional/ToolbarMenuTranslationTest.php new file mode 100644 index 000000000..995d49ee3 --- /dev/null +++ b/web/core/modules/toolbar/tests/src/Functional/ToolbarMenuTranslationTest.php @@ -0,0 +1,96 @@ +adminUser = $this->drupalCreateUser(['access toolbar', 'translate interface', 'administer languages', 'access administration pages']); + $this->drupalLogin($this->adminUser); + } + + /** + * Tests that toolbar classes don't change when adding a translation. + */ + public function testToolbarClasses() { + $langcode = 'es'; + + // Add Spanish. + $edit['predefined_langcode'] = $langcode; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + + // The menu item 'Structure' in the toolbar will be translated. + $menu_item = 'Structure'; + + // Visit a page that has the string on it so it can be translated. + $this->drupalGet($langcode . '/admin/structure'); + + // Search for the menu item. + $search = [ + 'string' => $menu_item, + 'langcode' => $langcode, + 'translation' => 'untranslated', + ]; + $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter')); + // Make sure will be able to translate the menu item. + $this->assertNoText('No strings available.', 'Search found the menu item as untranslated.'); + + // Check that the class is on the item before we translate it. + $xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]'); + $this->assertEqual(count($xpath), 1, 'The menu item class ok before translation.'); + + // Translate the menu item. + $menu_item_translated = $this->randomMachineName(); + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea->getAttribute('name'); + $edit = [ + $lid => $menu_item_translated, + ]; + $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations')); + + // Search for the translated menu item. + $search = [ + 'string' => $menu_item, + 'langcode' => $langcode, + 'translation' => 'translated', + ]; + $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter')); + // Make sure the menu item string was translated. + $this->assertText($menu_item_translated, 'Search found the menu item as translated: ' . $menu_item_translated . '.'); + + // Go to another page in the custom language and make sure the menu item + // was translated. + $this->drupalGet($langcode . '/admin/structure'); + $this->assertText($menu_item_translated, 'Found the menu translated.'); + + // Toolbar icons are included based on the presence of a specific class on + // the menu item. Ensure that class also exists for a translated menu item. + $xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]'); + $this->assertEqual(count($xpath), 1, 'The menu item class is the same.'); + } + +}