Example #1
0
    public function testCondition()
    {
        $xml = '<event key="core/test" subject="foo">
  <call>Jarves\\Tests\\Configuration\\EventTest::fireEvent</call>
  <condition>
    <rule key="field1" type="equal">50</rule>
    <or/>
    <rule key="field1" type="greater">200</rule>
  </condition>
</event>';
        $event = new Event($xml, $this->getJarves());
        $this->assertEquals($xml, $event->toXml());
        $this->getJarvesEventDispatcher()->detachEvents();
        $this->getJarvesEventDispatcher()->attachEvent($event);
        self::$fired = 0;
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent('foo'));
        $this->assertEquals(0, self::$fired, 'no args, therefore condition not satisfied');
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent('foo', ['field1' => 50]));
        $this->assertEquals(1, self::$fired);
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent('foo', ['field1' => 201]));
        $this->assertEquals(2, self::$fired);
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent('notFoo', ['field1' => 201]));
        $this->assertEquals(2, self::$fired);
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent('foo', ['field1' => 200]));
        $this->assertEquals(2, self::$fired);
        $this->getEventDispatcher()->dispatch('core/test', new GenericEvent());
        $this->assertEquals(2, self::$fired);
        $this->getEventDispatcher()->dispatch('core/notTest', new GenericEvent());
        $this->assertEquals(2, self::$fired);
        $this->getJarvesEventDispatcher()->detachEvents();
    }