protected function ConfigurationPermissionTest::assertPaths in Apigee Edge 8
Checks access to the admin pages.
Parameters
bool $access: Whether the current user should access the pages or not.
1 call to ConfigurationPermissionTest::assertPaths()
- ConfigurationPermissionTest::testAccess in tests/
src/ Functional/ ConfigurationPermissionTest.php - Tests access to the admin pages with admin/authenticated/anonymous roles.
File
- tests/
src/ Functional/ ConfigurationPermissionTest.php, line 76
Class
- ConfigurationPermissionTest
- Module administration permission test.
Namespace
Drupal\Tests\apigee_edge\FunctionalCode
protected function assertPaths(bool $access) {
$expected_code = $access ? 200 : 403;
$visit_path = function (string $path, array $query = []) use ($expected_code) {
$options = [];
if ($query) {
$options['query'] = $query;
}
$this
->drupalGetNoMetaRefresh($path, $options);
$this
->assertEquals($expected_code, $this
->getSession()
->getStatusCode(), $path);
};
// Get all routes defined by the module and check every route that requires
// the permission "administer apigee edge".
$module_path = $this->container
->get('module_handler')
->getModule('apigee_edge')
->getPath();
$discovery = new YamlDiscovery('routing', [
'apigee_edge' => DRUPAL_ROOT . '/' . $module_path,
]);
$module_routes = $discovery
->findAll()['apigee_edge'];
// These routes are checked manually.
unset($module_routes['apigee_edge.developer_sync.run'], $module_routes['apigee_edge.developer_sync.schedule']);
foreach ($module_routes as $route => $data) {
// Check routes that require permission "administer apigee edge".
if (in_array('administer apigee edge', $data['requirements'])) {
$visit_path($data['path']);
if ($route === 'apigee_edge.settings.developer.sync') {
if ($access) {
list($schedule_path, $schedule_query) = $this
->findLink('Background developer sync');
list($run_path, $run_query) = $this
->findLink('Run developer sync');
$visit_path($schedule_path, $schedule_query);
$visit_path($run_path, $run_query);
}
else {
$visit_path(Url::fromRoute('apigee_edge.developer_sync.run')
->getInternalPath());
$visit_path(Url::fromRoute('apigee_edge.developer_sync.schedule')
->getInternalPath());
}
}
}
}
}