Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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 overall tests of calculated multiple-choice questions.
  19   *
  20   * @package    qtype
  21   * @subpackage calculatedmulti
  22   * @copyright  2011 The Open University
  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 calculated multiple-choice question type.
  35   *
  36   * @copyright  2011 The Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class qtype_calculatedmulti_walkthrough_test extends qbehaviour_walkthrough_test_base {
  40  
  41      public function test_interactive_single_response() {
  42  
  43          // Create a gapselect question.
  44          $q = test_question_maker::make_question('calculatedmulti', 'singleresponse');
  45          $q->shuffleanswers = false;
  46          $q->hints = array(
  47              new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false),
  48              new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false),
  49          );
  50          $this->start_attempt_at_question($q, 'interactive', 3, 2);
  51          $values = $q->vs->get_values();
  52          $this->assertEquals($values, $q->datasetloader->load_values(2));
  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_marked_out_of_summary(),
  59                  $this->get_contains_submit_button_expectation(true),
  60                  $this->get_does_not_contain_feedback_expectation(),
  61                  $this->get_does_not_contain_validation_error_expectation(),
  62                  $this->get_does_not_contain_try_again_button_expectation(),
  63                  $this->get_no_hint_visible_expectation());
  64  
  65          // Submit a wrong answer.
  66          $this->process_submission(array('-submit' => 1, 'answer' => '1'));
  67  
  68          // Verify.
  69          $this->check_current_state(question_state::$todo);
  70          $this->check_current_mark(null);
  71          $this->check_current_output(
  72                  $this->get_contains_marked_out_of_summary(),
  73                  $this->get_does_not_contain_submit_button_expectation(),
  74                  $this->get_contains_try_again_button_expectation(true),
  75                  $this->get_contains_hint_expectation('This is the first hint.'));
  76  
  77          // Do try again.
  78          $this->process_submission(array('-tryagain' => 1));
  79  
  80          // Verify.
  81          $this->check_current_state(question_state::$todo);
  82          $this->check_current_mark(null);
  83          $this->check_current_output(
  84                  $this->get_contains_marked_out_of_summary(),
  85                  $this->get_contains_submit_button_expectation(true),
  86                  $this->get_does_not_contain_feedback_expectation(),
  87                  $this->get_does_not_contain_validation_error_expectation(),
  88                  $this->get_does_not_contain_try_again_button_expectation(),
  89                  $this->get_no_hint_visible_expectation());
  90  
  91          // Now get it right.
  92          $this->process_submission(array('-submit' => 1, 'answer' => '0'));
  93  
  94          // Verify.
  95          $this->check_current_state(question_state::$gradedright);
  96          $this->check_current_mark(2);
  97          $this->check_current_output(
  98                  $this->get_contains_mark_summary(2),
  99                  $this->get_does_not_contain_submit_button_expectation(),
 100                  $this->get_contains_correct_expectation(),
 101                  $this->get_does_not_contain_validation_error_expectation(),
 102                  $this->get_no_hint_visible_expectation());
 103      }
 104  
 105      public function test_interactive_multi_response() {
 106  
 107          // Create a gapselect question.
 108          $q = test_question_maker::make_question('calculatedmulti', 'multiresponse');
 109          $q->shuffleanswers = false;
 110          $q->hints = array(
 111                  new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false),
 112                  new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false),
 113          );
 114          $this->start_attempt_at_question($q, 'interactive', 3, 2);
 115          $values = $q->vs->get_values();
 116          $this->assertEquals($values, $q->datasetloader->load_values(2));
 117  
 118          // Check the initial state.
 119          $this->check_current_state(question_state::$todo);
 120          $this->check_current_mark(null);
 121          $this->check_current_output(
 122                  $this->get_contains_marked_out_of_summary(),
 123                  $this->get_contains_submit_button_expectation(true),
 124                  $this->get_does_not_contain_feedback_expectation(),
 125                  $this->get_does_not_contain_validation_error_expectation(),
 126                  $this->get_does_not_contain_try_again_button_expectation(),
 127                  $this->get_no_hint_visible_expectation());
 128  
 129          // Submit all boxes ticked.
 130          $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '1'));
 131  
 132          // Verify.
 133          $this->check_current_state(question_state::$todo);
 134          $this->check_current_mark(null);
 135          $this->check_current_output(
 136                  $this->get_contains_marked_out_of_summary(),
 137                  $this->get_does_not_contain_submit_button_expectation(),
 138                  $this->get_contains_try_again_button_expectation(true),
 139                  $this->get_contains_hint_expectation('This is the first hint.'));
 140  
 141          // Do try again.
 142          $this->process_submission(array('-tryagain' => 1));
 143  
 144          // Verify.
 145          $this->check_current_state(question_state::$todo);
 146          $this->check_current_mark(null);
 147          $this->check_current_output(
 148                  $this->get_contains_marked_out_of_summary(),
 149                  $this->get_contains_submit_button_expectation(true),
 150                  $this->get_does_not_contain_feedback_expectation(),
 151                  $this->get_does_not_contain_validation_error_expectation(),
 152                  $this->get_does_not_contain_try_again_button_expectation(),
 153                  $this->get_no_hint_visible_expectation());
 154  
 155          // Now get it right.
 156          $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '0'));
 157  
 158          // Verify.
 159          $this->check_current_state(question_state::$gradedright);
 160          $this->check_current_mark(2);
 161          $this->check_current_output(
 162                  $this->get_contains_mark_summary(2),
 163                  $this->get_does_not_contain_submit_button_expectation(),
 164                  $this->get_contains_correct_expectation(),
 165                  $this->get_does_not_contain_validation_error_expectation(),
 166                  $this->get_no_hint_visible_expectation());
 167      }
 168  }