1 menu.test MenuRebuildTestCase::testMenuRebuildByVariable()

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

File

core/modules/simpletest/tests/menu.test, line 800
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', "The path 'admin/' exists prior to deleting.");

  // Delete the path item 'admin', and test that the path doesn't exist in the database.
  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.
  state_set('menu_rebuild_needed', TRUE);
  // menu_execute_active_handler() should trigger the rebuild.
  $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.");
}