class CsrfRequestHeaderAccessCheckTest
Tests that the CSRF request header access check is attached to routes.
Attributes
#[CoversClass(CsrfRequestHeaderAccessCheck::class)]
#[Group('Access')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Access\CsrfRequestHeaderAccessCheckTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of CsrfRequestHeaderAccessCheckTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Access/ CsrfRequestHeaderAccessCheckTest.php, line 17
Namespace
Drupal\KernelTests\Core\AccessView source
class CsrfRequestHeaderAccessCheckTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'csrf_test',
];
/**
* Tests which routes the access check is attached to.
*
* The check is registered against the '_csrf_request_header_token'
* requirement, so it is attached regardless of the methods a route allows.
* There is no need to filter out read-only routes when building the route
* collection, because CsrfRequestHeaderAccessCheck::access() allows
* read-only requests.
*
* @param string $route_name
* The name of the route to check.
* @param bool $expected
* Whether the access check is expected to be attached to the route.
*/
public function testChecksAttachedToRoutes(string $route_name, bool $expected) : void {
$route = $this->container
->get('router.route_provider')
->getRouteByName($route_name);
$access_checks = $route->getOption('_access_checks') ?? [];
if ($expected) {
$this->assertContains('access_check.header.csrf', $access_checks);
}
else {
$this->assertNotContains('access_check.header.csrf', $access_checks);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.