function MenuRebuildTestCase::testMenuRebuildByVariable

Test if the 'menu_rebuild_needed' variable triggers a menu_rebuild() call.

File

modules/simpletest/tests/menu.test, line 905

Class

MenuRebuildTestCase
Tests rebuilding the menu by setting 'menu_rebuild_needed.'

Code

function testMenuRebuildByVariable() {
    // Check if 'admin' path exists.
    $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.");
    // Delete the path item 'admin', and test that the path doesn't exist in the database.
    $delete = 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.");
    // Now we enable the rebuild variable and trigger menu_execute_active_handler()
    // to rebuild the menu item. Now 'admin' should exist.
    variable_set('menu_rebuild_needed', TRUE);
    // menu_execute_active_handler() should trigger the rebuild.
    $this->drupalGet('<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.");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.