MDL-39915 cleanup core_eventslib_testcase

This commit is contained in:
Petr Škoda
2013-07-27 18:11:58 +02:00
parent 96deb95070
commit e6e632ec6e
+26 -32
View File
@@ -15,10 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests events subsystems
* Tests events subsystem.
*
* @package core
* @subpackage event
* @package core_event
* @subpackage phpunit
* @copyright 2007 onwards Martin Dougiamas (http://dougiamas.com)
* @author Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -34,35 +34,31 @@ class core_eventslib_testcase extends advanced_testcase {
* These tests have to work no matter the data currently in the database
* (meaning they should run on a brand new site). This means several items of
* data have to be artificially inseminated (:-) in the DB.
* @return void
*/
protected function setUp() {
parent::setUp();
// Set global category settings to -1 (not force)
// Set global category settings to -1 (not force).
eventslib_sample_function_handler('reset');
eventslib_sample_handler_class::static_method('reset');
events_update_definition('unittest');
$this->resetAfterTest(true);
$this->resetAfterTest();
}
/**
* Tests the installation of event handlers from file
* @return void
*/
public function test_events_update_definition__install() {
global $CFG, $DB;
global $DB;
$dbcount = $DB->count_records('events_handlers', array('component'=>'unittest'));
$handlers = array();
require(__DIR__.'/fixtures/events.php');
$filecount = count($handlers);
$this->assertEquals($dbcount, $filecount, 'Equal number of handlers in file and db: %s');
$this->assertCount($dbcount, $handlers, 'Equal number of handlers in file and db: %s');
}
/**
* Tests the uninstallation of event handlers from file
* @return void
* Tests the uninstallation of event handlers from file.
*/
public function test_events_update_definition__uninstall() {
global $DB;
@@ -72,36 +68,33 @@ class core_eventslib_testcase extends advanced_testcase {
}
/**
* Tests the update of event handlers from file
* @return void
* Tests the update of event handlers from file.
*/
public function test_events_update_definition__update() {
global $DB;
// first modify directly existing handler
// First modify directly existing handler.
$handler = $DB->get_record('events_handlers', array('component'=>'unittest', 'eventname'=>'test_instant'));
$original = $handler->handlerfunction;
// change handler in db
// Change handler in db.
$DB->set_field('events_handlers', 'handlerfunction', serialize('some_other_function_handler'), array('id'=>$handler->id));
// update the definition, it should revert the handler back
// Update the definition, it should revert the handler back.
events_update_definition('unittest');
$handler = $DB->get_record('events_handlers', array('component'=>'unittest', 'eventname'=>'test_instant'));
$this->assertEquals($handler->handlerfunction, $original, 'update should sync db with file definition: %s');
$this->assertSame($handler->handlerfunction, $original, 'update should sync db with file definition: %s');
}
/**
* tests events_trigger_is_registered funtion()
* @return void
* Tests events_trigger_is_registered() function.
*/
public function test_events_is_registered() {
$this->assertTrue(events_is_registered('test_instant', 'unittest'));
}
/**
* tests events_trigger funtion()
* @return void
* Tests events_trigger() function.
*/
public function test_events_trigger__instant() {
$this->assertEquals(0, events_trigger('test_instant', 'ok'));
@@ -110,8 +103,7 @@ class core_eventslib_testcase extends advanced_testcase {
}
/**
* tests events_trigger funtion()
* @return void
* Tests events_trigger() function.
*/
public function test_events_trigger__cron() {
$this->assertEquals(0, events_trigger('test_cron', 'ok'));
@@ -121,8 +113,7 @@ class core_eventslib_testcase extends advanced_testcase {
}
/**
* tests events_pending_count()
* @return void
* Tests events_pending_count() function.
*/
public function test_events_pending_count() {
events_trigger('test_cron', 'ok');
@@ -132,8 +123,7 @@ class core_eventslib_testcase extends advanced_testcase {
}
/**
* tests events_trigger funtion() when instant handler fails
* @return void
* Tests events_trigger() function when instant handler fails.
*/
public function test_events_trigger__failed_instant() {
$this->assertEquals(1, events_trigger('test_instant', 'fail'), 'fail first event: %s');
@@ -141,7 +131,7 @@ class core_eventslib_testcase extends advanced_testcase {
$this->assertEquals(0, events_cron('test_instant'), 'all events should stay in queue: %s');
$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
eventslib_sample_function_handler('ignorefail'); // Ignore "fail" eventdata from now on.
$this->assertEquals(1, events_trigger('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');
@@ -155,7 +145,9 @@ class core_eventslib_testcase extends advanced_testcase {
}
// test handler function
/**
* Test handler function.
*/
function eventslib_sample_function_handler($eventdata) {
static $called = 0;
static $ignorefail = false;
@@ -189,9 +181,11 @@ function eventslib_sample_function_handler($eventdata) {
}
// test handler class with static method
/**
* Test handler class with static method.
*/
class eventslib_sample_handler_class {
static function static_method($eventdata) {
public static function static_method($eventdata) {
static $called = 0;
static $ignorefail = false;