diff --git a/question/behaviour/behaviourbase.php b/question/behaviour/behaviourbase.php index 3b9943f62bc..b321cf22d72 100644 --- a/question/behaviour/behaviourbase.php +++ b/question/behaviour/behaviourbase.php @@ -392,11 +392,20 @@ abstract class question_behaviour { $previouscomment = $this->qa->get_last_behaviour_var('comment'); $newcomment = $pendingstep->get_behaviour_var('comment'); - if (is_null($previouscomment) && !html_is_blank($newcomment) || - $previouscomment != $newcomment) { + if ($previouscomment != $newcomment) { + // The comment has changed. return false; } + if (!html_is_blank($newcomment)) { + // Check comment format. + $previouscommentformat = $this->qa->get_last_behaviour_var('commentformat'); + $newcommentformat = $pendingstep->get_behaviour_var('commentformat'); + if ($previouscommentformat != $newcommentformat) { + return false; + } + } + // So, now we know the comment is the same, so check the mark, if present. $previousfraction = $this->qa->get_fraction(); $newmark = question_utils::clean_param_mark($pendingstep->get_behaviour_var('mark')); diff --git a/question/behaviour/manualgraded/tests/walkthrough_test.php b/question/behaviour/manualgraded/tests/walkthrough_test.php index c47e2053e1b..c7e1d0f6b10 100644 --- a/question/behaviour/manualgraded/tests/walkthrough_test.php +++ b/question/behaviour/manualgraded/tests/walkthrough_test.php @@ -432,6 +432,35 @@ class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthroug $this->check_current_mark(0); } + public function test_manual_graded_change_comment_format() { + global $PAGE; + + // The current text editor depends on the users profile setting - so it needs a valid user. + $this->setAdminUser(); + // Required to init a text editor. + $PAGE->set_url('/'); + + // Create an essay question. + $essay = test_question_maker::make_an_essay_question(); + $this->start_attempt_at_question($essay, 'deferredfeedback', 10); + + // Simulate some data submitted by the student. + $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); + + // Finish the attempt. + $this->quba->finish_all_questions(); + + // Process an example comment and a grade of 0. + $this->manual_grade('example', 0, FORMAT_HTML); + // Verify the format is FORMAT_HTML. + $this->check_comment('example', FORMAT_HTML); + + // Process the same grade and comment with different format. + $this->manual_grade('example', 0, FORMAT_MARKDOWN); + // Verify the format is FORMAT_MARKDOWN. + $this->check_comment('example', FORMAT_MARKDOWN); + } + public function test_manual_graded_respects_display_options() { // This test is for MDL-43874. Manual comments were not respecting the // Display options for feedback. diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index 93d3ecb9a52..eec70bf123e 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -778,6 +778,20 @@ abstract class qbehaviour_walkthrough_test_base extends question_testcase { $this->quba = null; } + /** + * Asserts if the manual comment for the question is equal to the provided arguments. + * @param $comment Comment text + * @param $commentformat Comment format + */ + protected function check_comment($comment, $commentformat) { + $actualcomment = $this->quba->get_question_attempt($this->slot)->get_manual_comment(); + + $this->assertEquals( + [$comment, $commentformat], + [$actualcomment[0], $actualcomment[1]] + ); + } + protected function check_current_state($state) { $this->assertEquals($state, $this->quba->get_question_state($this->slot), 'Questions is in the wrong state.');