Skip to content

Commit

Permalink
Merge branch 'MDL-52556-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Dec 22, 2015
2 parents b687494 + 6a03246 commit 40b6fbd
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
23 changes: 23 additions & 0 deletions mod/scorm/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ public static function get_scorm_scoes($scormid, $organization = '') {
if (!$scoes = scorm_get_scoes($scorm->id, $params['organization'])) {
// Function scorm_get_scoes return false, not an empty array.
$scoes = array();
} else {
$scoreturnstructure = self::get_scorm_scoes_returns();
foreach ($scoes as $sco) {
$extradata = array();
foreach ($sco as $element => $value) {
// Check if the element is extra data (not a basic SCO element).
if (!isset($scoreturnstructure->keys['scoes']->content->keys[$element])) {
$extradata[] = array(
'element' => $element,
'value' => $value
);
}
}
$sco->extradata = $extradata;
}
}

$result = array();
Expand Down Expand Up @@ -257,6 +272,14 @@ public static function get_scorm_scoes_returns() {
'scormtype' => new external_value(PARAM_ALPHA, 'scorm type (asset, sco)'),
'title' => new external_value(PARAM_NOTAGS, 'sco title'),
'sortorder' => new external_value(PARAM_INT, 'sort order'),
'extradata' => new external_multiple_structure(
new external_single_structure(
array(
'element' => new external_value(PARAM_RAW, 'element name'),
'value' => new external_value(PARAM_RAW, 'element value')
)
), 'Additional SCO data', VALUE_OPTIONAL
)
), 'SCORM SCO data'
)
),
Expand Down
58 changes: 57 additions & 1 deletion mod/scorm/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,27 @@ public function test_mod_scorm_get_scorm_scoes() {

$scoes = scorm_get_scoes($scorm->id);
$sco = array_shift($scoes);
$sco->extradata = array();
$this->assertEquals((array) $sco, $result['scoes'][0]);

$sco = array_shift($scoes);
// Remove specific sco data.
$sco->extradata = array();
$sco->extradata[] = array(
'element' => 'isvisible',
'value' => $sco->isvisible
);
$sco->extradata[] = array(
'element' => 'parameters',
'value' => $sco->parameters
);
unset($sco->isvisible);
unset($sco->parameters);

// Sort the array (if we don't sort tests will fails for Postgres).
usort($result['scoes'][1]['extradata'], function($a, $b) {
return strcmp($a['element'], $b['element']);
});

$this->assertEquals((array) $sco, $result['scoes'][1]);

// Use organization.
Expand All @@ -284,6 +299,47 @@ public function test_mod_scorm_get_scorm_scoes() {
} catch (moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}

}

/**
* Test get scorm scoes (with a complex SCORM package)
*/
public function test_mod_scorm_get_scorm_scoes_complex_package() {
global $CFG;

// As student.
self::setUser($this->student);

$record = new stdClass();
$record->course = $this->course->id;
$record->packagefilepath = $CFG->dirroot.'/mod/scorm/tests/packages/complexscorm.zip';
$scorm = self::getDataGenerator()->create_module('scorm', $record);

$result = mod_scorm_external::get_scorm_scoes($scorm->id);
$result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
$this->assertCount(9, $result['scoes']);
$this->assertCount(0, $result['warnings']);

$expectedscoes = array();
$scoreturnstructure = mod_scorm_external::get_scorm_scoes_returns();
$scoes = scorm_get_scoes($scorm->id);
foreach ($scoes as $sco) {
$sco->extradata = array();
foreach ($sco as $element => $value) {
// Add the extra data to the extradata array and remove the object element.
if (!isset($scoreturnstructure->keys['scoes']->content->keys[$element])) {
$sco->extradata[] = array(
'element' => $element,
'value' => $value
);
unset($sco->{$element});
}
}
$expectedscoes[] = (array) $sco;
}

$this->assertEquals($expectedscoes, $result['scoes']);
}

/*
Expand Down
Binary file added mod/scorm/tests/packages/complexscorm.zip
Binary file not shown.

0 comments on commit 40b6fbd

Please sign in to comment.