MDL-81458 qtype_ordering: Address failing unit tests

Fixes the failing unit tests in the ordering question type by
implementing the following adjustments and corrections:
- Ensure the missing required files are imported in
  questionhint_test.php and questiontype_test.php.
- Modify the expected fraction values in testexport.moodle.xml to
  accurately reflect the recent changes, specifically the type
  casting of the fraction value stored for each answer into the
  question object.
- Reorder the items in the answers array within the failing scenario
  in specific_grade_detail_feedback_test.php to guarantee that, in
  accordance with the randomly generated subset of correct answers,
  the question attempt will consistently be incorrect as required.
- Pass the answer codes in the order of the defined response when
  calling the process_submission() function in feedback_test.php
  to ensure the response in the current question attempt is properly
  set, rather than relying on random generation of the response which
  may result in random test failures.
This commit is contained in:
Mihail Geshoski 2024-04-09 00:54:36 +08:00
parent 72e9a1bbd9
commit 4b1dfe6a40
5 changed files with 11 additions and 9 deletions

View File

@ -29,37 +29,37 @@
<text>That is not right at all.</text>
</incorrectfeedback>
<shownumcorrect>1</shownumcorrect>
<answer fraction="1.0000000" format="html">
<answer fraction="1" format="html">
<text>Modular</text>
<feedback format="html">
<text>Modular is correct.</text>
</feedback>
</answer>
<answer fraction="2.0000000" format="html">
<answer fraction="2" format="html">
<text>Object</text>
<feedback format="html">
<text>Object is correct.</text>
</feedback>
</answer>
<answer fraction="3.0000000" format="html">
<answer fraction="3" format="html">
<text>Oriented</text>
<feedback format="html">
<text>Oriented is correct.</text>
</feedback>
</answer>
<answer fraction="4.0000000" format="html">
<answer fraction="4" format="html">
<text>Dynamic</text>
<feedback format="html">
<text>Dynamic is correct.</text>
</feedback>
</answer>
<answer fraction="5.0000000" format="html">
<answer fraction="5" format="html">
<text>Learning</text>
<feedback format="html">
<text>Learning is correct.</text>
</feedback>
</answer>
<answer fraction="6.0000000" format="html">
<answer fraction="6" format="html">
<text>Environment</text>
<feedback format="html">
<text>Environment is correct.</text>

View File

@ -98,7 +98,8 @@ final class feedback_test extends qbehaviour_walkthrough_test_base {
$attempt = $qa;
} else {
$this->start_attempt_at_question($question, 'interactive');
$this->process_submission(array_merge(['-submit' => 1], ['answers' => array_values($answeritems)]));
$response = qtype_ordering_test_helper::get_response($question, array_values($answeritems));
$this->process_submission(array_merge(['-submit' => 1], $response));
$attempt = $this->get_question_attempt();
// Omit the numparts as we are not testing it here, and it can be a bit flaky when manually processing an attempt.
$this->displayoptions->numpartscorrect = false;

View File

@ -197,7 +197,7 @@ final class specific_grade_detail_feedback_test extends advanced_testcase {
qtype_ordering_question::SELECT_ALL,
],
'Incorrect question attempt (SELECT_RANDOM). Grading type: GRADING_ABSOLUTE_POSITION' => [
[14 => 'Object', 16 => 'Dynamic', 13 => 'Modular', 17 => 'Learning', 18 => 'Environment', 15 => 'Oriented'],
[16 => 'Dynamic', 14 => 'Object', 13 => 'Modular', 17 => 'Learning', 18 => 'Environment', 15 => 'Oriented'],
qtype_ordering_question::GRADING_ABSOLUTE_POSITION,
'vertical',
[

View File

@ -24,6 +24,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
require_once($CFG->dirroot . '/question/type/ordering/questiontype.php');
/**
* A test class used to test question_hint_ordering.

View File

@ -39,7 +39,7 @@ require_once($CFG->dirroot . '/question/type/ordering/edit_ordering_form.php');
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/format/gift/format.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
require_once($CFG->dirroot . '/question/format/xml/format.php');
/**
* Unit tests for the ordering question type class.