You are here

function MenuModuleReset::testMenuModuleReset in SimpleTest 6

File

tests/menu_module.test, line 201

Class

MenuModuleReset

Code

function testMenuModuleReset() {
  $web_user = $this
    ->drupalCreateUserRolePerm(array(
    'administer menu',
  ));
  $this
    ->drupalLoginUser($web_user);
  $form_state = array();
  $menu['menu_name'] = 'navigation';
  require_once drupal_get_path('module', 'menu') . '/menu.admin.inc';
  $form = drupal_retrieve_form('menu_overview_form', $form_state, $menu);
  $found = FALSE;
  foreach ($form as $mlid => $elements) {
    if (isset($elements['#item']) && $elements['#item']['module'] == 'system') {
      $found = TRUE;
      $mlid = substr($mlid, 5);
      break;
    }
  }
  $this
    ->assertTrue($found, 'System module item found');
  if ($found) {

    // We can't use menu API here because of localization issues.
    $item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid));
    $edit['menu[link_title]'] = $this
      ->randomName(16);
    $path = 'admin/build/menu/item/' . $mlid;
    $this
      ->drupalPost($path . '/edit', $edit, 'Save');
    $new_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid));
    $this
      ->assertTrue($new_title == $edit['menu[link_title]'], 'Edit succesful');
    $this
      ->assertFalse($item['link_title'] == $new_title, 'Item changed');
    $reset_path = $path . '/reset';
    $this
      ->assertWantedRaw($reset_path, 'Reset link found');
    $this
      ->drupalPost($reset_path, array(), 'Reset');
    $reset_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid));
    $this
      ->assertFalse($edit['menu[link_title]'] == $reset_title, 'Item reset');
    $this
      ->assertText(t('The menu item was reset to its default settings.'), 'Reset message');
    drupal_write_record('menu_links', $item, 'mlid');
    $restored_item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid));
    $this
      ->assertTrue($item == $restored_item, 'Item restored');
  }
}