function CsrfAccessCheckTest::testAccessTokenPass

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php \Drupal\Tests\Core\Access\CsrfAccessCheckTest::testAccessTokenPass()
  2. 8.9.x core/tests/Drupal/Tests/Core/Access/CsrfAccessCheckTest.php \Drupal\Tests\Core\Access\CsrfAccessCheckTest::testAccessTokenPass()
  3. 11.x 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 58

Class

CsrfAccessCheckTest
@coversDefaultClass \Drupal\Core\Access\CsrfAccessCheck[[api-linebreak]] @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testAccessTokenPass() : void {
  $this->csrfToken
    ->expects($this->once())
    ->method('validate')
    ->with('test_query', 'test-path/42')
    ->willReturn(TRUE);
  $this->routeMatch
    ->expects($this->once())
    ->method('getRawParameters')
    ->willReturn([
    '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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.