function RouteProcessorCsrfTest::testProcessOutboundDynamicOne

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

Tests the processOutbound() method with a dynamic path and one replacement.

File

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

Class

RouteProcessorCsrfTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Access%21RouteProcessorCsrf.php/class/RouteProcessorCsrf/9" title="Processes the outbound route to handle the CSRF token." class="local">\Drupal\Core\Access\RouteProcessorCsrf</a> @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testProcessOutboundDynamicOne() {
    $route = new Route('/test-path/{slug}', [], [
        '_csrf_token' => 'TRUE',
    ]);
    $parameters = [
        'slug' => 100,
    ];
    $bubbleable_metadata = new BubbleableMetadata();
    $this->processor
        ->processOutbound('test', $route, $parameters, $bubbleable_metadata);
    // Bubbleable metadata of routes with a _csrf_token route requirement is a
    // placeholder.
    $path = 'test-path/100';
    $placeholder = Crypt::hashBase64($path);
    $placeholder_render_array = [
        '#lazy_builder' => [
            'route_processor_csrf:renderPlaceholderCsrfToken',
            [
                $path,
            ],
        ],
    ];
    $this->assertEquals((new BubbleableMetadata())->setAttachments([
        'placeholders' => [
            $placeholder => $placeholder_render_array,
        ],
    ]), $bubbleable_metadata);
}

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