Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: menu.test,v 1.8 2008/04/01 23:33:54 boombatower Exp $
|
3 | |
|
4 | | class MenuTestCase extends DrupalTestCase {
|
5 | |
|
6 | | /**
|
7 | | * Implementation of getInfo() for information
|
8 | | */
|
9 | | function getInfo() {
|
10 | | return array(
|
11 | 1 | 'name' => t('Menu link creation/deletion'),
|
12 | | 'description' => t('Create two links in the Navigation menu, check their data, and delete them using the menu module UI.'),
|
13 | | 'group' => 'Menu Module Tests',
|
14 | | );
|
15 | | }
|
16 | |
|
17 | | function setUp() {
|
18 | | parent::setUp();
|
19 | |
|
20 | | $this->drupalModuleEnable('menu');
|
21 | | }
|
22 | |
|
23 | | function testCreateCheckDelete() {
|
24 | |
|
25 | | $web_user = $this->drupalCreateUser(array('access content', 'administer menu', 'access administration pages',));
|
26 | | $this->drupalLogin($web_user);
|
27 | |
|
28 | | $mlid1 = $this->uiCreateLink();
|
29 | | $mlid2 = $this->uiCreateLink($mlid1);
|
30 | |
|
31 | | $link1 = menu_link_load($mlid1);
|
32 | | $this->assertTrue((bool)$link1, '1st link created and loaded');
|
33 | |
|
34 | | $link2 = menu_link_load($mlid2);
|
35 | | $this->assertTrue((bool)$link2, '2nd link created as child and loaded');
|
36 | |
|
37 | | // Check the structure in the DB of the two links.
|
38 | | // In general, if $n = $link['depth'] then $link['p'. $n] == $link['mlid'] and $link['p'. ($n - 1)] == $link['plid'] (unless depth == 0).
|
39 | | // All $link['p'. $n] for $n > depth must be 0.
|
40 | | // We know link1 is at the top level, so $link1['deptj'] == 1 and $link1['plid'] == 0.
|
41 | | // We know that the parent of link2 is link1, so $link2['plid'] == $link1['mlid'].
|
42 | | // Both links were created in the avigation menu.
|
43 | | $this->assertTrue($link1['p2'] == 0 && $link1['p1'] == $mlid1 && $link1['plid'] == 0 && $link1['depth'] == 1 && $link1['has_children'], '1st link has correct data');
|
44 | | $this->assertTrue($link2['menu_name'] == 'navigation' && $link2['p2'] == $mlid2 && $link2['p1'] == $mlid1 && $link2['plid'] == $mlid1 && $link2['depth'] == 2 , '2nd link has correct data');
|
45 | | $this->uiDeleteLink($mlid1);
|
46 | | $this->assertFalse(menu_link_load($mlid1), '1st link deleted');
|
47 | |
|
48 | | $link2 = menu_link_load($mlid2);
|
49 | | $this->assertTrue($link2['plid'] == 0, '2nd link re-parented');
|
50 | | $this->uiDeleteLink($mlid2);
|
51 | | $this->assertFalse(menu_link_load($mlid2), '2nd link link deleted');
|
52 | | }
|
53 | | /**
|
54 | | * Delete a menu link using the menu module UI.
|
55 | | */
|
56 | | function uiDeleteLink($mlid) {
|
57 | | $this->drupalPost("admin/build/menu/item/$mlid/delete", array(), t('Confirm'));
|
58 | | }
|
59 | | /**
|
60 | | * Create a menu link using the menu module UI.
|
61 | | */
|
62 | | function uiCreateLink($plid = 0, $menu_name = 'navigation') {
|
63 | | $this->drupalGet("admin/build/menu-customize/$menu_name/add");
|
64 | | $this->assertResponse(200);
|
65 | |
|
66 | | $title = '!link_'. $this->randomName(16);
|
67 | | $edit = array (
|
68 | | 'menu[link_path]' => '<front>',
|
69 | | 'menu[link_title]' => $title,
|
70 | | 'menu[description]' => '',
|
71 | | 'menu[parent]' => $menu_name.':'.$plid,
|
72 | | 'menu[weight]' => '0',
|
73 | | );
|
74 | |
|
75 | | $this->drupalPost("admin/build/menu-customize/$menu_name/add", $edit, t('Save'));
|
76 | | $out = $this->drupalGet("admin/build/menu-customize/$menu_name");
|
77 | | $this->assertText($title, 'Link created');
|
78 | | $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_title = '%s'", $title));
|
79 | |
|
80 | | return $mlid;
|
81 | | }
|
82 | | }
|
83 | |
|
84 | | class CustomMenuTestCase extends MenuTestCase {
|
85 | |
|
86 | | /**
|
87 | | * Implementation of getInfo() for information
|
88 | | */
|
89 | | function getInfo() {
|
90 | | return array(
|
91 | 1 | 'name' => t('Custom menu creation/deletion'),
|
92 | | 'description' => t('Create a custom menu, add a link to it, and delete it using the menu module UI.'),
|
93 | | 'group' => 'Menu Module Tests',
|
94 | | );
|
95 | | }
|
96 | |
|
97 | | function setUp() {
|
98 | | parent::setUp();
|
99 | |
|
100 | | $this->drupalModuleEnable('menu');
|
101 | | }
|
102 | |
|
103 | | function tearDown() {
|
104 | | parent::tearDown();
|
105 | | }
|
106 | |
|
107 | | function testCreateCheckDelete() {
|
108 | | $web_user = $this->drupalCreateUser(array('access content', 'administer menu', 'access administration pages',));
|
109 | | $this->drupalLogin($web_user);
|
110 | |
|
111 | | $this->drupalGet('admin/build/menu/add');
|
112 | | $name = substr(md5($this->randomName(16)), 0, 20);
|
113 | | $title = $this->randomName(16);
|
114 | | $edit = array (
|
115 | | 'menu_name' => $name,
|
116 | | 'description' => '',
|
117 | | 'title' => $title,
|
118 | | );
|
119 | | $this->drupalPost('admin/build/menu/add', $edit, t('Save'));
|
120 | |
|
121 | | $name = 'menu-' .$name;
|
122 | | $this->drupalGet('admin/build/menu');
|
123 | | $this->assertText($title, 'Menu created');
|
124 | |
|
125 | | $mlid1 = $this->uiCreateLink(0, $name);
|
126 | | $link1 = menu_link_load($mlid1);
|
127 | | $this->assertTrue((bool)$link1, '1st link created and loaded');
|
128 | |
|
129 | | $this->drupalPost("admin/build/menu-customize/$name/delete", array(), t('Delete'));
|
130 | | $this->assertFalse(menu_load($name), 'Custom menu deleted');
|
131 | | $this->assertFalse(menu_link_load($mlid1), '1st link deleted with menu');
|
132 | | }
|
133 | | }
|
134 | |
|
135 | |
|
136 | | class MenuEnableTestCase extends DrupalTestCase {
|
137 | | /**
|
138 | | * Implementation of getInfo() for information
|
139 | | */
|
140 | | function getInfo() {
|
141 | | return array(
|
142 | 1 | 'name' => t('Menu enable'),
|
143 | | 'description' => 'Enable / disable a menu item',
|
144 | | 'group' => 'Menu Module Tests',
|
145 | | );
|
146 | | }
|
147 | |
|
148 | | function setUp() {
|
149 | | parent::setUp();
|
150 | |
|
151 | | $this->drupalModuleEnable('menu');
|
152 | | }
|
153 | |
|
154 | | function tearDown() {
|
155 | | parent::tearDown();
|
156 | | }
|
157 | |
|
158 | | function testMenuModuleEnable() {
|
159 | | $web_user = $this->drupalCreateUser(array('administer menu'));
|
160 | | $this->drupalLogin($web_user);
|
161 | | $this->drupalGet('admin/build/menu-customize/navigation');
|
162 | | $this->clickLink(t('edit'), 0);
|
163 | | $url = $this->getUrl();
|
164 | | preg_match('/\d+/', $url, $matches);
|
165 | | $item = menu_link_load($matches[0]);
|
166 | | $hidden = $item['hidden'];
|
167 | | $edit['menu[enabled]'] = $hidden ? 1 : FALSE;
|
168 | | $this->assertTrue(TRUE, $hidden ? 'Disabled item found' : 'Enabled item found');
|
169 | | $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, t('Save'));
|
170 | | $item = menu_link_load($item['mlid']);
|
171 | | $this->assertTrue($item['hidden'] != $hidden, $item['hidden'] ? 'Item is now disabled' : 'Item is now enabled');
|
172 | | $edit['menu[enabled]'] = $hidden ? FALSE : 1;
|
173 | | $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, t('Save'));
|
174 | | $item = menu_link_load($item['mlid']);
|
175 | | $this->assertTrue($item['hidden'] == $hidden, $item['hidden'] ? 'Item is disabled again' : 'Item is now enabled again');
|
176 | | }
|
177 | | }
|
178 | |
|
179 | |
|
180 | | class MenuResetTestCase extends DrupalTestCase {
|
181 | | /**
|
182 | | * Implementation of getInfo() for information
|
183 | | */
|
184 | | function getInfo() {
|
185 | | return array(
|
186 | 1 | 'name' => t('Menu reset'),
|
187 | | 'description' => 'Edit and reset a menu item',
|
188 | | 'group' => 'Menu Module Tests',
|
189 | | );
|
190 | | }
|
191 | |
|
192 | | function setUp() {
|
193 | | parent::setUp();
|
194 | |
|
195 | | $this->drupalModuleEnable('menu');
|
196 | | }
|
197 | |
|
198 | | function tearDown() {
|
199 | | parent::tearDown();
|
200 | | }
|
201 | |
|
202 | | function testMenuModuleReset() {;
|
203 | | $web_user = $this->drupalCreateUser(array('administer menu'));
|
204 | | $this->drupalLogin($web_user);
|
205 | | $form_state = array();
|
206 | | $menu['menu_name'] = 'navigation';
|
207 | | require_once drupal_get_path('module', 'menu') .'/menu.admin.inc';
|
208 | | $form = drupal_retrieve_form('menu_overview_form', $form_state, $menu);
|
209 | | $found = FALSE;
|
210 | | foreach ($form as $mlid => $elements) {
|
211 | | if (isset($elements['#item']) && $elements['#item']['module'] == 'system') {
|
212 | | $found = TRUE;
|
213 | | $mlid = substr($mlid, 5);
|
214 | | break;
|
215 | | }
|
216 | | }
|
217 | | $this->assertTrue($found, 'System module item found');
|
218 | | if ($found) {
|
219 | | // We can't use menu API here because of localization issues.
|
220 | | $item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid));
|
221 | | $edit['menu[link_title]'] = $this->randomName(16);
|
222 | | $path = 'admin/build/menu/item/'. $mlid;
|
223 | | $this->drupalPost("$path/edit", $edit, t('Save'));
|
224 | | $new_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid));
|
225 | | $this->assertTrue($new_title == $edit['menu[link_title]'], 'Edit succesful');
|
226 | | $this->assertFalse($item['link_title'] == $new_title, 'Item changed' );
|
227 | | $reset_path = $path .'/reset';
|
228 | | $this->assertRaw($reset_path, 'Reset link found');
|
229 | | $this->drupalPost($reset_path, array(), t('Reset'));
|
230 | | $reset_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid));
|
231 | | $this->assertFalse($edit['menu[link_title]'] == $reset_title, 'Item reset');
|
232 | | $this->assertText(t('The menu item was reset to its default settings.'), 'Reset message');
|
233 | | drupal_write_record('menu_links', $item, 'mlid');
|
234 | | $restored_item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid));
|
235 | | $this->assertTrue($item == $restored_item, 'Item restored');
|
236 | | }
|
237 | | }
|
238 | | }
|
239 | |
|
240 | |
|
241 | | class MenuInvalidPathTestCase extends DrupalTestCase {
|
242 | | /**
|
243 | | * Implementation of getInfo() for information
|
244 | | */
|
245 | | function getInfo() {
|
246 | | return array(
|
247 | 1 | 'name' => t('Menu invalid path'),
|
248 | | 'description' => 'Try to create a menu item with an invalid / inaccesible path.',
|
249 | | 'group' => 'Menu Module Tests',
|
250 | | );
|
251 | | }
|
252 | |
|
253 | | function setUp() {
|
254 | | parent::setUp();
|
255 | |
|
256 | | $this->drupalModuleEnable('menu');
|
257 | | }
|
258 | |
|
259 | | function tearDown() {
|
260 | | parent::tearDown();
|
261 | | }
|
262 | |
|
263 | | function testMenuModuleInvalidPath() {
|
264 | | $web_user = $this->drupalCreateUser(array('administer menu'));
|
265 | | $this->drupalLogin($web_user);
|
266 | | foreach (array('-&-', 'admin/user/permissions') as $invalid_path) {
|
267 | | $edit = array (
|
268 | | 'menu[link_path]' => $invalid_path,
|
269 | | 'menu[link_title]' => 'title',
|
270 | | );
|
271 | | $this->drupalPost('admin/build/menu-customize/navigation/add', $edit, t('Save'));
|
272 | | $this->assertRaw(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $invalid_path)), 'Invalid path failed');
|
273 | | }
|
274 | | }
|
275 | | }
|