Commit bb253b05 authored by Dries's avatar Dries

- Patch #423690 by Berdir: fixed bug in menu_link_maintain(). With tests.

parent a8597119
......@@ -2349,9 +2349,10 @@ function menu_link_maintain($module, $op, $link_path, $link_title) {
->condition('link_path', $link_path)
->condition('customized', 0)
->condition('module', $module)
->execute();
foreach ($result as $item) {
menu_cache_clear($item['menu_name']);
->groupBy('menu_name')
->execute()->fetchCol();
foreach ($result as $menu_name) {
menu_cache_clear($menu_name);
}
break;
case 'delete':
......
......@@ -29,6 +29,52 @@ class MenuIncTestCase extends DrupalWebTestCase {
$this->assertNoText(t('A title with @placeholder', array('@placeholder' => 'some other text')), t('Text with placeholder substitutions not found.'));
}
/**
* Tests for menu_link_maintain().
*/
function testMenuLinkMaintain() {
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
// Create three menu items.
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');
// Move second link to the main-menu, to test caching later on.
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');
// Load front page.
$this->drupalGet('node');
$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');
// Rename all links for the given path.
menu_link_maintain('menu_test', 'update', 'menu_test_maintain/1', 'Menu link updated');
// Load a different page to be sure that we have up to date information.
$this->drupalGet('menu_test_maintain/1');
$this->assertLink(t('Menu link updated'), 0, t('Found updated menu link'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1-1'));
$this->assertLink(t('Menu link #2'), 0, t('Found menu link #2'));
// Delete all links for the given path.
menu_link_maintain('menu_test', 'delete', 'menu_test_maintain/1', '');
// Load a different page to be sure that we have up to date information.
$this->drupalGet('menu_test_maintain/2');
$this->assertNoLink(t('Menu link updated'), 0, t('Not found deleted menu link'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1-1'));
$this->assertLink(t('Menu link #2'), 0, t('Found menu link #2'));
}
/**
* Tests for menu_name parameter for hook_menu().
*/
......
......@@ -25,6 +25,12 @@ function menu_test_menu() {
'access arguments' => array('access content'),
);
// Hidden link for menu_link_maintain tests
$items['menu_test_maintain/%'] = array(
'title' => 'Menu maintain test',
'page callback' => 'node_page_default',
'access arguments' => array('access content'),
);
// Hierarchical tests.
$items['menu-test/hierarchy/parent'] = array(
'title' => 'Parent menu router',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment