Mercurial > hg > isophonics-drupal-site
comparison core/modules/menu_ui/src/Tests/MenuLanguageTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\menu_ui\Tests; | |
4 | |
5 use Drupal\Component\Utility\Unicode; | |
6 use Drupal\language\Entity\ConfigurableLanguage; | |
7 use Drupal\language\Entity\ContentLanguageSettings; | |
8 | |
9 /** | |
10 * Tests for menu_ui language settings. | |
11 * | |
12 * Create menu and menu links in non-English language, and edit language | |
13 * settings. | |
14 * | |
15 * @group menu_ui | |
16 */ | |
17 class MenuLanguageTest extends MenuWebTestBase { | |
18 | |
19 /** | |
20 * Modules to enable. | |
21 * | |
22 * @var array | |
23 */ | |
24 public static $modules = ['language']; | |
25 | |
26 protected function setUp() { | |
27 parent::setUp(); | |
28 | |
29 $this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer menu'])); | |
30 | |
31 // Add some custom languages. | |
32 foreach (['aa', 'bb', 'cc', 'cs'] as $language_code) { | |
33 ConfigurableLanguage::create([ | |
34 'id' => $language_code, | |
35 'label' => $this->randomMachineName(), | |
36 ])->save(); | |
37 } | |
38 } | |
39 | |
40 /** | |
41 * Tests menu language settings and the defaults for menu link items. | |
42 */ | |
43 public function testMenuLanguage() { | |
44 // Create a test menu to test the various language-related settings. | |
45 // Machine name has to be lowercase. | |
46 $menu_name = Unicode::strtolower($this->randomMachineName(16)); | |
47 $label = $this->randomString(); | |
48 $edit = [ | |
49 'id' => $menu_name, | |
50 'description' => '', | |
51 'label' => $label, | |
52 'langcode' => 'aa', | |
53 ]; | |
54 $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save')); | |
55 ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content') | |
56 ->setDefaultLangcode('bb') | |
57 ->setLanguageAlterable(TRUE) | |
58 ->save(); | |
59 | |
60 // Check menu language. | |
61 $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The menu language was correctly selected.'); | |
62 | |
63 // Test menu link language. | |
64 $link_path = '/'; | |
65 | |
66 // Add a menu link. | |
67 $link_title = $this->randomString(); | |
68 $edit = [ | |
69 'title[0][value]' => $link_title, | |
70 'link[0][uri]' => $link_path, | |
71 ]; | |
72 $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); | |
73 // Check the link was added with the correct menu link default language. | |
74 $menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); | |
75 $menu_link = reset($menu_links); | |
76 $this->assertMenuLink($menu_link->getPluginId(), [ | |
77 'menu_name' => $menu_name, | |
78 'route_name' => '<front>', | |
79 'langcode' => 'bb', | |
80 ]); | |
81 | |
82 // Edit menu link default, changing it to cc. | |
83 ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content') | |
84 ->setDefaultLangcode('cc') | |
85 ->setLanguageAlterable(TRUE) | |
86 ->save(); | |
87 | |
88 // Add a menu link. | |
89 $link_title = $this->randomString(); | |
90 $edit = [ | |
91 'title[0][value]' => $link_title, | |
92 'link[0][uri]' => $link_path, | |
93 ]; | |
94 $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); | |
95 // Check the link was added with the correct new menu link default language. | |
96 $menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); | |
97 $menu_link = reset($menu_links); | |
98 $this->assertMenuLink($menu_link->getPluginId(), [ | |
99 'menu_name' => $menu_name, | |
100 'route_name' => '<front>', | |
101 'langcode' => 'cc', | |
102 ]); | |
103 | |
104 // Now change the language of the new link to 'bb'. | |
105 $edit = [ | |
106 'langcode[0][value]' => 'bb', | |
107 ]; | |
108 $this->drupalPostForm('admin/structure/menu/item/' . $menu_link->id() . '/edit', $edit, t('Save')); | |
109 $this->assertMenuLink($menu_link->getPluginId(), [ | |
110 'menu_name' => $menu_name, | |
111 'route_name' => '<front>', | |
112 'langcode' => 'bb', | |
113 ]); | |
114 | |
115 // Saving menu link items ends up on the edit menu page. To check the menu | |
116 // link has the correct language default on edit, go to the menu link edit | |
117 // page first. | |
118 $this->drupalGet('admin/structure/menu/item/' . $menu_link->id() . '/edit'); | |
119 // Check that the language selector has the correct default value. | |
120 $this->assertOptionSelected('edit-langcode-0-value', 'bb', 'The menu link language was correctly selected.'); | |
121 | |
122 // Edit menu to hide the language select on menu link item add. | |
123 ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content') | |
124 ->setDefaultLangcode('cc') | |
125 ->setLanguageAlterable(FALSE) | |
126 ->save(); | |
127 | |
128 // Check that the language selector is not available on menu link add page. | |
129 $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); | |
130 $this->assertNoField('edit-langcode-0-value', 'The language selector field was hidden the page'); | |
131 } | |
132 | |
133 } |