public function testCanSafelyRedirectWithinRedirect()
{
$this->hooks->registerHandler('forward', (string) ELGG_HTTP_NOT_FOUND, function () {
$this->fooHandlerCalls++;
_elgg_services()->responseFactory->redirect('error', ELGG_HTTP_BAD_REQUEST);
});
$this->hooks->registerHandler('forward', (string) ELGG_HTTP_BAD_REQUEST, function () {
$this->fooHandlerCalls++;
_elgg_services()->responseFactory->redirect('error', ELGG_HTTP_INTERNAL_SERVER_ERROR);
});
$this->request = $this->prepareHttpRequest('phpunit', 'GET');
$this->createService();
elgg_register_page_handler('phpunit', function () {
_elgg_services()->responseFactory->redirect('error', ELGG_HTTP_NOT_FOUND);
return elgg_ok_response('foo');
});
$this->assertTrue($this->route());
$response = _elgg_services()->responseFactory->getSentResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(ELGG_HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
$error_page = elgg_view_resource('error', ['type' => (string) ELGG_HTTP_INTERNAL_SERVER_ERROR]);
$this->assertEquals($error_page, $response->getContent());
$this->assertTrue($this->fooHandlerCalls > 0);
}