function RouteProcessorCsrfTest::setUp

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php \Drupal\Tests\Core\Access\RouteProcessorCsrfTest::setUp()
  2. 9 core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php \Drupal\Tests\Core\Access\RouteProcessorCsrfTest::setUp()
  3. 8.9.x core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php \Drupal\Tests\Core\Access\RouteProcessorCsrfTest::setUp()
  4. main core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php \Drupal\Tests\Core\Access\RouteProcessorCsrfTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php, line 45

Class

RouteProcessorCsrfTest
Tests Drupal\Core\Access\RouteProcessorCsrf.

Namespace

Drupal\Tests\Core\Access

Code

protected function setUp() : void {
  parent::setUp();
  $this->csrfToken = $this->getMockBuilder('Drupal\\Core\\Access\\CsrfTokenGenerator')
    ->disableOriginalConstructor()
    ->getMock();
  $this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
    ->disableOriginalConstructor()
    ->getMock();
  $request = $this->createMock('Symfony\\Component\\HttpFoundation\\Request');
  $request->expects($this->any())
    ->method('getRequestFormat')
    ->willReturn('html');
  $this->requestStack
    ->expects($this->any())
    ->method('getCurrentRequest')
    ->willReturn($request);
  $this->processor = new RouteProcessorCsrf($this->csrfToken, $this->requestStack);
  // Add a cache_contexts_manager so BubbleableMetadata::addCacheContexts()
  // can validate the bubbled 'session' context.
  $cache_contexts_manager = $this->createStub(CacheContextsManager::class);
  $cache_contexts_manager->method('assertValidTokens')
    ->willReturn(TRUE);
  $container = new ContainerBuilder();
  $container->set('cache_contexts_manager', $cache_contexts_manager);
  \Drupal::setContainer($container);
}

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