weekly release 3.10.4+
[moodle.git] / question / behaviour / manualgraded / tests / walkthrough_test.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17 /**
18  * This file contains tests that walks a question through the manual graded
19  * behaviour.
20  *
21  * @package    qbehaviour_manualgraded
22  * @copyright  2009 The Open University
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
27 defined('MOODLE_INTERNAL') || die();
29 global $CFG;
30 require_once(__DIR__ . '/../../../engine/lib.php');
31 require_once(__DIR__ . '/../../../engine/tests/helpers.php');
34 /**
35  * Unit tests for the manual graded behaviour.
36  *
37  * @copyright  2009 The Open University
38  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39  */
40 class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthrough_test_base {
41     public function test_manual_graded_essay() {
42         global $PAGE;
44         // The current text editor depends on the users profile setting - so it needs a valid user.
45         $this->setAdminUser();
46         // Required to init a text editor.
47         $PAGE->set_url('/');
49         // Create an essay question.
50         $essay = test_question_maker::make_an_essay_question();
51         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
53         // Check the right model is being used.
54         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
55                 $this->slot)->get_behaviour_name());
57         // Check the initial state.
58         $this->check_current_state(question_state::$todo);
59         $this->check_current_mark(null);
60         $this->check_current_output($this->get_contains_question_text_expectation($essay),
61                 $this->get_does_not_contain_feedback_expectation());
63         // Simulate some data submitted by the student.
64         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
66         // Verify.
67         $this->check_current_state(question_state::$complete);
68         $this->check_current_mark(null);
69         $this->check_current_output(
70                 new question_contains_tag_with_attribute('textarea', 'name',
71                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
72                 $this->get_does_not_contain_feedback_expectation());
74         // Process the same data again, check it does not create a new step.
75         $numsteps = $this->get_step_count();
76         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
77         $this->check_step_count($numsteps);
79         // Process different data, check it creates a new step.
80         $this->process_submission(array('answer' => '', 'answerformat' => FORMAT_HTML));
81         $this->check_step_count($numsteps + 1);
82         $this->check_current_state(question_state::$todo);
84         // Change back, check it creates a new step.
85         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
86         $this->check_step_count($numsteps + 2);
88         // Finish the attempt.
89         $this->quba->finish_all_questions();
91         // Verify.
92         $this->check_current_state(question_state::$needsgrading);
93         $this->check_current_mark(null);
94         $this->assertEquals('This is my wonderful essay!',
95                 $this->quba->get_response_summary($this->slot));
97         // Process a manual comment.
98         $this->manual_grade('Not good enough!', 10, FORMAT_HTML);
100         // Verify.
101         $this->check_current_state(question_state::$mangrright);
102         $this->check_current_mark(10);
103         $this->check_current_output(
104                 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
106         // Now change the max mark for the question and regrade.
107         $this->quba->regrade_question($this->slot, true, 1);
109         // Verify.
110         $this->check_current_state(question_state::$mangrright);
111         $this->check_current_mark(1);
112     }
114     public function test_manual_graded_essay_not_answered() {
115         global $PAGE;
117         // The current text editor depends on the users profile setting - so it needs a valid user.
118         $this->setAdminUser();
119         // Required to init a text editor.
120         $PAGE->set_url('/');
122         // Create an essay question.
123         $essay = test_question_maker::make_an_essay_question();
124         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
126         // Check the right model is being used.
127         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
128                 $this->slot)->get_behaviour_name());
130         // Check the initial state.
131         $this->check_current_state(question_state::$todo);
132         $this->check_current_mark(null);
133         $this->check_current_output($this->get_contains_question_text_expectation($essay),
134                 $this->get_does_not_contain_feedback_expectation());
136         // Finish the attempt.
137         $this->quba->finish_all_questions();
139         // Verify.
140         $this->check_current_state(question_state::$gaveup);
141         $this->check_current_mark(null);
142         $this->assertEquals('',
143                 $this->quba->get_response_summary($this->slot));
145         // Process a manual comment.
146         $this->manual_grade('Not good enough!', 1, FORMAT_HTML);
148         // Verify.
149         $this->check_current_state(question_state::$mangrpartial);
150         $this->check_current_mark(1);
151         $this->check_current_output(
152                 new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/'));
154         // Now change the max mark for the question and regrade.
155         $this->quba->regrade_question($this->slot, true, 1);
157         // Verify.
158         $this->check_current_state(question_state::$mangrpartial);
159         $this->check_current_mark(0.1);
160     }
162     public function test_manual_graded_truefalse() {
164         // Create a true-false question with correct answer true.
165         $tf = test_question_maker::make_question('truefalse', 'true');
166         $this->start_attempt_at_question($tf, 'manualgraded', 2);
168         // Check the initial state.
169         $this->check_current_state(question_state::$todo);
170         $this->check_current_mark(null);
171         $this->check_current_output(
172                 $this->get_contains_question_text_expectation($tf),
173                 $this->get_does_not_contain_feedback_expectation());
175         // Process a true answer and check the expected result.
176         $this->process_submission(array('answer' => 1));
178         $this->check_current_state(question_state::$complete);
179         $this->check_current_mark(null);
180         $this->check_current_output(
181                 $this->get_contains_tf_true_radio_expectation(true, true),
182                 $this->get_does_not_contain_correctness_expectation(),
183                 $this->get_does_not_contain_feedback_expectation());
185         // Finish the attempt.
186         $this->quba->finish_all_questions();
188         // Verify.
189         $this->check_current_state(question_state::$needsgrading);
190         $this->check_current_mark(null);
191         $this->check_current_output(
192                 $this->get_does_not_contain_correctness_expectation(),
193                 $this->get_does_not_contain_specific_feedback_expectation());
195         // Process a manual comment.
196         $this->manual_grade('Not good enough!', 1, FORMAT_HTML);
198         $this->check_current_state(question_state::$mangrpartial);
199         $this->check_current_mark(1);
200         $this->check_current_output(
201             $this->get_does_not_contain_correctness_expectation(),
202             $this->get_does_not_contain_specific_feedback_expectation(),
203             new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
204     }
206     public function test_manual_grade_ungraded_question() {
207         global $PAGE;
209         // The current text editor depends on the users profile setting - so it needs a valid user.
210         $this->setAdminUser();
211         // Required to init a text editor.
212         $PAGE->set_url('/');
214         // Create an essay question.
215         $essay = test_question_maker::make_an_essay_question();
216         $this->start_attempt_at_question($essay, 'deferredfeedback', 0);
218         // Check the right model is being used.
219         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
220                 $this->slot)->get_behaviour_name());
222         // Check the initial state.
223         $this->check_current_state(question_state::$todo);
224         $this->check_current_mark(null);
225         $this->check_current_output($this->get_contains_question_text_expectation($essay),
226                 $this->get_does_not_contain_feedback_expectation());
228         // Simulate some data submitted by the student.
229         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
231         // Verify.
232         $this->check_current_state(question_state::$complete);
233         $this->check_current_mark(null);
234         $this->check_current_output(
235                 new question_contains_tag_with_attribute('textarea', 'name',
236                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
237                 $this->get_does_not_contain_feedback_expectation());
239         // Finish the attempt.
240         $this->quba->finish_all_questions();
242         // Verify.
243         $this->check_current_state(question_state::$needsgrading);
244         $this->check_current_mark(null);
245         $this->assertEquals('This is my wonderful essay!',
246                 $this->quba->get_response_summary($this->slot));
248         // Process a manual comment. Note: null mark is the whole point here.
249         $this->manual_grade('Not good enough!', null, FORMAT_HTML);
251         // Verify.
252         // I am pretty sure this next assertion is incorrect. We should change
253         // the question state to indicate that this quetion has now been commented
254         // on. However, that is tricky, because what if, after that, the mam mark
255         // for the qusetions is changed. So, for now, this assertion verifies
256         // the current behaviour.
257         $this->check_current_state(question_state::$needsgrading);
258         $this->check_current_mark(null);
259         $this->check_current_output(
260                 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
261     }
263     public function test_manual_graded_ignore_repeat_sumbission() {
264         // Create an essay question.
265         $essay = test_question_maker::make_an_essay_question();
266         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
268         // Check the right model is being used.
269         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
270                 $this->slot)->get_behaviour_name());
272         // Check the initial state.
273         $this->check_current_state(question_state::$todo);
274         $this->check_current_mark(null);
276         // Simulate some data submitted by the student.
277         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
279         // Verify.
280         $this->check_current_state(question_state::$complete);
281         $this->check_current_mark(null);
283         // Finish the attempt.
284         $this->quba->finish_all_questions();
286         // Verify.
287         $this->check_current_state(question_state::$needsgrading);
288         $this->check_current_mark(null);
289         $this->assertEquals('This is my wonderful essay!',
290                 $this->quba->get_response_summary($this->slot));
292         // Process a blank manual comment. Ensure it does not change the state.
293         $numsteps = $this->get_step_count();
294         $this->manual_grade('', '', FORMAT_HTML);
295         $this->check_step_count($numsteps);
296         $this->check_current_state(question_state::$needsgrading);
297         $this->check_current_mark(null);
299         // Process a comment, but with the mark blank. Should be recorded, but
300         // not change the mark.
301         $this->manual_grade('I am not sure what grade to award.', '', FORMAT_HTML);
302         $this->check_step_count($numsteps + 1);
303         $this->check_current_state(question_state::$needsgrading);
304         $this->check_current_mark(null);
305         $this->check_current_output(
306                 new question_pattern_expectation('/' .
307                         preg_quote('I am not sure what grade to award.', '/') . '/'));
309         // Now grade it.
310         $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML);
311         $this->check_step_count($numsteps + 2);
312         $this->check_current_state(question_state::$mangrpartial);
313         $this->check_current_mark(9);
314         $this->check_current_output(
315                 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/'));
317         // Process the same data again, and make sure it does not add a step.
318         $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML);
319         $this->check_step_count($numsteps + 2);
320         $this->check_current_state(question_state::$mangrpartial);
321         $this->check_current_mark(9);
323         // Now set the mark back to blank.
324         $this->manual_grade('Actually, I am not sure any more.', '', FORMAT_HTML);
325         $this->check_step_count($numsteps + 3);
326         $this->check_current_state(question_state::$needsgrading);
327         $this->check_current_mark(null);
328         $this->check_current_output(
329                 new question_pattern_expectation('/' .
330                         preg_quote('Actually, I am not sure any more.', '/') . '/'));
332         $qa = $this->quba->get_question_attempt($this->slot);
333         $this->assertEquals('Commented: Actually, I am not sure any more.',
334                 $qa->summarise_action($qa->get_last_step()));
335     }
337     public function test_manual_graded_ignore_repeat_sumbission_commas() {
338         // Create an essay question.
339         $essay = test_question_maker::make_an_essay_question();
340         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
342         // Check the right model is being used.
343         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
344                 $this->slot)->get_behaviour_name());
346         // Check the initial state.
347         $this->check_current_state(question_state::$todo);
348         $this->check_current_mark(null);
350         // Simulate some data submitted by the student.
351         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
353         // Verify.
354         $this->check_current_state(question_state::$complete);
355         $this->check_current_mark(null);
357         // Finish the attempt.
358         $this->quba->finish_all_questions();
360         // Verify.
361         $this->check_current_state(question_state::$needsgrading);
362         $this->check_current_mark(null);
363         $this->assertEquals('This is my wonderful essay!',
364                 $this->quba->get_response_summary($this->slot));
366         // Now grade it with a mark with a comma.
367         $numsteps = $this->get_step_count();
368         $this->manual_grade('Pretty good!', '9,00000', FORMAT_HTML);
369         $this->check_step_count($numsteps + 1);
370         $this->check_current_state(question_state::$mangrpartial);
371         $this->check_current_mark(9);
372         $qa = $this->get_question_attempt();
373         $this->assertEquals('Manually graded 9 with comment: Pretty good!',
374                 $qa->summarise_action($qa->get_last_step()));
375         $this->check_current_output(
376                 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/'));
378         // Process the same mark with a dot. Verify it does not add a new step.
379         $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML);
380         $this->check_step_count($numsteps + 1);
381         $this->check_current_state(question_state::$mangrpartial);
382         $this->check_current_mark(9);
383     }
385     public function test_manual_graded_essay_can_grade_0() {
386         global $PAGE;
388         // The current text editor depends on the users profile setting - so it needs a valid user.
389         $this->setAdminUser();
390         // Required to init a text editor.
391         $PAGE->set_url('/');
393         // Create an essay question.
394         $essay = test_question_maker::make_an_essay_question();
395         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
397         // Check the right model is being used.
398         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
399                 $this->slot)->get_behaviour_name());
401         // Check the initial state.
402         $this->check_current_state(question_state::$todo);
403         $this->check_current_mark(null);
404         $this->check_current_output($this->get_contains_question_text_expectation($essay),
405                 $this->get_does_not_contain_feedback_expectation());
407         // Simulate some data submitted by the student.
408         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
410         // Verify.
411         $this->check_current_state(question_state::$complete);
412         $this->check_current_mark(null);
413         $this->check_current_output(
414                 new question_contains_tag_with_attribute('textarea', 'name',
415                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
416                 $this->get_does_not_contain_feedback_expectation());
418         // Finish the attempt.
419         $this->quba->finish_all_questions();
421         // Verify.
422         $this->check_current_state(question_state::$needsgrading);
423         $this->check_current_mark(null);
424         $this->assertEquals('This is my wonderful essay!',
425                 $this->quba->get_response_summary($this->slot));
427         // Process a blank comment and a grade of 0.
428         $this->manual_grade('', 0, FORMAT_HTML);
430         // Verify.
431         $this->check_current_state(question_state::$mangrwrong);
432         $this->check_current_mark(0);
433     }
435     public function test_manual_graded_change_comment_format() {
436         global $PAGE;
438         // The current text editor depends on the users profile setting - so it needs a valid user.
439         $this->setAdminUser();
440         // Required to init a text editor.
441         $PAGE->set_url('/');
443         // Create an essay question.
444         $essay = test_question_maker::make_an_essay_question();
445         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
447         // Simulate some data submitted by the student.
448         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
450         // Finish the attempt.
451         $this->quba->finish_all_questions();
453         // Process an example comment and a grade of 0.
454         $this->manual_grade('example', 0, FORMAT_HTML);
455         // Verify the format is FORMAT_HTML.
456         $this->check_comment('example', FORMAT_HTML);
458         // Process the same grade and comment with different format.
459         $this->manual_grade('example', 0, FORMAT_MARKDOWN);
460         // Verify the format is FORMAT_MARKDOWN.
461         $this->check_comment('example', FORMAT_MARKDOWN);
462     }
464     public function test_manual_graded_respects_display_options() {
465         // This test is for MDL-43874. Manual comments were not respecting the
466         // Display options for feedback.
467         global $PAGE;
469         // The current text editor depends on the users profile setting - so it needs a valid user.
470         $this->setAdminUser();
471         // Required to init a text editor.
472         $PAGE->set_url('/');
474         // Create an essay question.
475         $essay = test_question_maker::make_an_essay_question();
476         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
478         // Check the right model is being used.
479         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
480                 $this->slot)->get_behaviour_name());
482         // Check the initial state.
483         $this->check_current_state(question_state::$todo);
484         $this->check_current_mark(null);
485         $this->check_current_output($this->get_contains_question_text_expectation($essay),
486                 $this->get_does_not_contain_feedback_expectation());
488         // Simulate some data submitted by the student.
489         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
491         // Verify.
492         $this->check_current_state(question_state::$complete);
493         $this->check_current_mark(null);
494         $this->check_current_output(
495                 new question_contains_tag_with_attribute('textarea', 'name',
496                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
497                 $this->get_does_not_contain_feedback_expectation());
499         // Finish the attempt.
500         $this->quba->finish_all_questions();
502         // Verify.
503         $this->check_current_state(question_state::$needsgrading);
504         $this->check_current_mark(null);
505         $this->assertEquals('This is my wonderful essay!',
506                 $this->quba->get_response_summary($this->slot));
508         // Process a comment and a grade.
509         $this->manual_grade('This should only appear if the displya options allow it', 5, FORMAT_HTML);
511         // Verify.
512         $this->check_current_state(question_state::$mangrpartial);
513         $this->check_current_mark(5);
515         $this->displayoptions->manualcomment = question_display_options::HIDDEN;
516         $this->check_output_does_not_contain('This should only appear if the displya options allow it');
517         $this->displayoptions->manualcomment = question_display_options::VISIBLE;
518         $this->check_output_contains('This should only appear if the displya options allow it');
519     }
521     public function test_manual_graded_invalid_value_throws_exception() {
522         global $PAGE;
524         // The current text editor depends on the users profile setting - so it needs a valid user.
525         $this->setAdminUser();
526         // Required to init a text editor.
527         $PAGE->set_url('/');
529         // Create an essay question.
530         $essay = test_question_maker::make_an_essay_question();
531         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
533         // Check the right model is being used.
534         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
535                 $this->slot)->get_behaviour_name());
537         // Check the initial state.
538         $this->check_current_state(question_state::$todo);
539         $this->check_current_mark(null);
540         $this->check_current_output($this->get_contains_question_text_expectation($essay),
541                 $this->get_does_not_contain_feedback_expectation());
543         // Simulate some data submitted by the student.
544         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
546         // Verify.
547         $this->check_current_state(question_state::$complete);
548         $this->check_current_mark(null);
549         $this->check_current_output(
550                 new question_contains_tag_with_attribute('textarea', 'name',
551                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
552                 $this->get_does_not_contain_feedback_expectation());
554         // Finish the attempt.
555         $this->quba->finish_all_questions();
557         // Verify.
558         $this->check_current_state(question_state::$needsgrading);
559         $this->check_current_mark(null);
560         $this->assertEquals('This is my wonderful essay!',
561                 $this->quba->get_response_summary($this->slot));
563         // Try to process a an invalid grade.
564         $this->expectException('coding_exception');
565         $this->manual_grade('Comment', 'frog', FORMAT_HTML);
566     }
568     public function test_manual_graded_out_of_range_throws_exception() {
569         global $PAGE;
571         // The current text editor depends on the users profile setting - so it needs a valid user.
572         $this->setAdminUser();
573         // Required to init a text editor.
574         $PAGE->set_url('/');
576         // Create an essay question.
577         $essay = test_question_maker::make_an_essay_question();
578         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
580         // Check the right model is being used.
581         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
582                 $this->slot)->get_behaviour_name());
584         // Check the initial state.
585         $this->check_current_state(question_state::$todo);
586         $this->check_current_mark(null);
587         $this->check_current_output($this->get_contains_question_text_expectation($essay),
588                 $this->get_does_not_contain_feedback_expectation());
590         // Simulate some data submitted by the student.
591         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
593         // Verify.
594         $this->check_current_state(question_state::$complete);
595         $this->check_current_mark(null);
596         $this->check_current_output(
597                 new question_contains_tag_with_attribute('textarea', 'name',
598                 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
599                 $this->get_does_not_contain_feedback_expectation());
601         // Finish the attempt.
602         $this->quba->finish_all_questions();
604         // Verify.
605         $this->check_current_state(question_state::$needsgrading);
606         $this->check_current_mark(null);
607         $this->assertEquals('This is my wonderful essay!',
608                 $this->quba->get_response_summary($this->slot));
610         // Try to process a an invalid grade.
611         $this->expectException('coding_exception');
612         $this->manual_grade('Comment', '10.1', FORMAT_HTML);
613     }
615     public function test_manual_graded_displays_proper_comment_format () {
617         global $PAGE;
619         // The current text editor depends on the users profile setting - so it needs a valid user.
620         $this->setAdminUser();
621         // Required to init a text editor.
622         $PAGE->set_url('/');
624         // Create an essay question.
625         $essay = test_question_maker::make_an_essay_question();
626         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
628         // Check the right model is being used.
629         $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
630                 $this->slot)->get_behaviour_name());
632         // Simulate some data submitted by the student.
633         $this->process_submission(
634                 array(
635                     'answer' => "A submission!",
636                     'answerformat' => FORMAT_PLAIN
637                 )
638         );
640         // Finish the attempt.
641         $this->quba->finish_all_questions();
643         // Write a manual comment in markdown.
644         $this->manual_grade("*one\n*two\n*three\n", 10, FORMAT_MARKDOWN);
646         // Check that feedback contains the original markdown format.
647         $preg = '/<textarea [^>]+name="[^"]+-comment"[^>]+>\*one\n\*two\n\*three\n/';
648         $this->displayoptions->manualcomment = question_display_options::EDITABLE;
649         $this->check_current_output(
650             new question_pattern_expectation($preg)
651         );
652     }
654     public function test_manual_grading_reshows_exactly_the_mark_input() {
655         global $PAGE;
657         // The current text editor depends on the users profile setting - so it needs a valid user.
658         $this->setAdminUser();
659         // Required to init a text editor.
660         $PAGE->set_url('/');
662         // Create an essay question graded out of 15 and attempt it.
663         $essay = test_question_maker::make_an_essay_question();
664         $this->start_attempt_at_question($essay, 'deferredfeedback', 15);
665         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
666         $this->quba->finish_all_questions();
668         // Verify.
669         $this->check_current_state(question_state::$needsgrading);
670         $this->check_current_mark(null);
671         $this->assertEquals('This is my wonderful essay!',
672                 $this->quba->get_response_summary($this->slot));
674         // Try to process a grade where the score will be stored rounded.
675         $this->manual_grade('Comment', '5.0', FORMAT_HTML);
677         // Verify.
678         $this->check_current_state(question_state::$mangrpartial);
679         $this->check_current_mark(5);
680         $this->displayoptions->manualcomment = question_display_options::EDITABLE;
681         $this->render();
682         $this->check_output_contains_text_input('-mark', '5.0');
684         // Rescale what the question is worth, and verify the display.
685         $this->get_question_attempt()->set_max_mark(1);
686         $this->render();
687         $this->check_output_contains_text_input('-mark', '0.3333333');
688     }
690     public function test_manual_grading_history_display() {
691         global $PAGE;
693         // The current text editor depends on the users profile setting - so it needs a valid user.
694         $this->setAdminUser();
695         // Required to init a text editor.
696         $PAGE->set_url('/');
698         // Create an essay question graded out of 15 and attempt it.
699         $essay = test_question_maker::make_an_essay_question();
700         $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
701         $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
702         $this->quba->finish_all_questions();
704         // Verify.
705         $this->check_current_state(question_state::$needsgrading);
707         // Process an initial grade and comment.
708         $this->manual_grade('First comment', '5.0', FORMAT_HTML);
710         // Process a second grade and comment.
711         $this->manual_grade('Second comment', '7.0', FORMAT_HTML);
713         // Verify.
714         $this->check_current_state(question_state::$mangrpartial);
715         $this->check_current_mark(7);
716         $this->displayoptions->history = question_display_options::VISIBLE;
717         $this->render();
718         $this->check_output_contains('Manually graded 5 with comment: First comment');
719         $this->check_output_contains('Manually graded 7 with comment: Second comment');
720     }