Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/numerical/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 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
00030 require_once($CFG->dirroot . '/question/type/numerical/simpletest/helper.php');
00031 
00032 
00039 class qtype_numerical_walkthrough_test extends qbehaviour_walkthrough_test_base {
00040     public function test_interactive_currency() {
00041 
00042         // Create a gapselect question.
00043         $q = test_question_maker::make_question('numerical', 'currency');
00044         $q->hints = array(
00045             new question_hint(1, 'This is the first hint.', FORMAT_HTML),
00046             new question_hint(2, 'This is the second hint.', FORMAT_HTML),
00047         );
00048         $this->start_attempt_at_question($q, 'interactive', 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_marked_out_of_summary(),
00055                 $this->get_contains_submit_button_expectation(true),
00056                 $this->get_does_not_contain_feedback_expectation(),
00057                 $this->get_does_not_contain_validation_error_expectation(),
00058                 $this->get_does_not_contain_try_again_button_expectation(),
00059                 $this->get_no_hint_visible_expectation());
00060 
00061         // Submit blank.
00062         $this->process_submission(array('-submit' => 1, 'answer' => ''));
00063 
00064         // Verify.
00065         $this->check_current_state(question_state::$invalid);
00066         $this->check_current_mark(null);
00067         $this->check_current_output(
00068                 $this->get_contains_marked_out_of_summary(),
00069                 $this->get_contains_submit_button_expectation(true),
00070                 $this->get_does_not_contain_feedback_expectation(),
00071                 $this->get_contains_validation_error_expectation(),
00072                 $this->get_does_not_contain_try_again_button_expectation(),
00073                 $this->get_no_hint_visible_expectation());
00074 
00075         // Sumit something that does not look liek a number.
00076         $this->process_submission(array('-submit' => 1, 'answer' => 'newt'));
00077 
00078         // Verify.
00079         $this->check_current_state(question_state::$invalid);
00080         $this->check_current_mark(null);
00081         $this->check_current_output(
00082                 $this->get_contains_marked_out_of_summary(),
00083                 $this->get_contains_submit_button_expectation(true),
00084                 $this->get_does_not_contain_feedback_expectation(),
00085                 $this->get_contains_validation_error_expectation(),
00086                 new PatternExpectation('/' .
00087                         preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
00088                 $this->get_does_not_contain_try_again_button_expectation(),
00089                 $this->get_no_hint_visible_expectation());
00090 
00091         // Now get it right.
00092         $this->process_submission(array('-submit' => 1, 'answer' => '$1332'));
00093 
00094         // Verify.
00095         $this->check_current_state(question_state::$gradedright);
00096         $this->check_current_mark(3);
00097         $this->check_current_output(
00098                 $this->get_contains_mark_summary(3),
00099                 $this->get_contains_submit_button_expectation(false),
00100                 $this->get_contains_correct_expectation(),
00101                 $this->get_does_not_contain_validation_error_expectation(),
00102                 $this->get_no_hint_visible_expectation());
00103         $this->assertEqual('$1332',
00104                 $this->quba->get_response_summary($this->slot));
00105     }
00106 
00107     public function test_deferredfeedback_currency() {
00108 
00109         // Create a gapselect question.
00110         $q = test_question_maker::make_question('numerical', 'currency');
00111         $this->start_attempt_at_question($q, 'deferredfeedback', 3);
00112 
00113         // Check the initial state.
00114         $this->check_current_state(question_state::$todo);
00115         $this->check_current_mark(null);
00116         $this->check_current_output(
00117                 $this->get_contains_marked_out_of_summary(),
00118                 $this->get_does_not_contain_feedback_expectation(),
00119                 $this->get_does_not_contain_validation_error_expectation(),
00120                 $this->get_does_not_contain_try_again_button_expectation(),
00121                 $this->get_no_hint_visible_expectation());
00122 
00123         // Submit blank.
00124         $this->process_submission(array('answer' => ''));
00125 
00126         // Verify.
00127         $this->check_current_state(question_state::$todo);
00128         $this->check_current_mark(null);
00129         $this->check_current_output(
00130                 $this->get_contains_marked_out_of_summary(),
00131                 $this->get_does_not_contain_feedback_expectation(),
00132                 $this->get_does_not_contain_validation_error_expectation(),
00133                 $this->get_does_not_contain_try_again_button_expectation(),
00134                 $this->get_no_hint_visible_expectation());
00135 
00136         // Sumit something that does not look like a number.
00137         $this->process_submission(array('answer' => '$newt'));
00138 
00139         // Verify.
00140         $this->check_current_state(question_state::$invalid);
00141         $this->check_current_mark(null);
00142         $this->check_current_output(
00143                 $this->get_contains_marked_out_of_summary(),
00144                 $this->get_does_not_contain_feedback_expectation(),
00145                 $this->get_contains_validation_error_expectation(),
00146                 new PatternExpectation('/' .
00147                         preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
00148                 $this->get_does_not_contain_try_again_button_expectation(),
00149                 $this->get_no_hint_visible_expectation());
00150 
00151         // Now put in the right answer but without a unit.
00152         $this->process_submission(array('answer' => '1332'));
00153 
00154         $this->check_current_state(question_state::$complete);
00155         $this->check_current_mark(null);
00156         $this->check_current_output(
00157                 $this->get_contains_marked_out_of_summary(),
00158                 $this->get_does_not_contain_feedback_expectation(),
00159                 $this->get_does_not_contain_validation_error_expectation(),
00160                 $this->get_does_not_contain_try_again_button_expectation(),
00161                 $this->get_no_hint_visible_expectation());
00162 
00163         // Submit all and finish.
00164         $this->process_submission(array('-finish' => '1'));
00165 
00166         // Verify.
00167         $this->check_current_state(question_state::$gradedpartial);
00168         $this->check_current_mark(2.4);
00169         $this->check_current_output(
00170                 $this->get_contains_mark_summary(2.4),
00171                 $this->get_contains_partcorrect_expectation(),
00172                 $this->get_does_not_contain_validation_error_expectation(),
00173                 $this->get_no_hint_visible_expectation());
00174         $this->assertEqual('1332',
00175                 $this->quba->get_response_summary($this->slot));
00176     }
00177 
00178     // Todo. Test validation if you try to type a unit into a question that does
00179     // not expect one.
00180 
00181     public function test_deferredfeedback_unit() {
00182 
00183         // Create a gapselect question.
00184         $q = test_question_maker::make_question('numerical', 'unit');
00185         $this->start_attempt_at_question($q, 'deferredfeedback', 1);
00186 
00187         $unitchoices = array(
00188             '' => get_string('choosedots'),
00189             'm' => 'm',
00190             'cm' => 'cm',
00191         );
00192 
00193         // Check the initial state.
00194         $this->check_current_state(question_state::$todo);
00195         $this->check_current_mark(null);
00196         $this->check_current_output(
00197                 $this->get_contains_marked_out_of_summary(),
00198                 $this->get_does_not_contain_feedback_expectation(),
00199                 $this->get_does_not_contain_validation_error_expectation(),
00200                 $this->get_contains_select_expectation('unit', $unitchoices, null, true),
00201                 $this->get_does_not_contain_try_again_button_expectation(),
00202                 $this->get_no_hint_visible_expectation());
00203 
00204         // Submit blank.
00205         $this->process_submission(array('answer' => ''));
00206 
00207         // Verify.
00208         $this->check_current_state(question_state::$todo);
00209         $this->check_current_mark(null);
00210         $this->check_current_output(
00211                 $this->get_contains_marked_out_of_summary(),
00212                 $this->get_does_not_contain_feedback_expectation(),
00213                 $this->get_does_not_contain_validation_error_expectation(),
00214                 $this->get_contains_select_expectation('unit', $unitchoices, null, true),
00215                 $this->get_does_not_contain_try_again_button_expectation(),
00216                 $this->get_no_hint_visible_expectation());
00217 
00218         // Sumit something that does not look like a number, but with a unit.
00219         $this->process_submission(array('answer' => 'newt', 'unit' => 'cm'));
00220 
00221         // Verify.
00222         $this->check_current_state(question_state::$invalid);
00223         $this->check_current_mark(null);
00224         $this->check_current_output(
00225                 $this->get_contains_marked_out_of_summary(),
00226                 $this->get_does_not_contain_feedback_expectation(),
00227                 $this->get_contains_validation_error_expectation(),
00228                 new PatternExpectation('/' .
00229                         preg_quote(get_string('invalidnumber', 'qtype_numerical') . '/')),
00230                 $this->get_contains_select_expectation('unit', $unitchoices, 'cm', true),
00231                 $this->get_does_not_contain_try_again_button_expectation(),
00232                 $this->get_no_hint_visible_expectation());
00233 
00234         // Now put in the right answer but without a unit.
00235         $this->process_submission(array('answer' => '1.25', 'unit' => ''));
00236 
00237         $this->check_current_state(question_state::$invalid);
00238         $this->check_current_mark(null);
00239         $this->check_current_output(
00240                 $this->get_contains_marked_out_of_summary(),
00241                 $this->get_does_not_contain_feedback_expectation(),
00242                 $this->get_contains_validation_error_expectation(),
00243                 new PatternExpectation('/' .
00244                         preg_quote(get_string('unitnotselected', 'qtype_numerical') . '/')),
00245                 $this->get_contains_select_expectation('unit', $unitchoices, '', true),
00246                 $this->get_does_not_contain_try_again_button_expectation(),
00247                 $this->get_no_hint_visible_expectation());
00248 
00249         // Now put in the right answer with a unit.
00250         $this->process_submission(array('answer' => '1.25', 'unit' => 'm'));
00251 
00252         $this->check_current_state(question_state::$complete);
00253         $this->check_current_mark(null);
00254         $this->check_current_output(
00255                 $this->get_contains_marked_out_of_summary(),
00256                 $this->get_does_not_contain_feedback_expectation(),
00257                 $this->get_does_not_contain_validation_error_expectation(),
00258                 $this->get_contains_select_expectation('unit', $unitchoices, 'm', true),
00259                 $this->get_does_not_contain_try_again_button_expectation(),
00260                 $this->get_no_hint_visible_expectation());
00261 
00262         // Submit all and finish.
00263         $this->process_submission(array('-finish' => '1'));
00264 
00265         // Verify.
00266         $this->check_current_state(question_state::$gradedright);
00267         $this->check_current_mark(1);
00268         $this->check_current_output(
00269                 $this->get_contains_mark_summary(1),
00270                 $this->get_contains_correct_expectation(),
00271                 $this->get_does_not_contain_validation_error_expectation(),
00272                 $this->get_contains_select_expectation('unit', $unitchoices, 'm', false),
00273                 $this->get_no_hint_visible_expectation());
00274         $this->assertEqual('1.25 m',
00275                 $this->quba->get_response_summary($this->slot));
00276     }
00277 }
 All Data Structures Namespaces Files Functions Variables Enumerations