function CustomPageExceptionHtmlSubscriberTest::testHandleWithPostRequest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::testHandleWithPostRequest()
- 8.9.x core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::testHandleWithPostRequest()
- 11.x core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest::testHandleWithPostRequest()
Tests onHandleException with a POST request.
File
-
core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ CustomPageExceptionHtmlSubscriberTest.php, line 133
Class
- CustomPageExceptionHtmlSubscriberTest
- @coversDefaultClass \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber @group EventSubscriber
Namespace
Drupal\Tests\Core\EventSubscriberCode
public function testHandleWithPostRequest() : void {
$request = Request::create('/test', 'POST', [
'name' => 'druplicon',
'pass' => '12345',
]);
$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 HtmlResponse($request->getMethod());
});
$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('POST name=druplicon&pass=12345', $result);
$this->assertEquals(AccessResult::allowed()->addCacheTags([
'foo',
'bar',
]), $request->attributes
->get(AccessAwareRouterInterface::ACCESS_RESULT));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.