View source
<?php
namespace Drupal\toolbar\Tests;
use Drupal\simpletest\WebTestBase;
class ToolbarMenuTranslationTest extends WebTestBase {
protected $adminUser;
public static $modules = array(
'toolbar',
'toolbar_test',
'locale',
'locale_test',
);
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser(array(
'access toolbar',
'translate interface',
'administer languages',
'access administration pages',
));
$this
->drupalLogin($this->adminUser);
}
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 = array(
'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
->assertEqual(count($xpath), 1, 'The menu item class ok before translation.');
$menu_item_translated = $this
->randomMachineName();
$textarea = current($this
->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$lid => $menu_item_translated,
);
$this
->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
$search = array(
'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
->assertEqual(count($xpath), 1, 'The menu item class is the same.');
}
}