public function CustomPageExceptionHtmlSubscriberTest::testHandleWithGetRequest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::testHandleWithGetRequest()
- 9 core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::testHandleWithGetRequest()
Tests onHandleException with a GET request.
File
- core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ CustomPageExceptionHtmlSubscriberTest.php, line 155
Class
- CustomPageExceptionHtmlSubscriberTest
- @coversDefaultClass \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber @group EventSubscriber
Namespace
Drupal\Tests\Core\EventSubscriberCode
public function testHandleWithGetRequest() {
$request = Request::create('/test', 'GET', [
'name' => 'druplicon',
'pass' => '12345',
]);
$request->attributes
->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()
->addCacheTags([
'druplicon',
]));
$request_context = new RequestContext();
$request_context
->fromRequest($request);
$this->accessUnawareRouter
->expects($this
->any())
->method('getContext')
->willReturn($request_context);
$this->kernel
->expects($this
->once())
->method('handle')
->willReturnCallback(function (Request $request) {
return new Response($request
->getMethod() . ' ' . UrlHelper::buildQuery($request->query
->all()));
});
$event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, new NotFoundHttpException('foo'));
$this->customPageSubscriber
->onException($event);
$response = $event
->getResponse();
$result = $response
->getContent() . " " . UrlHelper::buildQuery($request->request
->all());
$this
->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
$this
->assertEquals(AccessResult::forbidden()
->addCacheTags([
'druplicon',
'foo',
'bar',
]), $request->attributes
->get(AccessAwareRouterInterface::ACCESS_RESULT));
}