Beispiel #1
0
 /**
  * Tests menu functionality using the admin and user interfaces.
  */
 function testMenu()
 {
     // Login the user.
     $this->drupalLogin($this->admin_user);
     $this->items = array();
     $this->menu = $this->addCustomMenu();
     $this->doMenuTests();
     $this->addInvalidMenuLink();
     $this->addCustomMenuCRUD();
     // Verify that the menu links rebuild is idempotent and leaves the same
     // number of links in the table.
     $before_count = db_query('SELECT COUNT(*) FROM {menu_links}')->fetchField();
     menu_link_rebuild_defaults();
     $after_count = db_query('SELECT COUNT(*) FROM {menu_links}')->fetchField();
     $this->assertIdentical($before_count, $after_count, 'menu_link_rebuild_defaults() does not add more links');
     // Do standard user tests.
     // Login the user.
     $this->drupalLogin($this->authenticated_user);
     $this->verifyAccess(403);
     foreach ($this->items as $item) {
         // Paths were set as 'node/$nid'.
         $node = node_load(substr($item['link_path'], 5));
         $this->verifyMenuLink($item, $node);
     }
     // Login the administrator.
     $this->drupalLogin($this->admin_user);
     // Delete menu links.
     foreach ($this->items as $item) {
         $this->deleteMenuLink($item);
     }
     // Delete custom menu.
     $this->deleteCustomMenu();
     // Modify and reset a standard menu link.
     $item = $this->getStandardMenuLink();
     $old_title = $item['link_title'];
     $this->modifyMenuLink($item);
     $item = entity_load('menu_link', $item['mlid']);
     // Verify that a change to the description is saved.
     $description = $this->randomName(16);
     $item['options']['attributes']['title'] = $description;
     $return_value = menu_link_save($item);
     // Save the menu link again to test the return value of the procedural save
     // helper.
     $this->assertIdentical($return_value, $item->save(), 'Return value of menu_link_save() is identical to the return value of $menu_link->save().');
     $saved_item = entity_load('menu_link', $item['mlid']);
     $this->assertEqual($description, $saved_item['options']['attributes']['title'], 'Saving an existing link updates the description (title attribute)');
     $this->resetMenuLink($item, $old_title);
 }
 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             menu_link_rebuild_defaults();
             // Clear the menu cache.
             menu_cache_clear_all();
             // Track which menu items are expanded.
             _menu_update_expanded_menus();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }
Beispiel #3
0
 /**
  * Tests uninstall a module providing default links.
  */
 public function testModuleUninstalledMenuLinks()
 {
     \Drupal::moduleHandler()->install(array('menu_test'));
     \Drupal::service('router.builder')->rebuild();
     menu_link_rebuild_defaults();
     $result = $menu_link = \Drupal::entityQuery('menu_link')->condition('machine_name', 'menu_test')->execute();
     $menu_links = \Drupal::entityManager()->getStorage('menu_link')->loadMultiple($result);
     $this->assertEqual(count($menu_links), 1);
     $menu_link = reset($menu_links);
     $this->assertEqual($menu_link->machine_name, 'menu_test');
     // Uninstall the module and ensure the menu link got removed.
     \Drupal::moduleHandler()->uninstall(array('menu_test'));
     $result = $menu_link = \Drupal::entityQuery('menu_link')->condition('machine_name', 'menu_test')->execute();
     $menu_links = \Drupal::entityManager()->getStorage('menu_link')->loadMultiple($result);
     $this->assertEqual(count($menu_links), 0);
 }