function ActiveLinkResponseFilterTest::testSkipCertainResponseTypes

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testSkipCertainResponseTypes()
  2. 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testSkipCertainResponseTypes()
  3. 10 core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testSkipCertainResponseTypes()

Tests certain response types ignored by the ActiveLinkResponseFilter.

@covers ::onResponse

File

core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php, line 452

Class

ActiveLinkResponseFilterTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21EventSubscriber%21ActiveLinkResponseFilter.php/class/ActiveLinkResponseFilter/11.x" title="Subscribes to filter HTML responses, to set attributes on active links." class="local">\Drupal\Core\EventSubscriber\ActiveLinkResponseFilter</a> @group EventSubscriber

Namespace

Drupal\Tests\Core\EventSubscriber

Code

public function testSkipCertainResponseTypes() : void {
    $session = new AnonymousUserSession();
    $language_manager = new LanguageManager(new LanguageDefault([]));
    $request_stack = new RequestStack();
    $request_stack->push(new Request());
    $current_path_stack = new CurrentPathStack($request_stack);
    // Ensure path matcher is not called. This also tests that the
    // ActiveLinkResponseFilter ignores the response.
    $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()
        ->shouldNotBeCalled();
    $subscriber = new ActiveLinkResponseFilter($session, $current_path_stack, $path_matcher->reveal(), $language_manager);
    // Test BinaryFileResponse is ignored. Calling setContent() would throw a
    // logic exception.
    $response = new BinaryFileResponse(__FILE__, 200, [
        'Content-Type' => 'text/html',
    ]);
    $subscriber->onResponse(new ResponseEvent($this->prophesize(KernelInterface::class)
        ->reveal(), $request_stack->getCurrentRequest(), HttpKernelInterface::MAIN_REQUEST, $response));
    // Test StreamedResponse is ignored. Calling setContent() would throw a
    // logic exception.
    $response = new StreamedResponse(function () {
        echo 'Success!';
    }, 200, [
        'Content-Type' => 'text/html',
    ]);
    $subscriber->onResponse(new ResponseEvent($this->prophesize(KernelInterface::class)
        ->reveal(), $request_stack->getCurrentRequest(), HttpKernelInterface::MAIN_REQUEST, $response));
}

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