View source
<?php
namespace Drupal\Tests\toolbar\Functional;
use Drupal\Tests\BrowserTestBase;
class ToolbarMenuTranslationTest extends BrowserTestBase {
protected $adminUser;
protected static $modules = [
'toolbar',
'toolbar_test',
'locale',
'locale_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
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
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$menu_item = 'Structure';
$this
->drupalGet($langcode . '/admin/structure');
$search = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'untranslated',
];
$this
->drupalGet('admin/config/regional/translate');
$this
->submitForm($search, 'Filter');
$this
->assertSession()
->pageTextNotContains('No strings available.');
$this
->assertSession()
->elementsCount('xpath', '//a[contains(@class, "icon-system-admin-structure")]', 1);
$menu_item_translated = $this
->randomMachineName();
$textarea = $this
->assertSession()
->elementExists('xpath', '//textarea');
$lid = (string) $textarea
->getAttribute('name');
$edit = [
$lid => $menu_item_translated,
];
$this
->drupalGet('admin/config/regional/translate');
$this
->submitForm($edit, 'Save translations');
$search = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'translated',
];
$this
->drupalGet('admin/config/regional/translate');
$this
->submitForm($search, 'Filter');
$this
->assertSession()
->pageTextContains($menu_item_translated);
$this
->drupalGet($langcode . '/admin/structure');
$this
->assertSession()
->pageTextContains($menu_item_translated);
$this
->assertSession()
->elementsCount('xpath', '//a[contains(@class, "icon-system-admin-structure")]', 1);
}
}