diff --git a/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php b/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php new file mode 100644 index 0000000..6220cd4 --- /dev/null +++ b/core/modules/system/src/Tests/Menu/MenuParentChildRelationshipTest.php @@ -0,0 +1,85 @@ +menuLinkManager = \Drupal::service('plugin.manager.menu.link'); + + entity_create('menu', array( + '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 = array( + 'title' => 'Menu link test', + 'provider' => 'menu_test', + 'menu_name' => 'menu_test', + ); + + $node = entity_create('node', array('type' => 'page', 'title' => 'Test Title')); + $node->save(); + + $parent = $base_options + array( + 'link' => [['uri' => 'entity:node/' . $node->id()]], + ); + + $link = entity_create('menu_link_content', $parent); + $link->save(); + $links['parent'] = $link->getPluginId(); + + $child = $base_options + array( + 'link' => [['uri' => 'internal:/admin/content/files']], + 'parent' => $links['parent'], + ); + $link = entity_create('menu_link_content', $child); + $link->save(); + $links['child'] = $link->getPluginId(); + + \Drupal::service('plugin.manager.menu.link')->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.', array('%id' => $links['child'], '%parent' => $child_menu->getParent(), '%expected_parent' => $links['parent']))); + } + +}