View source
<?php
namespace Drupal\Tests\menu_link_content\Functional;
use Drupal\Tests\content_translation\Functional\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',
];
protected static $modules = [
'language',
'content_translation',
'menu_link_content',
'menu_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
$this->entityTypeId = 'menu_link_content';
$this->bundle = 'menu_link_content';
parent::setUp();
}
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), [
'administer menu',
]);
}
protected function getAdministratorPermissions() {
return array_merge(parent::getAdministratorPermissions(), [
'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
->assertSession()
->linkNotExists('Translate');
$menu_link_content = MenuLinkContent::create([
'menu_name' => 'tools',
'link' => [
'uri' => 'internal:/admin/structure/menu',
],
'title' => 'Link test',
]);
$menu_link_content
->save();
$this
->drupalGet('admin/structure/menu/manage/tools');
$this
->assertSession()
->linkExists('Translate');
}
public function testTranslationLinkTheme() {
$this
->drupalLogin($this->administrator);
$entityId = $this
->createEntity([], 'en');
$this->container
->get('theme_installer')
->install([
'claro',
]);
$edit = [];
$edit['admin_theme'] = 'claro';
$this
->drupalGet('admin/appearance');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('admin/structure/menu/item/' . $entityId . '/edit');
$this
->assertSession()
->responseContains('core/themes/claro/css/base/elements.css');
$this
->drupalGet('admin/structure/menu/item/' . $entityId . '/edit/translations');
$this
->assertSession()
->responseContains('core/themes/claro/css/base/elements.css');
}
protected function doTestTranslationEdit() {
$storage = $this->container
->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage
->resetCache([
$this->entityId,
]);
$entity = $storage
->load($this->entityId);
$languages = $this->container
->get('language_manager')
->getLanguages();
foreach ($this->langcodes as $langcode) {
if ($langcode != 'en') {
$options = [
'language' => $languages[$langcode],
];
$url = $entity
->toUrl('edit-form', $options);
$this
->drupalGet($url);
$this
->assertSession()
->pageTextContains("{$entity->getTranslation($langcode)->label()} [{$languages[$langcode]->getName()} translation]");
}
}
}
}