You are here

public function RouteProcessorCsrfTest::testProcessOutbound in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/RouteProcessorCsrfTest.php \Drupal\Tests\Core\Access\RouteProcessorCsrfTest::testProcessOutbound()

Tests the processOutbound() method with a _csrf_token route requirement.

File

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

Class

RouteProcessorCsrfTest
@coversDefaultClass \Drupal\Core\Access\RouteProcessorCsrf @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testProcessOutbound() {
  $route = new Route('/test-path', [], [
    '_csrf_token' => 'TRUE',
  ]);
  $parameters = [];
  $bubbleable_metadata = new BubbleableMetadata();
  $this->processor
    ->processOutbound('test', $route, $parameters, $bubbleable_metadata);

  // 'token' should be added to the parameters array.
  $this
    ->assertArrayHasKey('token', $parameters);

  // Bubbleable metadata of routes with a _csrf_token route requirement is a
  // placeholder.
  $path = 'test-path';
  $placeholder = Crypt::hashBase64($path);
  $placeholder_render_array = [
    '#lazy_builder' => [
      'route_processor_csrf:renderPlaceholderCsrfToken',
      [
        $path,
      ],
    ],
  ];
  $this
    ->assertSame($parameters['token'], $placeholder);
  $this
    ->assertEquals((new BubbleableMetadata())
    ->setAttachments([
    'placeholders' => [
      $placeholder => $placeholder_render_array,
    ],
  ]), $bubbleable_metadata);
}