|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00031 00038 class qtype_calculatedsimple_walkthrough_test extends qbehaviour_walkthrough_test_base { 00039 public function test_interactive() { 00040 00041 // Create a gapselect question. 00042 $q = test_question_maker::make_question('calculatedsimple'); 00043 $q->hints = array( 00044 new question_hint(1, 'This is the first hint.', FORMAT_HTML), 00045 new question_hint(2, 'This is the second hint.', FORMAT_HTML), 00046 ); 00047 $this->start_attempt_at_question($q, 'interactive', 3); 00048 $values = $q->vs->get_values(); 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 like 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' => $values['a'] + $values['b'])); 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 } 00104 }