From 2d708a7365147376d7f580b9f99fc32e2fc94d96 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 30 Jan 2017 14:31:15 +0000 Subject: [PATCH] MDL-57588 questions: regrading should not lose flags --- question/engine/questionattempt.php | 2 + question/engine/tests/walkthrough_test.php | 63 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 question/engine/tests/walkthrough_test.php diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index bd252801cff..fa110dde2ae 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1311,6 +1311,8 @@ class question_attempt { if ($finished) { $this->finish(); } + + $this->set_flagged($oldqa->is_flagged()); } /** diff --git a/question/engine/tests/walkthrough_test.php b/question/engine/tests/walkthrough_test.php new file mode 100644 index 00000000000..79fd0217b5f --- /dev/null +++ b/question/engine/tests/walkthrough_test.php @@ -0,0 +1,63 @@ +. + +/** + * This file contains tests that walks a question through a whole attempt. + * + * @package core_question + * @copyright 2017 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once(__DIR__ . '/..//lib.php'); +require_once(__DIR__ . '/helpers.php'); + + +/** + * End-to-end tests of attempting a question. + * + * @copyright 2017 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class core_question_walkthrough_testcase extends qbehaviour_walkthrough_test_base { + + public function test_regrade_does_not_lose_flag() { + + // Create a true-false question with correct answer true. + $tf = test_question_maker::make_question('truefalse', 'true'); + $this->start_attempt_at_question($tf, 'deferredfeedback', 2); + + // Process a true answer. + $this->process_submission(array('answer' => 1)); + + // Finish the attempt. + $this->quba->finish_all_questions(); + + // Flag the question. + $this->get_question_attempt()->set_flagged(true); + + // Now change the correct answer to the question, and regrade. + $tf->rightanswer = false; + $this->quba->regrade_all_questions(); + + // Verify the flag has not been lost. + $this->assertTrue($this->get_question_attempt()->is_flagged()); + } +}