| Línea 17... |
Línea 17... |
| 17 |
namespace quiz_responses;
|
17 |
namespace quiz_responses;
|
| Línea 18... |
Línea 18... |
| 18 |
|
18 |
|
| 19 |
use mod_quiz\quiz_attempt;
|
19 |
use mod_quiz\quiz_attempt;
|
| Línea 20... |
Línea -... |
| 20 |
use question_bank;
|
- |
|
| 21 |
|
- |
|
| 22 |
defined('MOODLE_INTERNAL') || die();
|
- |
|
| 23 |
|
- |
|
| 24 |
global $CFG;
|
- |
|
| 25 |
require_once($CFG->dirroot . '/mod/quiz/tests/attempt_walkthrough_from_csv_test.php');
|
- |
|
| 26 |
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php');
|
- |
|
| 27 |
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
|
20 |
use question_bank;
|
| 28 |
|
21 |
|
| 29 |
/**
|
22 |
/**
|
| 30 |
* Quiz attempt walk through using data from csv file.
|
23 |
* Quiz attempt walk through using data from csv file.
|
| 31 |
*
|
24 |
*
|
| 32 |
* @package quiz_responses
|
25 |
* @package quiz_responses
|
| 33 |
* @category test
|
26 |
* @category test
|
| 34 |
* @copyright 2013 The Open University
|
27 |
* @copyright 2013 The Open University
|
| 35 |
* @author Jamie Pratt <me@jamiep.org>
|
28 |
* @author Jamie Pratt <me@jamiep.org>
|
| 36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| - |
|
30 |
*/
|
| 37 |
*/
|
31 |
final class responses_from_steps_walkthrough_test extends \mod_quiz\tests\attempt_walkthrough_testcase {
|
| - |
|
32 |
#[\Override]
|
| - |
|
33 |
public static function setUpBeforeClass(): void {
|
| - |
|
34 |
global $CFG;
|
| - |
|
35 |
|
| 38 |
class responses_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_from_csv_test {
|
36 |
parent::setUpBeforeClass();
|
| 39 |
protected function get_full_path_of_csv_file(string $setname, string $test): string {
|
37 |
|
| 40 |
// Overridden here so that __DIR__ points to the path of this file.
|
38 |
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php');
|
| Línea 41... |
Línea 39... |
| 41 |
return __DIR__."/fixtures/{$setname}{$test}.csv";
|
39 |
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
|
| 42 |
}
|
40 |
}
|
| 43 |
|
- |
|
| 44 |
/**
|
41 |
|
| - |
|
42 |
#[\Override]
|
| Línea 45... |
Línea 43... |
| 45 |
* @var string[] names of the files which contain the test data.
|
43 |
protected static function get_test_files(): array {
|
| 46 |
*/
|
44 |
return ['questions', 'steps', 'responses'];
|
| 47 |
protected $files = ['questions', 'steps', 'responses'];
|
45 |
}
|
| 48 |
|
46 |
|
| 49 |
/**
|
47 |
/**
|
| - |
|
48 |
* Create a quiz add questions to it, walk through quiz attempts and then check results.
|
| 50 |
* Create a quiz add questions to it, walk through quiz attempts and then check results.
|
49 |
*
|
| 51 |
*
|
50 |
* @param array $quizsettings settings to override default settings for quiz created by generator. Taken from quizzes.csv.
|
| 52 |
* @param array $quizsettings settings to override default settings for quiz created by generator. Taken from quizzes.csv.
|
51 |
* @param array $csvdata of data read from csv file "questionsXX.csv", "stepsXX.csv" and "responsesXX.csv".
|
| 53 |
* @param array $csvdata of data read from csv file "questionsXX.csv", "stepsXX.csv" and "responsesXX.csv".
|
- |
|
| 54 |
* @dataProvider get_data_for_walkthrough
|
52 |
* // phpcs:ignore moodle.PHPUnit.TestCaseProvider.dataProviderSyntaxMethodNotFound
|
| 55 |
*/
|
53 |
* @dataProvider get_data_for_walkthrough
|
| Línea 56... |
Línea 54... |
| 56 |
public function test_walkthrough_from_csv($quizsettings, $csvdata): void {
|
54 |
*/
|
| Línea 70... |
Línea 68... |
| 70 |
}
|
68 |
}
|
| 71 |
$this->assert_response_test($quizattemptids[$responses['quizattempt']], $responses);
|
69 |
$this->assert_response_test($quizattemptids[$responses['quizattempt']], $responses);
|
| 72 |
}
|
70 |
}
|
| 73 |
}
|
71 |
}
|
| Línea -... |
Línea 72... |
| - |
|
72 |
|
| - |
|
73 |
/**
|
| - |
|
74 |
* Helper to assert a response.
|
| - |
|
75 |
*
|
| - |
|
76 |
* @param mixed $quizattemptid
|
| - |
|
77 |
* @param mixed $responses
|
| - |
|
78 |
* @throws \coding_exception
|
| 74 |
|
79 |
*/
|
| 75 |
protected function assert_response_test($quizattemptid, $responses) {
|
80 |
protected function assert_response_test($quizattemptid, $responses): void {
|
| Línea 76... |
Línea 81... |
| 76 |
$quizattempt = quiz_attempt::create($quizattemptid);
|
81 |
$quizattempt = quiz_attempt::create($quizattemptid);
|
| 77 |
|
82 |
|
| 78 |
foreach ($responses['slot'] as $slot => $tests) {
|
83 |
foreach ($responses['slot'] as $slot => $tests) {
|
| Línea 87... |
Línea 92... |
| 87 |
}
|
92 |
}
|
| 88 |
$qa = $quizattempt->get_question_attempt($slot);
|
93 |
$qa = $quizattempt->get_question_attempt($slot);
|
| 89 |
$stepswithsubmit = $qa->get_steps_with_submitted_response_iterator();
|
94 |
$stepswithsubmit = $qa->get_steps_with_submitted_response_iterator();
|
| 90 |
$step = $stepswithsubmit[$responses['submittedstepno']];
|
95 |
$step = $stepswithsubmit[$responses['submittedstepno']];
|
| 91 |
if (null === $step) {
|
96 |
if (null === $step) {
|
| 92 |
throw new \coding_exception("There is no step no {$responses['submittedstepno']} ".
|
97 |
throw new \coding_exception("There is no step no {$responses['submittedstepno']} " .
|
| 93 |
"for slot $slot in quizattempt {$responses['quizattempt']}!");
|
98 |
"for slot $slot in quizattempt {$responses['quizattempt']}!");
|
| 94 |
}
|
99 |
}
|
| 95 |
foreach (['responsesummary', 'fraction', 'state'] as $column) {
|
100 |
foreach (['responsesummary', 'fraction', 'state'] as $column) {
|
| 96 |
if (isset($tests[$column]) && $tests[$column] != '') {
|
101 |
if (isset($tests[$column]) && $tests[$column] != '') {
|
| 97 |
switch($column) {
|
102 |
switch ($column) {
|
| 98 |
case 'responsesummary' :
|
103 |
case 'responsesummary':
|
| 99 |
$actual = $qa->get_question()->summarise_response($step->get_qt_data());
|
104 |
$actual = $qa->get_question()->summarise_response($step->get_qt_data());
|
| 100 |
break;
|
105 |
break;
|
| 101 |
case 'fraction' :
|
106 |
case 'fraction':
|
| 102 |
if (count($stepswithsubmit) == $responses['submittedstepno']) {
|
107 |
if (count($stepswithsubmit) == $responses['submittedstepno']) {
|
| 103 |
// If this is the last step then we need to look at the fraction after the question has been
|
108 |
// If this is the last step then we need to look at the fraction after the question has been
|
| 104 |
// finished.
|
109 |
// finished.
|
| 105 |
$actual = $qa->get_fraction();
|
110 |
$actual = $qa->get_fraction();
|
| 106 |
} else {
|
111 |
} else {
|
| 107 |
$actual = $step->get_fraction();
|
112 |
$actual = $step->get_fraction();
|
| 108 |
}
|
113 |
}
|
| 109 |
break;
|
114 |
break;
|
| 110 |
case 'state' :
|
115 |
case 'state':
|
| 111 |
if (count($stepswithsubmit) == $responses['submittedstepno']) {
|
116 |
if (count($stepswithsubmit) == $responses['submittedstepno']) {
|
| 112 |
// If this is the last step then we need to look at the state after the question has been
|
117 |
// If this is the last step then we need to look at the state after the question has been
|
| 113 |
// finished.
|
118 |
// finished.
|
| 114 |
$state = $qa->get_state();
|
119 |
$state = $qa->get_state();
|
| 115 |
} else {
|
120 |
} else {
|
| 116 |
$state = $step->get_state();
|
121 |
$state = $step->get_state();
|
| 117 |
}
|
122 |
}
|
| 118 |
$actual = substr(get_class($state), strlen('question_state_'));
|
123 |
$actual = substr(get_class($state), strlen('question_state_'));
|
| 119 |
}
|
124 |
}
|
| 120 |
$expected = $tests[$column];
|
125 |
$expected = $tests[$column];
|
| 121 |
$failuremessage = "Error in quizattempt {$responses['quizattempt']} in $column, slot $slot, ".
|
126 |
$failuremessage = "Error in quizattempt {$responses['quizattempt']} in $column, slot $slot, " .
|
| 122 |
"submittedstepno {$responses['submittedstepno']}";
|
127 |
"submittedstepno {$responses['submittedstepno']}";
|
| 123 |
$this->assertEquals($expected, $actual, $failuremessage);
|
128 |
$this->assertEquals($expected, $actual, $failuremessage);
|
| 124 |
}
|
129 |
}
|
| 125 |
}
|
130 |
}
|
| 126 |
}
|
131 |
}
|