/** * 1. Register a page handler for `/foo` * 2. Register a plugin hook that uses the "handler" result param * to route all `/bar/*` requests to the `/foo` handler. * 3. Route a request for a `/bar` page. * 4. Check that the `/foo` handler was called. */ function testRouteSupportsSettingHandlerInHookResultForBackwardsCompatibility() { $this->router->registerPageHandler('foo', array($this, 'foo_page_handler')); $this->hooks->registerHandler('route', 'bar', array($this, 'bar_route_handler')); $query = http_build_query(array('__elgg_uri' => 'bar/baz')); ob_start(); $this->router->route(\Elgg\Http\Request::create("http://localhost/?{$query}")); ob_end_clean(); $this->assertEquals(1, $this->fooHandlerCalls); }
function testRouteOverridenFromHook() { $this->router->registerPageHandler('foo', array($this, 'foo_page_handler')); $this->hooks->registerHandler('route', 'foo', array($this, 'bar_route_override')); $query = http_build_query(array(Application::GET_PATH_KEY => 'foo')); ob_start(); $this->router->route(\Elgg\Http\Request::create("http://localhost/?{$query}")); $result = ob_get_contents(); ob_end_clean(); $this->assertEquals("Page handler override from hook", $result); $this->assertEquals(0, $this->fooHandlerCalls); }
function testRouteOverridenFromHook() { $this->router->registerPageHandler('foo', array($this, 'foo_page_handler')); $this->hooks->registerHandler('route', 'foo', array($this, 'bar_route_override')); ob_start(); $this->router->route($this->prepareHttpRequest('foo')); $result = ob_get_clean(); $this->assertEquals("Page handler override from hook", $result); $this->assertEquals(0, $this->fooHandlerCalls); $response = _elgg_services()->responseFactory->getSentResponse(); $this->assertInstanceOf(Response::class, $response); $this->assertEquals("Page handler override from hook", $response->getContent()); }