/** * Tests events_trigger_legacy() function when instant handler fails. */ public function test_events_trigger__failed_instant() { global $CFG; events_update_definition('unittest'); $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); $olddebug = $CFG->debug; $this->assertEquals(1, events_trigger_legacy('test_instant', 'fail'), 'fail first event: %s'); $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should fail too: %s'); $this->assertDebuggingNotCalled(); $this->assertEquals(0, events_cron('test_instant'), 'all events should stay in queue: %s'); // events_cron + one for each dispatched event. $this->assertDebuggingCalledCount(3); $this->assertEquals(2, events_pending_count('test_instant'), 'two events should in queue: %s'); $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER); $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify no event dispatched yet: %s'); eventslib_sample_function_handler('ignorefail'); // Ignore "fail" eventdata from now on. $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should go to queue directly: %s'); $this->assertDebuggingNotCalled(); $this->assertEquals(3, events_pending_count('test_instant'), 'three events should in queue: %s'); $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER); $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify previous event was not dispatched: %s'); $this->assertEquals(3, events_cron('test_instant'), 'all events should be dispatched: %s'); // events_cron + one for each dispatched event. $this->assertDebuggingCalledCount(4); $this->assertEquals(3, eventslib_sample_function_handler('status'), 'verify three events were dispatched: %s'); $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s'); $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER); $this->assertEquals(0, events_trigger_legacy('test_instant', 'ok'), 'this event should be dispatched immediately: %s'); $this->assertDebuggingCalled(self::DEBUGGING_MSG, DEBUG_DEVELOPER); $this->assertEquals(4, eventslib_sample_function_handler('status'), 'verify event was dispatched: %s'); $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s'); $this->assertDebuggingCalled('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2' . ' API, please use it instead.', DEBUG_DEVELOPER); }
/** * tests events_trigger funtion() when instant handler fails */ function test__events_trigger__failed_instant() { $this->assertEqual(1, events_trigger('test_instant', 'fail'), 'fail first event: %s'); $this->assertEqual(1, events_trigger('test_instant', 'ok'), 'this one should fail too: %s'); $this->assertEqual(0, events_cron('test_instant'), 'all events should stay in queue: %s'); $this->assertEqual(2, events_pending_count('test_instant'), 'two events should in queue: %s'); $this->assertEqual(0, sample_function_handler('status'), 'verify no event dispatched yet: %s'); sample_function_handler('ignorefail'); //ignore "fail" eventdata from now on $this->assertEqual(1, events_trigger('test_instant', 'ok'), 'this one should go to queue directly: %s'); $this->assertEqual(3, events_pending_count('test_instant'), 'three events should in queue: %s'); $this->assertEqual(0, sample_function_handler('status'), 'verify previous event was not dispatched: %s'); $this->assertEqual(3, events_cron('test_instant'), 'all events should be dispatched: %s'); $this->assertEqual(3, sample_function_handler('status'), 'verify three events were dispatched: %s'); $this->assertEqual(0, events_pending_count('test_instant'), 'no events should in queue: %s'); $this->assertEqual(0, events_trigger('test_instant', 'ok'), 'this event should be dispatched immediately: %s'); $this->assertEqual(4, sample_function_handler('status'), 'verify event was dispatched: %s'); $this->assertEqual(0, events_pending_count('test_instant'), 'no events should in queue: %s'); }
/** * Tests events_trigger_legacy() function when instant handler fails. */ public function test_events_trigger__failed_instant() { global $CFG; $olddebug = $CFG->debug; $this->assertEquals(1, events_trigger_legacy('test_instant', 'fail'), 'fail first event: %s'); $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should fail too: %s'); $this->assertEquals(0, events_cron('test_instant'), 'all events should stay in queue: %s'); $this->assertDebuggingCalled(); $this->assertEquals(2, events_pending_count('test_instant'), 'two events should in queue: %s'); $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify no event dispatched yet: %s'); eventslib_sample_function_handler('ignorefail'); // Ignore "fail" eventdata from now on. $this->assertEquals(1, events_trigger_legacy('test_instant', 'ok'), 'this one should go to queue directly: %s'); $this->assertEquals(3, events_pending_count('test_instant'), 'three events should in queue: %s'); $this->assertEquals(0, eventslib_sample_function_handler('status'), 'verify previous event was not dispatched: %s'); $this->assertEquals(3, events_cron('test_instant'), 'all events should be dispatched: %s'); $this->assertEquals(3, eventslib_sample_function_handler('status'), 'verify three events were dispatched: %s'); $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s'); $this->assertEquals(0, events_trigger_legacy('test_instant', 'ok'), 'this event should be dispatched immediately: %s'); $this->assertEquals(4, eventslib_sample_function_handler('status'), 'verify event was dispatched: %s'); $this->assertEquals(0, events_pending_count('test_instant'), 'no events should in queue: %s'); }