示例#1
0
 /**
  * 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 JEventDispatcher) {
         $this->dispatcher->register($event, $handler);
     }
     return $this;
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.6
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$session = $this->getMockSession();
     $this->dispatcher = new JEventDispatcher();
     TestReflection::setValue($this->dispatcher, 'instance', $this->dispatcher);
     $this->dispatcher->register('onAfterRenderModules', array($this, 'eventCallback'));
 }
示例#3
0
 /**
  * Test JEventDispatcher::trigger().
  *
  * @since    11.3
  *
  * @return void
  */
 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()));
     // Let's check the existing event "onTestEvent" without parameters
     $this->assertThat($this->object->trigger('onTestEvent'), $this->equalTo(array('JEventDispatcherMockFunction executed', '')));
     // Let's check the existing event "onTestEvent" with parameters
     $this->assertThat($this->object->trigger('onTestEvent', array('one', 'two')), $this->equalTo(array('JEventDispatcherMockFunction executed', 'onetwo')));
     // We check a situation where the observer is broken. Joomla should handle this gracefully
     TestReflection::setValue($this->object, '_observers', array());
     $this->assertThat($this->object->trigger('onTestEvent'), $this->equalTo(array()));
 }