9fd1ce43fe97f20572c8bd91347dd839a77e7bcc
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Functional / MenuLinkContentTranslationUITest.php
1 <?php
2
3 namespace Drupal\Tests\menu_link_content\Functional;
4
5 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
6 use Drupal\menu_link_content\Entity\MenuLinkContent;
7
8 /**
9  * Tests the menu link content translation UI.
10  *
11  * @group Menu
12  */
13 class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
14
15   /**
16    * {inheritdoc}
17    */
18   protected $defaultCacheContexts = ['languages:language_interface', 'session', 'theme', 'url.path', 'url.query_args', 'user.permissions', 'user.roles:authenticated'];
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = [
26     'language',
27     'content_translation',
28     'menu_link_content',
29     'menu_ui',
30   ];
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp() {
36     $this->entityTypeId = 'menu_link_content';
37     $this->bundle = 'menu_link_content';
38     parent::setUp();
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   protected function getTranslatorPermissions() {
45     return array_merge(parent::getTranslatorPermissions(), ['administer menu']);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   protected function getAdministratorPermissions() {
52     return array_merge(parent::getAdministratorPermissions(), ['administer themes', 'view the administration theme']);
53   }
54
55   /**
56    * {@inheritdoc}
57    */
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';
62
63     return parent::createEntity($values, $langcode, $bundle_name);
64   }
65
66   /**
67    * Ensure that a translate link can be found on the menu edit form.
68    */
69   public function testTranslationLinkOnMenuEditForm() {
70     $this->drupalGet('admin/structure/menu/manage/tools');
71     $this->assertNoLink(t('Translate'));
72
73     $menu_link_content = MenuLinkContent::create([
74       'menu_name' => 'tools',
75       'link' => ['uri' => 'internal:/admin/structure/menu'],
76       'title' => 'Link test',
77     ]);
78     $menu_link_content->save();
79     $this->drupalGet('admin/structure/menu/manage/tools');
80     $this->assertLink(t('Translate'));
81   }
82
83   /**
84    * Tests that translation page inherits admin status of edit page.
85    */
86   public function testTranslationLinkTheme() {
87     $this->drupalLogin($this->administrator);
88     $entityId = $this->createEntity([], 'en');
89
90     // Set up Seven as the admin theme to test.
91     $this->container->get('theme_handler')->install(['seven']);
92     $edit = [];
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.');
99   }
100
101   /**
102    * {@inheritdoc}
103    */
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();
110
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);
117
118         $title = t('@title [%language translation]', [
119           '@title' => $entity->getTranslation($langcode)->label(),
120           '%language' => $languages[$langcode]->getName(),
121         ]);
122         $this->assertRaw($title);
123       }
124     }
125   }
126
127 }