/** * 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); }
public function testCanPassParamsAndChangeReturnValue() { $hooks = new Elgg_PluginHooksService(); $hooks->registerHandler('foo', 'bar', array('Elgg_PluginHooksServiceTest', 'changeReturn')); $returnval = $hooks->trigger('foo', 'bar', array('testCase' => $this), 1); $this->assertEquals(2, $returnval); }
public function testUncallableHandlersAreLogged() { $hooks = new Elgg_PluginHooksService(); $loggerMock = $this->getMock('Elgg_Logger', array(), array(), '', false); $hooks->setLogger($loggerMock); $hooks->registerHandler('foo', 'bar', array(new stdClass(), 'uncallableMethod')); $expectedMsg = 'handler for plugin hook [foo, bar] is not callable: (stdClass)->uncallableMethod'; $loggerMock->expects($this->once())->method('warn')->with($expectedMsg); $hooks->trigger('foo', 'bar'); }