Skip to content

Commit

Permalink
Merge branch 'MDL-41029-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Aug 5, 2013
2 parents 698be6b + 513d879 commit 50c6e3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/classes/event/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static final function create(array $data = null) {

if (!isset($event->data['courseid'])) {
if ($coursecontext = $event->context->get_course_context(false)) {
$event->data['courseid'] = $coursecontext->id;
$event->data['courseid'] = $coursecontext->instanceid;
} else {
$event->data['courseid'] = 0;
}
Expand Down
33 changes: 33 additions & 0 deletions lib/tests/event_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ public function test_event_properties() {
$this->assertEquals($event->get_context(), $event2->get_context());
}

public function test_event_properties_guessing() {
global $USER;
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
$context = context_module::instance($forum->cmid);
$event = \core_tests\event\unittest_executed::create(array('context' => $context, 'objectid' => 5));

// Check guessed course ID, and default properties.
$this->assertSame('\core_tests\event\unittest_executed', $event->eventname);
$this->assertSame('core_tests', $event->component);
$this->assertSame('executed', $event->action);
$this->assertSame('unittest', $event->target);
$this->assertSame(5, $event->objectid);
$this->assertEquals($context, $event->get_context());
$this->assertEquals($course->id, $event->courseid);
$this->assertSame($USER->id, $event->userid);
$this->assertNull($event->relateduserid);

$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$event = \core_tests\event\unittest_executed::create(array('contextid' => $context->id, 'objectid' => 5));

// Check guessing on contextid, and user context level.
$this->assertEquals($context, $event->get_context());
$this->assertEquals($context->id, $event->contextid);
$this->assertEquals($context->contextlevel, $event->contextlevel);
$this->assertSame(0, $event->courseid);
$this->assertSame($USER->id, $event->userid);
$this->assertSame($user->id, $event->relateduserid);
}

public function test_observers_parsing() {

$observers = array(
Expand Down

0 comments on commit 50c6e3e

Please sign in to comment.