diff --git a/core/modules/menu_ui/src/Tests/MenuNodeTest.php b/core/modules/menu_ui/src/Tests/MenuNodeTest.php index 3fc8423..a6d7f18 100644 --- a/core/modules/menu_ui/src/Tests/MenuNodeTest.php +++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php @@ -2,7 +2,8 @@ namespace Drupal\menu_ui\Tests; -use Drupal\simpletest\WebTestBase; +use Drupal\Core\Url; +use Drupal\node\Entity\NodeType; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\node\Entity\Node; @@ -12,7 +13,7 @@ * * @group menu_ui */ -class MenuNodeTest extends WebTestBase { +class MenuNodeTest extends MenuWebTestBase { /** * An editor user. @@ -338,4 +339,38 @@ function testMultilingualMenuNodeFormWidget() { $this->assertFieldById('edit-menu-title', $translated_node_title); } + /** + * Tests adding links to nodes using the /node/{uuid} format. + */ + public function testNodeUuidLink() { + /* @var \Drupal\node\NodeTypeInterface $type */ + $type = NodeType::load('page'); + // Enable the main menu for this node type.. + $menu_name = 'main'; + $type->setThirdPartySetting('menu_ui', 'available_menus', [$menu_name]); + $type->save(); + // Test links using node/{uuid}. + $node6 = $this->drupalCreateNode(array('type' => 'page')); + $uuid_link = $this->addMenuLink('', '/node/' . $node6->uuid(), $menu_name); + $this->verifyMenuLink($uuid_link, $node6); + $this->drupalGet($node6->url('edit-form')); + $this->assertFieldByName('menu[title]', $uuid_link->label()); + $this->drupalPostForm(NULL, [], t('Save')); + \Drupal::entityManager()->getStorage('menu_link_content')->resetCache([$uuid_link->id()]); + /** @var \Drupal\menu_link_content\MenuLinkContentInterface $uuid_link */ + $uuid_link = MenuLinkContent::load($uuid_link->id()); + $this->assertEqual($uuid_link->getUrlObject(), Url::fromUri('internal:/node/' . $node6->uuid())); + // Test with entity:node/{uuid}. + $node7 = $this->drupalCreateNode(array('type' => 'page')); + $uuid_link = $this->addMenuLink('', 'entity:node/' . $node7->uuid(), $menu_name); + $this->verifyMenuLink($uuid_link, $node7); + $this->drupalGet($node7->url('edit-form')); + $this->assertFieldByName('menu[title]', $uuid_link->label()); + $this->drupalPostForm(NULL, [], t('Save')); + \Drupal::entityManager()->getStorage('menu_link_content')->resetCache([$uuid_link->id()]); + /** @var \Drupal\menu_link_content\MenuLinkContentInterface $uuid_link */ + $uuid_link = MenuLinkContent::load($uuid_link->id()); + $this->assertEqual($uuid_link->getUrlObject(), Url::fromUri('entity:node/' . $node7->uuid())); + } + } diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 1ce52a5..ecd28ca 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -223,13 +223,6 @@ function addCustomMenu() { $block = $this->drupalPlaceBlock('system_menu_block:' . $menu_name); $this->blockPlacements[$menu_name] = $block->id(); - // Make this menu available for node-edit forms. - /* @var \Drupal\node\NodeTypeInterface $type */ - $type = NodeType::load('article'); - $node_menus = $type->getThirdPartySetting('menu_ui', 'available_menus', array('main')); - $node_menus[] = $menu_name; - $type->setThirdPartySetting('menu_ui', 'available_menus', $node_menus); - $type->save(); return Menu::load($menu_name); } @@ -475,29 +468,6 @@ function doMenuTests() { // Save menu links for later tests. $this->items[] = $item1; $this->items[] = $item2; - - // Test links using node/{uuid}. - $node6 = $this->drupalCreateNode(array('type' => 'article')); - $uuid_link = $this->addMenuLink('', '/node/' . $node6->uuid(), $menu_name); - $this->verifyMenuLink($uuid_link, $node6); - $this->drupalGet($node6->url('edit-form')); - $this->assertFieldByName('menu[title]', $uuid_link->label()); - $this->drupalPostForm(NULL, [], t('Save')); - \Drupal::entityManager()->getStorage('menu_link_content')->resetCache([$uuid_link->id()]); - /** @var \Drupal\menu_link_content\MenuLinkContentInterface $uuid_link */ - $uuid_link = MenuLinkContent::load($uuid_link->id()); - $this->assertEqual($uuid_link->getUrlObject(), Url::fromUri('internal:/node/' . $node6->uuid())); - // Test with entity:node/{uuid}. - $node7 = $this->drupalCreateNode(array('type' => 'article')); - $uuid_link = $this->addMenuLink('', 'entity:node/' . $node7->uuid(), $menu_name); - $this->verifyMenuLink($uuid_link, $node7); - $this->drupalGet($node7->url('edit-form')); - $this->assertFieldByName('menu[title]', $uuid_link->label()); - $this->drupalPostForm(NULL, [], t('Save')); - \Drupal::entityManager()->getStorage('menu_link_content')->resetCache([$uuid_link->id()]); - /** @var \Drupal\menu_link_content\MenuLinkContentInterface $uuid_link */ - $uuid_link = MenuLinkContent::load($uuid_link->id()); - $this->assertEqual($uuid_link->getUrlObject(), Url::fromUri('entity:node/' . $node7->uuid())); } /** @@ -615,55 +585,6 @@ public function testBlockContextualLinks() { } /** - * Adds a menu link using the UI. - * - * @param string $parent - * Optional parent menu link id. - * @param string $path - * The path to enter on the form. Defaults to the front page. - * @param string $menu_name - * Menu name. Defaults to 'tools'. - * @param bool $expanded - * Whether or not this menu link is expanded. Setting this to TRUE should - * test whether it works when we do the authenticatedUser tests. Defaults - * to FALSE. - * @param string $weight - * Menu weight. Defaults to 0. - * - * @return \Drupal\menu_link_content\Entity\MenuLinkContent - * A menu link entity. - */ - function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') { - // View add menu link page. - $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); - $this->assertResponse(200); - - $title = '!link_' . $this->randomMachineName(16); - $edit = array( - 'link[0][uri]' => $path, - 'title[0][value]' => $title, - 'description[0][value]' => '', - 'enabled[value]' => 1, - 'expanded[value]' => $expanded, - 'menu_parent' => $menu_name . ':' . $parent, - 'weight[0][value]' => $weight, - ); - - // Add menu link. - $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertResponse(200); - $this->assertText('The menu link has been saved.'); - - $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $title)); - - $menu_link = reset($menu_links); - $this->assertTrue($menu_link, 'Menu link was found in database.'); - $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'children' => array(), 'parent' => $parent)); - - return $menu_link; - } - - /** * Attempts to add menu link with invalid path or no access permission. */ function addInvalidMenuLink() { @@ -720,45 +641,6 @@ function checkInvalidParentMenuLinks() { } /** - * Verifies a menu link using the UI. - * - * @param \Drupal\menu_link_content\Entity\MenuLinkContent $item - * Menu link. - * @param object $item_node - * Menu link content node. - * @param \Drupal\menu_link_content\Entity\MenuLinkContent $parent - * Parent menu link. - * @param object $parent_node - * Parent menu link content node. - */ - function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) { - // View home page. - $this->drupalGet(''); - $this->assertResponse(200); - - // Verify parent menu link. - if (isset($parent)) { - // Verify menu link. - $title = $parent->getTitle(); - $this->assertLink($title, 0, 'Parent menu link was displayed'); - - // Verify menu link link. - $this->clickLink($title); - $title = $parent_node->label(); - $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Parent menu link link target was correct'); - } - - // Verify menu link. - $title = $item->getTitle(); - $this->assertLink($title, 0, 'Menu link was displayed'); - - // Verify menu link link. - $this->clickLink($title); - $title = $item_node->label(); - $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Menu link link target was correct'); - } - - /** * Changes the parent of a menu link using the UI. * * @param \Drupal\menu_link_content\MenuLinkContentInterface $item diff --git a/core/modules/menu_ui/src/Tests/MenuWebTestBase.php b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php index c08fc14..e45068e 100644 --- a/core/modules/menu_ui/src/Tests/MenuWebTestBase.php +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\menu_ui\Tests; +use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\simpletest\WebTestBase; /** @@ -74,4 +75,97 @@ function assertMenuLink($menu_plugin_id, array $expected_item) { } } + /** + * Adds a menu link using the UI. + * + * @param string $parent + * Optional parent menu link id. + * @param string $path + * The path to enter on the form. Defaults to the front page. + * @param string $menu_name + * Menu name. Defaults to 'tools'. + * @param bool $expanded + * Whether or not this menu link is expanded. Setting this to TRUE should + * test whether it works when we do the authenticatedUser tests. Defaults + * to FALSE. + * @param string $weight + * Menu weight. Defaults to 0. + * + * @return \Drupal\menu_link_content\Entity\MenuLinkContent + * A menu link entity. + */ + public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') { + // View add menu link page. + $this->drupalGet("admin/structure/menu/manage/$menu_name/add"); + $this->assertResponse(200); + + $title = '!link_' . $this->randomMachineName(16); + $edit = array( + 'link[0][uri]' => $path, + 'title[0][value]' => $title, + 'description[0][value]' => '', + 'enabled[value]' => 1, + 'expanded[value]' => $expanded, + 'menu_parent' => $menu_name . ':' . $parent, + 'weight[0][value]' => $weight, + ); + + // Add menu link. + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertResponse(200); + $this->assertText('The menu link has been saved.'); + + $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $title)); + + $menu_link = reset($menu_links); + $this->assertTrue($menu_link, 'Menu link was found in database.'); + $this->assertMenuLink($menu_link->getPluginId(), [ + 'menu_name' => $menu_name, + 'children' => [], + 'parent' => $parent, + ]); + + return $menu_link; + } + + + /** + * Verifies a menu link using the UI. + * + * @param \Drupal\menu_link_content\Entity\MenuLinkContent $item + * Menu link. + * @param object $item_node + * Menu link content node. + * @param \Drupal\menu_link_content\Entity\MenuLinkContent $parent + * Parent menu link. + * @param object $parent_node + * Parent menu link content node. + */ + public function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) { + // View home page. + $this->drupalGet(''); + $this->assertResponse(200); + + // Verify parent menu link. + if (isset($parent)) { + // Verify menu link. + $title = $parent->getTitle(); + $this->assertLink($title, 0, 'Parent menu link was displayed'); + + // Verify menu link link. + $this->clickLink($title); + $title = $parent_node->label(); + $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Parent menu link link target was correct'); + } + + // Verify menu link. + $title = $item->getTitle(); + $this->assertLink($title, 0, 'Menu link was displayed'); + + // Verify menu link link. + $this->clickLink($title); + $title = $item_node->label(); + $this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Menu link link target was correct'); + } + }