3 namespace Drupal\Tests\toolbar\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests that the toolbar icon class remains for translated menu items.
12 class ToolbarMenuTranslationTest extends BrowserTestBase {
15 * A user with permission to access the administrative toolbar.
17 * @var \Drupal\user\UserInterface
26 public static $modules = ['toolbar', 'toolbar_test', 'locale', 'locale_test'];
28 protected function setUp() {
31 // Create an administrative user and log it in.
32 $this->adminUser = $this->drupalCreateUser(['access toolbar', 'translate interface', 'administer languages', 'access administration pages']);
33 $this->drupalLogin($this->adminUser);
37 * Tests that toolbar classes don't change when adding a translation.
39 public function testToolbarClasses() {
43 $edit['predefined_langcode'] = $langcode;
44 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
46 // The menu item 'Structure' in the toolbar will be translated.
47 $menu_item = 'Structure';
49 // Visit a page that has the string on it so it can be translated.
50 $this->drupalGet($langcode . '/admin/structure');
52 // Search for the menu item.
54 'string' => $menu_item,
55 'langcode' => $langcode,
56 'translation' => 'untranslated',
58 $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
59 // Make sure will be able to translate the menu item.
60 $this->assertNoText('No strings available.', 'Search found the menu item as untranslated.');
62 // Check that the class is on the item before we translate it.
63 $xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]');
64 $this->assertEqual(count($xpath), 1, 'The menu item class ok before translation.');
66 // Translate the menu item.
67 $menu_item_translated = $this->randomMachineName();
68 $textarea = current($this->xpath('//textarea'));
69 $lid = (string) $textarea->getAttribute('name');
71 $lid => $menu_item_translated,
73 $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
75 // Search for the translated menu item.
77 'string' => $menu_item,
78 'langcode' => $langcode,
79 'translation' => 'translated',
81 $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
82 // Make sure the menu item string was translated.
83 $this->assertText($menu_item_translated, 'Search found the menu item as translated: ' . $menu_item_translated . '.');
85 // Go to another page in the custom language and make sure the menu item
87 $this->drupalGet($langcode . '/admin/structure');
88 $this->assertText($menu_item_translated, 'Found the menu translated.');
90 // Toolbar icons are included based on the presence of a specific class on
91 // the menu item. Ensure that class also exists for a translated menu item.
92 $xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]');
93 $this->assertEqual(count($xpath), 1, 'The menu item class is the same.');