Skip to content

Commit

Permalink
Merge branch 'MDL-66554-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 4, 2019
2 parents 38d2c99 + 7a30377 commit f37035c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 7 additions & 1 deletion mod/scorm/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ public static function launch_sco_parameters() {
* @throws moodle_exception
*/
public static function launch_sco($scormid, $scoid = 0) {
global $DB;
global $DB, $CFG;

require_once($CFG->libdir . '/completionlib.php');

$params = self::validate_parameters(self::launch_sco_parameters(),
array(
Expand All @@ -882,6 +884,10 @@ public static function launch_sco($scormid, $scoid = 0) {
throw new moodle_exception('cannotfindsco', 'scorm');
}

// Mark module viewed.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

list($sco, $scolaunchurl) = scorm_get_sco_and_launch_url($scorm, $params['scoid'], $context);
// Trigger the SCO launched event.
scorm_launch_sco($scorm, $sco, $cm, $context, $scolaunchurl);
Expand Down
20 changes: 15 additions & 5 deletions mod/scorm/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
* Set up for every test
*/
public function setUp() {
global $DB;
global $DB, $CFG;
$this->resetAfterTest();
$this->setAdminUser();

$CFG->enablecompletion = 1;
// Setup test data.
$this->course = $this->getDataGenerator()->create_course();
$this->scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $this->course->id));
$this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$this->scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $this->course->id),
array('completion' => 2, 'completionview' => 1));
$this->context = context_module::instance($this->scorm->cmid);
$this->cm = get_coursemodule_from_instance('scorm', $this->scorm->id);

Expand Down Expand Up @@ -849,8 +851,8 @@ public function test_launch_sco() {
$result = external_api::clean_returnvalue(mod_scorm_external::launch_sco_returns(), $result);

$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
$this->assertCount(3, $events);
$event = array_pop($events);

// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_scorm\event\sco_launched', $event);
Expand All @@ -860,6 +862,14 @@ public function test_launch_sco() {
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());

$event = array_shift($events);
$this->assertInstanceOf('\core\event\course_module_completion_updated', $event);

// Check completion status.
$completion = new completion_info($this->course);
$completiondata = $completion->get_data($this->cm);
$this->assertEquals(COMPLETION_VIEWED, $completiondata->completionstate);

// Invalid SCO.
try {
mod_scorm_external::launch_sco($this->scorm->id, -1);
Expand Down

0 comments on commit f37035c

Please sign in to comment.