Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/immediatefeedback/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_immediatefeedback_walkthrough_test extends qbehaviour_walkthrough_test_base {
00041     public function test_immediatefeedback_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, 'immediatefeedback');
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 
00061         // Save the wrong answer.
00062         $this->process_submission(array('answer' => $wrongindex));
00063 
00064         // Verify.
00065         $this->check_current_state(question_state::$todo);
00066         $this->check_current_mark(null);
00067         $this->check_current_output(
00068                 $this->get_contains_mc_radio_expectation($wrongindex, true, true),
00069                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00070                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00071                 $this->get_contains_submit_button_expectation(true),
00072                 $this->get_does_not_contain_correctness_expectation(),
00073                 $this->get_does_not_contain_feedback_expectation());
00074 
00075         // Submit the right answer.
00076         $this->process_submission(array('answer' => $rightindex, '-submit' => 1));
00077 
00078         // Verify.
00079         $this->check_current_state(question_state::$gradedright);
00080         $this->check_current_mark(1);
00081         $this->check_current_output(
00082                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00083                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00084                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00085                 $this->get_contains_correct_expectation());
00086         $this->assertEqual('A',
00087                 $this->quba->get_response_summary($this->slot));
00088 
00089         $numsteps = $this->get_step_count();
00090 
00091         // Now try to save again - as if the user clicked next in the quiz.
00092         $this->process_submission(array('answer' => $rightindex));
00093 
00094         // Verify.
00095         $this->assertEqual($numsteps, $this->get_step_count());
00096         $this->check_current_state(question_state::$gradedright);
00097         $this->check_current_mark(1);
00098         $this->check_current_output(
00099                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00100                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00101                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00102                 $this->get_contains_correct_expectation());
00103 
00104         // Finish the attempt - should not need to add a new state.
00105         $this->quba->finish_all_questions();
00106 
00107         // Verify.
00108         $this->assertEqual($numsteps, $this->get_step_count());
00109         $this->check_current_state(question_state::$gradedright);
00110         $this->check_current_mark(1);
00111         $this->check_current_output(
00112                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00113                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00114                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00115                 $this->get_contains_correct_expectation());
00116 
00117         // Process a manual comment.
00118         $this->manual_grade('Not good enough!', 0.5);
00119 
00120         // Verify.
00121         $this->check_current_state(question_state::$mangrpartial);
00122         $this->check_current_mark(0.5);
00123         $this->check_current_output(
00124                 $this->get_contains_partcorrect_expectation(),
00125                 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
00126 
00127         // Now change the correct answer to the question, and regrade.
00128         $mc->answers[13]->fraction = -0.33333333;
00129         $mc->answers[15]->fraction = 1;
00130         $this->quba->regrade_all_questions();
00131 
00132         // Verify.
00133         $this->check_current_state(question_state::$mangrpartial);
00134         $this->check_current_mark(0.5);
00135         $this->check_current_output(
00136                 $this->get_contains_partcorrect_expectation());
00137 
00138         $autogradedstep = $this->get_step($this->get_step_count() - 2);
00139         $this->assertWithinMargin($autogradedstep->get_fraction(), -0.3333333, 0.0000001);
00140     }
00141 
00142     public function test_immediatefeedback_feedback_multichoice_try_to_submit_blank() {
00143 
00144         // Create a true-false question with correct answer true.
00145         $mc = test_question_maker::make_a_multichoice_single_question();
00146         $this->start_attempt_at_question($mc, 'immediatefeedback');
00147 
00148         // Check the initial state.
00149         $this->check_current_state(question_state::$todo);
00150         $this->check_current_mark(null);
00151         $this->check_current_output(
00152                 $this->get_contains_question_text_expectation($mc),
00153                 $this->get_contains_mc_radio_expectation(0, true, false),
00154                 $this->get_contains_mc_radio_expectation(1, true, false),
00155                 $this->get_contains_mc_radio_expectation(2, true, false),
00156                 $this->get_contains_submit_button_expectation(true),
00157                 $this->get_does_not_contain_feedback_expectation());
00158 
00159         // Submit nothing.
00160         $this->process_submission(array('-submit' => 1));
00161 
00162         // Verify.
00163         $this->check_current_state(question_state::$invalid);
00164         $this->check_current_mark(null);
00165         $this->check_current_output(
00166                 $this->get_contains_mc_radio_expectation(0, true, false),
00167                 $this->get_contains_mc_radio_expectation(1, true, false),
00168                 $this->get_contains_mc_radio_expectation(2, true, false),
00169                 $this->get_contains_submit_button_expectation(true),
00170                 $this->get_does_not_contain_correctness_expectation(),
00171                 $this->get_does_not_contain_feedback_expectation(),
00172                 $this->get_contains_validation_error_expectation());
00173         $this->assertNull($this->quba->get_response_summary($this->slot));
00174 
00175         // Finish the attempt.
00176         $this->quba->finish_all_questions();
00177 
00178         // Verify.
00179         $this->check_current_state(question_state::$gaveup);
00180         $this->check_current_mark(null);
00181         $this->check_current_output(
00182                 $this->get_contains_mc_radio_expectation(0, false, false),
00183                 $this->get_contains_mc_radio_expectation(1, false, false),
00184                 $this->get_contains_mc_radio_expectation(2, false, false));
00185 
00186         // Process a manual comment.
00187         $this->manual_grade('Not good enough!', 0.5);
00188 
00189         // Verify.
00190         $this->check_current_state(question_state::$mangrpartial);
00191         $this->check_current_mark(0.5);
00192         $this->check_current_output(
00193                 $this->get_contains_partcorrect_expectation(),
00194                 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
00195     }
00196 
00197     public function test_immediatefeedback_feedback_multichoice_wrong_on_finish() {
00198 
00199         // Create a true-false question with correct answer true.
00200         $mc = test_question_maker::make_a_multichoice_single_question();
00201         $this->start_attempt_at_question($mc, 'immediatefeedback');
00202 
00203         // Check the initial state.
00204         $this->check_current_state(question_state::$todo);
00205         $this->check_current_mark(null);
00206         $this->check_current_output(
00207                 $this->get_contains_question_text_expectation($mc),
00208                 $this->get_contains_mc_radio_expectation(0, true, false),
00209                 $this->get_contains_mc_radio_expectation(1, true, false),
00210                 $this->get_contains_mc_radio_expectation(2, true, false),
00211                 $this->get_contains_submit_button_expectation(true),
00212                 $this->get_does_not_contain_feedback_expectation());
00213 
00214         $rightindex = $this->get_mc_right_answer_index($mc);
00215         $wrongindex = ($rightindex + 1) % 3;
00216 
00217         // Save the wrong answer.
00218         $this->process_submission(array('answer' => $wrongindex));
00219 
00220         // Verify.
00221         $this->check_current_state(question_state::$todo);
00222         $this->check_current_mark(null);
00223         $this->check_current_output(
00224                 $this->get_contains_mc_radio_expectation($wrongindex, true, true),
00225                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00226                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00227                 $this->get_contains_submit_button_expectation(true),
00228                 $this->get_does_not_contain_correctness_expectation(),
00229                 $this->get_does_not_contain_feedback_expectation());
00230 
00231         // Finish the attempt.
00232         $this->quba->finish_all_questions();
00233 
00234         // Verify.
00235         $this->check_current_state(question_state::$gradedwrong);
00236         $this->check_current_mark(-0.3333333);
00237         $this->check_current_output(
00238                 $this->get_contains_mc_radio_expectation($wrongindex, false, true),
00239                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false),
00240                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false),
00241                 $this->get_contains_incorrect_expectation());
00242         $this->assertPattern('/B|C/',
00243                 $this->quba->get_response_summary($this->slot));
00244     }
00245 }
 All Data Structures Namespaces Files Functions Variables Enumerations