public function testCanRespondToAjax2RequestFromErrorResponseBuilder()
{
$this->request = $this->prepareHttpRequest('foo/bar/baz', 'GET', [], 2);
$this->createService();
elgg_register_page_handler('foo', function ($segments, $identifier) {
$this->assertEquals(['bar', 'baz'], $segments);
$this->assertEquals('foo', $identifier);
return elgg_error_response('', 'phpunit', ELGG_HTTP_NOT_FOUND);
});
$this->assertTrue($this->route());
$response = _elgg_services()->responseFactory->getSentResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(ELGG_HTTP_NOT_FOUND, $response->getStatusCode());
$this->assertContains('application/json', $response->headers->get('Content-Type'));
$output = json_encode(['error' => ''], ELGG_JSON_ENCODING);
$this->assertEquals($output, $response->getContent());
}