Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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 mod_quiz;
  18  
  19  use mod_quiz_display_options;
  20  
  21  defined('MOODLE_INTERNAL') || die();
  22  
  23  global $CFG;
  24  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  25  
  26  /**
  27   * Unit tests for {@link mod_quiz_display_options}.
  28   *
  29   * @package    mod_quiz
  30   * @category   test
  31   * @copyright  2010 The Open University
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class quizdisplayoptions_test extends \basic_testcase {
  35      public function test_num_attempts_access_rule() {
  36          $quiz = new \stdClass();
  37          $quiz->decimalpoints = 2;
  38          $quiz->questiondecimalpoints = -1;
  39          $quiz->reviewattempt          = 0x11110;
  40          $quiz->reviewcorrectness      = 0x10000;
  41          $quiz->reviewmarks            = 0x01110;
  42          $quiz->reviewspecificfeedback = 0x10000;
  43          $quiz->reviewgeneralfeedback  = 0x01000;
  44          $quiz->reviewrightanswer      = 0x00100;
  45          $quiz->reviewoverallfeedback  = 0x00010;
  46  
  47          $options = mod_quiz_display_options::make_from_quiz($quiz,
  48              mod_quiz_display_options::DURING);
  49  
  50          $this->assertEquals(true, $options->attempt);
  51          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->correctness);
  52          $this->assertEquals(mod_quiz_display_options::MAX_ONLY, $options->marks);
  53          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->feedback);
  54          // The next two should be controlled by the same settings as ->feedback.
  55          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->numpartscorrect);
  56          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->manualcomment);
  57          $this->assertEquals(2, $options->markdp);
  58  
  59          $quiz->questiondecimalpoints = 5;
  60          $options = mod_quiz_display_options::make_from_quiz($quiz,
  61              mod_quiz_display_options::IMMEDIATELY_AFTER);
  62  
  63          $this->assertEquals(mod_quiz_display_options::MARK_AND_MAX, $options->marks);
  64          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->generalfeedback);
  65          $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->feedback);
  66          // The next two should be controlled by the same settings as ->feedback.
  67          $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->numpartscorrect);
  68          $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->manualcomment);
  69          $this->assertEquals(5, $options->markdp);
  70  
  71          $options = mod_quiz_display_options::make_from_quiz($quiz,
  72              mod_quiz_display_options::LATER_WHILE_OPEN);
  73  
  74          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->rightanswer);
  75          $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->generalfeedback);
  76  
  77          $options = mod_quiz_display_options::make_from_quiz($quiz,
  78              mod_quiz_display_options::AFTER_CLOSE);
  79  
  80          $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->overallfeedback);
  81          $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->rightanswer);
  82      }
  83  }