- <?php
- * @file
- * Provides SimpleTests for menu.inc.
- */
-
- class MenuWebTestCase extends BackdropWebTestCase {
- function setUp() {
- $modules = func_get_args();
- if (isset($modules[0]) && is_array($modules[0])) {
- $modules = $modules[0];
- }
- parent::setUp($modules);
- }
-
-
- * Assert that a given path shows certain breadcrumb links.
- *
- * @param string $goto
- * (optional) A system path to pass to BackdropWebTestCase::backdropGet().
- * @param array $trail
- * An associative array whose keys are expected breadcrumb link paths and
- * whose values are expected breadcrumb link texts (not sanitized).
- * @param string $page_title
- * (optional) A page title to additionally assert via
- * BackdropWebTestCase::assertTitle(). Without site name suffix.
- * @param array $tree
- * (optional) An associative array whose keys are link paths and whose
- * values are link titles (not sanitized) of an expected active trail in a
- * menu tree output on the page.
- * @param $last_active
- * (optional) Whether the last link in $tree is expected to be active (TRUE)
- * or just to be in the active trail (FALSE).
- */
- protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, array $tree = array(), $last_active = TRUE) {
- if (isset($goto)) {
- $this->backdropGet($goto);
- }
-
- $parts = $this->getParts();
- $pass = TRUE;
- foreach ($trail as $path => $title) {
- $url = url($path);
- $part = array_shift($parts);
- $pass = ($pass && $part['href'] === $url && $part['text'] === check_plain($title));
- }
-
- $pass = ($pass && empty($parts));
-
- $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array(
- '%parts' => implode(' ', $trail),
- '@path' => $this->getUrl(),
- )));
-
-
- if (isset($page_title)) {
- $this->assertTitle(strtr('@title | Backdrop CMS', array('@title' => $page_title)));
- }
-
-
- if ($tree) {
- end($tree);
- $active_link_path = key($tree);
- $active_link_title = array_pop($tree);
- $xpath = '';
- if ($tree) {
- $i = 0;
- foreach ($tree as $link_path => $link_title) {
- $part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::');
- $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]';
- $part_args = array(
- ':class' => 'active-trail',
- ':href' => url($link_path),
- ':title' => $link_title,
- );
- $xpath .= $this->buildXPathQuery($part_xpath, $part_args);
- $i++;
- }
- $elements = $this->xpath($xpath);
- $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.');
-
-
- $xpath .= '/following-sibling::ul/descendant::';
- }
- else {
- $xpath .= '//';
- }
- $xpath_last_active = ($last_active ? 'and contains(@class, :class-active)' : '');
- $xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]';
- $args = array(
- ':class-trail' => 'active-trail',
- ':class-active' => 'active',
- ':href' => url($active_link_path),
- ':title' => $active_link_title,
- );
- $elements = $this->xpath($xpath, $args);
- $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', array(
- '%title' => $active_link_title,
- '%tree' => implode(' ', $tree),
- )));
- }
- }
-
-
- * Returns the breadcrumb contents of the current page in the internal browser.
- */
- protected function getParts() {
- $parts = array();
- $elements = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
- if (!empty($elements)) {
- foreach ($elements as $element) {
- $parts[] = array(
- 'text' => (string) $element,
- 'href' => (string) $element['href'],
- 'title' => (string) $element['title'],
- );
- }
- }
- return $parts;
- }
- }
-
- class MenuRouterTestCase extends BackdropWebTestCase {
- protected $profile = 'minimal';
-
- function setUp() {
-
- parent::setUp('menu_test');
-
-
- theme_enable(array('bartik'));
- config_set('system.core', 'theme_default', 'bartik');
- config_set('system.core', 'admin_theme', 'seven');
- }
-
-
- * Tests title and theme callbacks in hook_menu().
- */
- function testMenuCallbacks() {
-
- $this->backdropGet('node');
- $this->assertText('A title with @placeholder', 'Raw text found on the page');
- $this->assertNoText(t('A title with @placeholder', array('@placeholder' => 'some other text')), 'Text with placeholder substitutions not found.');
-
-
-
- $this->backdropGet('');
- $this->assertNoText(t('Menu Callback Title'));
-
- $this->backdropGet('menu_callback_title');
- $this->assertText(t('Menu Callback Title'));
-
-
- $this->backdropGet('menu-test/theme-callback/use-admin-theme');
- $this->assertText('Custom theme: seven. Actual theme: seven.', 'The administrative theme can be correctly set in a theme callback.');
- $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");
-
-
- $this->backdropGet('menu-test/theme-callback/use-admin-theme/inheritance');
- $this->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', 'Theme callback inheritance correctly uses the administrative theme.');
- $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");
-
-
-
- $this->backdropGet('admin/config/development/file-inheritance');
- $this->assertText('File inheritance test description', 'File inheritance works.');
-
-
- $path = "menu-test/ -._~!$'\"()*@[]?&+%#,;=:" .
- "%23%25%26%2B%2F%3F" .
- "éøïвβ中國書۞";
- $this->backdropGet($path);
- $this->assertRaw('This is menu_test_callback().');
-
-
- state_set('maintenance_mode', TRUE);
-
-
-
- $this->backdropGet('menu-test/theme-callback/use-admin-theme');
- $this->assertRaw('bartik/css/style.css', "The maintenance theme's CSS appears on the page.");
-
-
- $admin_user = $this->backdropCreateUser(array('access site in maintenance mode'));
- $this->backdropLogin($admin_user);
- $this->backdropGet('menu-test/theme-callback/use-admin-theme');
- $this->assertText('Custom theme: seven. Actual theme: seven.', 'The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.');
- $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");
- $this->backdropLogout();
-
-
-
- $offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => config_get_translated('system.core', 'site_name')));
- $this->backdropGet('node');
- $this->assertText($offline_message);
- $this->backdropGet('menu_login_callback');
- $this->assertText('This is menu_login_callback().', 'Maintenance mode can be bypassed through hook_login_paths().');
- state_set('maintenance_mode', FALSE);
-
-
-
- $this->backdropGet('menu-test/theme-callback/use-stark-theme');
- $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that is not enabled is requested.');
- $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
-
-
- theme_enable(array('stark'));
- $this->backdropGet('menu-test/theme-callback/use-stark-theme');
- $this->assertText('Custom theme: stark. Actual theme: stark.', 'The theme callback system uses an optional theme once it has been enabled.');
- $this->assertRaw('stark/layout.css', "The optional theme's CSS appears on the page.");
-
-
- $this->backdropGet('menu-test/theme-callback/use-fake-theme');
- $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that does not exist is requested.');
- $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
-
-
- $this->backdropGet('menu-test/theme-callback/no-theme-requested');
- $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when no theme is requested.');
- $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
- }
-
-
- * Test that an authenticated user hitting 'user/login' gets redirected to
- * 'user' and 'user/register' gets redirected to the user edit page.
- */
- function testAuthUserUserLogin() {
- $loggedInUser = $this->backdropCreateUser(array());
- $this->backdropLogin($loggedInUser);
-
- $this->backdropGet('user/login');
-
- $this->assertTrue($this->url == url('user/' . $loggedInUser->uid, array('absolute' => TRUE)), "Logged-in user redirected to q=user on accessing q=user/login");
-
-
- $this->backdropGet('user/register');
- $this->assertTrue($this->url == url('user/' . $this->loggedInUser->uid . '/edit', array('absolute' => TRUE)), "Logged-in user redirected to q=user/UID/edit on accessing q=user/register");
- }
-
-
- * Test that hook_custom_theme() can control the theme of a page.
- */
- function testHookCustomTheme() {
-
-
- state_set('menu_test_hook_custom_theme_name', 'stark');
- theme_enable(array('stark'));
-
-
-
- $this->backdropGet('menu-test/no-theme-callback');
- $this->assertText('Custom theme: stark. Actual theme: stark.', 'The result of hook_custom_theme() is used as the theme for the current page.');
- $this->assertRaw('stark/layout.css', "The Stark theme's CSS appears on the page.");
- }
-
-
- * Test that the theme callback wins out over hook_custom_theme().
- */
- function testThemeCallbackHookCustomTheme() {
-
-
- state_set('menu_test_hook_custom_theme_name', 'stark');
- theme_enable(array('stark'));
-
-
-
- $this->backdropGet('menu-test/theme-callback/use-admin-theme');
- $this->assertText('Custom theme: seven. Actual theme: seven.', 'The result of hook_custom_theme() does not override what was set in a theme callback.');
- $this->assertRaw('seven/css/style.css', "The Seven theme's CSS appears on the page.");
- }
-
-
- * Tests for menu_link_maintain().
- */
- function testMenuLinkMaintain() {
- $admin_user = $this->backdropCreateUser(array('administer site configuration'));
- $this->backdropLogin($admin_user);
-
-
- menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/1', 'Menu link #1');
- menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/1', 'Menu link #1-1');
- menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/2', 'Menu link #2');
-
-
- db_update('menu_links')
- ->fields(array('menu_name' => 'main-menu'))
- ->condition('link_title', 'Menu link #1-1')
- ->condition('customized', 0)
- ->condition('module', 'menu_test')
- ->execute();
- menu_cache_clear('main-menu');
-
-
- $this->backdropGet('<front>');
- $this->assertLink(t('Menu link #1'), 0, 'Found menu link #1');
- $this->assertLink(t('Menu link #1-1'), 0, 'Found menu link #1-1');
- $this->assertLink(t('Menu link #2'), 0, 'Found menu link #2');
-
-
- menu_link_maintain('menu_test', 'update', 'menu_test_maintain/1', 'Menu link updated');
-
- $this->backdropGet('menu_test_maintain/1');
- $this->assertLink(t('Menu link updated'), 0, 'Found updated menu link');
- $this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1');
- $this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1-1');
- $this->assertLink(t('Menu link #2'), 0, 'Found menu link #2');
-
-
- menu_link_maintain('menu_test', 'delete', 'menu_test_maintain/1', '');
-
- $this->backdropGet('menu_test_maintain/2');
- $this->assertNoLink(t('Menu link updated'), 0, 'Not found deleted menu link');
- $this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1');
- $this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1-1');
- $this->assertLink(t('Menu link #2'), 0, 'Found menu link #2');
- }
-
-
- * Tests for menu_name parameter for hook_menu().
- */
- function testMenuName() {
- $admin_user = $this->backdropCreateUser(array('administer site configuration'));
- $this->backdropLogin($admin_user);
-
- $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
- $name = db_query($sql)->fetchField();
- $this->assertEqual($name, 'original', 'Menu name is "original".');
-
-
-
- menu_test_menu_name('changed');
- menu_rebuild();
-
- $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
- $name = db_query($sql)->fetchField();
- $this->assertEqual($name, 'changed', 'Menu name was successfully changed after rebuild.');
- }
-
-
- * Tests for menu hierarchy.
- */
- function testMenuHierarchy() {
- $parent_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent'))->fetchAssoc();
- $child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc();
- $unattached_child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc();
-
- $this->assertEqual($child_link['plid'], $parent_link['mlid'], 'The parent of a directly attached child is correct.');
- $this->assertEqual($unattached_child_link['plid'], $parent_link['mlid'], 'The parent of a non-directly attached child is correct.');
- }
-
-
- * Tests menu link depth and parents of local tasks and menu callbacks.
- */
- function testMenuHidden() {
-
- $links = db_select('menu_links', 'ml')
- ->fields('ml')
- ->condition('ml.router_path', 'menu-test/hidden/menu%', 'LIKE')
- ->orderBy('ml.router_path')
- ->execute()
- ->fetchAllAssoc('router_path', PDO::FETCH_ASSOC);
-
- $parent = $links['menu-test/hidden/menu'];
- $depth = $parent['depth'] + 1;
- $plid = $parent['mlid'];
-
- $link = $links['menu-test/hidden/menu/list'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/add'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/settings'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/manage/%'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $parent = $links['menu-test/hidden/menu/manage/%'];
- $depth = $parent['depth'] + 1;
- $plid = $parent['mlid'];
-
- $link = $links['menu-test/hidden/menu/manage/%/list'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/manage/%/add'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/manage/%/edit'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/menu/manage/%/delete'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
-
- $links = db_select('menu_links', 'ml')
- ->fields('ml')
- ->condition('ml.router_path', 'menu-test/hidden/block%', 'LIKE')
- ->orderBy('ml.router_path')
- ->execute()
- ->fetchAllAssoc('router_path', PDO::FETCH_ASSOC);
-
- $parent = $links['menu-test/hidden/block'];
- $depth = $parent['depth'] + 1;
- $plid = $parent['mlid'];
-
- $link = $links['menu-test/hidden/block/list'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/block/add'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/block/manage/%/%'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $parent = $links['menu-test/hidden/block/manage/%/%'];
- $depth = $parent['depth'] + 1;
- $plid = $parent['mlid'];
-
- $link = $links['menu-test/hidden/block/manage/%/%/configure'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
-
- $link = $links['menu-test/hidden/block/manage/%/%/delete'];
- $this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
- $this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
- }
-
-
- * Test menu_get_item() with empty ancestors.
- */
- function testMenuGetItemNoAncestors() {
- state_set('menu_masks', array());
- $this->backdropGet('');
- }
-
-
- * Test menu_set_item().
- */
- function testMenuSetItem() {
- $item = menu_get_item('node');
-
- $this->assertEqual($item['path'], 'node', "Path from menu_get_item('node') is equal to 'node'", 'menu');
-
-
- $item['path'] = 'node_test';
- $item['href'] = 'node_test';
-
- menu_set_item('node', $item);
- $compare_item = menu_get_item('node');
- $this->assertEqual($compare_item, $item, 'Modified menu item is equal to newly retrieved menu item.', 'menu');
- }
-
-
- * Test menu maintenance hooks.
- */
- function testMenuItemHooks() {
-
- menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/4', 'Menu link #4');
- $this->assertEqual(menu_test_static_variable(), 'insert', 'hook_menu_link_insert() fired correctly');
-
- menu_link_maintain('menu_test', 'update', 'menu_test_maintain/4', 'Menu link updated');
- $this->assertEqual(menu_test_static_variable(), 'update', 'hook_menu_link_update() fired correctly');
-
- menu_link_maintain('menu_test', 'delete', 'menu_test_maintain/4', '');
- $this->assertEqual(menu_test_static_variable(), 'delete', 'hook_menu_link_delete() fired correctly');
- }
-
-
- * Test menu link 'options' storage and rendering.
- */
- function testMenuLinkOptions() {
-
- $menu_link = array(
- 'link_title' => 'Menu link options test',
- 'link_path' => 'node',
- 'module' => 'menu_test',
- 'options' => array(
- 'attributes' => array(
- 'title' => 'Test title attribute',
- ),
- 'query' => array(
- 'test_param' => 'test_value',
- ),
- ),
- );
- menu_link_save($menu_link);
-
-
- $this->backdropGet('<front>');
- $this->assertRaw('title="Test title attribute"', 'Title attribute of a menu link renders.');
- $this->assertRaw('test_param=test_value', 'Query parameter added to menu link.');
- }
-
-
- * Tests the possible ways to set the title for menu items.
- * Also tests that menu item titles work with string overrides.
- *
- * @see menu_test_init()
- */
- function testMenuItemTitlesCases() {
- for ($case_no = 1; $case_no <= 4; $case_no++) {
- $this->backdropGet('menu-title-test/case' . $case_no);
- $this->assertResponse(200);
- $asserted_title = 'Alternative example title - Case ' . $case_no;
- $this->assertTitle($asserted_title . ' | Backdrop CMS', 'Menu title is: ' . $asserted_title, 'Menu');
- }
- }
-
-
- * Load the router for a given path.
- */
- protected function menuLoadRouter($router_path) {
- return db_query('SELECT * FROM {menu_router} WHERE path = :path', array(':path' => $router_path))->fetchAssoc();
- }
-
-
- * Tests inheritance of 'load arguments'.
- */
- function testMenuLoadArgumentsInheritance() {
- $expected = array(
- 'menu-test/arguments/%/%' => array(
- 2 => array('menu_test_argument_load' => array(3)),
- 3 => NULL,
- ),
-
- 'menu-test/arguments/%/%/default' => array(
- 2 => array('menu_test_argument_load' => array(3)),
- 3 => NULL,
- ),
-
- 'menu-test/arguments/%/%/task' => array(
- 2 => array('menu_test_argument_load' => array(3)),
- 3 => NULL,
- ),
-
- 'menu-test/arguments/%/%/common-loader' => array(
- 2 => array('menu_test_argument_load' => array(3)),
- 3 => 'menu_test_other_argument_load',
- ),
-
-
- 'menu-test/arguments/%/%/different-loaders-1' => array(
- 2 => NULL,
- 3 => 'menu_test_argument_load',
- ),
- 'menu-test/arguments/%/%/different-loaders-2' => array(
- 2 => 'menu_test_other_argument_load',
- 3 => NULL,
- ),
- 'menu-test/arguments/%/%/different-loaders-3' => array(
- 2 => NULL,
- 3 => NULL,
- ),
-
- 'menu-test/arguments/%/%/explicit-arguments' => array(
- 2 => array('menu_test_argument_load' => array()),
- 3 => NULL,
- ),
- );
-
- foreach ($expected as $router_path => $load_functions) {
- $router_item = $this->menuLoadRouter($router_path);
- $this->assertIdentical(unserialize($router_item['load_functions']), $load_functions, format_string('Expected load functions for router %router_path' , array('%router_path' => $router_path)));
- }
- }
- }
-
- * Tests for menu links.
- */
- class MenuLinksUnitTestCase extends BackdropWebTestCase {
-
- protected $profile = 'testing';
-
-
- * Create a simple hierarchy of links.
- */
- function createLinkHierarchy($module = 'menu_test') {
-
- db_truncate('menu_links')->execute();
-
-
-
-
-
-
-
- $base_options = array(
- 'link_title' => 'Menu link test',
- 'module' => $module,
- 'menu_name' => 'menu_test',
- );
-
- $links['parent'] = $base_options + array(
- 'link_path' => 'menu-test/parent',
- );
- menu_link_save($links['parent']);
-
- $links['child-1'] = $base_options + array(
- 'link_path' => 'menu-test/parent/child-1',
- 'plid' => $links['parent']['mlid'],
- );
- menu_link_save($links['child-1']);
-
- $links['child-1-1'] = $base_options + array(
- 'link_path' => 'menu-test/parent/child-1/child-1-1',
- 'plid' => $links['child-1']['mlid'],
- );
- menu_link_save($links['child-1-1']);
-
- $links['child-1-2'] = $base_options + array(
- 'link_path' => 'menu-test/parent/child-1/child-1-2',
- 'plid' => $links['child-1']['mlid'],
- );
- menu_link_save($links['child-1-2']);
-
- $links['child-2'] = $base_options + array(
- 'link_path' => 'menu-test/parent/child-2',
- 'plid' => $links['parent']['mlid'],
- );
- menu_link_save($links['child-2']);
-
- return $links;
- }
-
-
- * Assert that at set of links is properly parented.
- */
- function assertMenuLinkParents($links, $expected_hierarchy) {
- foreach ($expected_hierarchy as $child => $parent) {
- $mlid = $links[$child]['mlid'];
- $plid = $parent ? $links[$parent]['mlid'] : 0;
-
- $menu_link = menu_link_load($mlid);
- menu_link_save($menu_link);
- $this->assertEqual($menu_link['plid'], $plid, format_string('Menu link %mlid has parent of %plid, expected %expected_plid.', array('%mlid' => $mlid, '%plid' => $menu_link['plid'], '%expected_plid' => $plid)));
- }
- }
-
-
- * Test automatic re-parenting of menu links.
- */
- function testMenuLinkReparenting($module = 'menu_test') {
-
- $links = $this->createLinkHierarchy($module);
-
- $expected_hierarchy = array(
- 'parent' => FALSE,
- 'child-1' => 'parent',
- 'child-1-1' => 'child-1',
- 'child-1-2' => 'child-1',
- 'child-2' => 'parent',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
-
-
-
- $links = $this->createLinkHierarchy($module);
- $links['child-1']['plid'] = $links['child-2']['mlid'];
- menu_link_save($links['child-1']);
-
- $expected_hierarchy = array(
- 'parent' => FALSE,
- 'child-1' => 'child-2',
- 'child-1-1' => 'child-1',
- 'child-1-2' => 'child-1',
- 'child-2' => 'parent',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
-
-
-
-
-
- if ($module != 'system') {
- $links = $this->createLinkHierarchy($module);
- menu_link_delete($links['child-1']['mlid']);
-
- $expected_hierarchy = array(
- 'parent' => FALSE,
- 'child-1-1' => 'parent',
- 'child-1-2' => 'parent',
- 'child-2' => 'parent',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
- }
-
-
-
-
-
- $links = $this->createLinkHierarchy($module);
-
- db_delete('menu_links')
- ->condition('mlid', $links['child-1']['mlid'])
- ->execute();
-
- $expected_hierarchy = array(
- 'parent' => FALSE,
- 'child-1-1' => 'parent',
- 'child-1-2' => 'parent',
- 'child-2' => 'parent',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
-
-
-
- $links = $this->createLinkHierarchy($module);
-
- db_delete('menu_links')
- ->condition('mlid', $links['parent']['mlid'])
- ->execute();
-
- $expected_hierarchy = array(
- 'child-1-1' => 'child-1',
- 'child-1-2' => 'child-1',
- 'child-2' => FALSE,
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
- }
-
-
- * Test automatic reparenting of menu links derived from menu routers.
- */
- function testMenuLinkRouterReparenting() {
-
-
- $this->testMenuLinkReparenting('system');
-
-
- $links = $this->createLinkHierarchy('system');
-
-
-
- $links['child-1-2']['plid'] = $links['child-2']['mlid'];
- menu_link_save($links['child-1-2']);
-
-
- $expected_hierarchy = array(
- 'parent' => FALSE,
- 'child-1' => 'parent',
- 'child-1-1' => 'child-1',
- 'child-2' => 'parent',
- 'child-1-2' => 'child-2',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
-
-
-
-
-
- db_delete('menu_links')
- ->condition('mlid', $links['parent']['mlid'])
- ->execute();
- $expected_hierarchy = array(
- 'child-1' => FALSE,
- 'child-1-1' => 'child-1',
- 'child-2' => FALSE,
- 'child-1-2' => 'child-2',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
-
-
-
-
-
- db_delete('menu_links')
- ->condition('mlid', $links['child-2']['mlid'])
- ->execute();
- $expected_hierarchy = array(
- 'child-1' => FALSE,
- 'child-1-1' => 'child-1',
- 'child-1-2' => 'child-1',
- );
- $this->assertMenuLinkParents($links, $expected_hierarchy);
- }
- }
-
- * Tests rebuilding the menu by setting 'menu_rebuild_needed.'
- */
- class MenuRebuildTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
-
-
- * Test if the 'menu_rebuild_needed' variable triggers a menu_rebuild() call.
- */
- function testMenuRebuildByVariable() {
-
- $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
- $this->assertEqual($admin_exists, 'admin', "The path 'admin/' exists prior to deleting.");
-
-
- db_delete('menu_router')
- ->condition('path', 'admin')
- ->execute();
- $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
- $this->assertFalse($admin_exists, "The path 'admin/' has been deleted and doesn't exist in the database.");
-
-
-
- state_set('menu_rebuild_needed', TRUE);
-
- $this->backdropGet('<front>');
- $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
- $this->assertEqual($admin_exists, 'admin', "The menu has been rebuilt, the path 'admin' now exists again.");
- }
-
- }
-
- * Menu tree data related tests.
- */
- class MenuTreeDataTestCase extends BackdropUnitTestCase {
- protected $profile = 'testing';
-
-
- * Dummy link structure acceptable for menu_tree_data().
- */
- var $links = array(
- 1 => array('mlid' => 1, 'depth' => 1),
- 2 => array('mlid' => 2, 'depth' => 1),
- 3 => array('mlid' => 3, 'depth' => 2),
- 4 => array('mlid' => 4, 'depth' => 3),
- 5 => array('mlid' => 5, 'depth' => 1),
- );
-
-
- * Validate the generation of a proper menu tree hierarchy.
- */
- function testMenuTreeData() {
- $tree = menu_tree_data($this->links);
-
-
- $this->assertSameLink($this->links[1], $tree[1]['link'], 'Parent item #1 exists.');
- $this->assertSameLink($this->links[2], $tree[2]['link'], 'Parent item #2 exists.');
- $this->assertSameLink($this->links[5], $tree[5]['link'], 'Parent item #5 exists.');
-
-
- $this->assertSameLink($this->links[4], $tree[2]['below'][3]['below'][4]['link'], 'Child item #4 exists in the hierarchy.');
- }
-
-
- * Check that two menu links are the same by comparing the mlid.
- *
- * @param $link1
- * A menu link item.
- * @param $link2
- * A menu link item.
- * @param $message
- * The message to display along with the assertion.
- * @return
- * TRUE if the assertion succeeded, FALSE otherwise.
- */
- protected function assertSameLink($link1, $link2, $message = '') {
- return $this->assert($link1['mlid'] == $link2['mlid'], $message ? $message : 'First link is identical to second link');
- }
- }
-
- * Menu tree output related tests.
- */
- class MenuTreeOutputTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
-
-
- * Dummy link structure acceptable for menu_tree_output().
- */
- protected $tree_data = array(
- '1'=> array(
- 'link' => array( 'menu_name' => 'main-menu', 'mlid' => 1, 'hidden'=>0, 'has_children' => 1, 'title' => 'Item 1', 'in_active_trail' => 1, 'access'=>1, 'href' => 'a', 'localized_options' => array('attributes' => array('title' =>'')) ),
- 'below' => array(
- '2' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 2, 'hidden'=>0, 'has_children' => 1, 'title' => 'Item 2', 'in_active_trail' => 1, 'access'=>1, 'href' => 'a/b', 'localized_options' => array('attributes' => array('title' =>'')) ),
- 'below' => array(
- '3' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 3, 'hidden'=>0, 'has_children' => 0, 'title' => 'Item 3', 'in_active_trail' => 0, 'access'=>1, 'href' => 'a/b/c', 'localized_options' => array('attributes' => array('title' =>'')) ),
- 'below' => array() ),
- '4' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 4, 'hidden'=>0, 'has_children' => 0, 'title' => 'Item 4', 'in_active_trail' => 0, 'access'=>1, 'href' => 'a/b/d', 'localized_options' => array('attributes' => array('title' =>'')) ),
- 'below' => array() )
- )
- )
- )
- ),
- '5' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 5, 'hidden'=>1, 'has_children' => 0, 'title' => 'Item 5', 'in_active_trail' => 0, 'access'=>1, 'href' => 'e', 'localized_options' => array('attributes' => array('title' =>'')) ), 'below' => array( ) ),
- '6' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 6, 'hidden'=>0, 'has_children' => 0, 'title' => 'Item 6', 'in_active_trail' => 0, 'access'=>0, 'href' => 'f', 'localized_options' => array('attributes' => array('title' =>'')) ), 'below' => array( ) ),
- '7' => array('link' => array( 'menu_name' => 'main-menu', 'mlid' => 7, 'hidden'=>0, 'has_children' => 0, 'title' => 'Item 7', 'in_active_trail' => 0, 'access'=>1, 'href' => 'g', 'localized_options' => array('attributes' => array('title' =>'')) ), 'below' => array( ) )
- );
-
-
- * Validate the generation of a proper menu tree output.
- */
- function testMenuTreeData() {
- $output = menu_tree_output($this->tree_data);
-
-
- $this->assertEqual($output['1']['#theme'], 'menu_link__main_menu', 'Hyphen is changed to a underscore on menu_link');
- $this->assertEqual($output['#theme_wrappers'][0], 'menu_tree__main_menu', 'Hyphen is changed to a underscore on menu_tree wrapper');
-
- $this->assertEqual($output['1']['#below']['2']['#href'], 'a/b', 'Checking the href on a child item');
- $this->assertTrue(in_array('active-trail',$output['1']['#below']['2']['#attributes']['class']) , 'Checking the active trail class');
-
- $this->assertFalse(isset($output['5']), 'Hidden item should be missing');
- $this->assertFalse(isset($output['6']), 'False access should be missing');
-
- $this->assertTrue(isset($output['7']), 'Item after hidden items is present');
- }
- }
-
- * Menu breadcrumbs related tests.
- */
- class MenuBreadcrumbTestCase extends MenuWebTestCase {
- protected $admin_user;
- protected $web_user;
-
- function setUp() {
- $modules = func_get_args();
- if (isset($modules[0]) && is_array($modules[0])) {
- $modules = $modules[0];
- }
- $modules[] = 'menu_test';
- parent::setUp($modules);
- $perms = array_keys(module_invoke_all('permission'));
- $this->admin_user = $this->backdropCreateUser($perms);
- $this->backdropLogin($this->admin_user);
-
-
-
-
- $layout = layout_load('admin_default');
- $layout->addBlock('system', 'main-menu', 'header');
- $layout->save();
- }
-
-
- * Tests breadcrumbs on node and administrative paths.
- */
- function testBreadCrumbs() {
- foreach (array('default', 'admin_default') as $layout_name) {
- $layout = layout_load($layout_name);
-
- $menu_uuid = $layout->positions['header'][1];
- $menu_block = $layout->content[$menu_uuid];
-
-
- $menu_block->settings['block_settings']['level'] = 1;
- $menu_block->settings['block_settings']['depth'] = 0;
-
-
- $layout->save();
- }
-
-
- $home = array('<front>' => 'Home');
- $admin = $home + array('admin' => t('Administration'));
- $config = $admin + array('admin/config' => t('Configuration'));
- $type = 'post';
- $langcode = LANGUAGE_NONE;
-
-
- $expected = array(
- 'menu-test' => t('Menu test root'),
- );
- $title = t('Breadcrumbs test: Local tasks');
- $trail = $home + $expected;
- $tree = $expected + array(
- 'menu-test/breadcrumb/tasks' => $title,
- );
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks', $trail, $title, $tree);
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first', $trail, $title, $tree);
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first/first', $trail, $title, $tree);
- $trail += array(
- 'menu-test/breadcrumb/tasks' => t('Breadcrumbs test: Local tasks'),
- );
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first/second', $trail, $title, $tree);
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second', $trail, $title, $tree);
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second/first', $trail, $title, $tree);
- $trail += array(
- 'menu-test/breadcrumb/tasks/second' => t('Second'),
- );
- $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second/second', $trail, $title, $tree);
-
-
- $trail = $admin + array(
- 'admin/structure' => t('Structure'),
- );
- $this->assertBreadcrumb('admin/structure/taxonomy', $trail);
-
- $trail += array(
- 'admin/structure/taxonomy' => t('Taxonomy'),
- );
- $this->assertBreadcrumb('admin/structure/taxonomy/tags', $trail);
- $trail += array(
- 'admin/structure/taxonomy/tags' => t('Tags'),
- );
- $this->assertBreadcrumb('admin/structure/taxonomy/tags/configure', $trail);
- $this->assertBreadcrumb('admin/structure/taxonomy/tags/fields', $trail);
- $this->assertBreadcrumb('admin/structure/taxonomy/tags/add', $trail);
-
-
- $trail = $admin + array(
- 'admin/structure' => t('Structure'),
- );
- $this->assertBreadcrumb('admin/structure/menu', $trail);
-
- $trail += array(
- 'admin/structure/menu' => t('Menus'),
- );
- $this->assertBreadcrumb('admin/structure/menu/manage/main-menu', $trail);
- $trail += array(
- 'admin/structure/menu/manage/main-menu' => t('Primary navigation'),
- );
- $this->assertBreadcrumb('admin/structure/menu/manage/main-menu/configure', $trail);
- $this->assertBreadcrumb('admin/structure/menu/manage/main-menu/add', $trail);
-
-
- $trail = $admin + array(
- 'admin/structure' => t('Structure'),
- 'admin/structure/types' => t('Content types'),
- );
- $this->assertBreadcrumb('admin/structure/types/add', $trail);
- $this->assertBreadcrumb("admin/structure/types/manage/$type", $trail);
- $trail += array(
- "admin/structure/types/manage/$type" => t('Post'),
- );
- $this->assertBreadcrumb("admin/structure/types/manage/$type/fields", $trail);
- $this->assertBreadcrumb("admin/structure/types/manage/$type/display", $trail);
- $trail_teaser = $trail + array(
- "admin/structure/types/manage/$type/display" => t('Manage displays'),
- );
- $this->assertBreadcrumb("admin/structure/types/manage/$type/display/teaser", $trail_teaser);
- $this->assertBreadcrumb("admin/structure/types/manage/$type/comment/fields", $trail);
- $this->assertBreadcrumb("admin/structure/types/manage/$type/comment/display", $trail);
- $this->assertBreadcrumb("admin/structure/types/manage/$type/delete", $trail);
- $trail += array(
- "admin/structure/types/manage/$type/fields" => t('Manage fields'),
- );
- $this->assertBreadcrumb("admin/structure/types/manage/$type/fields/body", $trail);
- $trail += array(
- "admin/structure/types/manage/$type/fields/body" => t('Body'),
- );
- $this->assertBreadcrumb("admin/structure/types/manage/$type/fields/body/widget-type", $trail);
-
-
- $format = filter_format_load('filtered_html');
- $format_id = $format->format;
- $trail = $config + array(
- 'admin/config/content' => t('Content authoring'),
- );
- $this->assertBreadcrumb('admin/config/content/formats', $trail);
-
- $trail += array(
- 'admin/config/content/formats' => t('Text editors and formats'),
- );
- $this->assertBreadcrumb('admin/config/content/formats/add', $trail);
- $this->assertBreadcrumb("admin/config/content/formats/$format_id", $trail);
- $trail += array(
- "admin/config/content/formats/$format_id" => $format->name,
- );
- $this->assertBreadcrumb("admin/config/content/formats/$format_id/disable", $trail);
-
-
- $node1 = $this->backdropCreateNode();
- $nid1 = $node1->nid;
- $trail = $home;
- $this->assertBreadcrumb("node/$nid1", $trail);
-
- $this->assertNoLink($node1->title);
-
-
- $this->assertBreadcrumb("node/$nid1/view", $trail);
-
- $this->assertNoLink($node1->title);
-
- $trail += array(
- "node/$nid1" => $node1->title,
- );
- $this->assertBreadcrumb("node/$nid1/edit", $trail);
-
-
- $trail = array();
- $this->assertBreadcrumb('home', $trail);
-
-
-
-
-
-
- $menus = array('main-menu', 'main-menu');
-
- $node_type = node_type_get_type($type);
- $node_type->settings['menu_options'] = $menus;
- $node_type->settings['menu_parent'] = 'main-menu:0';
- node_type_save($node_type);
-
- $child = $parent = NULL;
- foreach ($menus as $menu) {
-
- $title = $this->randomName();
- $node2 = $this->backdropCreateNode(array(
- 'type' => $type,
- 'title' => $title,
- 'menu' => array(
- 'enabled' => 1,
- 'link_title' => 'Parent ' . $title,
- 'description' => '',
- 'menu_name' => $menu,
- 'plid' => 0,
- ),
- ));
- $nid2 = $node2->nid;
-
- $trail = $home;
- $tree = array(
- "node/$nid2" => $node2->menu['link_title'],
- );
- $this->assertBreadcrumb("node/$nid2", $trail, $node2->title, $tree);
-
-
- $this->assertBreadcrumb("node/$nid2/view", $trail, $node2->title, $tree);
- $trail += array(
- "node/$nid2" => $node2->menu['link_title'],
- );
- $this->assertBreadcrumb("node/$nid2/edit", $trail);
-
-
- $title = $this->randomName();
- $node3 = $this->backdropCreateNode(array(
- 'type' => $type,
- 'title' => $title,
- 'menu' => array(
- 'enabled' => 1,
- 'link_title' => 'Child ' . $title,
- 'description' => '',
- 'menu_name' => $menu,
- 'plid' => $node2->menu['mlid'],
- ),
- ));
- $nid3 = $node3->nid;
-
- $this->assertBreadcrumb("node/$nid3", $trail, $node3->title, $tree, FALSE);
-
-
- $this->assertBreadcrumb("node/$nid3/view", $trail, $node3->title, $tree, FALSE);
- $trail += array(
- "node/$nid3" => $node3->menu['link_title'],
- );
- $this->assertBreadcrumb("node/$nid3/edit", $trail);
-
-
- $this->assertBreadcrumb('<front>', array());
-
- if ($menu == 'main-menu') {
- $parent = $node2;
- $child = $node3;
- }
- }
-
-
-
- $menu = 'main-menu';
- $edit = array(
- 'link_title' => 'Root',
- 'link_path' => 'node',
- );
- $this->backdropPost("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
- $link = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(':title' => 'Root'))->fetchAssoc();
-
- $edit = array(
- 'menu[parent]' => $link['menu_name'] . ':' . $link['mlid'],
- );
- $this->backdropPost("node/{$parent->nid}/edit", $edit, t('Save'));
- $expected = array(
- "node" => $link['link_title'],
- );
- $trail = $home + $expected;
- $tree = $expected + array(
- "node/{$parent->nid}" => $parent->menu['link_title'],
- );
- $this->assertBreadcrumb(NULL, $trail, $parent->title, $tree);
- $trail += array(
- "node/{$parent->nid}" => $parent->menu['link_title'],
- );
- $tree += array(
- "node/{$child->nid}" => $child->menu['link_title'],
- );
- $this->assertBreadcrumb("node/{$child->nid}", $trail, $child->title, $tree);
-
-
-
- $tags = array(
- 'Backdrop' => array(),
- 'Breadcrumbs' => array(),
- );
- $edit = array(
- "field_tags[$langcode]" => implode(',', array_keys($tags)),
- );
- $this->backdropPost("node/{$parent->nid}/edit", $edit, t('Save'));
-
-
-
-
- $parent_tid = 0;
- foreach ($tags as $name => $null) {
- $terms = taxonomy_term_load_multiple(NULL, array('name' => $name));
- $term = reset($terms);
- $tags[$name]['term'] = $term;
- if ($parent_tid) {
- $edit = array(
- 'parent[]' => array($parent_tid),
- );
- $this->backdropPost("taxonomy/term/{$term->tid}/edit", $edit, t('Save'));
- }
- $parent_tid = $term->tid;
- }
- $parent_mlid = 0;
- foreach ($tags as $name => $data) {
- $term = $data['term'];
- $edit = array(
- 'link_title' => "$name link",
- 'link_path' => "taxonomy/term/{$term->tid}",
- 'parent' => "$menu:{$parent_mlid}",
- );
- $this->backdropPost("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
- $tags[$name]['link'] = db_query('SELECT * FROM {menu_links} WHERE link_title = :title AND link_path = :href', array(
- ':title' => $edit['link_title'],
- ':href' => $edit['link_path'],
- ))->fetchAssoc();
- $tags[$name]['link']['link_path'] = $edit['link_path'];
- $parent_mlid = $tags[$name]['link']['mlid'];
- }
-
-
- $trail = $home;
- $tree = array();
- foreach ($tags as $name => $data) {
- $term = $data['term'];
- $link = $data['link'];
-
- $tree += array(
- $link['link_path'] => $link['link_title'],
- );
- $this->assertBreadcrumb($link['link_path'], $trail, $term->name, $tree);
- $this->assertRaw(check_plain($parent->title), 'Tagged node found.');
-
-
-
-
-
- $elements = $this->xpath('//*[contains(@class,:menu)]/descendant::a[@href=:href]', array(
- ':menu' => 'block-system-main-menu',
- ':href' => url($link['link_path']),
- ));
- $this->assertTrue(count($elements) == 1, "Link to {$link['link_path']} appears only once.");
-
-
-
- $trail += array(
- $link['link_path'] => $term->name,
- );
- }
-
-
- user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, array(
- 'access user profiles',
- ));
- $this->backdropLogout();
-
-
- $this->assertBreadcrumb('<front>', array());
-
-
- $trail = $home;
- $this->assertBreadcrumb('user/' . $this->admin_user->uid, $trail, $this->admin_user->name);
-
-
- $this->backdropLogin($this->admin_user);
- $trail = $home;
- $this->assertBreadcrumb('user', $trail, $this->admin_user->name);
- $this->assertBreadcrumb('user/' . $this->admin_user->uid, $trail, $this->admin_user->name);
- $trail += array(
- 'user/' . $this->admin_user->uid => $this->admin_user->name,
- );
- $this->assertBreadcrumb('user/' . $this->admin_user->uid . '/edit', $trail, $this->admin_user->name);
-
-
- $this->web_user = $this->backdropCreateUser(array(
- 'administer users',
- 'access user profiles',
- ));
- $this->backdropLogin($this->web_user);
-
-
- $trail = $home;
- $this->assertBreadcrumb('user/' . $this->admin_user->uid, $trail, $this->admin_user->name);
- $trail += array(
- 'user/' . $this->admin_user->uid => $this->admin_user->name,
- );
- $this->assertBreadcrumb('user/' . $this->admin_user->uid . '/edit', $trail, $this->admin_user->name);
-
-
- $trail = $home;
- $this->assertBreadcrumb('user/' . $this->web_user->uid, $trail, $this->web_user->name);
- $trail += array(
- 'user/' . $this->web_user->uid => $this->web_user->name,
- );
- $this->assertBreadcrumb('user/' . $this->web_user->uid . '/edit', $trail, $this->web_user->name);
-
-
- $this->backdropLogin($this->admin_user);
- $edit = array(
- 'link_title' => $this->admin_user->name . ' link',
- 'link_path' => 'user/' . $this->admin_user->uid,
- );
- $this->backdropPost("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
- $link_admin_user = db_query('SELECT * FROM {menu_links} WHERE link_title = :title AND link_path = :href', array(
- ':title' => $edit['link_title'],
- ':href' => $edit['link_path'],
- ))->fetchAssoc();
-
-
- $this->backdropLogout();
- $trail = $home;
- $tree = array(
- $link_admin_user['link_path'] => $link_admin_user['link_title'],
- );
- $this->assertBreadcrumb('user/' . $this->admin_user->uid, $trail, $link_admin_user['link_title'], $tree);
-
- $this->backdropLogin($this->admin_user);
- $trail += array(
- $link_admin_user['link_path'] => $link_admin_user['link_title'],
- );
- $this->assertBreadcrumb('user/' . $this->admin_user->uid . '/edit', $trail, $link_admin_user['link_title'], $tree, FALSE);
-
-
- $this->backdropLogin($this->admin_user);
-
- $edit = array(
- 'link_title' => $this->admin_user->name . ' edit',
- 'link_path' => 'user/' . $this->admin_user->uid . '/edit',
- );
- $this->backdropPost("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
-
- $link_admin_user_edit = db_query('SELECT * FROM {menu_links} WHERE link_title = :title AND link_path = :href', array(
- ':title' => $edit['link_title'],
- ':href' => $edit['link_path'],
- ))->fetchAssoc();
-
- $edit = array(
- 'parent' => "$menu:{$link_admin_user['mlid']}",
- );
- $this->backdropPost("admin/structure/menu/item/{$link_admin_user_edit['mlid']}/edit", $edit, t('Save'));
-
- $this->backdropLogout();
- $trail = $home;
- $tree += array(
- $link_admin_user['link_path'] => $link_admin_user['link_title'],
- );
-
- $this->backdropLogin($this->admin_user);
- $trail += array(
- $link_admin_user['link_path'] => $link_admin_user['link_title'],
- );
- $this->assertBreadcrumb('user/' . $this->admin_user->uid . '/edit', $trail, $link_admin_user['link_title'], $tree, FALSE);
-
-
-
- $this->web_user = $this->backdropCreateUser(array(
- 'access site reports',
- ));
- $this->backdropLogin($this->web_user);
-
-
-
-
- $trail = $home;
- $this->assertBreadcrumb('admin', $trail, t('Access denied'));
- $this->assertResponse(403);
-
- $this->assertBreadcrumb('admin/reports', $trail, t('Reports'));
- $this->assertNoResponse(403);
-
- $this->assertBreadcrumb('admin/reports/dblog', $trail, t('Recent log messages'));
- $this->assertNoResponse(403);
- }
- }
-
- * Tests active menu trails.
- */
- class MenuTrailTestCase extends MenuWebTestCase {
- protected $admin_user;
-
- function setUp() {
- $modules = func_get_args();
- if (isset($modules[0]) && is_array($modules[0])) {
- $modules = $modules[0];
- }
- $modules[] = 'menu_test';
- parent::setUp($modules);
- $this->admin_user = $this->backdropCreateUser(array('administer site configuration', 'access administration pages'));
- $this->backdropLogin($this->admin_user);
-
-
- $layout = layout_load('default');
- $layout->addBlock('system', 'management', 'content');
- $layout->save();
-
-
- $layout = layout_load('admin_default');
- $layout->addBlock('system', 'management', 'content');
- $layout->addBlock('system', 'main-menu', 'content');
- $layout->save();
-
- $layout = layout_load('default');
-
- $menu_uuid = $layout->positions['header'][1];
- $menu_block = $layout->content[$menu_uuid];
-
-
- $menu_block->settings['block_settings']['level'] = 1;
- $menu_block->settings['block_settings']['depth'] = 0;
-
-
- $layout->save();
- }
-
-
- * Tests active trails are properly affected by menu_tree_set_path().
- */
- function testMenuTreeSetPath() {
- $home = array('<front>' => 'Home');
- $config_tree = array(
- 'admin' => t('Administration'),
- 'admin/config' => t('Configuration'),
- );
- $config = $home + $config_tree;
-
-
-
-
- $test_menu_path = array(
- 'menu_name' => 'management',
- 'path' => 'admin/config/system/site-information',
- );
-
- $breadcrumb = $home + array(
- 'menu-test' => t('Menu test root'),
- );
- $tree = array(
- 'menu-test' => t('Menu test root'),
- 'menu-test/menu-trail' => t('Menu trail - Case 1'),
- );
-
-
- state_del('menu_test_menu_tree_set_path');
- $this->assertBreadcrumb('menu-test/menu-trail', $breadcrumb, t('Menu trail - Case 1'), $tree);
-
-
-
- state_set('menu_test_menu_tree_set_path', $test_menu_path);
- $this->assertBreadcrumb('menu-test/menu-trail', $breadcrumb, t('Menu trail - Case 1'), $tree);
-
- $breadcrumb = $config + array(
- 'admin/config/development' => t('Development'),
- );
- $tree = $config_tree + array(
- 'admin/config/development' => t('Development'),
- 'admin/config/development/menu-trail' => t('Menu trail - Case 2'),
- );
-
- $override_breadcrumb = $config + array(
- 'admin/config/system' => t('System'),
- 'admin/config/system/site-information' => t('Site information'),
- );
- $override_tree = $config_tree + array(
- 'admin/config/system' => t('System'),
- 'admin/config/system/site-information' => t('Site information'),
- );
-
-
- state_del('menu_test_menu_tree_set_path');
- $this->assertBreadcrumb('admin/config/development/menu-trail', $breadcrumb, t('Menu trail - Case 2'), $tree);
-
-
-
- state_set('menu_test_menu_tree_set_path', $test_menu_path);
- $this->assertBreadcrumb('admin/config/development/menu-trail', $override_breadcrumb, t('Menu trail - Case 2'), $override_tree);
- }
-
-
- * Tests that the active trail works correctly on custom 403 and 404 pages.
- */
- function testCustom403And404Pages() {
-
- config('system.core')
- ->set('site_403', 'menu-test/custom-403-page')
- ->set('site_404', 'menu-test/custom-404-page')
- ->save();
-
-
-
- $paths = array(
- 403 => 'admin/config',
- 404 => $this->randomName(),
- );
-
-
-
- $expected_trail[403]['initial'] = array(
- '<front>' => 'Home',
- 'admin/config' => 'Configuration',
- );
- $expected_trail[403]['final'] = array(
- '<front>' => 'Home',
- 'menu-test' => 'Menu test root',
- 'menu-test/custom-403-page' => 'Custom 403 page',
- );
-
-
-
-
-
- $expected_trail[404]['initial'] = array(
- '<front>' => 'Home',
- );
- $expected_trail[404]['final'] = array(
- '<front>' => 'Home',
- 'menu-test' => 'Menu test root',
- 'menu-test/custom-404-page' => 'Custom 404 page',
- );
-
-
-
- $this->backdropLogout();
- foreach (array(403, 404) as $status_code) {
-
-
- state_set('menu_test_record_active_trail', TRUE);
- $this->backdropGet($paths[$status_code]);
- $this->assertResponse($status_code);
-
-
-
- $initial_trail = state_get('menu_test_active_trail_initial', array());
- $this->assertEqual(count($initial_trail), count($expected_trail[$status_code]['initial']), format_string('The initial active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
- '@status_code' => $status_code,
- '@expected' => count($expected_trail[$status_code]['initial']),
- '@found' => count($initial_trail),
- )));
- foreach (array_keys($expected_trail[$status_code]['initial']) as $index => $path) {
- $this->assertEqual($initial_trail[$index]['href'], $path, format_string('Element number @number of the initial active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
- '@number' => $index + 1,
- '@status_code' => $status_code,
- '@expected' => $path,
- '@found' => $initial_trail[$index]['href'],
- )));
- }
-
-
-
- $final_trail = state_get('menu_test_active_trail_final', array());
- $this->assertEqual(count($final_trail), count($expected_trail[$status_code]['final']), format_string('The final active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
- '@status_code' => $status_code,
- '@expected' => count($expected_trail[$status_code]['final']),
- '@found' => count($final_trail),
- )));
- foreach (array_keys($expected_trail[$status_code]['final']) as $index => $path) {
- $this->assertEqual($final_trail[$index]['href'], $path, format_string('Element number @number of the final active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
- '@number' => $index + 1,
- '@status_code' => $status_code,
- '@expected' => $path,
- '@found' => $final_trail[$index]['href'],
- )));
- }
-
-
-
-
-
- array_pop($expected_trail[$status_code]['final']);
- $this->assertBreadcrumb(NULL, $expected_trail[$status_code]['final']);
- }
- }
- }
-
- * Tests menu changes.
- */
- class MenuChangeTestCase extends MenuWebTestCase {
-
- * Set up testing environment.
- */
- public function setUp() {
- parent::setUp('menu_test');
- }
-
-
- * Test that updating the type of a menu item works correctly.
- */
- public function testMenuChangeTypeTestCase() {
-
- $sql = "SELECT type FROM {menu_links}, {menu_router} WHERE {menu_links}.router_path = {menu_router}.path AND {menu_links}.router_path = 'menu-test/changes'";
- $type = db_query($sql)->fetchField();
- $this->assertEqual($type, MENU_NORMAL_ITEM, t('Menu item exists and is type MENU_NORMAL_ITEM.'));
-
-
- menu_test_change_menu_type('callback');
- menu_rebuild();
-
- $result = db_query($sql)->rowCount();
- $this->assertEqual($result, 0, t('Menu item no longer exists in menu_links table after menu_rebuild.'));
- }
-
- }