Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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