Elgg\RouterTest::testCanRespondToAjax2RequestForPageThatForwardsToErrorPage PHP Method

testCanRespondToAjax2RequestForPageThatForwardsToErrorPage() public method

    public function testCanRespondToAjax2RequestForPageThatForwardsToErrorPage()
    {
        $this->request = $this->prepareHttpRequest('phpunit', 'GET', [], 2);
        $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_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());
        // compensate for fact that ResponseFactory::redirect closes a buffer it didn't open
        ob_start();
    }
RouterTest