|
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_deferredfeedback_walkthrough_test extends qbehaviour_walkthrough_test_base { 00041 public function test_deferredfeedback_feedback_truefalse() { 00042 00043 // Create a true-false question with correct answer true. 00044 $tf = test_question_maker::make_question('truefalse', 'true'); 00045 $this->start_attempt_at_question($tf, 'deferredfeedback', 2); 00046 00047 // Check the initial state. 00048 $this->check_current_state(question_state::$todo); 00049 $this->check_current_mark(null); 00050 $this->check_current_output($this->get_contains_question_text_expectation($tf), 00051 $this->get_does_not_contain_feedback_expectation()); 00052 $this->assertEqual(get_string('true', 'qtype_truefalse'), 00053 $this->quba->get_right_answer_summary($this->slot)); 00054 $this->assertPattern('/' . preg_quote($tf->questiontext) . '/', 00055 $this->quba->get_question_summary($this->slot)); 00056 $this->assertNull($this->quba->get_response_summary($this->slot)); 00057 00058 // Process a true answer and check the expected result. 00059 $this->process_submission(array('answer' => 1)); 00060 00061 $this->check_current_state(question_state::$complete); 00062 $this->check_current_mark(null); 00063 $this->check_current_output($this->get_contains_tf_true_radio_expectation(true, true), 00064 $this->get_does_not_contain_correctness_expectation(), 00065 $this->get_does_not_contain_feedback_expectation()); 00066 00067 // Process the same data again, check it does not create a new step. 00068 $numsteps = $this->get_step_count(); 00069 $this->process_submission(array('answer' => 1)); 00070 $this->check_step_count($numsteps); 00071 00072 // Process different data, check it creates a new step. 00073 $this->process_submission(array('answer' => 0)); 00074 $this->check_step_count($numsteps + 1); 00075 $this->check_current_state(question_state::$complete); 00076 00077 // Change back, check it creates a new step. 00078 $this->process_submission(array('answer' => 1)); 00079 $this->check_step_count($numsteps + 2); 00080 00081 // Finish the attempt. 00082 $this->quba->finish_all_questions(); 00083 00084 // Verify. 00085 $this->check_current_state(question_state::$gradedright); 00086 $this->check_current_mark(2); 00087 $this->check_current_output($this->get_contains_correct_expectation(), 00088 $this->get_contains_tf_true_radio_expectation(false, true), 00089 new PatternExpectation('/class="r0 correct"/')); 00090 $this->assertEqual(get_string('true', 'qtype_truefalse'), 00091 $this->quba->get_response_summary($this->slot)); 00092 00093 // Process a manual comment. 00094 $this->manual_grade('Not good enough!', 1); 00095 00096 $this->check_current_state(question_state::$mangrpartial); 00097 $this->check_current_mark(1); 00098 $this->check_current_output( 00099 new PatternExpectation('/' . preg_quote('Not good enough!') . '/')); 00100 00101 // Now change the correct answer to the question, and regrade. 00102 $tf->rightanswer = false; 00103 $this->quba->regrade_all_questions(); 00104 00105 // Verify. 00106 $this->check_current_state(question_state::$mangrpartial); 00107 $this->check_current_mark(1); 00108 00109 $autogradedstep = $this->get_step($this->get_step_count() - 2); 00110 $this->assertWithinMargin($autogradedstep->get_fraction(), 0, 0.0000001); 00111 } 00112 00113 public function test_deferredfeedback_feedback_multichoice_single() { 00114 00115 // Create a true-false question with correct answer true. 00116 $mc = test_question_maker::make_a_multichoice_single_question(); 00117 $this->start_attempt_at_question($mc, 'deferredfeedback', 3); 00118 00119 // Start a deferred feedback attempt and add the question to it. 00120 $rightindex = $this->get_mc_right_answer_index($mc); 00121 00122 $this->check_current_state(question_state::$todo); 00123 $this->check_current_mark(null); 00124 $this->check_current_output( 00125 $this->get_contains_question_text_expectation($mc), 00126 $this->get_contains_mc_radio_expectation(0, true, false), 00127 $this->get_contains_mc_radio_expectation(1, true, false), 00128 $this->get_contains_mc_radio_expectation(2, true, false), 00129 $this->get_does_not_contain_feedback_expectation()); 00130 00131 // Process the data extracted for this question. 00132 $this->process_submission(array('answer' => $rightindex)); 00133 00134 // Verify. 00135 $this->check_current_state(question_state::$complete); 00136 $this->check_current_mark(null); 00137 $this->check_current_output( 00138 $this->get_contains_mc_radio_expectation($rightindex, true, true), 00139 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), 00140 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), 00141 $this->get_does_not_contain_correctness_expectation(), 00142 $this->get_does_not_contain_feedback_expectation()); 00143 00144 // Finish the attempt. 00145 $this->quba->finish_all_questions(); 00146 00147 // Verify. 00148 $this->check_current_state(question_state::$gradedright); 00149 $this->check_current_mark(3); 00150 $this->check_current_output( 00151 $this->get_contains_mc_radio_expectation($rightindex, false, true), 00152 $this->get_contains_correct_expectation()); 00153 00154 // Now change the correct answer to the question, and regrade. 00155 $mc->answers[13]->fraction = -0.33333333; 00156 $mc->answers[14]->fraction = 1; 00157 $this->quba->regrade_all_questions(); 00158 00159 // Verify. 00160 $this->check_current_state(question_state::$gradedwrong); 00161 $this->check_current_mark(-1); 00162 $this->check_current_output( 00163 $this->get_contains_incorrect_expectation()); 00164 } 00165 00166 public function test_deferredfeedback_resume_multichoice_single() { 00167 00168 // Create a multiple-choice question. 00169 $mc = test_question_maker::make_a_multichoice_single_question(); 00170 00171 // Attempt it getting it wrong. 00172 $this->start_attempt_at_question($mc, 'deferredfeedback', 3); 00173 $rightindex = $this->get_mc_right_answer_index($mc); 00174 $wrongindex = ($rightindex + 1) % 3; 00175 $this->process_submission(array('answer' => $wrongindex)); 00176 $this->quba->finish_all_questions(); 00177 00178 // Verify. 00179 $this->check_current_state(question_state::$gradedwrong); 00180 $this->check_current_mark(-1); 00181 $this->check_current_output( 00182 $this->get_contains_mc_radio_expectation($wrongindex, false, true), 00183 $this->get_contains_incorrect_expectation()); 00184 00185 // Save the old attempt. 00186 $oldqa = $this->quba->get_question_attempt($this->slot); 00187 00188 // Reinitialise. 00189 $this->setUp(); 00190 $this->quba->set_preferred_behaviour('deferredfeedback'); 00191 $this->slot = $this->quba->add_question($mc, 3); 00192 $this->quba->start_question_based_on($this->slot, $oldqa); 00193 00194 // Verify. 00195 $this->check_current_state(question_state::$todo); 00196 $this->check_current_mark(null); 00197 $this->check_current_output( 00198 $this->get_contains_mc_radio_expectation($wrongindex, true, true), 00199 $this->get_does_not_contain_feedback_expectation(), 00200 $this->get_does_not_contain_correctness_expectation()); 00201 00202 // Now get it right. 00203 $this->process_submission(array('answer' => $rightindex)); 00204 $this->quba->finish_all_questions(); 00205 00206 // Verify. 00207 $this->check_current_state(question_state::$gradedright); 00208 $this->check_current_mark(3); 00209 $this->check_current_output( 00210 $this->get_contains_mc_radio_expectation($rightindex, false, true), 00211 $this->get_contains_correct_expectation()); 00212 } 00213 }