[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 18 * This file contains tests that walks a question through the interactive 19 * behaviour. 20 * 21 * @package qtype_randomsamatch 22 * @copyright 2013 Jean-Michel Vedrine 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 31 32 33 /** 34 * Unit tests for the randomsamatch question type. 35 * 36 * @copyright 2013 Jean-Michel Vedrine 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class qtype_randomsamatch_walkthrough_test extends qbehaviour_walkthrough_test_base { 40 41 public function test_deferred_feedback_unanswered() { 42 43 // Create a randomsamatch question. 44 $m = test_question_maker::make_question('randomsamatch'); 45 $this->start_attempt_at_question($m, 'deferredfeedback', 4); 46 47 $choiceorder = $m->get_choice_order(); 48 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 49 $choices = array(0 => get_string('choose') . '...'); 50 foreach ($choiceorder as $key => $choice) { 51 $choices[$key] = $m->choices[$choice]; 52 } 53 54 // Check the initial state. 55 $this->check_current_state(question_state::$todo); 56 $this->check_current_mark(null); 57 $this->check_current_output( 58 $this->get_contains_select_expectation('sub0', $choices, null, true), 59 $this->get_contains_select_expectation('sub1', $choices, null, true), 60 $this->get_contains_select_expectation('sub2', $choices, null, true), 61 $this->get_contains_select_expectation('sub3', $choices, null, true), 62 $this->get_contains_question_text_expectation($m), 63 $this->get_does_not_contain_feedback_expectation()); 64 $this->check_step_count(1); 65 66 // Save a blank response. 67 $this->process_submission(array('sub0' => '0', 'sub1' => '0', 68 'sub2' => '0', 'sub3' => '0')); 69 70 // Verify. 71 $this->check_current_state(question_state::$todo); 72 $this->check_current_mark(null); 73 $this->check_current_output( 74 $this->get_contains_select_expectation('sub0', $choices, null, true), 75 $this->get_contains_select_expectation('sub1', $choices, null, true), 76 $this->get_contains_select_expectation('sub2', $choices, null, true), 77 $this->get_contains_select_expectation('sub3', $choices, null, true), 78 $this->get_contains_question_text_expectation($m), 79 $this->get_does_not_contain_feedback_expectation()); 80 $this->check_step_count(1); 81 82 // Finish the attempt. 83 $this->quba->finish_all_questions(); 84 85 // Verify. 86 $this->check_current_state(question_state::$gaveup); 87 $this->check_current_mark(null); 88 $this->check_current_output( 89 $this->get_contains_select_expectation('sub0', $choices, null, false), 90 $this->get_contains_select_expectation('sub1', $choices, null, false), 91 $this->get_contains_select_expectation('sub2', $choices, null, false), 92 $this->get_contains_select_expectation('sub3', $choices, null, false)); 93 } 94 95 public function test_deferred_feedback_partial_answer() { 96 97 // Create a randomsamatching question. 98 $m = test_question_maker::make_question('randomsamatch'); 99 $m->shufflestems = false; 100 $this->start_attempt_at_question($m, 'deferredfeedback', 4); 101 102 $choiceorder = $m->get_choice_order(); 103 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 104 $choices = array(0 => get_string('choose') . '...'); 105 foreach ($choiceorder as $key => $choice) { 106 $choices[$key] = $m->choices[$choice]; 107 } 108 109 // Check the initial state. 110 $this->check_current_state(question_state::$todo); 111 $this->check_current_mark(null); 112 $this->check_current_output( 113 $this->get_contains_select_expectation('sub0', $choices, null, true), 114 $this->get_contains_select_expectation('sub1', $choices, null, true), 115 $this->get_contains_select_expectation('sub2', $choices, null, true), 116 $this->get_contains_select_expectation('sub3', $choices, null, true), 117 $this->get_contains_question_text_expectation($m), 118 $this->get_does_not_contain_feedback_expectation()); 119 120 // Save a partial response. 121 $this->process_submission(array('sub0' => $orderforchoice[13], 122 'sub1' => $orderforchoice[16], 'sub2' => '0', 'sub3' => '0')); 123 124 // Verify. 125 $this->check_current_state(question_state::$invalid); 126 $this->check_current_mark(null); 127 $this->check_current_output( 128 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[13], true), 129 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[16], true), 130 $this->get_contains_select_expectation('sub2', $choices, null, true), 131 $this->get_contains_select_expectation('sub3', $choices, null, true), 132 $this->get_contains_question_text_expectation($m), 133 $this->get_does_not_contain_feedback_expectation()); 134 135 // Finish the attempt. 136 $this->quba->finish_all_questions(); 137 138 // Verify. 139 $this->check_current_state(question_state::$gradedpartial); 140 $this->check_current_mark(2); 141 $this->check_current_output( 142 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[13], false), 143 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[16], false), 144 $this->get_contains_select_expectation('sub2', $choices, null, false), 145 $this->get_contains_select_expectation('sub3', $choices, null, false), 146 $this->get_contains_partcorrect_expectation()); 147 } 148 149 public function test_interactive_correct_no_submit() { 150 151 // Create a randomsamatching question. 152 $m = test_question_maker::make_question('randomsamatch'); 153 $m->hints = array( 154 new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), 155 new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), 156 ); 157 $m->shufflestems = false; 158 $this->start_attempt_at_question($m, 'interactive', 4); 159 160 $choiceorder = $m->get_choice_order(); 161 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 162 $choices = array(0 => get_string('choose') . '...'); 163 foreach ($choiceorder as $key => $choice) { 164 $choices[$key] = $m->choices[$choice]; 165 } 166 167 // Check the initial state. 168 $this->check_current_state(question_state::$todo); 169 $this->check_current_mark(null); 170 $this->check_current_output( 171 $this->get_contains_select_expectation('sub0', $choices, null, true), 172 $this->get_contains_select_expectation('sub1', $choices, null, true), 173 $this->get_contains_select_expectation('sub2', $choices, null, true), 174 $this->get_contains_select_expectation('sub3', $choices, null, true), 175 $this->get_contains_submit_button_expectation(true), 176 $this->get_does_not_contain_feedback_expectation(), 177 $this->get_tries_remaining_expectation(3), 178 $this->get_no_hint_visible_expectation()); 179 180 // Save the right answer. 181 $this->process_submission(array('sub0' => $orderforchoice[13], 182 'sub1' => $orderforchoice[16], 'sub2' => $orderforchoice[16], 183 'sub3' => $orderforchoice[13])); 184 185 // Finish the attempt without clicking check. 186 $this->quba->finish_all_questions(); 187 188 // Verify. 189 $this->check_current_state(question_state::$gradedright); 190 $this->check_current_mark(4); 191 $this->check_current_output( 192 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[13], false), 193 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[16], false), 194 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[16], false), 195 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[13], false), 196 $this->get_does_not_contain_submit_button_expectation(), 197 $this->get_contains_correct_expectation(), 198 $this->get_no_hint_visible_expectation()); 199 } 200 201 public function test_interactive_partial_no_submit() { 202 203 // Create a randomsamatching question. 204 $m = test_question_maker::make_question('randomsamatch'); 205 $m->hints = array( 206 new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), 207 new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), 208 ); 209 $m->shufflestems = false; 210 $this->start_attempt_at_question($m, 'interactive', 4); 211 212 $choiceorder = $m->get_choice_order(); 213 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 214 $choices = array(0 => get_string('choose') . '...'); 215 foreach ($choiceorder as $key => $choice) { 216 $choices[$key] = $m->choices[$choice]; 217 } 218 219 // Check the initial state. 220 $this->check_current_state(question_state::$todo); 221 $this->check_current_mark(null); 222 $this->check_current_output( 223 $this->get_contains_select_expectation('sub0', $choices, null, true), 224 $this->get_contains_select_expectation('sub1', $choices, null, true), 225 $this->get_contains_select_expectation('sub2', $choices, null, true), 226 $this->get_contains_select_expectation('sub3', $choices, null, true), 227 $this->get_contains_submit_button_expectation(true), 228 $this->get_does_not_contain_feedback_expectation(), 229 $this->get_tries_remaining_expectation(3), 230 $this->get_no_hint_visible_expectation()); 231 232 // Save the right answer. 233 $this->process_submission(array('sub0' => $orderforchoice[13], 234 'sub1' => $orderforchoice[16], 'sub2' => $orderforchoice[13], 235 'sub3' => '0')); 236 237 // Finish the attempt without clicking check. 238 $this->quba->finish_all_questions(); 239 240 // Verify. 241 $this->check_current_state(question_state::$gradedpartial); 242 $this->check_current_mark(2); 243 $this->check_current_output( 244 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[13], false), 245 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[16], false), 246 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[13], false), 247 $this->get_contains_select_expectation('sub3', $choices, null, false), 248 $this->get_does_not_contain_submit_button_expectation(), 249 $this->get_contains_partcorrect_expectation(), 250 $this->get_no_hint_visible_expectation()); 251 } 252 253 public function test_interactive_with_invalid() { 254 255 // Create a randomsamatching question. 256 $m = test_question_maker::make_question('randomsamatch'); 257 $m->hints = array( 258 new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, false), 259 new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), 260 ); 261 $m->shufflestems = false; 262 $this->start_attempt_at_question($m, 'interactive', 4); 263 264 $choiceorder = $m->get_choice_order(); 265 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 266 $choices = array(0 => get_string('choose') . '...'); 267 foreach ($choiceorder as $key => $choice) { 268 $choices[$key] = $m->choices[$choice]; 269 } 270 271 // Check the initial state. 272 $this->check_current_state(question_state::$todo); 273 $this->check_current_mark(null); 274 $this->check_current_output( 275 $this->get_contains_select_expectation('sub0', $choices, null, true), 276 $this->get_contains_select_expectation('sub1', $choices, null, true), 277 $this->get_contains_select_expectation('sub2', $choices, null, true), 278 $this->get_contains_select_expectation('sub3', $choices, null, true), 279 $this->get_contains_submit_button_expectation(true), 280 $this->get_does_not_contain_feedback_expectation(), 281 $this->get_tries_remaining_expectation(3), 282 $this->get_no_hint_visible_expectation()); 283 284 // Try to submit an invalid answer. 285 $this->process_submission(array('sub0' => '0', 286 'sub1' => '0', 'sub2' => '0', 287 'sub3' => '0', '-submit' => '1')); 288 289 // Verify. 290 $this->check_current_state(question_state::$invalid); 291 $this->check_current_mark(null); 292 $this->check_current_output( 293 $this->get_contains_select_expectation('sub0', $choices, null, true), 294 $this->get_contains_select_expectation('sub1', $choices, null, true), 295 $this->get_contains_select_expectation('sub2', $choices, null, true), 296 $this->get_contains_select_expectation('sub3', $choices, null, true), 297 $this->get_contains_submit_button_expectation(true), 298 $this->get_does_not_contain_feedback_expectation(), 299 $this->get_invalid_answer_expectation(), 300 $this->get_no_hint_visible_expectation()); 301 302 // Now submit the right answer. 303 $this->process_submission(array('sub0' => $orderforchoice[13], 304 'sub1' => $orderforchoice[16], 'sub2' => $orderforchoice[16], 305 'sub3' => $orderforchoice[13], '-submit' => '1')); 306 307 // Verify. 308 $this->check_current_state(question_state::$gradedright); 309 $this->check_current_mark(4); 310 $this->check_current_output( 311 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[13], false), 312 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[16], false), 313 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[16], false), 314 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[13], false), 315 $this->get_does_not_contain_submit_button_expectation(), 316 $this->get_contains_correct_expectation(), 317 $this->get_no_hint_visible_expectation()); 318 } 319 320 public function test_randomsamatch_clear_wrong() { 321 322 // Create a randomsamatching question. 323 $m = test_question_maker::make_question('randomsamatch'); 324 $m->hints = array( 325 new question_hint_with_parts(11, 'This is the first hint.', FORMAT_HTML, false, true), 326 new question_hint_with_parts(12, 'This is the second hint.', FORMAT_HTML, true, true), 327 ); 328 $m->shufflestems = false; 329 $this->start_attempt_at_question($m, 'interactive', 4); 330 331 $choiceorder = $m->get_choice_order(); 332 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 333 $choices = array(0 => get_string('choose') . '...'); 334 foreach ($choiceorder as $key => $choice) { 335 $choices[$key] = $m->choices[$choice]; 336 } 337 338 // Check the initial state. 339 $this->check_current_state(question_state::$todo); 340 $this->check_current_mark(null); 341 $this->check_current_output( 342 $this->get_contains_select_expectation('sub0', $choices, null, true), 343 $this->get_contains_select_expectation('sub1', $choices, null, true), 344 $this->get_contains_select_expectation('sub2', $choices, null, true), 345 $this->get_contains_select_expectation('sub3', $choices, null, true), 346 $this->get_contains_submit_button_expectation(true), 347 $this->get_does_not_contain_feedback_expectation(), 348 $this->get_tries_remaining_expectation(3), 349 $this->get_no_hint_visible_expectation()); 350 351 // Submit a completely wrong response. 352 $this->process_submission(array('sub0' => $orderforchoice[16], 353 'sub1' => $orderforchoice[13], 'sub2' => $orderforchoice[13], 354 'sub3' => $orderforchoice[16], '-submit' => 1)); 355 356 // Verify. 357 $this->check_current_state(question_state::$todo); 358 $this->check_current_mark(null); 359 $this->check_current_output( 360 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[16], false), 361 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[13], false), 362 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[13], false), 363 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[16], false), 364 $this->get_contains_hidden_expectation( 365 $this->quba->get_field_prefix($this->slot) . 'sub0', '0'), 366 $this->get_contains_hidden_expectation( 367 $this->quba->get_field_prefix($this->slot) . 'sub1', '0'), 368 $this->get_contains_hidden_expectation( 369 $this->quba->get_field_prefix($this->slot) . 'sub2', '0'), 370 $this->get_contains_hidden_expectation( 371 $this->quba->get_field_prefix($this->slot) . 'sub3', '0'), 372 $this->get_does_not_contain_submit_button_expectation(), 373 $this->get_contains_hint_expectation('This is the first hint.')); 374 375 // Try again. 376 $this->process_submission(array('sub0' => 0, 377 'sub1' => 0, 'sub2' => 0, 378 'sub3' => 0, '-tryagain' => 1)); 379 380 // Verify. 381 $this->check_current_state(question_state::$todo); 382 $this->check_current_mark(null); 383 $this->check_current_output( 384 $this->get_contains_select_expectation('sub0', $choices, null, true), 385 $this->get_contains_select_expectation('sub1', $choices, null, true), 386 $this->get_contains_select_expectation('sub2', $choices, null, true), 387 $this->get_contains_select_expectation('sub3', $choices, null, true), 388 $this->get_contains_submit_button_expectation(true), 389 $this->get_does_not_contain_feedback_expectation(), 390 $this->get_tries_remaining_expectation(2), 391 $this->get_no_hint_visible_expectation()); 392 393 // Submit a partially wrong response. 394 $this->process_submission(array('sub0' => $orderforchoice[16], 395 'sub1' => $orderforchoice[13], 'sub2' => $orderforchoice[16], 396 'sub3' => $orderforchoice[13], '-submit' => 1)); 397 398 // Verify. 399 $this->check_current_state(question_state::$todo); 400 $this->check_current_mark(null); 401 $this->check_current_output( 402 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[16], false), 403 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[13], false), 404 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[16], false), 405 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[13], false), 406 $this->get_contains_hidden_expectation( 407 $this->quba->get_field_prefix($this->slot) . 'sub0', '0'), 408 $this->get_contains_hidden_expectation( 409 $this->quba->get_field_prefix($this->slot) . 'sub1', '0'), 410 $this->get_contains_hidden_expectation( 411 $this->quba->get_field_prefix($this->slot) . 'sub2', $orderforchoice[16]), 412 $this->get_contains_hidden_expectation( 413 $this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[13]), 414 $this->get_does_not_contain_submit_button_expectation(), 415 $this->get_contains_hint_expectation('This is the second hint.')); 416 417 // Try again. 418 $this->process_submission(array('sub0' => 0, 419 'sub1' => 0, 'sub2' => $orderforchoice[16], 420 'sub3' => $orderforchoice[13], '-tryagain' => 1)); 421 422 // Verify. 423 $this->check_current_state(question_state::$todo); 424 $this->check_current_mark(null); 425 $this->check_current_output( 426 $this->get_contains_select_expectation('sub0', $choices, null, true), 427 $this->get_contains_select_expectation('sub1', $choices, null, true), 428 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[16], true), 429 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[13], true), 430 $this->get_contains_submit_button_expectation(true), 431 $this->get_does_not_contain_feedback_expectation(), 432 $this->get_tries_remaining_expectation(1), 433 $this->get_no_hint_visible_expectation()); 434 } 435 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |