function FinishResponseSubscriberTest::testDefaultHeaders
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/EventSubscriber/FinishResponseSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\FinishResponseSubscriberTest::testDefaultHeaders()
Finish subscriber should set some default header values.
@covers ::onRespond
File
-
core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ FinishResponseSubscriberTest.php, line 85
Class
- FinishResponseSubscriberTest
- @coversDefaultClass \Drupal\Core\EventSubscriber\FinishResponseSubscriber @group EventSubscriber
Namespace
Drupal\Tests\Core\EventSubscriberCode
public function testDefaultHeaders() : void {
$finishSubscriber = new FinishResponseSubscriber($this->languageManager, $this->getConfigFactoryStub(), $this->requestPolicy, $this->responsePolicy, $this->cacheContextsManager, $this->time, FALSE);
$this->languageManager
->method('getCurrentLanguage')
->willReturn(new Language([
'id' => 'en',
]));
$request = $this->createMock(Request::class);
$response = $this->createMock(Response::class);
$response->headers = new ResponseHeaderBag();
$event = new ResponseEvent($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response);
$finishSubscriber->onRespond($event);
$this->assertEquals([
'en',
], $response->headers
->all('Content-language'));
$this->assertEquals([
'nosniff',
], $response->headers
->all('X-Content-Type-Options'));
$this->assertEquals([
'SAMEORIGIN',
], $response->headers
->all('X-Frame-Options'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.