Skip to content

Commit

Permalink
Merge branch 'MDL-42021-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Oct 1, 2013
2 parents 7f58018 + 31e571c commit 268f4cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/classes/event/base.php
Expand Up @@ -463,6 +463,9 @@ protected final function validate_before_trigger() {
if (!$DB->get_manager()->table_exists($this->data['objecttable'])) {
debugging('Unknown table specified in objecttable field', DEBUG_DEVELOPER);
}
if (!isset($this->data['objectid'])) {
debugging('Event property objectid must be set when objecttable is defined', DEBUG_DEVELOPER);
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions lib/tests/event_test.php
Expand Up @@ -619,17 +619,21 @@ public function test_bad_events() {
@$event->trigger();
$this->assertDebuggingCalled();

$event = \core_tests\event\bad_event6::create(array('context'=>\context_system::instance()));
$event = \core_tests\event\bad_event6::create(array('objectid'=>1, 'context'=>\context_system::instance()));
$event->trigger();
$this->assertDebuggingCalled();
$this->assertDebuggingCalled('Unknown table specified in objecttable field');

$event = \core_tests\event\bad_event7::create(array('objectid'=>1, 'context'=>\context_system::instance()));
try {
$event->trigger();
$this->fail('Exception expected when $data contains objectid by objecttable not specified');
$this->fail('Exception expected when $data contains objectid but objecttable not specified');
} catch (\moodle_exception $e) {
$this->assertInstanceOf('\coding_exception', $e);
}

$event = \core_tests\event\bad_event8::create(array('context'=>\context_system::instance()));
$event->trigger();
$this->assertDebuggingCalled('Event property objectid must be set when objecttable is defined');
}

public function test_problematic_events() {
Expand Down
8 changes: 8 additions & 0 deletions lib/tests/fixtures/event_fixtures.php
Expand Up @@ -174,6 +174,14 @@ protected function init() {
}
}

class bad_event8 extends \core\event\base {
protected function init() {
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'user';
}
}

class problematic_event1 extends \core\event\base {
protected function init() {
$this->data['crud'] = 'u';
Expand Down

0 comments on commit 268f4cb

Please sign in to comment.