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 * 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->timeclose = 0; 43 $quiz->timelimit = 3600; 44 $cm = new stdClass(); 45 $cm->id = 0; 46 $quizobj = new quiz($quiz, $cm, null); 47 $rule = new quizaccess_timelimit($quizobj, 10000); 48 $attempt = new stdClass(); 49 50 $this->assertEquals($rule->description(), 51 get_string('quiztimelimit', 'quizaccess_timelimit', format_time(3600))); 52 53 $attempt->timestart = 10000; 54 $attempt->preview = 0; 55 $this->assertEquals(13600, $rule->end_time($attempt)); 56 $this->assertEquals(3600, $rule->time_left_display($attempt, 10000)); 57 $this->assertEquals(1600, $rule->time_left_display($attempt, 12000)); 58 $this->assertEquals(-400, $rule->time_left_display($attempt, 14000)); 59 60 $this->assertFalse($rule->prevent_access()); 61 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 62 $this->assertFalse($rule->is_finished(0, $attempt)); 63 } 64 65 /** 66 * Data provider for test_time_limit_access_rule_with_time_close. 67 * 68 * @return array of ($timetoclose, $timelimit, $displaylimit, $actuallimit) 69 */ 70 public function time_limit_access_rule_with_time_close_provider() { 71 return [ 72 'Close time is earlier than time limit' => [1800, 3600, 3600, 1800], 73 'Close time is on time limit' => [3600, 3600, 3600, 3600], 74 'Close time is later than time limit' => [3600, 1800, 1800, 1800] 75 ]; 76 } 77 78 /** 79 * Test the time_left_display method of the quizaccess_timelimit class. 80 * 81 * @param int $timetoclose The number of seconds that is left to the quiz' closing time 82 * @param int $timelimit Time limit of the quiz 83 * @param int $displaylimit The limit that is displayed on the quiz page 84 * @param int $actuallimit The actual limit that is being applied 85 * @dataProvider time_limit_access_rule_with_time_close_provider 86 */ 87 public function test_time_limit_access_rule_with_time_close($timetoclose, $timelimit, $displaylimit, $actuallimit) { 88 $timenow = 10000; 89 90 $quiz = new stdClass(); 91 $quiz->timeclose = $timenow + $timetoclose; 92 $quiz->timelimit = $timelimit; 93 $cm = new stdClass(); 94 $cm->id = 0; 95 $quizobj = new quiz($quiz, $cm, null); 96 $rule = new quizaccess_timelimit($quizobj, $timenow); 97 $attempt = new stdClass(); 98 99 $this->assertEquals($rule->description(), 100 get_string('quiztimelimit', 'quizaccess_timelimit', format_time($displaylimit))); 101 102 $attempt->timestart = $timenow; 103 $attempt->preview = 0; 104 $this->assertEquals($timenow + $actuallimit, $rule->end_time($attempt)); 105 $this->assertEquals($actuallimit, $rule->time_left_display($attempt, $timenow)); 106 $this->assertEquals($actuallimit - 1000, $rule->time_left_display($attempt, $timenow + 1000)); 107 108 $this->assertFalse($rule->prevent_access()); 109 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 110 $this->assertFalse($rule->is_finished(0, $attempt)); 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body