function ActiveLinkResponseFilterTest::testOnlyHtml
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testOnlyHtml()
- 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testOnlyHtml()
- 11.x core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php \Drupal\Tests\Core\EventSubscriber\ActiveLinkResponseFilterTest::testOnlyHtml()
Tests ActiveLinkResponseFilter only affects HTML responses.
@covers ::onResponse
File
-
core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ ActiveLinkResponseFilterTest.php, line 413
Class
- ActiveLinkResponseFilterTest
- @coversDefaultClass \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter @group EventSubscriber
Namespace
Drupal\Tests\Core\EventSubscriberCode
public function testOnlyHtml() : 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);
// Make sure path matcher isn't called and we didn't get to the link logic.
$path_matcher = $this->prophesize(PathMatcherInterface::class);
$path_matcher->isFrontPage()
->shouldNotBeCalled();
$subscriber = new ActiveLinkResponseFilter($session, $current_path_stack, $path_matcher->reveal(), $language_manager);
// A link that might otherwise be set 'active'.
$content = '<a data-drupal-link-system-path="other-page">Other page</a>';
// Assert response with non-html content type gets ignored.
$response = new Response();
$response->setContent($content);
$response->headers
->get('Content-Type', 'application/json');
$subscriber->onResponse(new ResponseEvent($this->prophesize(KernelInterface::class)
->reveal(), $request_stack->getCurrentRequest(), HttpKernelInterface::MAIN_REQUEST, $response));
$this->assertSame($response->getContent(), $content);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.