Exemplo n.º 1
0
  /**
   * Tests the Drupal 6 menu to Drupal 8 migration.
   */
  public function testMenu() {
    $navigation_menu = Menu::load('navigation');
    $this->assertSame('navigation', $navigation_menu->id());
    $this->assertSame('Navigation', $navigation_menu->label());
    $expected = <<<EOT
The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.
EOT;
    $this->assertSame($expected, $navigation_menu->getDescription());

    // Test that we can re-import using the ConfigEntityBase destination.
    Database::getConnection('default', 'migrate')
      ->update('menu_custom')
      ->fields(array('title' => 'Home Navigation'))
      ->condition('menu_name', 'navigation')
      ->execute();

    $migration = $this->getMigration('d6_menu');
    \Drupal::database()
        ->truncate($migration->getIdMap()->mapTableName())
        ->execute();
    $this->executeMigration($migration);

    $navigation_menu = Menu::load('navigation');
    $this->assertSame('Home Navigation', $navigation_menu->label());
  }
 /**
  * Tests the Drupal 6 menu to Drupal 8 migration.
  */
 public function testMenu()
 {
     $navigation_menu = Menu::load('navigation');
     $this->assertEqual($navigation_menu->id(), 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Navigation');
     $this->assertEqual($navigation_menu->description, 'The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.');
     // Test that we can re-import using the ConfigEntityBase destination.
     Database::getConnection('default', 'migrate')->update('menu_custom')->fields(array('title' => 'Home Navigation'))->condition('menu_name', 'navigation')->execute();
     db_truncate(entity_load('migration', 'd6_menu')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_menu');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $navigation_menu = entity_load_unchanged('menu', 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Home Navigation');
 }
 /**
  * Tests the MenuLinkContentDeleteForm class.
  */
 public function testMenuLinkContentDeleteForm()
 {
     // Add new menu item.
     $this->drupalPostForm('admin/structure/menu/manage/admin/add', ['title[0][value]' => t('Front page'), 'link[0][uri]' => '<front>'], t('Save'));
     $this->assertText(t('The menu link has been saved.'));
     $menu_link = MenuLinkContent::load(1);
     $this->drupalGet($menu_link->urlInfo('delete-form'));
     $this->assertRaw(t('Are you sure you want to delete the custom menu link %name?', ['%name' => $menu_link->label()]));
     $this->assertLink(t('Cancel'));
     // Make sure cancel link points to link edit
     $this->assertLinkByHref($menu_link->url('edit-form'));
     \Drupal::service('module_installer')->install(['menu_ui']);
     // Make sure cancel URL points to menu_ui route now.
     $this->drupalGet($menu_link->urlInfo('delete-form'));
     $menu = Menu::load($menu_link->getMenuName());
     $this->assertLinkByHref($menu->url('edit-form'));
     $this->drupalPostForm(NULL, [], t('Delete'));
     $this->assertRaw(t('The menu link %title has been deleted.', ['%title' => $menu_link->label()]));
 }
Exemplo n.º 4
0
  /**
   * Tests the Drupal 7 menu to Drupal 8 migration.
   */
  public function testMenu() {
    $this->assertEntity('main', 'Main menu', 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.');
    $this->assertEntity('admin', 'Management', 'The <em>Management</em> menu contains links for administrative tasks.');
    $this->assertEntity('menu-test-menu', 'Test Menu', 'Test menu description.');
    $this->assertEntity('tools', 'Navigation', 'The <em>Navigation</em> menu contains links intended for site visitors. Links are added to the <em>Navigation</em> menu automatically by some modules.');
    $this->assertEntity('account', 'User menu', 'The <em>User</em> menu contains links related to the user\'s account, as well as the \'Log out\' link.');

    // Test that we can re-import using the ConfigEntityBase destination.
    Database::getConnection('default', 'migrate')
      ->update('menu_custom')
      ->fields(array('title' => 'Home Navigation'))
      ->condition('menu_name', 'navigation')
      ->execute();

    $migration = $this->getMigration('d7_menu');
    \Drupal::database()
        ->truncate($migration->getIdMap()->mapTableName())
        ->execute();
    $this->executeMigration($migration);

    $navigation_menu = Menu::load('tools');
    $this->assertSame('Home Navigation', $navigation_menu->label());
  }
Exemplo n.º 5
0
 /**
  * Tests Menu uninstall.
  */
 public function testMenuUninstall()
 {
     \Drupal::service('module_installer')->uninstall(array('menu_ui'));
     \Drupal::entityManager()->getStorage('menu')->resetCache(array('admin'));
     $this->assertTrue(Menu::load('admin'), 'The \'admin\' menu still exists after uninstalling Menu UI module.');
 }
Exemplo n.º 6
0
 /**
  * Deletes the locally stored custom menu.
  *
  * This deletes the custom menu that is stored in $this->menu and performs
  * tests on the menu delete user interface.
  */
 function deleteCustomMenu()
 {
     $menu_name = $this->menu->id();
     $label = $this->menu->label();
     // Delete custom menu.
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}/delete", array(), t('Delete'));
     $this->assertResponse(200);
     $this->assertRaw(t('The menu %title has been deleted.', array('%title' => $label)), 'Custom menu was deleted');
     $this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
     // Test if all menu links associated with the menu were removed from
     // database.
     $result = entity_load_multiple_by_properties('menu_link_content', array('menu_name' => $menu_name));
     $this->assertFalse($result, 'All menu links associated with the custom menu were deleted.');
     // Make sure there's no delete button on system menus.
     $this->drupalGet('admin/structure/menu/manage/main');
     $this->assertNoRaw('edit-delete', 'The delete button was not found');
     // Try to delete the main menu.
     $this->drupalGet('admin/structure/menu/manage/main/delete');
     $this->assertText(t('You are not authorized to access this page.'));
 }
Exemplo n.º 7
0
 /**
  * Deletes custom generated menus
  */
 protected function deleteMenus()
 {
     if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
         foreach (menu_ui_get_menus(FALSE) as $menu => $menu_title) {
             if (strpos($menu, 'devel-') === 0) {
                 Menu::load($menu)->delete();
             }
         }
     }
     // Delete menu links generated by devel.
     $result = db_select('menu_links', 'm')->fields('m', array('mlid'))->condition('m.menu_name', 'devel', '<>')->condition('m.options', '%' . db_like('s:5:"devel";b:1') . '%', 'LIKE')->execute();
     foreach ($result as $link) {
         menu_link_delete($link->mlid);
     }
 }
