public function testCanFilterAjax2Response()
{
$this->hooks->registerHandler(Services\AjaxResponse::RESPONSE_HOOK, 'action:output3', function ($hook, $type, $api_response) {
/* @var $api_response Services\AjaxResponse */
$api_response->setTtl(1000);
$api_response->setData((object) ['value' => 'output3_modified']);
return $api_response;
});
$this->assertTrue($this->actions->register('output3', "{$this->actionsDir}/output3.php", 'public'));
$this->request = $this->prepareHttpRequest('action/output3', 'POST', [], 2, true);
$this->createService();
set_input('output', 'output3');
set_input('system_message', 'success');
$this->route();
$response = _elgg_services()->responseFactory->getSentResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(ELGG_HTTP_OK, $response->getStatusCode());
$this->assertContains('application/json', $response->headers->get('Content-Type'));
$this->assertNotEmpty($date = $response->headers->get('Date'));
$this->assertNotEmpty($expires = $response->headers->get('Expires'));
$this->assertEquals(strtotime($date) + 1000, strtotime($expires));
$this->assertContains('max-age=1000', $response->headers->get('Cache-Control'));
$this->assertContains('private', $response->headers->get('Cache-Control'));
$output = json_encode(['value' => 'output3_modified', '_elgg_msgs' => ['success' => ['success']], '_elgg_deps' => []]);
$this->assertEquals($output, $response->getContent());
}