function RoutePathGenerationTraitTest::setUp

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Access/RoutePathGenerationTraitTest.php \Drupal\Tests\Core\Access\RoutePathGenerationTraitTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Access/RoutePathGenerationTraitTest.php, line 43

Class

RoutePathGenerationTraitTest
Tests Route Path Generation Trait.

Namespace

Drupal\Tests\Core\Access

Code

protected function setUp() : void {
  parent::setUp();
  $csrfToken = $this->createStub(CsrfTokenGenerator::class);
  // Make CsrfTokenGenerator mock use a simple hash of the value passed as
  // parameter, as it is enough for the sake of our tests.
  $csrfToken->method('get')
    ->willReturnCallback(function ($value) : string {
    return hash('sha256', $value);
  });
  $csrfToken->method('validate')
    ->willReturnCallback(function ($token, $value) : bool {
    return $token === hash('sha256', $value);
  });
  $this->processor = new RouteProcessorCsrf($csrfToken, $this->createStub(RequestStack::class));
  $this->accessCheck = new CsrfAccessCheck($csrfToken);
}

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