protected function DeveloperAppPermissionTest::assertPermission in Apigee Edge 8
Asserts that an account with a given permission can or can't access pages.
Parameters
string $permission: Name of the permission to test.
1 call to DeveloperAppPermissionTest::assertPermission()
- DeveloperAppPermissionTest::testPermissions in tests/
src/ Functional/ DeveloperAppPermissionTest.php - Tests pages and permissions.
File
- tests/
src/ Functional/ DeveloperAppPermissionTest.php, line 220
Class
- DeveloperAppPermissionTest
- Developer app entity permission test.
Namespace
Drupal\Tests\apigee_edge\FunctionalCode
protected function assertPermission(string $permission) {
if ($this->loggedInUser) {
$this
->drupalLogout();
}
$old_roles = $this->myAccount
->getRoles(TRUE);
foreach ($old_roles as $old_role) {
$this->myAccount
->removeRole($old_role);
}
$this->myAccount
->addRole($this->roles[$permission]);
// It is not necessary to save the developer associated with this user.
$this
->disableUserPresave();
$this->myAccount
->save();
$this
->enableUserPresave();
$routesWithAccess = static::PERMISSION_MATRIX[$permission];
// A user with this permission has access to all routes by this entity.
if ($permission === static::ADMINISTER_PERMISSION) {
$routesWithAccess = $this->entityRoutes;
}
foreach ($this->entityRoutes as $rel) {
$myUrl = static::fixUrl((string) $this->myDeveloperApp
->toUrl($rel)
->toString());
$otherUrl = static::fixUrl((string) $this->otherDeveloperApp
->toUrl($rel)
->toString());
$shouldAccess = in_array($rel, $routesWithAccess);
if (strpos($permission, ' any ') !== FALSE) {
$this
->visitPages($myUrl, $shouldAccess, $rel, $permission);
$this
->visitPages($otherUrl, $shouldAccess, $rel, $permission);
}
elseif (strpos($permission, ' own ') !== FALSE) {
$this
->visitPages($myUrl, $shouldAccess, $rel, $permission);
$this
->visitPages($otherUrl, FALSE, $rel, $permission);
}
else {
$this
->visitPages($myUrl, $shouldAccess, $rel, $permission);
// Issue #285, a user should not have access to other user's create
// (own) app form.
$otherShouldAccess = $permission === 'create developer_app' ? FALSE : $shouldAccess;
$this
->visitPages($otherUrl, $otherShouldAccess, $rel, $permission);
}
}
}