Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'wip-MDL-43175-master' of git://github.com/abgreeve/moodle
  • Loading branch information
marinaglancy committed Dec 9, 2013
2 parents 895d305 + 5bb7158 commit 95971ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/classes/event/base.php
Expand Up @@ -444,7 +444,9 @@ protected final function validate_before_trigger() {
debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER);
}
$encoded = json_encode($this->data['other']);
if ($encoded === false or $this->data['other'] !== json_decode($encoded, true)) {
// The comparison here is not set to strict as whole float numbers will be converted to integers through JSON encoding /
// decoding and send an unwanted debugging message.
if ($encoded === false or $this->data['other'] != json_decode($encoded, true)) {
debugging('other event data must be compatible with json encoding', DEBUG_DEVELOPER);
}
if ($this->data['userid'] and !is_number($this->data['userid'])) {
Expand Down
6 changes: 6 additions & 0 deletions lib/tests/event_test.php
Expand Up @@ -666,6 +666,12 @@ public function test_problematic_events() {
$event6->trigger();
$this->assertDebuggingCalled();

// Check that whole float numbers do not trigger debugging messages.
$event7 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(),
'other' => array('wholenumber' => 90.0000, 'numberwithdecimals' => 54.7656, 'sample' => 1)));
$event7->trigger();
$this->assertDebuggingNotCalled();

$event = \core_tests\event\problematic_event2::create(array());
$this->assertDebuggingNotCalled();
$event = \core_tests\event\problematic_event2::create(array('context'=>\context_system::instance()));
Expand Down

0 comments on commit 95971ae

Please sign in to comment.