MenuRebuildTestCase::testMenuRebuildByVariable

7 menu.test MenuRebuildTestCase::testMenuRebuildByVariable()
8 menu.test MenuRebuildTestCase::testMenuRebuildByVariable()

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

File

modules/simpletest/tests/menu.test, line 905
Provides SimpleTests for menu.inc.

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."));
}
Login or register to post comments