public function MenuPerRoleAccessTest::testAdminBypass in Menu Per Role 8
Check the admin bypass feature in front.
Throws
\Drupal\Core\Entity\EntityStorageException
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ MenuPerRoleAccessTest.php, line 406
Class
- MenuPerRoleAccessTest
- Test access control to menu links.
Namespace
Drupal\Tests\menu_per_role\FunctionalCode
public function testAdminBypass() {
// No bypass.
$config = $this->configFactory
->getEditable('menu_per_role.settings');
$config
->set($this->adminBypassSetting, FALSE);
$config
->save();
$this
->prepareMenuLinkAndExpectations('link 1 - show anonymous', [
AccountInterface::ANONYMOUS_ROLE,
], [], [
'admin' => FALSE,
]);
$this
->prepareMenuLinkAndExpectations('link 2 - show role 1', [
$this->user1Role,
], [], [
'admin' => FALSE,
]);
$this
->prepareMenuLinkAndExpectations('link 3 - show admin', [
$this->adminRole,
], [], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 4 - hide anonymous', [], [
AccountInterface::ANONYMOUS_ROLE,
], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 5 - hide role 1', [], [
$this->user1Role,
], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 6 - hide admin', [], [
$this->adminRole,
], [
'admin' => FALSE,
]);
$this
->prepareMenuLinkAndExpectations('link 7 - show anonymous and hide role 1', [
AccountInterface::ANONYMOUS_ROLE,
], [
$this->user1Role,
], [
'admin' => FALSE,
]);
$this
->linksAccessTest();
// Bypass.
$config = $this->configFactory
->getEditable('menu_per_role.settings');
$config
->set($this->adminBypassSetting, TRUE);
$config
->save();
$this
->prepareMenuLinkAndExpectations('link 1 - show anonymous', [
AccountInterface::ANONYMOUS_ROLE,
], [], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 2 - show role 1', [
$this->user1Role,
], [], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 3 - show admin', [
$this->adminRole,
], [], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 4 - hide anonymous', [], [
AccountInterface::ANONYMOUS_ROLE,
], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 5 - hide role 1', [], [
$this->user1Role,
], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 6 - hide admin', [], [
$this->adminRole,
], [
'admin' => TRUE,
]);
$this
->prepareMenuLinkAndExpectations('link 7 - show anonymous and hide role 1', [
AccountInterface::ANONYMOUS_ROLE,
], [
$this->user1Role,
], [
'admin' => TRUE,
]);
$this
->linksAccessTest();
}