Elgg\RouterTest::testCanRedirectAjaxRequestFromRouteHook PHP Method

testCanRedirectAjaxRequestFromRouteHook() public method

    public function testCanRedirectAjaxRequestFromRouteHook()
    {
        $this->hooks->registerHandler('route', 'foo', function ($hook, $type, $return, $params) {
            $this->assertEquals($return, $params);
            $this->assertEquals('foo', $return['identifier']);
            $this->assertEquals(['bar', 'baz'], $return['segments']);
            _elgg_services()->responseFactory->redirect('foo2/bar2/baz2');
            return false;
        });
        $this->request = $this->prepareHttpRequest('foo/bar/baz', 'GET', [], 1);
        $this->createService();
        $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