diff --git a/core/modules/menu_ui/src/Tests/MenuWebTestBase.php b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php new file mode 100644 index 0000000000..79101d442f --- /dev/null +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php @@ -0,0 +1,41 @@ +phpUnitAssertMenuLink($expected_item, $menu_plugin_id); + } + +} diff --git a/core/modules/menu_ui/tests/src/Functional/MenuLanguageTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiLanguageTest.php similarity index 90% rename from core/modules/menu_ui/tests/src/Functional/MenuLanguageTest.php rename to core/modules/menu_ui/tests/src/Functional/MenuUiLanguageTest.php index efdf3a988d..ee9374141b 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuLanguageTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiLanguageTest.php @@ -5,6 +5,8 @@ use Drupal\Component\Utility\Unicode; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ContentLanguageSettings; +use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\menu_ui\Traits\MenuUiTrait; /** * Tests for menu_ui language settings. @@ -14,14 +16,20 @@ * * @group menu_ui */ -class MenuLanguageTest extends MenuWebTestBase { +class MenuUiLanguageTest extends BrowserTestBase { + + use MenuUiTrait; /** * Modules to enable. * * @var array */ - public static $modules = ['language']; + protected static $modules = [ + 'language', + 'menu_link_content', + 'menu_ui', + ]; protected function setUp() { parent::setUp(); @@ -73,11 +81,11 @@ public function testMenuLanguage() { // Check the link was added with the correct menu link default language. $menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); $menu_link = reset($menu_links); - $this->assertMenuLink($menu_link->getPluginId(), [ + $this->assertMenuLink([ 'menu_name' => $menu_name, 'route_name' => '', 'langcode' => 'bb', - ]); + ], $menu_link->getPluginId()); // Edit menu link default, changing it to cc. ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content') @@ -95,22 +103,22 @@ public function testMenuLanguage() { // Check the link was added with the correct new menu link default language. $menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); $menu_link = reset($menu_links); - $this->assertMenuLink($menu_link->getPluginId(), [ + $this->assertMenuLink([ 'menu_name' => $menu_name, 'route_name' => '', 'langcode' => 'cc', - ]); + ], $menu_link->getPluginId()); // Now change the language of the new link to 'bb'. $edit = [ 'langcode[0][value]' => 'bb', ]; $this->drupalPostForm('admin/structure/menu/item/' . $menu_link->id() . '/edit', $edit, t('Save')); - $this->assertMenuLink($menu_link->getPluginId(), [ + $this->assertMenuLink([ 'menu_name' => $menu_name, 'route_name' => '', 'langcode' => 'bb', - ]); + ], $menu_link->getPluginId()); // Saving menu link items ends up on the edit menu page. To check the menu // link has the correct language default on edit, go to the menu link edit diff --git a/core/modules/menu_ui/tests/src/Functional/MenuNodeTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php similarity index 99% rename from core/modules/menu_ui/tests/src/Functional/MenuNodeTest.php rename to core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php index 3288bcc8a9..7e22bcb46d 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuNodeTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiNodeTest.php @@ -12,7 +12,7 @@ * * @group menu_ui */ -class MenuNodeTest extends BrowserTestBase { +class MenuUiNodeTest extends BrowserTestBase { /** * An editor user. diff --git a/core/modules/menu_ui/tests/src/Functional/MenuTest.php b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php similarity index 92% rename from core/modules/menu_ui/tests/src/Functional/MenuTest.php rename to core/modules/menu_ui/tests/src/Functional/MenuUiTest.php index af9caa1bea..c03fb2f275 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuTest.php +++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\menu_ui\Functional; use Drupal\block\Entity\Block; -use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Unicode; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Menu\MenuLinkInterface; @@ -12,6 +11,8 @@ use Drupal\system\Entity\Menu; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; +use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\menu_ui\Traits\MenuUiTrait; /** * Add a custom menu, add menu links to the custom menu and Tools menu, check @@ -19,14 +20,25 @@ * * @group menu_ui */ -class MenuTest extends MenuWebTestBase { +class MenuUiTest extends BrowserTestBase { + + use MenuUiTrait; /** * Modules to enable. * * @var array */ - public static $modules = ['node', 'block', 'contextual', 'help', 'path', 'test_page_test']; + protected static $modules = [ + 'block', + 'contextual', + 'help', + 'menu_link_content', + 'menu_ui', + 'node', + 'path', + 'test_page_test', + ]; /** * A user with administration rights. @@ -311,25 +323,25 @@ public function doMenuTests() { // -- item2 // --- item3 - $this->assertMenuLink($item1->getPluginId(), [ + $this->assertMenuLink([ 'children' => [$item2->getPluginId(), $item3->getPluginId()], 'parents' => [$item1->getPluginId()], // We assert the language code here to make sure that the language // selection element degrades gracefully without the Language module. 'langcode' => 'en', - ]); - $this->assertMenuLink($item2->getPluginId(), [ + ], $item1->getPluginId()); + $this->assertMenuLink([ 'children' => [$item3->getPluginId()], 'parents' => [$item2->getPluginId(), $item1->getPluginId()], // See above. 'langcode' => 'en', - ]); - $this->assertMenuLink($item3->getPluginId(), [ + ], $item2->getPluginId()); + $this->assertMenuLink([ 'children' => [], 'parents' => [$item3->getPluginId(), $item2->getPluginId(), $item1->getPluginId()], // See above. 'langcode' => 'en', - ]); + ], $item3->getPluginId()); // Verify menu links. $this->verifyMenuLink($item1, $node1); @@ -351,18 +363,18 @@ public function doMenuTests() { // -- item5 // -- item6 - $this->assertMenuLink($item4->getPluginId(), [ + $this->assertMenuLink([ 'children' => [$item5->getPluginId(), $item6->getPluginId()], 'parents' => [$item4->getPluginId()], // See above. 'langcode' => 'en', - ]); - $this->assertMenuLink($item5->getPluginId(), [ + ], $item4->getPluginId()); + $this->assertMenuLink([ 'children' => [], 'parents' => [$item5->getPluginId(), $item4->getPluginId()], 'langcode' => 'en', - ]); - $this->assertMenuLink($item6->getPluginId(), [ + ], $item5->getPluginId()); + $this->assertMenuLink([ 'children' => [], 'parents' => [$item6->getPluginId(), $item4->getPluginId()], 'route_name' => 'entity.node.canonical', @@ -370,7 +382,7 @@ public function doMenuTests() { 'url' => '', // See above. 'langcode' => 'en', - ]); + ], $item6->getPluginId()); // Modify menu links. $this->modifyMenuLink($item1); @@ -391,37 +403,37 @@ public function doMenuTests() { // ---- item3 // -- item6 - $this->assertMenuLink($item1->getPluginId(), [ + $this->assertMenuLink([ 'children' => [], 'parents' => [$item1->getPluginId()], // See above. 'langcode' => 'en', - ]); - $this->assertMenuLink($item4->getPluginId(), [ + ], $item1->getPluginId()); + $this->assertMenuLink([ 'children' => [$item5->getPluginId(), $item6->getPluginId(), $item2->getPluginId(), $item3->getPluginId()], 'parents' => [$item4->getPluginId()], // See above. 'langcode' => 'en', - ]); + ], $item4->getPluginId()); - $this->assertMenuLink($item5->getPluginId(), [ + $this->assertMenuLink([ 'children' => [$item2->getPluginId(), $item3->getPluginId()], 'parents' => [$item5->getPluginId(), $item4->getPluginId()], // See above. 'langcode' => 'en', - ]); - $this->assertMenuLink($item2->getPluginId(), [ + ], $item5->getPluginId()); + $this->assertMenuLink([ 'children' => [$item3->getPluginId()], 'parents' => [$item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()], // See above. 'langcode' => 'en', - ]); - $this->assertMenuLink($item3->getPluginId(), [ + ], $item2->getPluginId()); + $this->assertMenuLink([ 'children' => [], 'parents' => [$item3->getPluginId(), $item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()], // See above. 'langcode' => 'en', - ]); + ], $item3->getPluginId()); // Add 102 menu links with increasing weights, then make sure the last-added // item's weight doesn't get changed because of the old hardcoded delta=50. @@ -429,7 +441,7 @@ public function doMenuTests() { for ($i = -50; $i <= 51; $i++) { $items[$i] = $this->addMenuLink('', '/node/' . $node1->id(), $menu_name, TRUE, strval($i)); } - $this->assertMenuLink($items[51]->getPluginId(), ['weight' => '51']); + $this->assertMenuLink(['weight' => '51'], $items[51]->getPluginId()); // Disable a link and then re-enable the link via the overview form. $this->disableMenuLink($item1); @@ -447,15 +459,15 @@ public function doMenuTests() { $item5->save(); // Verify in the database. - $this->assertMenuLink($item1->getPluginId(), ['enabled' => 1]); + $this->assertMenuLink(['enabled' => 1], $item1->getPluginId()); // Add an external link. $item7 = $this->addMenuLink('', 'https://www.drupal.org', $menu_name); - $this->assertMenuLink($item7->getPluginId(), ['url' => 'https://www.drupal.org']); + $this->assertMenuLink(['url' => 'https://www.drupal.org'], $item7->getPluginId()); // Add menu item. $item8 = $this->addMenuLink('', '/', $menu_name); - $this->assertMenuLink($item8->getPluginId(), ['route_name' => '']); + $this->assertMenuLink(['route_name' => ''], $item8->getPluginId()); $this->drupalGet(''); $this->assertResponse(200); // Make sure we get routed correctly. @@ -605,7 +617,7 @@ public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $ex $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]); + $this->assertMenuLink(['menu_name' => $menu_name, 'children' => [], 'parent' => $parent], $menu_link->getPluginId()); return $menu_link; } @@ -819,7 +831,7 @@ public function disableMenuLink(MenuLinkContent $item) { // Unlike most other modules, there is no confirmation message displayed. // Verify in the database. - $this->assertMenuLink($item->getPluginId(), ['enabled' => 0]); + $this->assertMenuLink(['enabled' => 0], $item->getPluginId()); } /** @@ -834,7 +846,7 @@ public function enableMenuLink(MenuLinkContent $item) { $this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save')); // Verify in the database. - $this->assertMenuLink($item->getPluginId(), ['enabled' => 1]); + $this->assertMenuLink(['enabled' => 1], $item->getPluginId()); } /** @@ -899,6 +911,22 @@ private function verifyAccess($response = 200) { } /** + * Tests if admin users, other than UID1, can access parents AJAX callback. + */ + public function testMenuParentsJsAccess() { + $this->drupalLogin($this->drupalCreateUser(['administer menu'])); + // Just check access to the callback overall, the POST data is irrelevant. + $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); + $this->assertSession()->statusCodeEquals(200); + + // Log in as authenticated user. + $this->drupalLogin($this->drupalCreateUser()); + // Check that a simple user is not able to access the menu. + $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); + $this->assertSession()->statusCodeEquals(403); + } + + /** * Tests menu block settings. */ protected function doTestMenuBlock() { diff --git a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuTest.php b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuTest.php deleted file mode 100644 index f6aa4a799b..0000000000 --- a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuTest.php +++ /dev/null @@ -1,196 +0,0 @@ -drupalPlaceBlock('page_title_block'); - - $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); - } - - /** - * Creates a custom menu. - * - * @return \Drupal\system\Entity\Menu - * The custom menu that has been created. - */ - public function addCustomMenu() { - // Try adding a menu using a menu_name that is too long. - $this->drupalGet('admin/structure/menu/add'); - $menu_name = substr(hash('sha256', $this->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1); - $label = $this->randomMachineName(16); - $edit = [ - 'id' => $menu_name, - 'description' => '', - 'label' => $label, - ]; - $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save')); - - // Verify that using a menu_name that is too long results in a validation - // message. - $this->assertRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [ - '@name' => t('Menu name'), - '%max' => MENU_MAX_MENU_NAME_LENGTH_UI, - '%length' => Unicode::strlen($menu_name), - ])); - - // Change the menu_name so it no longer exceeds the maximum length. - $menu_name = substr(hash('sha256', $this->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI); - $edit['id'] = $menu_name; - $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save')); - - // Verify that no validation error is given for menu_name length. - $this->assertNoRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [ - '@name' => t('Menu name'), - '%max' => MENU_MAX_MENU_NAME_LENGTH_UI, - '%length' => Unicode::strlen($menu_name), - ])); - // Verify that the confirmation message is displayed. - $this->assertRaw(t('Menu %label has been added.', ['%label' => $label])); - $this->drupalGet('admin/structure/menu'); - $this->assertText($label, 'Menu created'); - - // Confirm that the custom menu block is available. - $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default')); - $this->clickLink('Place block'); - $this->assertText($label); - - // Enable the block. - $block = $this->drupalPlaceBlock('system_menu_block:' . $menu_name); - $this->blockPlacements[$menu_name] = $block->id(); - return Menu::load($menu_name); - } - - /** - * Tests the contextual links on a menu block. - */ - public function testBlockContextualLinks() { - $this->drupalLogin($this->drupalCreateUser(['administer menu', 'access contextual links', 'administer blocks'])); - $custom_menu = $this->addCustomMenu(); - $this->addMenuLink('', '/', $custom_menu->id()); - $block = $this->drupalPlaceBlock('system_menu_block:' . $custom_menu->id(), ['label' => 'Custom menu', 'provider' => 'system']); - $this->drupalGet('test-page'); - - $id = 'block:block=' . $block->id() . ':langcode=en|menu:menu=' . $custom_menu->id() . ':langcode=en'; - // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() - $this->assertRaw('
', format_string('Contextual link placeholder with id @id exists.', ['@id' => $id])); - - // Get server-rendered contextual links. - // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks() - $post = ['ids[0]' => $id]; - $client = \Drupal::httpClient(); - $url = $this->buildUrl('contextual/render', ['query' => ['destination' => 'test-page']]); - $response = $client->post($url, [ - 'form_params' => $post, - 'headers' => [ - 'Accept' => 'application/json', - ], - ]); - $this->assertEquals(200, $response->getStatusCode()); - $json = Json::decode((string) $response); - $this->assertIdentical($json[$id], ''); - } - - /** - * 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 = [ - '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', ['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; - } - - /** - * Tests if administrative users other than user 1 can access the menu parents - * AJAX callback. - */ - public function testMenuParentsJsAccess() { - $admin = $this->drupalCreateUser(['administer menu']); - $this->drupalLogin($admin); - // Just check access to the callback overall, the POST data is irrelevant. - $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); - $this->assertResponse(200); - - // Do standard user tests. - // Log in the user. - $this->drupalLogin($this->authenticatedUser); - $this->drupalGet('admin/structure/menu/parents', ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']); - $this->assertResponse(403); - } - -} diff --git a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php new file mode 100644 index 0000000000..30db326e68 --- /dev/null +++ b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php @@ -0,0 +1,162 @@ +drupalLogin($this->drupalCreateUser(['administer menu', 'access contextual links', 'administer blocks'])); + $menu = $this->addCustomMenu(); + + $block = $this->drupalPlaceBlock('system_menu_block:' . $menu->id(), [ + 'label' => 'Custom menu', + 'provider' => 'system' + ]); + $this->addMenuLink('', '/', $menu->id()); + + $this->drupalGet('test-page'); + // Wait for contextual link AJAX request to alter the DOM. + $this->assertSession()->assertWaitOnAjaxRequest(); + + // Click on 'Configure block' contextual link. + $this->clickContextualLink("#block-{$block->id()}", 'Configure block'); + // Check that we're on block configuration form. + $this->getSession()->getPage()->findLink('Remove block'); + + $this->drupalGet('test-page'); + // Wait for contextual link AJAX request to alter the DOM. + $this->assertSession()->assertWaitOnAjaxRequest(); + + // Click on 'Configure block' contextual link. + $this->clickContextualLink("#block-{$block->id()}", 'Edit menu'); + // Check that we're on block configuration form. + $this->assertSession()->pageTextContains("Machine name: {$menu->id()}"); + } + + /** + * Creates a custom menu. + * + * @return \Drupal\system\Entity\Menu + * The custom menu that has been created. + */ + protected function addCustomMenu() { + // Try adding a menu using a menu_name that is too long. + $label = $this->randomMachineName(16); + $menu_id = strtolower($this->randomMachineName(MENU_MAX_MENU_NAME_LENGTH_UI + 1)); + + $this->drupalGet('admin/structure/menu/add'); + $page = $this->getSession()->getPage(); + // Type the label to activate the machine name field and the edit button. + $page->fillField('Title', $label); + // Wait for the machine name widget to be activated. + $this->assertSession()->waitForElementVisible('css', 'button[type=button].link:contains(Edit)'); + // Activate the machine name text field. + $page->pressButton('Edit'); + // Try to fill a text longer than the allowed limit. + $page->fillField('Menu name', $menu_id); + $page->pressButton('Save'); + // Check that the menu was saved with the ID truncated to the max length. + $menu = Menu::load(substr($menu_id, 0, MENU_MAX_MENU_NAME_LENGTH_UI)); + $this->assertEquals($label, $menu->label()); + + // Check that the menu was added. + $this->drupalGet('admin/structure/menu'); + $this->assertSession()->pageTextContains($label); + + // Confirm that the custom menu block is available. + $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default')); + $this->clickLink('Place block'); + // Wait for the modal dialog to be loaded. + $this->assertSession()->waitForElement('css', "div[aria-describedby=drupal-modal]"); + // Check that the block is available to be placed. + $this->assertSession()->pageTextContains($label); + + return $menu; + } + + /** + * 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_id + * Menu ID. 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. + */ + protected function addMenuLink($parent = '', $path = '/', $menu_id = 'tools', $expanded = FALSE, $weight = '0') { + // View add menu link page. + $this->drupalGet("admin/structure/menu/manage/$menu_id/add"); + $this->assertSession()->statusCodeEquals(200); + + $title = '!link_' . $this->randomMachineName(16); + $edit = [ + 'link[0][uri]' => $path, + 'title[0][value]' => $title, + 'description[0][value]' => '', + 'enabled[value]' => 1, + 'expanded[value]' => $expanded, + 'menu_parent' => $menu_id . ':' . $parent, + 'weight[0][value]' => $weight, + ]; + + // Add menu link. + $this->drupalPostForm(NULL, $edit, 'Save'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('The menu link has been saved.'); + + $storage = $this->container->get('entity_type.manager')->getStorage('menu_link_content'); + $menu_links = $storage->loadByProperties(['title' => $title]); + $menu_link = reset($menu_links); + + // Check that the stored menu link meeting the expectations. + $this->assertNotNull($menu_link); + $this->assertMenuLink([ + 'menu_name' => $menu_id, + 'children' => [], + 'parent' => $parent + ], $menu_link->getPluginId()); + + return $menu_link; + } + +} diff --git a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuWebTestBase.php b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuWebTestBase.php deleted file mode 100644 index cd84d44d53..0000000000 --- a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuWebTestBase.php +++ /dev/null @@ -1,77 +0,0 @@ -resetDefinitions(); - // Reset the static load cache. - \Drupal::entityManager()->getStorage('menu_link_content')->resetCache(); - $definition = $menu_link_manager->getDefinition($menu_plugin_id); - - $entity = NULL; - - // Pull the path from the menu link content. - if (strpos($menu_plugin_id, 'menu_link_content') === 0) { - list(, $uuid) = explode(':', $menu_plugin_id, 2); - /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */ - $entity = \Drupal::entityManager()->loadEntityByUuid('menu_link_content', $uuid); - } - - if (isset($expected_item['children'])) { - $child_ids = array_values($menu_link_manager->getChildIds($menu_plugin_id)); - sort($expected_item['children']); - if ($child_ids) { - sort($child_ids); - } - $this->assertEqual($expected_item['children'], $child_ids); - unset($expected_item['children']); - } - - if (isset($expected_item['parents'])) { - $parent_ids = array_values($menu_link_manager->getParentIds($menu_plugin_id)); - $this->assertEqual($expected_item['parents'], $parent_ids); - unset($expected_item['parents']); - } - - if (isset($expected_item['langcode']) && $entity) { - $this->assertEqual($entity->langcode->value, $expected_item['langcode']); - unset($expected_item['langcode']); - } - - if (isset($expected_item['enabled']) && $entity) { - $this->assertEqual($entity->enabled->value, $expected_item['enabled']); - unset($expected_item['enabled']); - } - - foreach ($expected_item as $key => $value) { - $this->assertTrue(isset($definition[$key])); - $this->assertEqual($definition[$key], $value); - } - } - -} diff --git a/core/modules/menu_ui/tests/src/Functional/MenuWebTestBase.php b/core/modules/menu_ui/tests/src/Traits/MenuUiTrait.php similarity index 56% rename from core/modules/menu_ui/tests/src/Functional/MenuWebTestBase.php rename to core/modules/menu_ui/tests/src/Traits/MenuUiTrait.php index b8dfb242d4..c471823510 100644 --- a/core/modules/menu_ui/tests/src/Functional/MenuWebTestBase.php +++ b/core/modules/menu_ui/tests/src/Traits/MenuUiTrait.php @@ -1,36 +1,27 @@ resetDefinitions(); // Reset the static load cache. - \Drupal::entityManager()->getStorage('menu_link_content')->resetCache(); + \Drupal::entityTypeManager()->getStorage('menu_link_content')->resetCache(); $definition = $menu_link_manager->getDefinition($menu_plugin_id); $entity = NULL; @@ -39,7 +30,8 @@ public function assertMenuLink($menu_plugin_id, array $expected_item) { if (strpos($menu_plugin_id, 'menu_link_content') === 0) { list(, $uuid) = explode(':', $menu_plugin_id, 2); /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */ - $entity = \Drupal::entityManager()->loadEntityByUuid('menu_link_content', $uuid); + $entity = \Drupal::service('entity.repository') + ->loadEntityByUuid('menu_link_content', $uuid); } if (isset($expected_item['children'])) { @@ -48,29 +40,29 @@ public function assertMenuLink($menu_plugin_id, array $expected_item) { if ($child_ids) { sort($child_ids); } - $this->assertEqual($expected_item['children'], $child_ids); + $this->assertSame($expected_item['children'], $child_ids); unset($expected_item['children']); } if (isset($expected_item['parents'])) { $parent_ids = array_values($menu_link_manager->getParentIds($menu_plugin_id)); - $this->assertEqual($expected_item['parents'], $parent_ids); + $this->assertSame($expected_item['parents'], $parent_ids); unset($expected_item['parents']); } if (isset($expected_item['langcode']) && $entity) { - $this->assertEqual($entity->langcode->value, $expected_item['langcode']); + $this->assertEquals($expected_item['langcode'], $entity->langcode->value); unset($expected_item['langcode']); } if (isset($expected_item['enabled']) && $entity) { - $this->assertEqual($entity->enabled->value, $expected_item['enabled']); + $this->assertEquals($expected_item['enabled'], $entity->enabled->value); unset($expected_item['enabled']); } foreach ($expected_item as $key => $value) { - $this->assertTrue(isset($definition[$key])); - $this->assertEqual($definition[$key], $value); + $this->assertNotNull($definition[$key]); + $this->assertSame($value, $definition[$key]); } }