mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 08:30:04 +01:00
MDL-77464 questions: regrading was losing question_attempt metadata
This is very similar to MDL-77090, but at the time, I missed that this also needed to be handled. (Question metadata is, I think, only used by the quiz 'Try another question like this one' feature.)
This commit is contained in:
parent
795e8ac70a
commit
bdcf29ab29
@ -55,6 +55,10 @@ Feature: Allow students to redo questions in a practice quiz, without starting a
|
||||
Then I should see "Finished regrading (1/1)"
|
||||
And I should see "Regrade completed"
|
||||
And I press "Continue"
|
||||
# Regrade a second time, to ensure the first regrade did not corrupt any data.
|
||||
And I press "Regrade all"
|
||||
And I should see "Finished regrading (1/1)"
|
||||
And I should see "Regrade completed"
|
||||
|
||||
@javascript
|
||||
Scenario: Start attempt, teacher edits question, redo picks up latest non-draft version
|
||||
|
@ -1472,11 +1472,16 @@ class question_attempt {
|
||||
if ($this->get_question(false) === $otherversion) {
|
||||
return $oldstep->get_all_data();
|
||||
} else {
|
||||
// Update the data belonging to the question type by asking the question to do it.
|
||||
$attemptstatedata = $this->get_question(false)->update_attempt_state_data_for_new_version(
|
||||
$oldstep, $otherversion);
|
||||
|
||||
foreach ($oldstep->get_behaviour_data() as $name => $value) {
|
||||
$attemptstatedata['-' . $name] = $value;
|
||||
// Then copy over all the behaviour and metadata variables.
|
||||
// This terminology is explained in the class comment on {@see question_attempt_step}.
|
||||
foreach ($oldstep->get_all_data() as $name => $value) {
|
||||
if (substr($name, 0, 1) === '-' || substr($name, 0, 2) === ':_') {
|
||||
$attemptstatedata[$name] = $value;
|
||||
}
|
||||
}
|
||||
return $attemptstatedata;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ class walkthrough_test extends \qbehaviour_walkthrough_test_base {
|
||||
*/
|
||||
public function test_regrading_an_interactive_attempt_while_in_progress() {
|
||||
|
||||
// Start at attempt at a matching question.
|
||||
// Start an attempt at a matching question.
|
||||
$q = test_question_maker::make_question('match');
|
||||
$this->start_attempt_at_question($q, 'interactive', 1);
|
||||
$this->save_quba();
|
||||
@ -156,4 +156,36 @@ class walkthrough_test extends \qbehaviour_walkthrough_test_base {
|
||||
$this->check_step_count(1);
|
||||
$this->check_current_output($this->get_tries_remaining_expectation(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \question_usage_by_activity::regrade_question
|
||||
* @covers \question_attempt::regrade
|
||||
* @covers \question_attempt::get_attempt_state_data_to_regrade_with_version
|
||||
*/
|
||||
public function test_regrading_does_not_lose_metadata() {
|
||||
|
||||
// Start an attempt at a matching question.
|
||||
$q = test_question_maker::make_question('match');
|
||||
$this->start_attempt_at_question($q, 'interactive', 1);
|
||||
// Like in process_redo_question in mod_quiz.
|
||||
$this->quba->set_question_attempt_metadata($this->slot, 'originalslot', 42);
|
||||
$this->save_quba();
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_step_count(1);
|
||||
$this->check_current_output($this->get_tries_remaining_expectation(1));
|
||||
|
||||
// Regrade the attempt.
|
||||
$reloadedquestion = clone($q);
|
||||
$this->quba->regrade_question($this->slot, false, null, $reloadedquestion);
|
||||
|
||||
// Verify.
|
||||
$this->check_current_state(question_state::$todo);
|
||||
$this->check_current_mark(null);
|
||||
$this->check_step_count(1);
|
||||
$this->check_current_output($this->get_tries_remaining_expectation(1));
|
||||
$this->assertEquals(42, $this->quba->get_question_attempt_metadata($this->slot, 'originalslot'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user