Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/immediatecbm/simpletest/testwalkthrough.php
Go to the documentation of this file.
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_immediatecbm_walkthrough_test extends qbehaviour_walkthrough_test_base {
00041     public function test_immediatecbm_feedback_multichoice_right() {
00042 
00043         // Create a true-false question with correct answer true.
00044         $mc = test_question_maker::make_a_multichoice_single_question();
00045         $this->start_attempt_at_question($mc, 'immediatecbm');
00046 
00047         $rightindex = $this->get_mc_right_answer_index($mc);
00048         $wrongindex = ($rightindex + 1) % 3;
00049 
00050         // Check the initial state.
00051         $this->check_current_state(question_state::$todo);
00052         $this->check_current_mark(null);
00053         $this->check_current_output(
00054                 $this->get_contains_question_text_expectation($mc),
00055                 $this->get_contains_mc_radio_expectation(0, true, false),
00056                 $this->get_contains_mc_radio_expectation(1, true, false),
00057                 $this->get_contains_mc_radio_expectation(2, true, false),
00058                 $this->get_contains_submit_button_expectation(true),
00059                 $this->get_does_not_contain_feedback_expectation());
00060         $this->assertEqual('A [' . question_cbm::get_string(question_cbm::HIGH) . ']',
00061                 $this->quba->get_right_answer_summary($this->slot));
00062         $this->assertPattern('/' . preg_quote($mc->questiontext) . '/',
00063                 $this->quba->get_question_summary($this->slot));
00064         $this->assertNull($this->quba->get_response_summary($this->slot));
00065 
00066         // Save the wrong answer.
00067         $this->process_submission(array('answer' => $wrongindex, '-certainty' => 1));
00068 
00069         // Verify.
00070         $this->check_current_state(question_state::$todo);
00071         $this->check_current_mark(null);
00072         $this->check_current_output(
00073                 $this->get_contains_mc_radio_expectation($wrongindex, true, true),
00074                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00075                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00076                 $this->get_contains_submit_button_expectation(true),
00077                 $this->get_does_not_contain_correctness_expectation(),
00078                 $this->get_does_not_contain_feedback_expectation());
00079 
00080         // Submit the right answer.
00081         $this->process_submission(
00082                 array('answer' => $rightindex, '-certainty' => 2, '-submit' => 1));
00083 
00084         // Verify.
00085         $this->check_current_state(question_state::$gradedright);
00086         $this->check_current_mark(2/3);
00087         $this->check_current_output(
00088                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00089                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00090                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00091                 $this->get_contains_correct_expectation());
00092         $this->assertEqual('A [' . question_cbm::get_string(2) . ']',
00093                 $this->quba->get_response_summary($this->slot));
00094 
00095         $numsteps = $this->get_step_count();
00096 
00097         // Finish the attempt - should not need to add a new state.
00098         $this->quba->finish_all_questions();
00099 
00100         // Verify.
00101         $this->assertEqual($numsteps, $this->get_step_count());
00102         $this->check_current_state(question_state::$gradedright);
00103         $this->check_current_mark(2/3);
00104         $this->check_current_output(
00105                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00106                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00107                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00108                 $this->get_contains_correct_expectation());
00109 
00110         // Process a manual comment.
00111         $this->manual_grade('Not good enough!', 0.5);
00112 
00113         // Verify.
00114         $this->check_current_state(question_state::$mangrpartial);
00115         $this->check_current_mark(0.5);
00116         $this->check_current_output(
00117                 $this->get_contains_partcorrect_expectation(),
00118                 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
00119 
00120         // Now change the correct answer to the question, and regrade.
00121         $mc->answers[13]->fraction = -0.33333333;
00122         $mc->answers[15]->fraction = 1;
00123         $this->quba->regrade_all_questions();
00124 
00125         // Verify.
00126         $this->check_current_state(question_state::$mangrpartial);
00127         $this->check_current_mark(0.5);
00128         $this->check_current_output(
00129                 $this->get_contains_partcorrect_expectation());
00130 
00131         $autogradedstep = $this->get_step($this->get_step_count() - 2);
00132         $this->assertWithinMargin($autogradedstep->get_fraction(), -10/9, 0.0000001);
00133     }
00134 
00135     public function test_immediatecbm_feedback_multichoice_try_to_submit_blank() {
00136 
00137         // Create a true-false question with correct answer true.
00138         $mc = test_question_maker::make_a_multichoice_single_question();
00139         $this->start_attempt_at_question($mc, 'immediatecbm');
00140 
00141         // Check the initial state.
00142         $this->check_current_state(question_state::$todo);
00143         $this->check_current_mark(null);
00144         $this->check_current_output(
00145                 $this->get_contains_question_text_expectation($mc),
00146                 $this->get_contains_mc_radio_expectation(0, true, false),
00147                 $this->get_contains_mc_radio_expectation(1, true, false),
00148                 $this->get_contains_mc_radio_expectation(2, true, false),
00149                 $this->get_contains_submit_button_expectation(true),
00150                 $this->get_does_not_contain_feedback_expectation());
00151 
00152         // Submit nothing.
00153         $this->process_submission(array('-submit' => 1));
00154 
00155         // Verify.
00156         $this->check_current_state(question_state::$invalid);
00157         $this->check_current_mark(null);
00158         $this->check_current_output(
00159                 $this->get_contains_mc_radio_expectation(0, true, false),
00160                 $this->get_contains_mc_radio_expectation(1, true, false),
00161                 $this->get_contains_mc_radio_expectation(2, true, false),
00162                 $this->get_contains_submit_button_expectation(true),
00163                 $this->get_does_not_contain_correctness_expectation(),
00164                 $this->get_contains_validation_error_expectation());
00165 
00166         // Finish the attempt.
00167         $this->quba->finish_all_questions();
00168 
00169         // Verify.
00170         $this->check_current_state(question_state::$gaveup);
00171         $this->check_current_mark(null);
00172         $this->check_current_output(
00173                 $this->get_contains_mc_radio_expectation(0, false, false),
00174                 $this->get_contains_mc_radio_expectation(1, false, false),
00175                 $this->get_contains_mc_radio_expectation(2, false, false));
00176 
00177         // Process a manual comment.
00178         $this->manual_grade('Not good enough!', 0.5);
00179 
00180         // Verify.
00181         $this->check_current_state(question_state::$mangrpartial);
00182         $this->check_current_mark(0.5);
00183         $this->check_current_output(
00184                 $this->get_contains_partcorrect_expectation(),
00185                 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
00186     }
00187 
00188     public function test_immediatecbm_feedback_shortanswer_try_to_submit_no_certainty() {
00189 
00190         // Create a short answer question with correct answer true.
00191         $sa = test_question_maker::make_question('shortanswer');
00192         $this->start_attempt_at_question($sa, 'immediatecbm');
00193 
00194         // Check the initial state.
00195         $this->check_current_state(question_state::$todo);
00196         $this->check_current_mark(null);
00197         $this->check_current_output(
00198                 $this->get_contains_submit_button_expectation(true),
00199                 $this->get_does_not_contain_feedback_expectation());
00200 
00201         // Submit with certainty missing.
00202         $this->process_submission(array('-submit' => 1, 'answer' => 'frog'));
00203 
00204         // Verify.
00205         $this->check_current_state(question_state::$invalid);
00206         $this->check_current_mark(null);
00207         $this->check_current_output(
00208                 $this->get_contains_submit_button_expectation(true),
00209                 $this->get_does_not_contain_correctness_expectation(),
00210                 $this->get_contains_validation_error_expectation());
00211 
00212         // Now get it right.
00213         $this->process_submission(array('-submit' => 1, 'answer' => 'frog', '-certainty' => 3));
00214 
00215         // Verify.
00216         $this->check_current_state(question_state::$gradedright);
00217         $this->check_current_mark(1);
00218         $this->check_current_output(
00219                 $this->get_does_not_contain_validation_error_expectation());
00220     }
00221 
00222     public function test_immediatecbm_feedback_multichoice_wrong_on_finish() {
00223 
00224         // Create a true-false question with correct answer true.
00225         $mc = test_question_maker::make_a_multichoice_single_question();
00226         $this->start_attempt_at_question($mc, 'immediatecbm');
00227 
00228         // Check the initial state.
00229         $this->check_current_state(question_state::$todo);
00230         $this->check_current_mark(null);
00231         $this->check_current_output(
00232                 $this->get_contains_question_text_expectation($mc),
00233                 $this->get_contains_mc_radio_expectation(0, true, false),
00234                 $this->get_contains_mc_radio_expectation(1, true, false),
00235                 $this->get_contains_mc_radio_expectation(2, true, false),
00236                 $this->get_contains_submit_button_expectation(true),
00237                 $this->get_does_not_contain_feedback_expectation());
00238 
00239         $rightindex = $this->get_mc_right_answer_index($mc);
00240         $wrongindex = ($rightindex + 1) % 3;
00241 
00242         // Save the wrong answer.
00243         $this->process_submission(array('answer' => $wrongindex, '-certainty' => 3));
00244 
00245         // Verify.
00246         $this->check_current_state(question_state::$todo);
00247         $this->check_current_mark(null);
00248         $this->check_current_output(
00249                 $this->get_contains_mc_radio_expectation($wrongindex, true, true),
00250                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00251                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00252                 $this->get_contains_submit_button_expectation(true),
00253                 $this->get_does_not_contain_correctness_expectation());
00254 
00255         // Finish the attempt.
00256         $this->quba->finish_all_questions();
00257 
00258         // Verify.
00259         $this->check_current_state(question_state::$gradedwrong);
00260         $this->check_current_mark(-3);
00261         $this->check_current_output(
00262                 $this->get_contains_mc_radio_expectation($wrongindex, false, true),
00263                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false),
00264                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false),
00265                 $this->get_contains_incorrect_expectation());
00266     }
00267 
00268     public function test_immediatecbm_cbm_truefalse_no_certainty_feedback_when_not_answered() {
00269 
00270         // Create a true-false question with correct answer true.
00271         $tf = test_question_maker::make_question('truefalse', 'true');
00272         $this->start_attempt_at_question($tf, 'deferredcbm', 2);
00273 
00274         // Verify.
00275         $this->check_current_state(question_state::$todo);
00276         $this->check_current_mark(null);
00277         $this->check_current_output(
00278                 $this->get_does_not_contain_correctness_expectation(),
00279                 $this->get_contains_cbm_radio_expectation(1, true, false),
00280                 $this->get_does_not_contain_feedback_expectation());
00281 
00282         // Finish without answering.
00283         $this->quba->finish_all_questions();
00284 
00285         // Verify.
00286         $this->check_current_state(question_state::$gaveup);
00287         $this->check_current_mark(null);
00288         $this->check_current_output(
00289                 new NoPatternExpectation('/class=\"im-feedback/'));
00290     }
00291 }
 All Data Structures Namespaces Files Functions Variables Enumerations