public function MenuAdminPerMenuMenuPagesTest::testLinkEditAndResetForm in Menu Admin per Menu 8
Test the menu_link_plugin edit and menu_link_plugin reset form.
File
- tests/
src/ Functional/ MenuAdminPerMenuMenuPagesTest.php, line 398
Class
- MenuAdminPerMenuMenuPagesTest
- Tests the Menu pages in combination with Menu Admin per Menu.
Namespace
Drupal\Tests\menu_admin_per_menu\FunctionalCode
public function testLinkEditAndResetForm() : void {
$assert_session = $this
->assertSession();
$menu_1_link = $this->menuLinkManager
->getInstance([
'id' => 'menu_1.link',
]);
$menu_2_link = $this->menuLinkManager
->getInstance([
'id' => 'menu_2.link',
]);
$menu_3_link = $this->menuLinkManager
->getInstance([
'id' => 'menu_3.link',
]);
// Anonymous users don't have access to this page.
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
// An authenticated user without permissions doesn't have access to this
// page.
$this
->drupalLogin($this->authenticatedUser);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
// Admin users have access to all menus.
$this
->drupalLogin($this->rootUser);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Reset');
$assert_session
->pageTextContains('The menu link was reset to its default settings.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
// Users with 'administer menu' permission have acces to all menus.
$this
->drupalLogin($this->adminMenuUser);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Reset');
$assert_session
->pageTextContains('The menu link was reset to its default settings.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
// Users with 'administer menu_1 menu items' only have access to menu_1.
$this
->drupalLogin($this->menu1User);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Reset');
$assert_session
->pageTextContains('The menu link was reset to its default settings.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
// Users with 'administer menu_2 menu items' only have access to menu_2.
$this
->drupalLogin($this->menu2User);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Reset');
$assert_session
->pageTextContains('The menu link was reset to its default settings.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
// Permission for this user was added by
// hook_menu_admin_per_menu_get_permissions_alter.
$this
->drupalLogin($this->menu3User);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_1_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_2_link
->getPluginId()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/edit', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/link/%s/reset', $menu_3_link
->getPluginId()));
$assert_session
->statusCodeEquals(200);
$this
->submitForm([], 'Reset');
$assert_session
->pageTextContains('The menu link was reset to its default settings.');
}