RoutingTest.php in XHProf 8
File
tests/src/Functional/RoutingTest.php
View source
<?php
namespace Drupal\Tests\xhprof\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class RoutingTest extends BrowserTestBase {
protected static $modules = [
'xhprof',
];
protected $defaultTheme = 'stark';
public function testRoutes() {
$urls = [
Url::fromRoute('xhprof.admin_configure'),
Url::fromRoute('xhprof.runs'),
];
foreach ($urls as $url) {
$this
->assertRouteStatusCode($url, 403);
}
$permissions = [
'access xhprof data' => [
'xhprof.admin_configure',
],
'administer xhprof' => [],
];
foreach ($permissions as $permission => $exclude) {
$this
->drupalLogin($this
->drupalCreateUser([
$permission,
], $permission));
foreach ($urls as $url) {
$code = in_array($url
->getRouteName(), $exclude) ? 403 : 200;
$this
->assertRouteStatusCode($url, $code);
}
}
}
protected function assertRouteStatusCode(Url $url, int $code) {
$this
->drupalGet($url);
$this
->assertSession()
->statusCodeEquals($code);
}
}
Classes
Name |
Description |
RoutingTest |
Tests behaviors when visiting the reports and settings pages. |