View source
<?php
namespace Drupal\Tests\toolbar\Functional;
use Drupal\Tests\BrowserTestBase;
class ToolbarMenuTranslationTest extends BrowserTestBase {
protected $adminUser;
public static $modules = [
'toolbar',
'toolbar_test',
'locale',
'locale_test',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access toolbar',
'translate interface',
'administer languages',
'access administration pages',
]);
$this
->drupalLogin($this->adminUser);
}
public function testToolbarClasses() {
$langcode = 'es';
$edit['predefined_langcode'] = $langcode;
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$menu_item = 'Structure';
$this
->drupalGet($langcode . '/admin/structure');
$search = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'untranslated',
];
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertNoText('No strings available.', 'Search found the menu item as untranslated.');
$xpath = $this
->xpath('//a[contains(@class, "icon-system-admin-structure")]');
$this
->assertCount(1, $xpath, 'The menu item class ok before translation.');
$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 = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'translated',
];
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText($menu_item_translated, 'Search found the menu item as translated: ' . $menu_item_translated . '.');
$this
->drupalGet($langcode . '/admin/structure');
$this
->assertText($menu_item_translated, 'Found the menu translated.');
$xpath = $this
->xpath('//a[contains(@class, "icon-system-admin-structure")]');
$this
->assertCount(1, $xpath, 'The menu item class is the same.');
}
}