3 namespace Drupal\Tests\menu_link_content\Functional;
5 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
6 use Drupal\menu_link_content\Entity\MenuLinkContent;
9 * Tests the menu link content translation UI.
13 class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
18 protected $defaultCacheContexts = ['languages:language_interface', 'session', 'theme', 'url.path', 'url.query_args', 'user.permissions', 'user.roles:authenticated'];
25 public static $modules = [
27 'content_translation',
35 protected function setUp() {
36 $this->entityTypeId = 'menu_link_content';
37 $this->bundle = 'menu_link_content';
44 protected function getTranslatorPermissions() {
45 return array_merge(parent::getTranslatorPermissions(), ['administer menu']);
51 protected function getAdministratorPermissions() {
52 return array_merge(parent::getAdministratorPermissions(), ['administer themes', 'view the administration theme']);
58 protected function createEntity($values, $langcode, $bundle_name = NULL) {
59 $values['menu_name'] = 'tools';
60 $values['link']['uri'] = 'internal:/admin/structure/menu';
61 $values['title'] = 'Test title';
63 return parent::createEntity($values, $langcode, $bundle_name);
67 * Ensure that a translate link can be found on the menu edit form.
69 public function testTranslationLinkOnMenuEditForm() {
70 $this->drupalGet('admin/structure/menu/manage/tools');
71 $this->assertNoLink(t('Translate'));
73 $menu_link_content = MenuLinkContent::create([
74 'menu_name' => 'tools',
75 'link' => ['uri' => 'internal:/admin/structure/menu'],
76 'title' => 'Link test',
78 $menu_link_content->save();
79 $this->drupalGet('admin/structure/menu/manage/tools');
80 $this->assertLink(t('Translate'));
84 * Tests that translation page inherits admin status of edit page.
86 public function testTranslationLinkTheme() {
87 $this->drupalLogin($this->administrator);
88 $entityId = $this->createEntity([], 'en');
90 // Set up Seven as the admin theme to test.
91 $this->container->get('theme_handler')->install(['seven']);
93 $edit['admin_theme'] = 'seven';
94 $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
95 $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit');
96 $this->assertRaw('core/themes/seven/css/base/elements.css', 'Edit uses admin theme.');
97 $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit/translations');
98 $this->assertRaw('core/themes/seven/css/base/elements.css', 'Translation uses admin theme as well.');
104 protected function doTestTranslationEdit() {
105 $storage = $this->container->get('entity_type.manager')
106 ->getStorage($this->entityTypeId);
107 $storage->resetCache([$this->entityId]);
108 $entity = $storage->load($this->entityId);
109 $languages = $this->container->get('language_manager')->getLanguages();
111 foreach ($this->langcodes as $langcode) {
112 // We only want to test the title for non-english translations.
113 if ($langcode != 'en') {
114 $options = ['language' => $languages[$langcode]];
115 $url = $entity->urlInfo('edit-form', $options);
116 $this->drupalGet($url);
118 $title = t('@title [%language translation]', [
119 '@title' => $entity->getTranslation($langcode)->label(),
120 '%language' => $languages[$langcode]->getName(),
122 $this->assertRaw($title);