Elgg\RouterTest::testCanRespondToAjaxRequestFromRedirectResponseBuilder PHP Method

testCanRespondToAjaxRequestFromRedirectResponseBuilder() public method

    public function testCanRespondToAjaxRequestFromRedirectResponseBuilder()
    {
        $this->request = $this->prepareHttpRequest('foo/bar/baz', 'GET', [], 1);
        $this->createService();
        elgg_register_page_handler('foo', function ($segments, $identifier) {
            $this->assertEquals(['bar', 'baz'], $segments);
            $this->assertEquals('foo', $identifier);
            return elgg_redirect_response('foo2/bar2/baz2');
        });
        $this->assertTrue($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->assertContains('charset=utf-8', strtolower($response->headers->get('Content-Type')));
        $output = json_encode(['output' => '', 'status' => 0, 'system_messages' => ['error' => [], 'success' => []], 'current_url' => current_page_url(), 'forward_url' => elgg_normalize_url('foo2/bar2/baz2')], ELGG_JSON_ENCODING);
        $this->assertEquals($output, $response->getContent());
        // compensate for fact that ResponseFactory::redirect closes a buffer it didn't open
        ob_start();
    }
RouterTest