You are here

public function CsrfAccessCheckTest::testAccessTokenPass in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php \Drupal\Tests\Core\Access\CsrfAccessCheckTest::testAccessTokenPass()
  2. 9 core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php \Drupal\Tests\Core\Access\CsrfAccessCheckTest::testAccessTokenPass()

Tests the access() method with a valid token.

File

core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php, line 51

Class

CsrfAccessCheckTest
@coversDefaultClass \Drupal\Core\Access\CsrfAccessCheck @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAccessTokenPass() {
  $this->csrfToken
    ->expects($this
    ->once())
    ->method('validate')
    ->with('test_query', 'test-path/42')
    ->will($this
    ->returnValue(TRUE));
  $this->routeMatch
    ->expects($this
    ->once())
    ->method('getRawParameters')
    ->will($this
    ->returnValue([
    'node' => 42,
  ]));
  $route = new Route('/test-path/{node}', [], [
    '_csrf_token' => 'TRUE',
  ]);
  $request = Request::create('/test-path/42?token=test_query');
  $this
    ->assertEquals(AccessResult::allowed()
    ->setCacheMaxAge(0), $this->accessCheck
    ->access($route, $request, $this->routeMatch));
}