Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/interactivecountback/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_interactivecountback_walkthrough_test extends qbehaviour_walkthrough_test_base {
00041     public function test_interactive_feedback_match_reset() {
00042 
00043         // Create a matching question.
00044         $m = test_question_maker::make_a_matching_question();
00045         $m->shufflestems = false;
00046         $m->hints = array(
00047             new question_hint_with_parts(0, 'This is the first hint.', FORMAT_HTML, true, true),
00048             new question_hint_with_parts(0, 'This is the second hint.', FORMAT_HTML, true, true),
00049         );
00050         $this->start_attempt_at_question($m, 'interactive', 12);
00051 
00052         $choiceorder = $m->get_choice_order();
00053         $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder));
00054         $choices = array(0 => get_string('choose') . '...');
00055         foreach ($choiceorder as $key => $choice) {
00056             $choices[$key] = $m->choices[$choice];
00057         }
00058 
00059         // Check the initial state.
00060         $this->check_current_state(question_state::$todo);
00061         $this->check_current_mark(null);
00062         $this->assertEqual('interactivecountback',
00063                 $this->quba->get_question_attempt($this->slot)->get_behaviour_name());
00064         $this->check_current_output(
00065                 $this->get_contains_select_expectation('sub0', $choices, null, true),
00066                 $this->get_contains_select_expectation('sub1', $choices, null, true),
00067                 $this->get_contains_select_expectation('sub2', $choices, null, true),
00068                 $this->get_contains_select_expectation('sub3', $choices, null, true),
00069                 $this->get_contains_question_text_expectation($m),
00070                 $this->get_contains_submit_button_expectation(true),
00071                 $this->get_does_not_contain_feedback_expectation(),
00072                 $this->get_tries_remaining_expectation(3),
00073                 $this->get_does_not_contain_num_parts_correct(),
00074                 $this->get_no_hint_visible_expectation());
00075 
00076         // Submit an answer with two right, and two wrong.
00077         $this->process_submission(array('sub0' => $orderforchoice[1],
00078                 'sub1' => $orderforchoice[1], 'sub2' => $orderforchoice[1],
00079                 'sub3' => $orderforchoice[1], '-submit' => 1));
00080 
00081         // Verify.
00082         $this->check_current_state(question_state::$todo);
00083         $this->check_current_mark(null);
00084         $this->check_current_output(
00085                 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
00086                 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[1], false),
00087                 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[1], false),
00088                 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false),
00089                 $this->get_contains_submit_button_expectation(false),
00090                 $this->get_contains_try_again_button_expectation(true),
00091                 $this->get_does_not_contain_correctness_expectation(),
00092                 new PatternExpectation('/' .
00093                         preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
00094                 $this->get_contains_hint_expectation('This is the first hint'),
00095                 $this->get_contains_num_parts_correct(2),
00096                 $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
00097                 $this->get_contains_hidden_expectation(
00098                         $this->quba->get_field_prefix($this->slot) . 'sub0', $orderforchoice[1]),
00099                 $this->get_contains_hidden_expectation(
00100                         $this->quba->get_field_prefix($this->slot) . 'sub1', '0'),
00101                 $this->get_contains_hidden_expectation(
00102                         $this->quba->get_field_prefix($this->slot) . 'sub2', '0'),
00103                 $this->get_contains_hidden_expectation(
00104                         $this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1]));
00105 
00106         // Check that extract responses will return the reset data.
00107         $prefix = $this->quba->get_field_prefix($this->slot);
00108         $this->assertEqual(array('sub0' => 1),
00109                 $this->quba->extract_responses($this->slot, array($prefix . 'sub0' => 1)));
00110 
00111         // Do try again.
00112         $this->process_submission(array('sub0' => $orderforchoice[1],
00113                 'sub3' => $orderforchoice[1], '-tryagain' => 1));
00114 
00115         // Verify.
00116         $this->check_current_state(question_state::$todo);
00117         $this->check_current_mark(null);
00118         $this->check_current_output(
00119                 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], true),
00120                 $this->get_contains_select_expectation('sub1', $choices, null, true),
00121                 $this->get_contains_select_expectation('sub2', $choices, null, true),
00122                 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], true),
00123                 $this->get_contains_submit_button_expectation(true),
00124                 $this->get_does_not_contain_correctness_expectation(),
00125                 $this->get_does_not_contain_feedback_expectation(),
00126                 $this->get_tries_remaining_expectation(2),
00127                 $this->get_no_hint_visible_expectation());
00128 
00129         // Submit the right answer.
00130         $this->process_submission(array('sub0' => $orderforchoice[1],
00131                 'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2],
00132                 'sub3' => $orderforchoice[1], '-submit' => 1));
00133 
00134         // Verify.
00135         $this->check_current_state(question_state::$gradedright);
00136         $this->check_current_mark(10);
00137         $this->check_current_output(
00138                 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false),
00139                 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false),
00140                 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false),
00141                 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false),
00142                 $this->get_contains_submit_button_expectation(false),
00143                 $this->get_does_not_contain_try_again_button_expectation(),
00144                 $this->get_contains_correct_expectation(),
00145                 $this->get_contains_standard_correct_combined_feedback_expectation(),
00146                 new NoPatternExpectation('/class="control\b[^"]*\bpartiallycorrect"/'));
00147     }
00148 }
 All Data Structures Namespaces Files Functions Variables Enumerations