/** * Registers a handler to a particular event group. * * @param string $event The event name. * @param callback $handler The handler, a function or an instance of a event object. * * @return JApplicationBase The application to allow chaining. * * @since 12.1 */ public function registerEvent($event, $handler) { if ($this->dispatcher instanceof JDispatcher) { $this->dispatcher->register($event, $handler); } return $this; }
/** * Test JDispatcher::trigger(). * * @since 11.3 */ public function testTrigger() { $this->object->register('onTestEvent', 'JEventMockFunction'); $this->object->register('', 'JEventInspector'); //We check a non-existing event $this->assertThat($this->object->trigger('onFakeEvent'), $this->equalTo(array())); //Lets check the existing event "onTestEvent" without parameters $this->assertThat($this->object->trigger('onTestEvent'), $this->equalTo(array('JDispatcherMockFunction executed', ''))); //Lets check the existing event "onTestEvent" with parameters $this->assertThat($this->object->trigger('onTestEvent', array('one', 'two')), $this->equalTo(array('JDispatcherMockFunction executed', 'onetwo'))); //We check a situation where the observer is broken. Joomla should handle this gracefully $this->object->_observers = array(); $this->assertThat($this->object->trigger('onTestEvent'), $this->equalTo(array())); }