a2ba9930fc1c52ed5e051689e7c9a7a27d900c1e
[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(['menu_name' => 'tools', 'link' => ['uri' => 'internal:/admin/structure/menu']]);
74     $menu_link_content->save();
75     $this->drupalGet('admin/structure/menu/manage/tools');
76     $this->assertLink(t('Translate'));
77   }
78
79   /**
80    * Tests that translation page inherits admin status of edit page.
81    */
82   public function testTranslationLinkTheme() {
83     $this->drupalLogin($this->administrator);
84     $entityId = $this->createEntity([], 'en');
85
86     // Set up Seven as the admin theme to test.
87     $this->container->get('theme_handler')->install(['seven']);
88     $edit = [];
89     $edit['admin_theme'] = 'seven';
90     $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
91     $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit');
92     $this->assertRaw('core/themes/seven/css/base/elements.css', 'Edit uses admin theme.');
93     $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit/translations');
94     $this->assertRaw('core/themes/seven/css/base/elements.css', 'Translation uses admin theme as well.');
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   protected function doTestTranslationEdit() {
101     $storage = $this->container->get('entity_type.manager')
102       ->getStorage($this->entityTypeId);
103     $storage->resetCache([$this->entityId]);
104     $entity = $storage->load($this->entityId);
105     $languages = $this->container->get('language_manager')->getLanguages();
106
107     foreach ($this->langcodes as $langcode) {
108       // We only want to test the title for non-english translations.
109       if ($langcode != 'en') {
110         $options = ['language' => $languages[$langcode]];
111         $url = $entity->urlInfo('edit-form', $options);
112         $this->drupalGet($url);
113
114         $title = t('@title [%language translation]', [
115           '@title' => $entity->getTranslation($langcode)->label(),
116           '%language' => $languages[$langcode]->getName(),
117         ]);
118         $this->assertRaw($title);
119       }
120     }
121   }
122
123 }