public function RoutingTest::testRoutes in XHProf 8
Tests access permissions to every route provided by the module.
File
- tests/
src/ Functional/ RoutingTest.php, line 28
Class
- RoutingTest
- Tests behaviors when visiting the reports and settings pages.
Namespace
Drupal\Tests\xhprof\FunctionalCode
public function testRoutes() {
$urls = [
Url::fromRoute('xhprof.admin_configure'),
Url::fromRoute('xhprof.runs'),
];
// Ensures Anonymous visitor getting no-access.
foreach ($urls as $url) {
$this
->assertRouteStatusCode($url, 403);
}
$permissions = [
'access xhprof data' => [
'xhprof.admin_configure',
],
'administer xhprof' => [],
];
// Make sure authorized getting access to all route except excluded.
foreach ($permissions as $permission => $exclude) {
$this
->drupalLogin($this
->drupalCreateUser([
$permission,
], $permission));
/** @var \Drupal\Core\Url $url */
foreach ($urls as $url) {
$code = in_array($url
->getRouteName(), $exclude) ? 403 : 200;
$this
->assertRouteStatusCode($url, $code);
}
}
}