|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 require_once(dirname(__FILE__) . '/../../../engine/lib.php'); 00031 require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php'); 00032 00033 00040 class qbehaviour_manualgraded_walkthrough_test extends qbehaviour_walkthrough_test_base { 00041 public function test_manual_graded_essay() { 00042 00043 // Create an essay question. 00044 $essay = test_question_maker::make_an_essay_question(); 00045 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 00046 00047 // Check the right model is being used. 00048 $this->assertEqual('manualgraded', $this->quba->get_question_attempt( 00049 $this->slot)->get_behaviour_name()); 00050 00051 // Check the initial state. 00052 $this->check_current_state(question_state::$todo); 00053 $this->check_current_mark(null); 00054 $this->check_current_output($this->get_contains_question_text_expectation($essay), 00055 $this->get_does_not_contain_feedback_expectation()); 00056 00057 // Simulate some data submitted by the student. 00058 $this->process_submission(array('answer' => 'This is my wonderful essay!')); 00059 00060 // Verify. 00061 $this->check_current_state(question_state::$complete); 00062 $this->check_current_mark(null); 00063 $this->check_current_output( 00064 new ContainsTagWithAttribute('textarea', 'name', 00065 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 00066 $this->get_does_not_contain_feedback_expectation()); 00067 00068 // Process the same data again, check it does not create a new step. 00069 $numsteps = $this->get_step_count(); 00070 $this->process_submission(array('answer' => 'This is my wonderful essay!')); 00071 $this->check_step_count($numsteps); 00072 00073 // Process different data, check it creates a new step. 00074 $this->process_submission(array('answer' => '')); 00075 $this->check_step_count($numsteps + 1); 00076 $this->check_current_state(question_state::$todo); 00077 00078 // Change back, check it creates a new step. 00079 $this->process_submission(array('answer' => 'This is my wonderful essay!')); 00080 $this->check_step_count($numsteps + 2); 00081 00082 // Finish the attempt. 00083 $this->quba->finish_all_questions(); 00084 00085 // Verify. 00086 $this->check_current_state(question_state::$needsgrading); 00087 $this->check_current_mark(null); 00088 $this->assertEqual('This is my wonderful essay!', 00089 $this->quba->get_response_summary($this->slot)); 00090 00091 // Process a manual comment. 00092 $this->manual_grade('Not good enough!', 10); 00093 00094 // Verify. 00095 $this->check_current_state(question_state::$mangrright); 00096 $this->check_current_mark(10); 00097 $this->check_current_output( 00098 new PatternExpectation('/' . preg_quote('Not good enough!') . '/')); 00099 00100 // Now change the max mark for the question and regrade. 00101 $this->quba->regrade_question($this->slot, true, 1); 00102 00103 // Verify. 00104 $this->check_current_state(question_state::$mangrright); 00105 $this->check_current_mark(1); 00106 } 00107 00108 public function test_manual_graded_truefalse() { 00109 00110 // Create a true-false question with correct answer true. 00111 $tf = test_question_maker::make_question('truefalse', 'true'); 00112 $this->start_attempt_at_question($tf, 'manualgraded', 2); 00113 00114 // Check the initial state. 00115 $this->check_current_state(question_state::$todo); 00116 $this->check_current_mark(null); 00117 $this->check_current_output( 00118 $this->get_contains_question_text_expectation($tf), 00119 $this->get_does_not_contain_feedback_expectation()); 00120 00121 // Process a true answer and check the expected result. 00122 $this->process_submission(array('answer' => 1)); 00123 00124 $this->check_current_state(question_state::$complete); 00125 $this->check_current_mark(null); 00126 $this->check_current_output( 00127 $this->get_contains_tf_true_radio_expectation(true, true), 00128 $this->get_does_not_contain_correctness_expectation(), 00129 $this->get_does_not_contain_feedback_expectation()); 00130 00131 // Finish the attempt. 00132 $this->quba->finish_all_questions(); 00133 00134 // Verify. 00135 $this->check_current_state(question_state::$needsgrading); 00136 $this->check_current_mark(null); 00137 $this->check_current_output( 00138 $this->get_does_not_contain_correctness_expectation(), 00139 $this->get_does_not_contain_specific_feedback_expectation()); 00140 00141 // Process a manual comment. 00142 $this->manual_grade('Not good enough!', 1); 00143 00144 $this->check_current_state(question_state::$mangrpartial); 00145 $this->check_current_mark(1); 00146 $this->check_current_output( 00147 $this->get_does_not_contain_correctness_expectation(), 00148 $this->get_does_not_contain_specific_feedback_expectation(), 00149 new PatternExpectation('/' . preg_quote('Not good enough!') . '/')); 00150 } 00151 00152 public function test_manual_graded_ignore_repeat_sumbission() { 00153 // Create an essay question. 00154 $essay = test_question_maker::make_an_essay_question(); 00155 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 00156 00157 // Check the right model is being used. 00158 $this->assertEqual('manualgraded', $this->quba->get_question_attempt( 00159 $this->slot)->get_behaviour_name()); 00160 00161 // Check the initial state. 00162 $this->check_current_state(question_state::$todo); 00163 $this->check_current_mark(null); 00164 00165 // Simulate some data submitted by the student. 00166 $this->process_submission(array('answer' => 'This is my wonderful essay!')); 00167 00168 // Verify. 00169 $this->check_current_state(question_state::$complete); 00170 $this->check_current_mark(null); 00171 00172 // Finish the attempt. 00173 $this->quba->finish_all_questions(); 00174 00175 // Verify. 00176 $this->check_current_state(question_state::$needsgrading); 00177 $this->check_current_mark(null); 00178 $this->assertEqual('This is my wonderful essay!', 00179 $this->quba->get_response_summary($this->slot)); 00180 00181 // Process a blank manual comment. Ensure it does not change the state. 00182 $numsteps = $this->get_step_count(); 00183 $this->manual_grade('', ''); 00184 $this->check_step_count($numsteps); 00185 $this->check_current_state(question_state::$needsgrading); 00186 $this->check_current_mark(null); 00187 00188 // Process a comment, but with the mark blank. Should be recorded, but 00189 // not change the mark. 00190 $this->manual_grade('I am not sure what grade to award.', ''); 00191 $this->check_step_count($numsteps + 1); 00192 $this->check_current_state(question_state::$needsgrading); 00193 $this->check_current_mark(null); 00194 $this->check_current_output( 00195 new PatternExpectation('/' . 00196 preg_quote('I am not sure what grade to award.') . '/')); 00197 00198 // Now grade it. 00199 $this->manual_grade('Pretty good!', '9.00000'); 00200 $this->check_step_count($numsteps + 2); 00201 $this->check_current_state(question_state::$mangrpartial); 00202 $this->check_current_mark(9); 00203 $this->check_current_output( 00204 new PatternExpectation('/' . preg_quote('Pretty good!') . '/')); 00205 00206 // Process the same data again, and make sure it does not add a step. 00207 $this->manual_grade('Pretty good!', '9.00000'); 00208 $this->check_step_count($numsteps + 2); 00209 $this->check_current_state(question_state::$mangrpartial); 00210 $this->check_current_mark(9); 00211 00212 // Now set the mark back to blank. 00213 $this->manual_grade('Actually, I am not sure any more.', ''); 00214 $this->check_step_count($numsteps + 3); 00215 $this->check_current_state(question_state::$needsgrading); 00216 $this->check_current_mark(null); 00217 $this->check_current_output( 00218 new PatternExpectation('/' . 00219 preg_quote('Actually, I am not sure any more.') . '/')); 00220 00221 $qa = $this->quba->get_question_attempt($this->slot); 00222 $this->assertEqual('Commented: Actually, I am not sure any more.', 00223 $qa->summarise_action($qa->get_last_step())); 00224 } 00225 00226 public function test_manual_graded_essay_can_grade_0() { 00227 00228 // Create an essay question. 00229 $essay = test_question_maker::make_an_essay_question(); 00230 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 00231 00232 // Check the right model is being used. 00233 $this->assertEqual('manualgraded', $this->quba->get_question_attempt( 00234 $this->slot)->get_behaviour_name()); 00235 00236 // Check the initial state. 00237 $this->check_current_state(question_state::$todo); 00238 $this->check_current_mark(null); 00239 $this->check_current_output($this->get_contains_question_text_expectation($essay), 00240 $this->get_does_not_contain_feedback_expectation()); 00241 00242 // Simulate some data submitted by the student. 00243 $this->process_submission(array('answer' => 'This is my wonderful essay!')); 00244 00245 // Verify. 00246 $this->check_current_state(question_state::$complete); 00247 $this->check_current_mark(null); 00248 $this->check_current_output( 00249 new ContainsTagWithAttribute('textarea', 'name', 00250 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 00251 $this->get_does_not_contain_feedback_expectation()); 00252 00253 // Finish the attempt. 00254 $this->quba->finish_all_questions(); 00255 00256 // Verify. 00257 $this->check_current_state(question_state::$needsgrading); 00258 $this->check_current_mark(null); 00259 $this->assertEqual('This is my wonderful essay!', 00260 $this->quba->get_response_summary($this->slot)); 00261 00262 // Process a blank comment and a grade of 0. 00263 $this->manual_grade('', 0); 00264 00265 // Verify. 00266 $this->check_current_state(question_state::$mangrwrong); 00267 $this->check_current_mark(0); 00268 } 00269 }