Exemplo n.º 8
0
 /**
  * Tests menu configuration is still English after English has been deleted.
  */
 function testMenuLanguageRemovedEnglish()
 {
     // Create a test menu to test language settings.
     // Machine name has to be lowercase.
     $menu_name = Unicode::strtolower($this->randomMachineName(16));
     $edit = array('id' => $menu_name, 'description' => '', 'label' => $this->randomString(), 'langcode' => 'en');
     $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
     // Check that the language settings were saved.
     $menu = Menu::load($menu_name);
     $this->assertEqual($menu->language()->getId(), 'en');
     // Remove English language. To do that another language has to be set as
     // default.
     $language = language_load('cs');
     $language->default = TRUE;
     language_save($language);
     language_delete('en');
     // Save the menu again and check if the language is still the same.
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}", array(), t('Save'));
     $menu = Menu::load($menu_name);
     $this->assertEqual($menu->language()->getId(), 'en');
 }
Exemplo n.º 9
0
 /**
  * Responds to GET requests.
  *
  * Returns the menu structure for the given menu name.
  *
  * @param string $menu_name
  *   The menu name.
  *
  * @return \Drupal\rest\ResourceResponse
  *   The response containing the log entry.
  *
  * @TODO: make $menu parameter a type-hinted MenuInterface parameter
  * @TODO: cacheability and access checks for menu links?
  * @TODO: optional whitelist to only allow menu links from defined providers.
  */
 public function get($menu_name)
 {
     $menu = Menu::load($menu_name);
     if ($menu) {
         $tree = $this->menuTree->load($menu->id(), new MenuTreeParameters());
         $result = array_values($tree);
         return new ResourceResponse($result);
     }
     throw new HttpException(t('No valid menu ID was provided.'));
 }
Exemplo n.º 10
0
 /**
  * Deletes custom generated menus
  */
 protected function deleteMenus()
 {
     if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
         foreach (menu_ui_get_menus(FALSE) as $menu => $menu_title) {
             if (strpos($menu, 'devel-') === 0) {
                 Menu::load($menu)->delete();
             }
         }
     }
     // Delete menu links generated by devel.
     $result = db_select('menu_link_content_data', 'm')->fields('m', array('id'))->condition('m.menu_name', 'devel', '<>')->condition('m.link__options', '%' . db_like('s:5:"devel";b:1') . '%', 'LIKE')->execute()->fetchCol();
     if ($result) {
         entity_delete_multiple('menu_link_content', $result);
     }
 }