summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/menu.test
blob: ee2a30a7b0ca0516ddc72817204f53d27c88f0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
// $Id$

/**
 * @file
 * Provides SimpleTests for menu.inc.
 */

class MenuIncTestCase extends DrupalWebTestCase {
  function getInfo() {
    return array(
      'name' => t('Hook menu tests'),
      'description' => t('Test menu hook functionality.'),
      'group' => t('Menu'),
    );
  }

  function setUp() {
    // Enable dummy module that implements hook_menu.
    parent::setUp('menu_test');
  }

  /**
   * Tests for menu_name parameter for hook_menu().
   */
  function testMenuName() {
    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
    $this->drupalLogin($admin_user);

    $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
    $name = db_result(db_query($sql));
    $this->assertEqual($name, 'original', t('Menu name is "original".'));

    // Force a menu rebuild by going to the modules page.
    $this->drupalGet('admin/build/modules', array('query' => array("hook_menu_name" => 'changed')));

    $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
    $name = db_result(db_query($sql));
    $this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.'));
  }
}

/**
 * Tests rebuilding the menu by setting 'menu_rebuild_needed.'
 */
class MenuRebuildTestCase extends DrupalWebTestCase {
  function getInfo() {
    return array(
      'name' => t('Menu rebuild test'),
      'description' => t('Test rebuilding of menu.'),
      'group' => t('Menu'),
    );
  }
  
  /**
   * Test if the 'menu_rebuild_needed' variable triggers a menu_rebuild() call.
   */
  function testMenuRebuildByVariable() {
    // Check if 'admin' path exists.
    $admin_exists = db_result(db_query("SELECT path from {menu_router} WHERE path = 'admin'"));
    $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_result(db_query("SELECT path from {menu_router} WHERE path = 'admin'"));
    $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_result(db_query("SELECT path from {menu_router} WHERE path = 'admin'"));
    $this->assertEqual($admin_exists, 'admin', t("The menu has been rebuilt, the path 'admin' now exists again."));
  }
  
}