Skip to content

Commit

Permalink
MDL-39955 completion: Added unittest for course_completed event
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Aug 13, 2013
1 parent 06f8ea7 commit 1cb1e5f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions badges/tests/badgeslib_test.php
Expand Up @@ -238,4 +238,26 @@ public function test_badges_observer_course_module_criteria_review() {
$this->assertDebuggingCalled('Error baking badge image!');
$this->assertTrue($badge->is_issued($this->user->id));
}

/**
* Test badges observer when course_completed event is fired.
*/
public function test_badges_observer_course_criteria_review() {
$badge = new badge($this->coursebadge);
$this->assertFalse($badge->is_issued($this->user->id));

$criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
$criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY));
$criteria_overall1 = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_COURSE, 'badgeid' => $badge->id));
$criteria_overall1->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ANY, 'course_'.$this->course->id => $this->course->id));

$ccompletion = new completion_completion(array('course' => $this->course->id, 'userid' => $this->user->id));

// Mark course as complete.
$ccompletion->mark_complete();

// Check if badge is awarded.
$this->assertDebuggingCalled('Error baking badge image!');
$this->assertTrue($badge->is_issued($this->user->id));
}
}
27 changes: 27 additions & 0 deletions lib/tests/completionlib_test.php
Expand Up @@ -782,6 +782,33 @@ public function test_course_module_completion_updated_event() {
$this->assertEventLegacyData($current, $event);
}

/**
* Test course completed event.
*/
public function test_course_completed_event() {
global $USER;

$this->setup_data();
$this->setAdminUser();

$completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
$ccompletion = new completion_completion(array('course' => $this->course->id, 'userid' => $this->user->id));

// Mark course as complete and get triggered event.
$sink = $this->redirectEvents();
$ccompletion->mark_complete();
$events = $sink->get_events();
$event = reset($events);

$this->assertInstanceOf('\core\event\course_completed', $event);
$this->assertEquals($this->course->id, $event->get_record_snapshot('course_completions', $event->objectid)->course);
$this->assertEquals($this->course->id, $event->courseid);
$this->assertEquals($USER->id, $event->userid);
$this->assertEquals($this->user->id, $event->other['relateduserid']);
$this->assertEquals(context_course::instance($this->course->id), $event->get_context());
$data = $ccompletion->get_record_data();
$this->assertEventLegacyData($data, $event);
}
}


Expand Down

0 comments on commit 1cb1e5f

Please sign in to comment.