Plugin devs should use these wrapper functions: * elgg_register_page_handler * elgg_unregister_page_handler
Since: 1.9.0
Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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());
 }