Skip to content
Snippets Groups Projects
Commit 0b6d9630 authored by David Pesce's avatar David Pesce
Browse files

adding appropriate tests - ignore duplicates for now

parent 2fdf0421
No related branches found
No related tags found
No related merge requests found
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace XREmitter\Tests;
defined('MOODLE_INTERNAL') || die();
use \XREmitter\Events\AttemptCompleted as Event;
class attempt_reviewed_test extends event_test {
protected static $recipename = 'attempt_reviewed';
/**
* Sets up the tests.
* @override EventTest
*/
public function setup() {
$this->event = new Event();
}
protected function construct_input() {
return array_merge(
parent::construct_input(),
$this->construct_object('course'),
$this->construct_object('module'),
$this->construct_attempt()
);
}
protected function construct_attempt() {
return array_merge(parent::construct_attempt(), [
'attempt_score_raw' => 1,
'attempt_score_min' => 0,
'attempt_score_max' => 5,
'attempt_score_scaled' => 0.2,
'attempt_success' => false,
'attempt_completed' => true,
'attempt_duration' => 'P01DT',
]);
}
protected function assert_output($input, $output) {
parent::assert_output($input, $output);
$this->assert_verb('http://adlnet.gov/expapi/verbs/reviewed', 'reviewed', $output['verb']);
$this->assert_attempt($input, $output['context']['contextActivities']['grouping'][2]);
$this->assert_object('course', $input, $output['context']['contextActivities']['grouping'][1]);
$this->assert_object('module', $input, $output['object']);
$this->assertEquals($input['attempt_score_raw'], $output['result']['score']['raw']);
$this->assertEquals($input['attempt_score_min'], $output['result']['score']['min']);
$this->assertEquals($input['attempt_score_max'], $output['result']['score']['max']);
$this->assertEquals($input['attempt_score_scaled'], $output['result']['score']['scaled']);
$this->assertEquals($input['attempt_success'], $output['result']['success']);
$this->assertEquals($input['attempt_completed'], $output['result']['completion']);
$this->assertEquals($input['attempt_duration'], $output['result']['duration']);
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace XREmitter\Tests;
defined('MOODLE_INTERNAL') || die();
use \XREmitter\Events\AttemptCompleted as Event;
class attempt_submitted_test extends event_test {
protected static $recipename = 'attempt_submitted';
/**
* Sets up the tests.
* @override EventTest
*/
public function setup() {
$this->event = new Event();
}
protected function construct_input() {
return array_merge(
parent::construct_input(),
$this->construct_object('course'),
$this->construct_object('module'),
$this->construct_attempt()
);
}
protected function construct_attempt() {
return array_merge(parent::construct_attempt(), [
'attempt_score_raw' => 1,
'attempt_score_min' => 0,
'attempt_score_max' => 5,
'attempt_score_scaled' => 0.2,
'attempt_success' => false,
'attempt_completed' => true,
'attempt_duration' => 'P01DT',
]);
}
protected function assert_output($input, $output) {
parent::assert_output($input, $output);
$this->assert_verb('http://adlnet.gov/expapi/verbs/submitted', 'submitted', $output['verb']);
$this->assert_attempt($input, $output['context']['contextActivities']['grouping'][2]);
$this->assert_object('course', $input, $output['context']['contextActivities']['grouping'][1]);
$this->assert_object('module', $input, $output['object']);
$this->assertEquals($input['attempt_score_raw'], $output['result']['score']['raw']);
$this->assertEquals($input['attempt_score_min'], $output['result']['score']['min']);
$this->assertEquals($input['attempt_score_max'], $output['result']['score']['max']);
$this->assertEquals($input['attempt_score_scaled'], $output['result']['score']['scaled']);
$this->assertEquals($input['attempt_success'], $output['result']['success']);
$this->assertEquals($input['attempt_completed'], $output['result']['completion']);
$this->assertEquals($input['attempt_duration'], $output['result']['duration']);
}
}
......@@ -55,7 +55,7 @@ class attempt_reviewed_test extends attempt_started_test {
protected function assert_attempt($input, $output) {
parent::assert_attempt($input, $output);
$this->assertEquals((float) $input->sumgrades, $output['attempt_score_raw']);
$this->assertEquals($input->state === 'finished', $output['attempt_completed']);
$this->assertEquals($input->state === 'finished', $output['attempt_reviewed']);
}
protected function assert_grade_items($input, $output) {
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace MXTranslator\Tests;
defined('MOODLE_INTERNAL') || die();
use \MXTranslator\Events\AttemptReviewed as Event;
class attempt_reviewed_test extends attempt_started_test {
protected static $recipename = 'attempt_submitted';
/**
* Sets up the tests.
* @override TestCase
*/
public function setup() {
parent::setup();
$this->event = new Event();
}
protected function construct_input() {
return array_merge(parent::construct_input(), [
'grade_items' => $this->construct_grade_items()
]);
}
private function construct_grade_items() {
return (object) [
'grademin' => 0,
'grademax' => 5,
'gradepass' => 5
];
}
protected function assert_output($input, $output) {
parent::assert_output($input, $output);
$this->assert_attempt($input['attempt'], $output);
$this->assert_grade_items($input, $output);
}
protected function assert_attempt($input, $output) {
parent::assert_attempt($input, $output);
$this->assertEquals((float) $input->sumgrades, $output['attempt_score_raw']);
$this->assertEquals($input->state === 'finished', $output['attempt_submitted']);
}
protected function assert_grade_items($input, $output) {
$this->assertEquals((float) $input['grade_items']->grademin, $output['attempt_score_min']);
$this->assertEquals((float) $input['grade_items']->grademax, $output['attempt_score_max']);
$this->assertEquals(($input['attempt']->sumgrades >= $input['grade_items']->gradepass), $output['attempt_success']);
if ($output['attempt_score_scaled'] >= 0) {
$this->assertEquals($output['attempt_score_scaled'], $output['attempt_score_raw'] / $output['attempt_score_max']);
} else {
$this->assertEquals($output['attempt_score_scaled'], $output['attempt_score_raw'] / $output['attempt_score_min']);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment