View source
<?php
namespace Drupal\menu_link_content\Tests;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\menu_link_content\Entity\MenuLinkContent;
class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
protected $defaultCacheContexts = [
'languages:language_interface',
'session',
'theme',
'url.path',
'url.query_args',
'user.permissions',
'user.roles:authenticated',
];
public static $modules = array(
'language',
'content_translation',
'menu_link_content',
'menu_ui',
);
protected function setUp() {
$this->entityTypeId = 'menu_link_content';
$this->bundle = 'menu_link_content';
parent::setUp();
}
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array(
'administer menu',
));
}
protected function getAdministratorPermissions() {
return array_merge(parent::getAdministratorPermissions(), array(
'administer themes',
'view the administration theme',
));
}
protected function createEntity($values, $langcode, $bundle_name = NULL) {
$values['menu_name'] = 'tools';
$values['link']['uri'] = 'internal:/admin/structure/menu';
$values['title'] = 'Test title';
return parent::createEntity($values, $langcode, $bundle_name);
}
public function testTranslationLinkOnMenuEditForm() {
$this
->drupalGet('admin/structure/menu/manage/tools');
$this
->assertNoLink(t('Translate'));
$menu_link_content = MenuLinkContent::create([
'menu_name' => 'tools',
'link' => [
'uri' => 'internal:/admin/structure/menu',
],
]);
$menu_link_content
->save();
$this
->drupalGet('admin/structure/menu/manage/tools');
$this
->assertLink(t('Translate'));
}
function testTranslationLinkTheme() {
$this
->drupalLogin($this->administrator);
$entityId = $this
->createEntity(array(), 'en');
$this->container
->get('theme_handler')
->install(array(
'seven',
));
$edit = array();
$edit['admin_theme'] = 'seven';
$this
->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
$this
->drupalGet('admin/structure/menu/item/' . $entityId . '/edit');
$this
->assertRaw('core/themes/seven/css/base/elements.css', 'Edit uses admin theme.');
$this
->drupalGet('admin/structure/menu/item/' . $entityId . '/edit/translations');
$this
->assertRaw('core/themes/seven/css/base/elements.css', 'Translation uses admin theme as well.');
}
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$languages = $this->container
->get('language_manager')
->getLanguages();
foreach ($this->langcodes as $langcode) {
if ($langcode != 'en') {
$options = array(
'language' => $languages[$langcode],
);
$url = $entity
->urlInfo('edit-form', $options);
$this
->drupalGet($url);
$title = t('@title [%language translation]', array(
'@title' => $entity
->getTranslation($langcode)
->label(),
'%language' => $languages[$langcode]
->getName(),
));
$this
->assertRaw($title);
}
}
}
}