public function MenuAdminPerMenuMenuPagesTest::testMenuEditAndMenuLinkAddForm in Menu Admin per Menu 8
Test menu edit and menu link add form.
File
- tests/
src/ Functional/ MenuAdminPerMenuMenuPagesTest.php, line 224
Class
- MenuAdminPerMenuMenuPagesTest
- Tests the Menu pages in combination with Menu Admin per Menu.
Namespace
Drupal\Tests\menu_admin_per_menu\FunctionalCode
public function testMenuEditAndMenuLinkAddForm() : void {
$assert_session = $this
->assertSession();
// Anonymous users don't have access to this page.
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu1
->id()));
$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/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(403);
// Admin users have access to all menus.
$this
->drupalLogin($this->rootUser);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(200);
$this
->clickLink('Add link');
$assert_session
->statusCodeEquals(200);
// Check if adding menu items still work.
$this
->submitForm([
'title[0][value]' => 'Test link',
'link[0][uri]' => '<front>',
], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
// Check if admin user has access to menu_2.
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu2
->id()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu2
->id()));
$assert_session
->statusCodeEquals(200);
// Check if admin user has access to menu_3.
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu3
->id()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu3
->id()));
$assert_session
->statusCodeEquals(200);
// User with 'administer menu' permission can edit all menus.
$this
->drupalLogin($this->adminMenuUser);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(200);
// Check that the menu properties are available for a user with the
// 'administer menu' permission.
$assert_session
->fieldExists('id');
$assert_session
->fieldExists('label');
$assert_session
->fieldExists('description');
$assert_session
->fieldExists('langcode');
$this
->clickLink('Add link');
$assert_session
->statusCodeEquals(200);
// Check that list of parent options is not filtered.
$assert_session
->optionExists('menu_parent', 'menu_1:menu_1.link');
$assert_session
->optionExists('menu_parent', 'menu_2:menu_2.link');
$assert_session
->optionExists('menu_parent', 'menu_3:menu_3.link');
$this
->submitForm([
'title[0][value]' => 'Test link',
'link[0][uri]' => '<front>',
], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu2
->id()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu2
->id()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu3
->id()));
$assert_session
->statusCodeEquals(200);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu3
->id()));
$assert_session
->statusCodeEquals(200);
// User with 'administer menu_1 menu items' can only edit menu_1.
$this
->drupalLogin($this->menu1User);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(200);
// Check that the menu properties are not available for a user without the
// 'administer menu' permission.
$assert_session
->fieldNotExists('id');
$assert_session
->fieldNotExists('label');
$assert_session
->fieldNotExists('description');
$assert_session
->fieldNotExists('langcode');
$this
->clickLink('Add link');
$assert_session
->statusCodeEquals(200);
// Check that list of parent options is filtered.
$assert_session
->optionExists('menu_parent', 'menu_1:menu_1.link');
$assert_session
->optionNotExists('menu_parent', 'menu_2:menu_2.link');
$assert_session
->optionNotExists('menu_parent', 'menu_3:menu_3.link');
$this
->submitForm([
'title[0][value]' => 'Test link',
'link[0][uri]' => '<front>',
], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu2
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu2
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu3
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu3
->id()));
$assert_session
->statusCodeEquals(403);
// User with 'administer menu_2 menu items' can only edit menu_2.
$this
->drupalLogin($this->menu2User);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu1
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu2
->id()));
$assert_session
->statusCodeEquals(200);
$this
->clickLink('Add link');
$assert_session
->statusCodeEquals(200);
// Check that list of parent options is filtered.
$assert_session
->optionNotExists('menu_parent', 'menu_1:menu_1.link');
$assert_session
->optionExists('menu_parent', 'menu_2:menu_2.link');
$assert_session
->optionNotExists('menu_parent', 'menu_3:menu_3.link');
$this
->submitForm([
'title[0][value]' => 'Test link',
'link[0][uri]' => '<front>',
], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu3
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu3
->id()));
$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/manage/%s', $this->menu1
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu1
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu2
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s/add', $this->menu2
->id()));
$assert_session
->statusCodeEquals(403);
$this
->drupalGet(sprintf('admin/structure/menu/manage/%s', $this->menu3
->id()));
$assert_session
->statusCodeEquals(200);
$this
->clickLink('Add link');
$assert_session
->statusCodeEquals(200);
// Check that list of parent options is filtered.
$assert_session
->optionNotExists('menu_parent', 'menu_1:menu_1.link');
$assert_session
->optionNotExists('menu_parent', 'menu_2:menu_2.link');
$assert_session
->optionExists('menu_parent', 'menu_3:menu_3.link');
$this
->submitForm([
'title[0][value]' => 'Test link',
'link[0][uri]' => '<front>',
], 'Save');
$assert_session
->pageTextContains('The menu link has been saved.');
}