Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/adaptivenopenalty/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_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base {
00041 
00042     protected function get_does_not_contain_gradingdetails_expectation() {
00043         return new NoPatternExpectation('/class="gradingdetails"/');
00044     }
00045 
00046     public function test_multichoice() {
00047 
00048         // Create a multiple choice, single response question.
00049         $mc = test_question_maker::make_a_multichoice_single_question();
00050         $mc->penalty = 0.3333333;
00051         $this->start_attempt_at_question($mc, 'adaptivenopenalty', 3);
00052 
00053         $rightindex = $this->get_mc_right_answer_index($mc);
00054         $wrongindex = ($rightindex + 1) % 3;
00055 
00056         // Check the initial state.
00057         $this->check_current_state(question_state::$todo);
00058         $this->check_current_mark(null);
00059         $this->check_current_output(
00060                 $this->get_contains_marked_out_of_summary(),
00061                 $this->get_contains_question_text_expectation($mc),
00062                 $this->get_contains_mc_radio_expectation(0, true, false),
00063                 $this->get_contains_mc_radio_expectation(1, true, false),
00064                 $this->get_contains_mc_radio_expectation(2, true, false),
00065                 $this->get_contains_submit_button_expectation(true),
00066                 $this->get_does_not_contain_feedback_expectation());
00067 
00068         // Process a submit.
00069         $this->process_submission(array('answer' => $wrongindex, '-submit' => 1));
00070 
00071         // Verify.
00072         $this->check_current_state(question_state::$todo);
00073         $this->check_current_mark(0);
00074         $this->check_current_output(
00075                 $this->get_contains_mark_summary(0),
00076                 $this->get_contains_mc_radio_expectation($wrongindex, true, true),
00077                 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false),
00078                 $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false),
00079                 $this->get_contains_incorrect_expectation());
00080         $this->assertPattern('/B|C/',
00081                 $this->quba->get_response_summary($this->slot));
00082 
00083         // Process a change of answer to the right one, but not sumbitted.
00084         $this->process_submission(array('answer' => $rightindex));
00085 
00086         // Verify.
00087         $this->check_current_state(question_state::$todo);
00088         $this->check_current_mark(0);
00089         $this->check_current_output(
00090                 $this->get_contains_mark_summary(0),
00091                 $this->get_contains_mc_radio_expectation($rightindex, true, true),
00092                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
00093                 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false));
00094         $this->assertPattern('/B|C/',
00095                 $this->quba->get_response_summary($this->slot));
00096 
00097         // Now submit the right answer.
00098         $this->process_submission(array('answer' => $rightindex, '-submit' => 1));
00099 
00100         // Verify.
00101         $this->check_current_state(question_state::$complete);
00102         $this->check_current_mark(3);
00103         $this->check_current_output(
00104                 $this->get_contains_mark_summary(3),
00105                 $this->get_contains_mc_radio_expectation($rightindex, true, true),
00106                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false),
00107                 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false),
00108                 $this->get_contains_correct_expectation());
00109         $this->assertEqual('A',
00110                 $this->quba->get_response_summary($this->slot));
00111 
00112         // Finish the attempt.
00113         $this->quba->finish_all_questions();
00114 
00115         // Verify.
00116         $this->check_current_state(question_state::$gradedright);
00117         $this->check_current_mark(3);
00118         $this->check_current_output(
00119                 $this->get_contains_mark_summary(3),
00120                 $this->get_contains_mc_radio_expectation($rightindex, false, true),
00121                 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false),
00122                 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false),
00123                 $this->get_contains_correct_expectation());
00124 
00125         // Process a manual comment.
00126         $this->manual_grade('Not good enough!', 1);
00127 
00128         // Verify.
00129         $this->check_current_state(question_state::$mangrpartial);
00130         $this->check_current_mark(1);
00131         $this->check_current_output(
00132                 $this->get_contains_mark_summary(1),
00133                 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
00134 
00135         // Now change the correct answer to the question, and regrade.
00136         $mc->answers[13]->fraction = -0.33333333;
00137         $mc->answers[14]->fraction = 1; // We don't know which "wrong" index we chose above!
00138         $mc->answers[15]->fraction = 1; // Therefore, treat answers B and C with the same score.
00139         $this->quba->regrade_all_questions();
00140 
00141         // Verify.
00142         $this->check_current_state(question_state::$mangrpartial);
00143         $this->check_current_mark(1);
00144         $this->check_current_output(
00145                 $this->get_contains_mark_summary(1),
00146                 $this->get_contains_partcorrect_expectation());
00147 
00148         $autogradedstep = $this->get_step($this->get_step_count() - 3);
00149         $this->assertWithinMargin($autogradedstep->get_fraction(), 1, 0.0000001);
00150     }
00151 
00152     public function test_multichoice2() {
00153 
00154         // Create a multiple choice, multiple response question.
00155         $mc = test_question_maker::make_a_multichoice_multi_question();
00156         $mc->penalty = 0.3333333;
00157         $mc->shuffleanswers = 0;
00158         $this->start_attempt_at_question($mc, 'adaptivenopenalty', 2);
00159 
00160         // Check the initial state.
00161         $this->check_current_state(question_state::$todo);
00162         $this->check_current_mark(null);
00163         $this->check_current_output(
00164                 $this->get_contains_marked_out_of_summary(),
00165                 $this->get_contains_question_text_expectation($mc),
00166                 $this->get_contains_submit_button_expectation(true),
00167                 $this->get_does_not_contain_feedback_expectation());
00168 
00169         // Process a submit.
00170         $this->process_submission(array('choice0' => 1, 'choice2' => 1, '-submit' => 1));
00171 
00172         // Verify.
00173         $this->check_current_state(question_state::$complete);
00174         $this->check_current_mark(2);
00175         $this->check_current_output(
00176                 $this->get_contains_mark_summary(2),
00177                 $this->get_contains_submit_button_expectation(true),
00178                 $this->get_contains_correct_expectation());
00179 
00180         // Save the same correct answer again. Should no do anything.
00181         $numsteps = $this->get_step_count();
00182         $this->process_submission(array('choice0' => 1, 'choice2' => 1));
00183 
00184         // Verify.
00185         $this->check_step_count($numsteps);
00186         $this->check_current_state(question_state::$complete);
00187 
00188         // Finish the attempt.
00189         $this->quba->finish_all_questions();
00190 
00191         // Verify.
00192         $this->check_step_count($numsteps + 1);
00193         $this->check_current_state(question_state::$gradedright);
00194         $this->check_current_mark(2);
00195         $this->check_current_output(
00196                 $this->get_contains_mark_summary(2),
00197                 $this->get_contains_submit_button_expectation(false),
00198                 $this->get_contains_correct_expectation());
00199     }
00200 
00201     public function test_numerical_invalid() {
00202 
00203         // Create a numerical question
00204         $numq = test_question_maker::make_question('numerical', 'pi');
00205         $numq->penalty = 0.1;
00206         $this->start_attempt_at_question($numq, 'adaptivenopenalty');
00207 
00208         // Check the initial state.
00209         $this->check_current_state(question_state::$todo);
00210         $this->check_current_mark(null);
00211         $this->check_current_output(
00212                 $this->get_contains_marked_out_of_summary(),
00213                 $this->get_contains_submit_button_expectation(true),
00214                 $this->get_does_not_contain_feedback_expectation());
00215 
00216         // Submit a non-numerical answer.
00217         $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
00218 
00219         // Verify.
00220         $this->check_current_state(question_state::$invalid);
00221         $this->check_current_mark(null);
00222         $this->check_current_output(
00223                 $this->get_contains_marked_out_of_summary(1),
00224                 $this->get_contains_submit_button_expectation(true),
00225                 $this->get_does_not_contain_correctness_expectation(),
00226                 $this->get_contains_validation_error_expectation(),
00227                 $this->get_does_not_contain_feedback_expectation());
00228 
00229         // Submit an incorrect answer.
00230         $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
00231 
00232         // Verify.
00233         $this->check_current_state(question_state::$todo);
00234         $this->check_current_mark(0);
00235         $this->check_current_output(
00236                 $this->get_contains_mark_summary(0),
00237                 $this->get_contains_submit_button_expectation(true),
00238                 $this->get_contains_incorrect_expectation(),
00239                 $this->get_does_not_contain_validation_error_expectation());
00240 
00241         // Submit another non-numerical answer.
00242         $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
00243 
00244         // Verify.
00245         $this->check_current_state(question_state::$invalid);
00246         $this->check_current_mark(0);
00247         $this->check_current_output(
00248                 $this->get_contains_mark_summary(0),
00249                 $this->get_contains_submit_button_expectation(true),
00250                 $this->get_does_not_contain_correctness_expectation(),
00251                 $this->get_contains_validation_error_expectation(),
00252                 $this->get_does_not_contain_gradingdetails_expectation());
00253 
00254         // Submit the correct answer.
00255         $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
00256 
00257         // Verify.
00258         $this->check_current_state(question_state::$complete);
00259         $this->check_current_mark(1.0);
00260         $this->check_current_output(
00261                 $this->get_contains_mark_summary(1.0),
00262                 $this->get_contains_submit_button_expectation(true),
00263                 $this->get_contains_correct_expectation(),
00264                 $this->get_does_not_contain_validation_error_expectation());
00265 
00266         // Submit another non-numerical answer.
00267         $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
00268 
00269         // Verify.
00270         $this->check_current_state(question_state::$invalid);
00271         $this->check_current_mark(1.0);
00272         $this->check_current_output(
00273                 $this->get_contains_mark_summary(1.0),
00274                 $this->get_contains_submit_button_expectation(true),
00275                 $this->get_does_not_contain_correctness_expectation(),
00276                 $this->get_contains_validation_error_expectation(),
00277                 $this->get_does_not_contain_gradingdetails_expectation());
00278 
00279         // Finish the attempt.
00280         $this->quba->finish_all_questions();
00281 
00282         // Verify.
00283         $this->check_current_state(question_state::$gradedwrong);
00284         $this->check_current_mark(1.0);
00285         $this->check_current_output(
00286                 $this->get_contains_mark_summary(1.0),
00287                 $this->get_contains_submit_button_expectation(false),
00288                 $this->get_contains_incorrect_expectation(),
00289                 $this->get_does_not_contain_validation_error_expectation());
00290     }
00291 }
 All Data Structures Namespaces Files Functions Variables Enumerations