diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de284d8..c5c3909 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: - name: Moodle Code Checker if: ${{ always() }} - run: moodle-plugin-ci phpcs --max-warnings 0 + run: moodle-plugin-ci phpcs # --max-warnings 0 # Add back once #[\Override] works. - name: Moodle PHPDoc Checker continue-on-error: true # This step will show errors but will not fail. diff --git a/backup/moodle2/backup_qtype_oumatrix_plugin.class.php b/backup/moodle2/backup_qtype_oumatrix_plugin.class.php index 4e778e5..5fdff32 100644 --- a/backup/moodle2/backup_qtype_oumatrix_plugin.class.php +++ b/backup/moodle2/backup_qtype_oumatrix_plugin.class.php @@ -66,6 +66,7 @@ protected function define_question_plugin_structure(): backup_plugin_element { return $plugin; } + #[\Override] public static function get_qtype_fileareas() { return [ 'feedback' => 'qtype_oumatrix_rows', diff --git a/edit_oumatrix_form.php b/edit_oumatrix_form.php index 891dbb2..db6ad55 100644 --- a/edit_oumatrix_form.php +++ b/edit_oumatrix_form.php @@ -27,22 +27,22 @@ class qtype_oumatrix_edit_form extends question_edit_form { /** The default starting number of columns (answers). */ - private const COL_NUM_START = 3; + protected const COL_NUM_START = 3; /** The number of columns (answers) that get added at a time. */ - private const COL_NUM_ADD = 2; + protected const COL_NUM_ADD = 2; /** The default starting number of rows (question row). */ - private const ROW_NUM_START = 4; + protected const ROW_NUM_START = 4; /** The number of rows (question row) that get added at a time.*/ - private const ROW_NUM_ADD = 2; + protected const ROW_NUM_ADD = 2; /** @var int Number of columns. */ - private $numcolumns; + protected int $numcolumns; /** @var string inputtype of rows. */ - private $inputtype; + protected string $inputtype; /** @var array of HTML tags allowed in column and row names. */ protected $allowedhtmltags = [ @@ -54,10 +54,10 @@ class qtype_oumatrix_edit_form extends question_edit_form { ]; /** @var string regex to match HTML open tags. */ - private $htmltstarttagsandattributes = '~<\s*\w+\b[^>]*>~'; + protected string $htmltstarttagsandattributes = '~<\s*\w+\b[^>]*>~'; /** @var string regex to match HTML close tags or br. */ - private $htmltclosetags = '~<\s*/\s*\w+\b[^>]*>~'; + protected string $htmltclosetags = '~<\s*/\s*\w+\b[^>]*>~'; /** * Set the inputtype and number of rows and columns method. @@ -81,6 +81,7 @@ protected function set_current_settings(): void { $this->numcolumns = $columns ? count($columns) : $this->numcolumns; } + #[\Override] protected function definition_inner($mform) { // Set the number of columns and rows. @@ -210,6 +211,7 @@ protected function get_per_row_fields(MoodleQuickForm $mform, string $label, arr return $repeated; } + #[\Override] public function data_preprocessing($question) { $question = parent::data_preprocessing($question); $question = $this->data_preprocessing_options($question); @@ -310,6 +312,7 @@ private function data_preprocessing_rows(stdClass $question): object { return $question; } + #[\Override] public function validation($data, $files) { $errors = parent::validation($data, $files); @@ -448,8 +451,8 @@ public function validation($data, $files) { } /** - * Vaidate some input to make sure it does not contain any tags other than - * $this->allowedhtmltags. + * Validate some input to make sure it does not contain any tags other than $this->allowedhtmltags. + * * @param string $text the input to validate. * @return string any validation errors. */ @@ -506,12 +509,7 @@ private function get_list_of_printable_allowed_tags(array $allowedhtmltags): str return implode(', ', $allowedtaglist); } - - /** - * Returns the question type name. - * - * @return string The question type name. - */ + #[\Override] public function qtype(): string { return 'oumatrix'; } diff --git a/question.php b/question.php index b666500..b13589b 100644 --- a/question.php +++ b/question.php @@ -34,26 +34,38 @@ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class qtype_oumatrix_base extends question_graded_automatically { - public $shuffleanswers; + /** @var bool whether the rows should be shuffled. */ + public bool $shuffleanswers; /** @var string 'All or none' or 'partial' grading method for multiple response. */ - public $grademethod; + public string $grademethod; - public $correctfeedback; - public $correctfeedbackformat; - public $partiallycorrectfeedback; - public $partiallycorrectfeedbackformat; - public $incorrectfeedback; - public $incorrectfeedbackformat; + /** @var string feedback for any correct response. */ + public string $correctfeedback; + + /** @var int format of $correctfeedback. */ + public int $correctfeedbackformat; + + /** @var string feedback for any partially correct response. */ + public string $partiallycorrectfeedback; + + /** @var int format of $partiallycorrectfeedback. */ + public int $partiallycorrectfeedbackformat; + + /** @var string feedback for any incorrect response. */ + public string $incorrectfeedback; + + /** @var int format of $incorrectfeedback. */ + public int $incorrectfeedbackformat; /** @var column[] The columns (answers) object, indexed by number. */ - public $columns; + public array $columns; /** @var row[] The rows (subquestions) object, indexed by number. */ - public $rows; + public array $rows; /** @var array The order of the rows, key => row number. */ - protected $roworder = null; + protected ?array $roworder = null; /** * Returns true if the response has been selected for that row and column. @@ -65,10 +77,13 @@ abstract class qtype_oumatrix_base extends question_graded_automatically { */ abstract public function is_choice_selected(array $response, int $rowkey, int $colnumber): bool; + #[\Override] abstract public function is_same_response(array $prevresponse, array $newresponse); + #[\Override] abstract public function grade_response(array $response); + #[\Override] public function start_attempt(question_attempt_step $step, $variant) { $this->roworder = array_keys($this->rows); if ($this->shuffleanswers) { @@ -77,6 +92,7 @@ public function start_attempt(question_attempt_step $step, $variant) { $step->set_qt_var('_roworder', implode(',', $this->roworder)); } + #[\Override] public function apply_attempt_state(question_attempt_step $step) { $this->roworder = explode(',', $step->get_qt_var('_roworder')); } @@ -103,10 +119,12 @@ protected function init_roworder(question_attempt $qa) { } } + #[\Override] public function is_gradable_response(array $response) { return $this->is_complete_response($response); } + #[\Override] public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { if ($component == 'question' && in_array($filearea, ['correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'])) { @@ -124,6 +142,7 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $ } } + #[\Override] public function get_validation_error(array $response): string { if ($this->is_complete_response($response)) { return ''; @@ -131,6 +150,7 @@ public function get_validation_error(array $response): string { return get_string('pleaseananswerallparts', 'qtype_oumatrix'); } + #[\Override] public function validate_can_regrade_with_other_version(question_definition $otherversion): ?string { $basemessage = parent::validate_can_regrade_with_other_version($otherversion); if ($basemessage) { @@ -168,10 +188,12 @@ public function has_specific_feedback(): bool { */ class qtype_oumatrix_single extends qtype_oumatrix_base { + #[\Override] public function get_renderer(moodle_page $page) { return $page->get_renderer('qtype_oumatrix', 'single'); } + #[\Override] public function get_expected_data(): array { $expected = []; foreach ($this->rows as $row) { @@ -180,6 +202,7 @@ public function get_expected_data(): array { return $expected; } + #[\Override] public function is_choice_selected(array $response, int $rowkey, int $colnumber): bool { $responsekey = $this->field($rowkey); if (array_key_exists($responsekey, $response)) { @@ -188,6 +211,7 @@ public function is_choice_selected(array $response, int $rowkey, int $colnumber) return false; } + #[\Override] public function is_same_response(array $prevresponse, array $newresponse): bool { foreach ($this->roworder as $key => $notused) { $fieldname = $this->field($key); @@ -208,6 +232,7 @@ protected function field(int $rowkey): string { return 'rowanswers' . $rowkey; } + #[\Override] public function get_correct_response(): array { $response = []; foreach ($this->roworder as $key => $rownumber) { @@ -220,6 +245,7 @@ public function get_correct_response(): array { return $response; } + #[\Override] public function summarise_response(array $response): ?string { $responsewords = []; foreach ($this->roworder as $key => $rownumber) { @@ -238,6 +264,7 @@ public function summarise_response(array $response): ?string { return implode('; ', $responsewords); } + #[\Override] public function is_complete_response(array $response): bool { foreach ($this->roworder as $key => $rownumber) { $fieldname = $this->field($key); @@ -248,6 +275,7 @@ public function is_complete_response(array $response): bool { return true; } + #[\Override] public function classify_response(array $response): array { $classifiedresponse = []; foreach ($this->roworder as $key => $rownumber) { @@ -269,6 +297,7 @@ public function classify_response(array $response): array { return $classifiedresponse; } + #[\Override] public function prepare_simulated_post_data($simulatedresponse): array { // Expected structure of $simulatedresponse is Row field name => Col name. // Each row must be present, in order. @@ -293,6 +322,7 @@ public function prepare_simulated_post_data($simulatedresponse): array { return $postdata; } + #[\Override] public function grade_response(array $response): array { // Retrieve the number of right responses and the total number of responses. [$numrightparts, $total] = $this->get_num_parts_right($response); @@ -300,6 +330,7 @@ public function grade_response(array $response): array { return [$fraction, question_state::graded_state_for_fraction($fraction)]; } + #[\Override] public function get_num_parts_right(array $response): array { $numright = 0; foreach ($this->roworder as $key => $rownumber) { @@ -318,10 +349,12 @@ public function get_num_parts_right(array $response): array { */ class qtype_oumatrix_multiple extends qtype_oumatrix_base { + #[\Override] public function get_renderer(moodle_page $page) { return $page->get_renderer('qtype_oumatrix', 'multiple'); } + #[\Override] public function get_expected_data(): array { $expected = []; foreach ($this->rows as $row) { @@ -332,6 +365,7 @@ public function get_expected_data(): array { return $expected; } + #[\Override] public function is_choice_selected(array $response, int $rowkey, int $colnumber): bool { $responsekey = $this->field($rowkey, $colnumber); if (array_key_exists($responsekey, $response)) { @@ -351,6 +385,7 @@ protected function field(int $rowkey, int $columnnumber): string { return 'rowanswers' . $rowkey . '_' . $columnnumber; } + #[\Override] public function is_same_response(array $prevresponse, array $newresponse): bool { foreach ($this->roworder as $key => $notused) { foreach ($this->columns as $column) { @@ -363,6 +398,7 @@ public function is_same_response(array $prevresponse, array $newresponse): bool return true; } + #[\Override] public function get_correct_response(): ?array { $response = []; foreach ($this->roworder as $key => $rownumber) { @@ -375,6 +411,7 @@ public function get_correct_response(): ?array { return $response; } + #[\Override] public function summarise_response(array $response): ?string { $responsewords = []; foreach ($this->roworder as $key => $rownumber) { @@ -396,6 +433,7 @@ public function summarise_response(array $response): ?string { return implode('; ', $responsewords); } + #[\Override] public function is_complete_response(array $response): bool { foreach ($this->roworder as $key => $rownumber) { $inputresponse = false; @@ -412,6 +450,7 @@ public function is_complete_response(array $response): bool { return true; } + #[\Override] public function classify_response(array $response) { $classifiedresponse = []; foreach ($this->roworder as $rowkey => $rownumber) { @@ -433,6 +472,7 @@ public function classify_response(array $response) { return $classifiedresponse; } + #[\Override] public function prepare_simulated_post_data($simulatedresponse): array { $postdata = []; $subquestions = array_keys($simulatedresponse); @@ -457,6 +497,7 @@ public function prepare_simulated_post_data($simulatedresponse): array { return $postdata; } + #[\Override] public function grade_response(array $response): array { // Retrieve the number of right responses and the total number of responses. if ($this->grademethod == 'allnone') { @@ -527,6 +568,8 @@ public function get_num_parts_grade_partial(array $response): array { } /** + * Get the number of selected choices in a response. + * * @param array $response responses, as returned by * {@link question_attempt_step::get_qt_data()}. * @return int the number of choices that were selected in this response. diff --git a/questiontype.php b/questiontype.php index 4fc4064..3094bc5 100644 --- a/questiontype.php +++ b/questiontype.php @@ -34,6 +34,8 @@ * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_oumatrix extends question_type { + + #[\Override] public function get_question_options($question) { global $DB, $OUTPUT; parent::get_question_options($question); @@ -52,6 +54,7 @@ public function get_question_options($question) { return true; } + #[\Override] public function save_defaults_for_new_questions(stdClass $fromform): void { parent::save_defaults_for_new_questions($fromform); $this->set_default_value('inputtype', $fromform->inputtype); @@ -60,6 +63,7 @@ public function save_defaults_for_new_questions(stdClass $fromform): void { $this->set_default_value('shownumcorrect', $fromform->shownumcorrect); } + #[\Override] public function save_question_options($question) { global $DB; $context = $question->context; @@ -168,6 +172,7 @@ public function save_rows(stdClass $question, array $columnslist) { } } + #[\Override] protected function make_question_instance($questiondata) { question_bank::load_question_definition_classes($this->name()); if ($questiondata->options->inputtype === 'single') { @@ -178,6 +183,7 @@ protected function make_question_instance($questiondata) { return new $class(); } + #[\Override] protected function initialise_question_instance(question_definition $question, $questiondata) { parent::initialise_question_instance($question, $questiondata); $question->grademethod = $questiondata->options->grademethod; @@ -245,10 +251,12 @@ public function make_row(stdClass $rowdata): row { explode(',', $rowdata->correctanswers), $rowdata->feedback, $rowdata->feedbackformat); } + #[\Override] protected function make_hint($hint) { return question_hint_with_parts::load_from_record($hint); } + #[\Override] public function delete_question($questionid, $contextid) { global $DB; $DB->delete_records('qtype_oumatrix_options', ['questionid' => $questionid]); @@ -257,6 +265,7 @@ public function delete_question($questionid, $contextid) { parent::delete_question($questionid, $contextid); } + #[\Override] public function get_random_guess_score($questiondata) { // We compute the random guess score here on the assumption we are using // the deferred feedback behaviour, and the question text tells the @@ -288,10 +297,11 @@ public function get_random_guess_score($questiondata) { /** * Return total number if choices for both (single, multiple) matrix choices. + * * @param stdClass $questiondata * @return int|null */ - public function get_total_number_of_choices(object $questiondata): ?int { + public function get_total_number_of_choices(stdClass $questiondata): ?int { // If rows or columns are not set return null. if (count($questiondata->columns) === 0 || count($questiondata->rows) === 0) { return null; @@ -304,7 +314,7 @@ public function get_total_number_of_choices(object $questiondata): ?int { /** * Returns the count of correct answers for the question. * - * @param stdClass The question data + * @param stdClass $questiondata The question data * @return int the number of choices that are correct. */ public function get_num_correct_choices(stdClass $questiondata): int { @@ -315,6 +325,7 @@ public function get_num_correct_choices(stdClass $questiondata): int { return $numright; } + #[\Override] public function get_possible_responses($questiondata) { if ($questiondata->options->inputtype == 'single') { return $this->get_possible_responses_single($questiondata); @@ -368,6 +379,7 @@ protected function get_possible_responses_multiple(stdClass $questiondata): arra return $parts; } + #[\Override] public function import_from_xml($data, $question, qformat_xml $format, $extra = null) { if (!isset($data['@']['type']) || $data['@']['type'] != 'oumatrix') { return false; @@ -465,6 +477,7 @@ public function import_rows(qformat_xml $format, stdClass $question, array $rows } } + #[\Override] public function export_to_xml($question, qformat_xml $format, $extra = null) { $output = ''; @@ -514,6 +527,7 @@ public function export_to_xml($question, qformat_xml $format, $extra = null) { return $output; } + #[\Override] public function move_files($questionid, $oldcontextid, $newcontextid) { $fs = get_file_storage(); @@ -530,8 +544,7 @@ public function move_files($questionid, $oldcontextid, $newcontextid) { } /** - * Move all the feedback files belonging to each sub-question - * when the question is moved from one context to another. + * Move the feedback files related to the row feedback. * * @param int $questionid the question being moved. * @param int $oldcontextid the context it is moving from. @@ -549,6 +562,7 @@ protected function move_files_in_row_feedback(int $questionid, int $oldcontextid } } + #[\Override] protected function delete_files($questionid, $contextid) { $fs = get_file_storage(); diff --git a/renderer.php b/renderer.php index abdeb42..99c1c33 100644 --- a/renderer.php +++ b/renderer.php @@ -36,6 +36,7 @@ abstract class qtype_oumatrix_renderer_base extends qtype_with_combined_feedback /** * Returns the value as radio/checkbox based on the single choice or multiple response question. + * * @return string */ abstract protected function get_input_type(): string; @@ -86,10 +87,12 @@ protected function is_right(question_definition $question, int $rowkey, int $col return 0; } + #[\Override] protected function feedback_class($fraction) { return question_state::graded_state_for_fraction($fraction)->get_feedback_class(); } + #[\Override] protected function feedback_image($fraction, $selected = true) { $feedbackclass = question_state::graded_state_for_fraction($fraction)->get_feedback_class(); @@ -99,6 +102,7 @@ protected function feedback_image($fraction, $selected = true) { ['class' => 'position-absolute ml-1 mt-1']); } + #[\Override] public function formulation_and_controls(question_attempt $qa, question_display_options $options) { $question = $qa->get_question(); @@ -224,12 +228,14 @@ public function matrix_table(question_attempt $qa, question_display_options $opt return $table; } + #[\Override] public function specific_feedback(question_attempt $qa) { return $this->combined_feedback($qa); } /** * Function returns string based on number of correct answers + * * @param array $right An Array of correct responses to the current question * @return string based on number of correct responses */ @@ -253,22 +259,28 @@ protected function correct_choices(array $right): string { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_oumatrix_single_renderer extends qtype_oumatrix_renderer_base { + + #[\Override] protected function get_input_type(): string { return 'radio'; } + #[\Override] protected function get_input_name(question_attempt $qa, int $rowkey, int $columnnumber): string { return $qa->get_qt_field_name('rowanswers' . $rowkey); } + #[\Override] protected function get_input_value(int $value): string { return $value; } + #[\Override] protected function get_input_id(question_attempt $qa, int $rowkey, int $columnnumber): string { return $qa->get_qt_field_name('rowanswers' . $rowkey . '_' . $columnnumber); } + #[\Override] public function correct_response(question_attempt $qa) { $question = $qa->get_question(); $right = []; @@ -278,6 +290,7 @@ public function correct_response(question_attempt $qa) { return $this->correct_choices($right); } + #[\Override] protected function num_parts_correct(question_attempt $qa): string { $a = new stdClass(); list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right( @@ -301,22 +314,28 @@ protected function num_parts_correct(question_attempt $qa): string { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_oumatrix_multiple_renderer extends qtype_oumatrix_renderer_base { + + #[\Override] protected function get_input_type(): string { return 'checkbox'; } + #[\Override] protected function get_input_name(question_attempt $qa, int $rowkey, int $columnnumber): string { return $qa->get_qt_field_name('rowanswers' . $rowkey . '_' . $columnnumber); } + #[\Override] protected function get_input_value(int $value): string { return "1"; } + #[\Override] protected function get_input_id(question_attempt $qa, int $rowkey, int $columnnumber): string { return $this->get_input_name($qa, $rowkey, $columnnumber); } + #[\Override] public function correct_response(question_attempt $qa) { $question = $qa->get_question(); foreach ($question->rows as $row) { @@ -334,6 +353,7 @@ public function correct_response(question_attempt $qa) { return $this->correct_choices($rightanswers); } + #[\Override] protected function num_parts_correct(question_attempt $qa): string { if ($qa->get_question()->get_num_selected_choices($qa->get_last_qt_data()) > $qa->get_question()->get_num_correct_choices()) { diff --git a/tests/edit_oumatrix_form_test.php b/tests/edit_oumatrix_form_test.php index 5f68e42..d415e30 100644 --- a/tests/edit_oumatrix_form_test.php +++ b/tests/edit_oumatrix_form_test.php @@ -84,8 +84,7 @@ protected function get_form(string $classname): array { */ public function test_validation_cols_rows_minimum(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; // Minumum number of columns. @@ -116,8 +115,7 @@ public function test_validation_cols_rows_minimum(): void { */ public function test_validation_cols_rows_duplicates(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; // Duplicate a column name. @@ -144,8 +142,7 @@ public function test_validation_cols_rows_duplicates(): void { */ public function test_validation_column_names_empty(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; // Empty columns names (second and third columns are empty). @@ -168,8 +165,7 @@ public function test_validation_column_names_empty(): void { */ public function test_validation_rowanswers(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; // Rows without chosen answer(s) are not valid. @@ -188,10 +184,9 @@ public function test_validation_rowanswers(): void { */ public function test_validation_rowanswers_on_empty_columns(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); // Single choice test. - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; // Rows with chosen answer on empty columns are not valid(single choice). @@ -207,7 +202,7 @@ public function test_validation_rowanswers_on_empty_columns(): void { $this->assertEquals($expectedanswer, $errors['rowoptions[1]']); // Multiple response test. - $formdata = $helper->get_test_question_form_data('food_multiple'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'food_multiple'); $formdata['category'] = $category->id; // Rows with chosen answers on empty columns are not valid(multi response). @@ -225,10 +220,9 @@ public function test_validation_rowanswers_on_empty_columns(): void { */ public function test_get_illegal_tag_error(): void { [$form, $category] = $this->get_form('qtype_oumatrix_edit_form'); - $helper = new qtype_oumatrix_test_helper(); // Single choice test. - $formdata = $helper->get_test_question_form_data('animals_single'); + $formdata = \test_question_maker::get_question_form_data('oumatrix', 'animals_single'); $formdata['category'] = $category->id; $testdata = $formdata; diff --git a/tests/helper.php b/tests/helper.php index 084d849..18d87d0 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -27,6 +27,7 @@ */ class qtype_oumatrix_test_helper extends question_test_helper { + #[\Override] public function get_test_questions(): array { return [ 'animals_single', @@ -441,14 +442,6 @@ public static function get_oumatrix_question_form_data_food_multiple(): stdClass return $qfdata; } - public function get_test_question_data(string $which) { - return \test_question_maker::get_question_data('oumatrix', $which); - } - - public function get_test_question_form_data(string $which) { - return (array)\test_question_maker::get_question_form_data('oumatrix', $which); - } - /** * Returns a qtype_oumatrix_single question. * diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index 42896fc..07aebdd 100644 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -39,13 +39,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \qtype_oumatrix */ -class questiontype_test extends \advanced_testcase { - protected $qtype; +final class questiontype_test extends \advanced_testcase { + /** @var qtype_oumatrix|null instance of the question type to use in tests. */ + protected ?qtype_oumatrix $qtype; + #[\Override] protected function setUp(): void { $this->qtype = new qtype_oumatrix(); } + #[\Override] protected function tearDown(): void { $this->qtype = null; } @@ -54,20 +57,17 @@ public function test_name(): void { $this->assertEquals($this->qtype->name(), 'oumatrix'); } - public function test_get_random_guess_score(): void { - $helper = new qtype_oumatrix_test_helper(); - $qdata = $helper->get_test_question_data('animals_single'); + $qdata = \test_question_maker::get_question_data('oumatrix', 'animals_single'); $this->assertEquals(0.25, $this->qtype->get_random_guess_score($qdata)); - $qdata = $helper->get_test_question_data('food_multiple'); + $qdata = \test_question_maker::get_question_data('oumatrix', 'food_multiple'); $this->assertEquals(null, $this->qtype->get_random_guess_score($qdata)); } public function test_get_random_guess_score_broken_question(): void { - $helper = new qtype_oumatrix_test_helper(); - $q = $helper->get_test_question_data('animals_single'); + $q = \test_question_maker::get_question_data('oumatrix', 'animals_single'); $q->columns = []; $this->assertNull($this->qtype->get_random_guess_score($q)); } @@ -147,10 +147,6 @@ public function test_get_possible_responses_multiple(): void { $this->assertEquals($expected, $this->qtype->get_possible_responses($q)); } - public function get_save_question_which() { - return [['animals_single'], ['oumatrix_multiple']]; - } - public function test_load_question(): void { $this->resetAfterTest();