[ 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 with 19 * countback behaviour. 20 * 21 * @package qbehaviour 22 * @subpackage interactivecountback 23 * @copyright 2009 The Open University 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 global $CFG; 31 require_once (__DIR__ . '/../../../engine/lib.php'); 32 require_once (__DIR__ . '/../../../engine/tests/helpers.php'); 33 34 35 /** 36 * Unit tests for the interactive with countback behaviour. 37 * 38 * @copyright 2009 The Open University 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class qbehaviour_interactivecountback_walkthrough_test extends qbehaviour_walkthrough_test_base { 42 public function test_interactive_feedback_match_reset() { 43 44 // Create a matching question. 45 $m = test_question_maker::make_a_matching_question(); 46 $m->shufflestems = false; 47 $m->hints = array( 48 new question_hint_with_parts(0, 'This is the first hint.', FORMAT_HTML, true, true), 49 new question_hint_with_parts(0, 'This is the second hint.', FORMAT_HTML, true, true), 50 ); 51 $this->start_attempt_at_question($m, 'interactive', 12); 52 53 $choiceorder = $m->get_choice_order(); 54 $orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder)); 55 $choices = array(0 => get_string('choose') . '...'); 56 foreach ($choiceorder as $key => $choice) { 57 $choices[$key] = $m->choices[$choice]; 58 } 59 60 // Check the initial state. 61 $this->check_current_state(question_state::$todo); 62 $this->check_current_mark(null); 63 $this->assertEquals('interactivecountback', 64 $this->quba->get_question_attempt($this->slot)->get_behaviour_name()); 65 $this->check_current_output( 66 $this->get_contains_select_expectation('sub0', $choices, null, true), 67 $this->get_contains_select_expectation('sub1', $choices, null, true), 68 $this->get_contains_select_expectation('sub2', $choices, null, true), 69 $this->get_contains_select_expectation('sub3', $choices, null, true), 70 $this->get_contains_question_text_expectation($m), 71 $this->get_contains_submit_button_expectation(true), 72 $this->get_does_not_contain_feedback_expectation(), 73 $this->get_tries_remaining_expectation(3), 74 $this->get_does_not_contain_num_parts_correct(), 75 $this->get_no_hint_visible_expectation()); 76 77 // Submit an answer with two right, and two wrong. 78 $this->process_submission(array('sub0' => $orderforchoice[1], 79 'sub1' => $orderforchoice[1], 'sub2' => $orderforchoice[1], 80 'sub3' => $orderforchoice[1], '-submit' => 1)); 81 82 // Verify. 83 $this->check_current_state(question_state::$todo); 84 $this->check_current_mark(null); 85 $this->check_current_output( 86 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false), 87 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[1], false), 88 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[1], false), 89 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false), 90 $this->get_does_not_contain_submit_button_expectation(), 91 $this->get_contains_try_again_button_expectation(true), 92 $this->get_does_not_contain_correctness_expectation(), 93 new question_pattern_expectation('/Tries remaining: 2/'), 94 $this->get_contains_hint_expectation('This is the first hint'), 95 $this->get_contains_num_parts_correct(2), 96 $this->get_contains_standard_partiallycorrect_combined_feedback_expectation(), 97 $this->get_contains_hidden_expectation( 98 $this->quba->get_field_prefix($this->slot) . 'sub0', $orderforchoice[1]), 99 $this->get_contains_hidden_expectation( 100 $this->quba->get_field_prefix($this->slot) . 'sub1', '0'), 101 $this->get_contains_hidden_expectation( 102 $this->quba->get_field_prefix($this->slot) . 'sub2', '0'), 103 $this->get_contains_hidden_expectation( 104 $this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1])); 105 106 // Check that extract responses will return the reset data. 107 $prefix = $this->quba->get_field_prefix($this->slot); 108 $this->assertEquals(array('sub0' => 1), 109 $this->quba->extract_responses($this->slot, array($prefix . 'sub0' => 1))); 110 111 // Do try again. 112 $this->process_submission(array('sub0' => $orderforchoice[1], 113 'sub3' => $orderforchoice[1], '-tryagain' => 1)); 114 115 // Verify. 116 $this->check_current_state(question_state::$todo); 117 $this->check_current_mark(null); 118 $this->check_current_output( 119 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], true), 120 $this->get_contains_select_expectation('sub1', $choices, null, true), 121 $this->get_contains_select_expectation('sub2', $choices, null, true), 122 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], true), 123 $this->get_contains_submit_button_expectation(true), 124 $this->get_does_not_contain_correctness_expectation(), 125 $this->get_does_not_contain_feedback_expectation(), 126 $this->get_tries_remaining_expectation(2), 127 $this->get_no_hint_visible_expectation()); 128 129 // Submit the right answer. 130 $this->process_submission(array('sub0' => $orderforchoice[1], 131 'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2], 132 'sub3' => $orderforchoice[1], '-submit' => 1)); 133 134 // Verify. 135 $this->check_current_state(question_state::$gradedright); 136 $this->check_current_mark(10); 137 $this->check_current_output( 138 $this->get_contains_select_expectation('sub0', $choices, $orderforchoice[1], false), 139 $this->get_contains_select_expectation('sub1', $choices, $orderforchoice[2], false), 140 $this->get_contains_select_expectation('sub2', $choices, $orderforchoice[2], false), 141 $this->get_contains_select_expectation('sub3', $choices, $orderforchoice[1], false), 142 $this->get_does_not_contain_submit_button_expectation(), 143 $this->get_does_not_contain_try_again_button_expectation(), 144 $this->get_contains_correct_expectation(), 145 $this->get_contains_standard_correct_combined_feedback_expectation(), 146 new question_no_pattern_expectation('/class="control\b[^"]*\bpartiallycorrect"/')); 147 } 148 }
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 |