forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-81521 mod_quiz: Fix attempt walkthrough tests
- Loading branch information
1 parent
a6acb01
commit 9adfbcd
Showing
9 changed files
with
688 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
issueNumber: MDL-81521 | ||
notes: | ||
mod_quiz: | ||
- message: > | ||
The `\mod_quiz\attempt_walkthrough_from_csv_test` unit test has been | ||
marked as final and should not be extended by other tests. | ||
All shared functionality has been moved to a new autoloadable test-case: | ||
`\mod_quiz\tests\attempt_walkthrough_testcase`. | ||
To support this testcase the existing `$files` instance property should be replaced with a | ||
new static method, `::get_test_files`. | ||
Both the existing instance property and the new static method can co-exist. | ||
type: changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,6 @@ | |
use mod_quiz\quiz_attempt; | ||
use question_bank; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once($CFG->dirroot . '/mod/quiz/tests/attempt_walkthrough_from_csv_test.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); | ||
|
||
/** | ||
* Quiz attempt walk through using data from csv file. | ||
* | ||
|
@@ -35,16 +28,21 @@ | |
* @author Jamie Pratt <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class responses_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_from_csv_test { | ||
protected function get_full_path_of_csv_file(string $setname, string $test): string { | ||
// Overridden here so that __DIR__ points to the path of this file. | ||
return __DIR__."/fixtures/{$setname}{$test}.csv"; | ||
final class responses_from_steps_walkthrough_test extends \mod_quiz\tests\attempt_walkthrough_testcase { | ||
#[\Override] | ||
public static function setUpBeforeClass(): void { | ||
global $CFG; | ||
|
||
parent::setUpBeforeClass(); | ||
|
||
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); | ||
} | ||
|
||
/** | ||
* @var string[] names of the files which contain the test data. | ||
*/ | ||
protected $files = ['questions', 'steps', 'responses']; | ||
#[\Override] | ||
protected static function get_test_files(): array { | ||
return ['questions', 'steps', 'responses']; | ||
} | ||
|
||
/** | ||
* Create a quiz add questions to it, walk through quiz attempts and then check results. | ||
|
@@ -54,7 +52,6 @@ protected function get_full_path_of_csv_file(string $setname, string $test): str | |
* @dataProvider get_data_for_walkthrough | ||
*/ | ||
public function test_walkthrough_from_csv($quizsettings, $csvdata): void { | ||
|
||
$this->resetAfterTest(true); | ||
question_bank::get_qtype('random')->clear_caches_before_testing(); | ||
|
||
|
@@ -72,7 +69,14 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata): void { | |
} | ||
} | ||
|
||
protected function assert_response_test($quizattemptid, $responses) { | ||
/** | ||
* Helper to assert a response. | ||
* | ||
* @param mixed $quizattemptid | ||
* @param mixed $responses | ||
* @throws \coding_exception | ||
*/ | ||
protected function assert_response_test($quizattemptid, $responses): void { | ||
$quizattempt = quiz_attempt::create($quizattemptid); | ||
|
||
foreach ($responses['slot'] as $slot => $tests) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,6 @@ | |
use question_finder; | ||
use quiz_statistics_report; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once($CFG->dirroot . '/mod/quiz/tests/attempt_walkthrough_from_csv_test.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); | ||
|
||
/** | ||
* Quiz attempt walk through using data from csv file. | ||
* | ||
|
@@ -45,22 +38,26 @@ | |
* @author Jamie Pratt <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class stats_from_steps_walkthrough_test extends \mod_quiz\attempt_walkthrough_from_csv_test { | ||
|
||
final class stats_from_steps_walkthrough_test extends \mod_quiz\tests\attempt_walkthrough_testcase { | ||
/** | ||
* @var quiz_statistics_report object to do stats calculations. | ||
*/ | ||
protected $report; | ||
|
||
protected function get_full_path_of_csv_file(string $setname, string $test): string { | ||
// Overridden here so that __DIR__ points to the path of this file. | ||
return __DIR__."/fixtures/{$setname}{$test}.csv"; | ||
#[\Override] | ||
public static function setUpBeforeClass(): void { | ||
global $CFG; | ||
|
||
parent::setUpBeforeClass(); | ||
|
||
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php'); | ||
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); | ||
} | ||
|
||
/** | ||
* @var string[] names of the files which contain the test data. | ||
*/ | ||
protected $files = ['questions', 'steps', 'results', 'qstats', 'responsecounts']; | ||
#[\Override] | ||
protected static function get_test_files(): array { | ||
return ['questions', 'steps', 'results', 'qstats', 'responsecounts']; | ||
} | ||
|
||
/** | ||
* Create a quiz add questions to it, walk through quiz attempts and then check results. | ||
|
@@ -69,7 +66,6 @@ protected function get_full_path_of_csv_file(string $setname, string $test): str | |
* @dataProvider get_data_for_walkthrough | ||
*/ | ||
public function test_walkthrough_from_csv($quizsettings, $csvdata): void { | ||
|
||
$this->create_quiz_simulate_attempts_and_check_results($quizsettings, $csvdata); | ||
|
||
$whichattempts = QUIZ_GRADEAVERAGE; // All attempts. | ||
|
Oops, something went wrong.