Elgg\RouterTest::testCanRespondToAjaxRequestThroughRouteHook PHP Method

testCanRespondToAjaxRequestThroughRouteHook() public method

    public function testCanRespondToAjaxRequestThroughRouteHook()
    {
        $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']);
            echo 'good bye';
            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('text/html', $response->headers->get('Content-Type'));
        $this->assertContains('charset=utf-8', strtolower($response->headers->get('Content-Type')));
        // no forward call, so API outputs content
        $this->assertEquals('good bye', $response->getContent());
    }
RouterTest