diff --git a/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php b/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php deleted file mode 100644 index c56b5d3..0000000 --- a/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php +++ /dev/null @@ -1,94 +0,0 @@ -installSchema('system', ['router']); - $this->installEntitySchema('node'); - $this->installEntitySchema('user'); - $this->installEntitySchema('menu_link_content'); - - $this->menuLinkManager = \Drupal::service('plugin.manager.menu.link'); - - Menu::create([ - 'id' => 'menu_test', - 'label' => 'Test menu', - 'description' => 'Description text', - ])->save(); - } - - /** - * Tests creating links with the path created using views and test - * relationship on rebuild. - */ - public function testParentChildRelationshipOnMenuRebuild() { - $this->menuLinkManager->deleteLinksInMenu('menu_test'); - $base_options = [ - 'title' => 'Menu link test', - 'provider' => 'menu_test', - 'menu_name' => 'menu_test', - ]; - - $node = Node::create(['type' => 'page', 'title' => 'Test Title']); - $node->save(); - - $parent = $base_options + [ - 'link' => [['uri' => 'entity:node/' . $node->id()]], - ]; - - $link = MenuLinkContent::create($parent); - $link->save(); - $links['parent'] = $link->getPluginId(); - - $child = $base_options + [ - 'link' => [['uri' => 'internal:/admin/content/files']], - 'parent' => $links['parent'], - ]; - $link = MenuLinkContent::create($child); - $link->save(); - $links['child'] = $link->getPluginId(); - - $this->menuLinkManager->rebuild(); - - $child_menu = $this->menuLinkManager->createInstance($links['child']); - $this->assertEqual($child_menu->getParent(), $links['parent'], SafeMarkup::format('Menu link %id has parent %parent, expected %expected_parent.', ['%id' => $links['child'], '%parent' => $child_menu->getParent(), '%expected_parent' => $links['parent']])); - } - -} diff --git a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php index 1df4050..52f4722 100644 --- a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php +++ b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php @@ -8,9 +8,13 @@ namespace Drupal\system\Tests\Menu; use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Menu\MenuTreeStorage; +use Drupal\menu_link_content\Entity\MenuLinkContent; +use Drupal\node\Entity\Node; use Drupal\simpletest\KernelTestBase; +use Drupal\system\Entity\Menu; /** * Tests the menu tree storage. @@ -36,11 +40,18 @@ class MenuTreeStorageTest extends KernelTestBase { protected $connection; /** + * The menu link plugin manager. + * + * @var \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager + */ + protected $menuLinkManager; + + /** * Modules to enable. * * @var array */ - public static $modules = array('system'); + public static $modules = array('system', 'link', 'node', 'menu_link_content', 'user'); /** * {@inheritdoc} @@ -50,6 +61,20 @@ protected function setUp() { $this->treeStorage = new MenuTreeStorage($this->container->get('database'), $this->container->get('cache.menu'), $this->container->get('cache_tags.invalidator'), 'menu_tree'); $this->connection = $this->container->get('database'); + + $this->installSchema('system', ['router']); + $this->installEntitySchema('node'); + $this->installEntitySchema('user'); + $this->installEntitySchema('menu_link_content'); + + $this->menuLinkManager = \Drupal::service('plugin.manager.menu.link'); + + Menu::create([ + 'id' => 'menu_test', + 'label' => 'Test menu', + 'description' => 'Description text', + ])->save(); + } /** @@ -432,4 +457,38 @@ protected function assertMenuLink($id, array $expected_properties, array $parent $this->assertEqual(array_intersect($children, $found_children), $children, 'Child IDs match'); } + /** + * Tests creating links with the path created using views and test + * relationship on rebuild. + */ + public function testParentChildRelationshipOnMenuRebuild() { + $this->menuLinkManager->deleteLinksInMenu('menu_test'); + $base_options = [ + 'title' => 'Menu link test', + 'provider' => 'menu_test', + 'menu_name' => 'menu_test', + ]; + + $parent = $base_options + [ + 'link' => [['uri' => 'entity:admin/structure/types']], + ]; + + $link = MenuLinkContent::create($parent); + $link->save(); + $links['parent'] = $link->getPluginId(); + + $child = $base_options + [ + 'link' => [['uri' => 'internal:/admin/content']], + 'parent' => $links['parent'], + ]; + $link = MenuLinkContent::create($child); + $link->save(); + $links['child'] = $link->getPluginId(); + + $this->menuLinkManager->rebuild(); + + $child_menu = $this->menuLinkManager->createInstance($links['child']); + $this->assertEqual($child_menu->getParent(), $links['parent'], SafeMarkup::format('Menu link %id has parent %parent, expected %expected_parent.', ['%id' => $links['child'], '%parent' => $child_menu->getParent(), '%expected_parent' => $links['parent']])); + } + }