[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/quiz/accessrule/timelimit/tests/ -> rule_test.php (source)

   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   * Unit tests for the quizaccess_timelimit plugin.
  19   *
  20   * @package    quizaccess
  21   * @subpackage timelimit
  22   * @copyright  2008 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 . '/mod/quiz/accessrule/timelimit/rule.php');
  31  
  32  
  33  /**
  34   * Unit tests for the quizaccess_timelimit plugin.
  35   *
  36   * @copyright  2008 The Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class quizaccess_timelimit_testcase extends basic_testcase {
  40      public function test_time_limit_access_rule() {
  41          $quiz = new stdClass();
  42          $quiz->timelimit = 3600;
  43          $cm = new stdClass();
  44          $cm->id = 0;
  45          $quizobj = new quiz($quiz, $cm, null);
  46          $rule = new quizaccess_timelimit($quizobj, 10000);
  47          $attempt = new stdClass();
  48  
  49          $this->assertEquals($rule->description(),
  50              get_string('quiztimelimit', 'quizaccess_timelimit', format_time(3600)));
  51  
  52          $attempt->timestart = 10000;
  53          $attempt->preview = 0;
  54          $this->assertEquals($rule->end_time($attempt), 13600);
  55          $this->assertEquals($rule->time_left_display($attempt, 10000), 3600);
  56          $this->assertEquals($rule->time_left_display($attempt, 12000), 1600);
  57          $this->assertEquals($rule->time_left_display($attempt, 14000), -400);
  58  
  59          $this->assertFalse($rule->prevent_access());
  60          $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
  61          $this->assertFalse($rule->is_finished(0, $attempt));
  62      }
  63  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1