You are here

function MenuRebuildTestCase::testMenuRebuildByVariable in SimpleTest 7

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

File

tests/menu.test, line 262
Provides SimpleTests for menu.inc.

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', t("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, t("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', t("The menu has been rebuilt, the path 'admin' now exists again."));
}