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'); }
/** * 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); }
/** * Process logging data * * @param mixed $data The data to process * @param bool $display Whether to display the data to the user. Otherwise log it. * @param int $level The logging level for this data * @return void */ protected function process($data, $display, $level) { global $CONFIG; // plugin can return false to stop the default logging method $params = array('level' => $level, 'msg' => $data, 'display' => $display, 'to_screen' => $display); if (!$this->hooks->trigger('debug', 'log', $params, true)) { return; } // Do not want to write to screen before page creation has started. // This is not fool-proof but probably fixes 95% of the cases when logging // results in data sent to the browser before the page is begun. if (!isset($CONFIG->pagesetupdone)) { $display = false; } // Do not want to write to JS or CSS pages if (elgg_in_context('js') || elgg_in_context('css')) { $display = false; } if ($display == true) { echo '<pre class="elgg-logger-data">'; echo htmlspecialchars(print_r($data, true), ENT_QUOTES, 'UTF-8'); echo '</pre>'; } else { error_log(print_r($data, true)); } }
/** * Is someone using the deprecated override * * @param Elgg_Notifications_Event $event Event * @return boolean */ protected function existsDeprecatedNotificationOverride(Elgg_Notifications_Event $event) { $entity = $event->getObject(); if (!elgg_instanceof($entity)) { return false; } $params = array('event' => $event->getAction(), 'object_type' => $entity->getType(), 'object' => $entity); $hookresult = $this->hooks->trigger('object:notifications', $entity->getType(), $params, false); if ($hookresult === true) { elgg_deprecated_notice("Using the plugin hook 'object:notifications' has been deprecated by the hook 'send:before', 'notifications'", 1.9); return true; } else { return false; } }