mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-57915 mod_data: Move view completion and event code to function
This commit is contained in:
parent
1034421264
commit
023ffa656d
3 changed files with 74 additions and 14 deletions
|
@ -879,4 +879,46 @@ class mod_data_lib_testcase extends advanced_testcase {
|
|||
$config = json_decode($database->config);
|
||||
$this->assertEquals($value, $config->$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test data_view
|
||||
* @return void
|
||||
*/
|
||||
public function test_data_view() {
|
||||
global $CFG;
|
||||
|
||||
$CFG->enablecompletion = 1;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
// Setup test data.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1));
|
||||
$context = context_module::instance($data->cmid);
|
||||
$cm = get_coursemodule_from_instance('data', $data->id);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
data_view($data, $course, $cm, $context);
|
||||
|
||||
$events = $sink->get_events();
|
||||
// 2 additional events thanks to completion.
|
||||
$this->assertCount(3, $events);
|
||||
$event = array_shift($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_data\event\course_module_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$moodleurl = new \moodle_url('/mod/data/view.php', array('id' => $cm->id));
|
||||
$this->assertEquals($moodleurl, $event->get_url());
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertNotEmpty($event->get_name());
|
||||
|
||||
// Check completion status.
|
||||
$completion = new completion_info($course);
|
||||
$completiondata = $completion->get_data($cm);
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue