Merge branch 'MDL-52132-master' of git://github.com/rezaies/moodle

This commit is contained in:
Jake Dallimore 2019-01-23 09:20:27 +08:00
commit b028dc05b8
3 changed files with 54 additions and 2 deletions

View File

@ -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'));

View File

@ -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.

View File

@ -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.');