Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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  use quiz;
  21  
  22  defined('MOODLE_INTERNAL') || die();
  23  
  24  global $CFG;
  25  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  26  
  27  /**
  28   * Unit tests for the quiz class
  29   *
  30   * @package    mod_quiz
  31   * @copyright  2008 The Open University
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class quizobj_test extends \basic_testcase {
  35      public function test_cannot_review_message() {
  36          $quiz = new \stdClass();
  37          $quiz->reviewattempt = 0x10010;
  38          $quiz->timeclose = 0;
  39          $quiz->attempts = 0;
  40  
  41          $cm = new \stdClass();
  42          $cm->id = 123;
  43  
  44          $quizobj = new quiz($quiz, $cm, new \stdClass(), false);
  45  
  46          $this->assertEquals('',
  47              $quizobj->cannot_review_message(mod_quiz_display_options::DURING));
  48          $this->assertEquals('',
  49              $quizobj->cannot_review_message(mod_quiz_display_options::IMMEDIATELY_AFTER));
  50          $this->assertEquals(get_string('noreview', 'quiz'),
  51              $quizobj->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
  52          $this->assertEquals(get_string('noreview', 'quiz'),
  53              $quizobj->cannot_review_message(mod_quiz_display_options::AFTER_CLOSE));
  54  
  55          $closetime = time() + 10000;
  56          $quiz->timeclose = $closetime;
  57          $quizobj = new quiz($quiz, $cm, new \stdClass(), false);
  58  
  59          $this->assertEquals(get_string('noreviewuntil', 'quiz', userdate($closetime)),
  60              $quizobj->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
  61      }
  62  }