Differences Between: [Versions 310 and 311] [Versions 39 and 311]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace qtype_calculatedmulti; 18 19 use question_hint_with_parts; 20 use question_state; 21 22 defined('MOODLE_INTERNAL') || die(); 23 24 global $CFG; 25 require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 26 27 28 /** 29 * Unit tests for the calculated multiple-choice question type. 30 * 31 * @package qtype_calculatedmulti 32 * @copyright 2011 The Open University 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class walkthrough_test extends \qbehaviour_walkthrough_test_base { 36 37 public function test_interactive_single_response() { 38 39 // Create a gapselect question. 40 $q = \test_question_maker::make_question('calculatedmulti', 'singleresponse'); 41 $q->shuffleanswers = false; 42 $q->hints = array( 43 new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false), 44 new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false), 45 ); 46 $this->start_attempt_at_question($q, 'interactive', 3, 2); 47 $values = $q->vs->get_values(); 48 $this->assertEquals($values, $q->datasetloader->load_values(2)); 49 50 // Check the initial state. 51 $this->check_current_state(question_state::$todo); 52 $this->check_current_mark(null); 53 $this->check_current_output( 54 $this->get_contains_marked_out_of_summary(), 55 $this->get_contains_submit_button_expectation(true), 56 $this->get_does_not_contain_feedback_expectation(), 57 $this->get_does_not_contain_validation_error_expectation(), 58 $this->get_does_not_contain_try_again_button_expectation(), 59 $this->get_no_hint_visible_expectation()); 60 61 // Submit a wrong answer. 62 $this->process_submission(array('-submit' => 1, 'answer' => '1')); 63 64 // Verify. 65 $this->check_current_state(question_state::$todo); 66 $this->check_current_mark(null); 67 $this->check_current_output( 68 $this->get_contains_marked_out_of_summary(), 69 $this->get_does_not_contain_submit_button_expectation(), 70 $this->get_contains_try_again_button_expectation(true), 71 $this->get_contains_hint_expectation('This is the first hint.')); 72 73 // Do try again. 74 $this->process_submission(array('-tryagain' => 1)); 75 76 // Verify. 77 $this->check_current_state(question_state::$todo); 78 $this->check_current_mark(null); 79 $this->check_current_output( 80 $this->get_contains_marked_out_of_summary(), 81 $this->get_contains_submit_button_expectation(true), 82 $this->get_does_not_contain_feedback_expectation(), 83 $this->get_does_not_contain_validation_error_expectation(), 84 $this->get_does_not_contain_try_again_button_expectation(), 85 $this->get_no_hint_visible_expectation()); 86 87 // Now get it right. 88 $this->process_submission(array('-submit' => 1, 'answer' => '0')); 89 90 // Verify. 91 $this->check_current_state(question_state::$gradedright); 92 $this->check_current_mark(2); 93 $this->check_current_output( 94 $this->get_contains_mark_summary(2), 95 $this->get_does_not_contain_submit_button_expectation(), 96 $this->get_contains_correct_expectation(), 97 $this->get_does_not_contain_validation_error_expectation(), 98 $this->get_no_hint_visible_expectation()); 99 } 100 101 public function test_interactive_multi_response() { 102 103 // Create a gapselect question. 104 $q = \test_question_maker::make_question('calculatedmulti', 'multiresponse'); 105 $q->shuffleanswers = false; 106 $q->hints = array( 107 new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false), 108 new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false), 109 ); 110 $this->start_attempt_at_question($q, 'interactive', 3, 2); 111 $values = $q->vs->get_values(); 112 $this->assertEquals($values, $q->datasetloader->load_values(2)); 113 114 // Check the initial state. 115 $this->check_current_state(question_state::$todo); 116 $this->check_current_mark(null); 117 $this->check_current_output( 118 $this->get_contains_marked_out_of_summary(), 119 $this->get_contains_submit_button_expectation(true), 120 $this->get_does_not_contain_feedback_expectation(), 121 $this->get_does_not_contain_validation_error_expectation(), 122 $this->get_does_not_contain_try_again_button_expectation(), 123 $this->get_no_hint_visible_expectation()); 124 125 // Submit all boxes ticked. 126 $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '1')); 127 128 // Verify. 129 $this->check_current_state(question_state::$todo); 130 $this->check_current_mark(null); 131 $this->check_current_output( 132 $this->get_contains_marked_out_of_summary(), 133 $this->get_does_not_contain_submit_button_expectation(), 134 $this->get_contains_try_again_button_expectation(true), 135 $this->get_contains_hint_expectation('This is the first hint.')); 136 137 // Do try again. 138 $this->process_submission(array('-tryagain' => 1)); 139 140 // Verify. 141 $this->check_current_state(question_state::$todo); 142 $this->check_current_mark(null); 143 $this->check_current_output( 144 $this->get_contains_marked_out_of_summary(), 145 $this->get_contains_submit_button_expectation(true), 146 $this->get_does_not_contain_feedback_expectation(), 147 $this->get_does_not_contain_validation_error_expectation(), 148 $this->get_does_not_contain_try_again_button_expectation(), 149 $this->get_no_hint_visible_expectation()); 150 151 // Now get it right. 152 $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '0')); 153 154 // Verify. 155 $this->check_current_state(question_state::$gradedright); 156 $this->check_current_mark(2); 157 $this->check_current_output( 158 $this->get_contains_mark_summary(2), 159 $this->get_does_not_contain_submit_button_expectation(), 160 $this->get_contains_correct_expectation(), 161 $this->get_does_not_contain_validation_error_expectation(), 162 $this->get_no_hint_visible_expectation()); 163 } 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body