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_delaybetweenattempts plugin. 19 * 20 * @package quizaccess 21 * @subpackage delaybetweenattempts 22 * @category phpunit 23 * @copyright 2008 The Open University 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once($CFG->dirroot . '/mod/quiz/accessrule/delaybetweenattempts/rule.php'); 31 32 33 /** 34 * Unit tests for the quizaccess_delaybetweenattempts 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_delaybetweenattempts_testcase extends basic_testcase { 40 public function test_just_first_delay() { 41 $quiz = new stdClass(); 42 $quiz->attempts = 3; 43 $quiz->timelimit = 0; 44 $quiz->delay1 = 1000; 45 $quiz->delay2 = 0; 46 $quiz->timeclose = 0; 47 $cm = new stdClass(); 48 $cm->id = 0; 49 $quizobj = new quiz($quiz, $cm, null); 50 $attempt = new stdClass(); 51 $attempt->timefinish = 10000; 52 53 $rule = new quizaccess_delaybetweenattempts($quizobj, 10000); 54 $this->assertEmpty($rule->description()); 55 $this->assertFalse($rule->prevent_access()); 56 $this->assertFalse($rule->is_finished(0, $attempt)); 57 $this->assertFalse($rule->end_time($attempt)); 58 $this->assertFalse($rule->time_left_display($attempt, 0)); 59 60 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 61 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 62 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 63 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 64 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 65 $attempt->timefinish = 9000; 66 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 67 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 68 $attempt->timefinish = 9001; 69 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 70 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 71 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 72 } 73 74 public function test_just_second_delay() { 75 $quiz = new stdClass(); 76 $quiz->attempts = 5; 77 $quiz->timelimit = 0; 78 $quiz->delay1 = 0; 79 $quiz->delay2 = 1000; 80 $quiz->timeclose = 0; 81 $cm = new stdClass(); 82 $cm->id = 0; 83 $quizobj = new quiz($quiz, $cm, null); 84 $attempt = new stdClass(); 85 $attempt->timefinish = 10000; 86 87 $rule = new quizaccess_delaybetweenattempts($quizobj, 10000); 88 $this->assertEmpty($rule->description()); 89 $this->assertFalse($rule->prevent_access()); 90 $this->assertFalse($rule->is_finished(0, $attempt)); 91 $this->assertFalse($rule->end_time($attempt)); 92 $this->assertFalse($rule->time_left_display($attempt, 0)); 93 94 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 95 $this->assertFalse($rule->prevent_new_attempt(5, $attempt)); 96 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 97 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 98 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 99 $this->assertEquals($rule->prevent_new_attempt(3, $attempt), 100 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 101 $attempt->timefinish = 9000; 102 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 103 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 104 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 105 $attempt->timefinish = 9001; 106 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 107 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 108 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 109 $this->assertEquals($rule->prevent_new_attempt(4, $attempt), 110 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 111 } 112 113 public function test_just_both_delays() { 114 $quiz = new stdClass(); 115 $quiz->attempts = 5; 116 $quiz->timelimit = 0; 117 $quiz->delay1 = 2000; 118 $quiz->delay2 = 1000; 119 $quiz->timeclose = 0; 120 $cm = new stdClass(); 121 $cm->id = 0; 122 $quizobj = new quiz($quiz, $cm, null); 123 $attempt = new stdClass(); 124 $attempt->timefinish = 10000; 125 126 $rule = new quizaccess_delaybetweenattempts($quizobj, 10000); 127 $this->assertEmpty($rule->description()); 128 $this->assertFalse($rule->prevent_access()); 129 $this->assertFalse($rule->is_finished(0, $attempt)); 130 $this->assertFalse($rule->end_time($attempt)); 131 $this->assertFalse($rule->time_left_display($attempt, 0)); 132 133 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 134 $this->assertFalse($rule->prevent_new_attempt(5, $attempt)); 135 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 136 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(12000))); 137 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 138 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 139 $this->assertEquals($rule->prevent_new_attempt(3, $attempt), 140 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 141 $attempt->timefinish = 8000; 142 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 143 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 144 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 145 $attempt->timefinish = 8001; 146 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 147 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 148 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 149 $this->assertFalse($rule->prevent_new_attempt(4, $attempt)); 150 $attempt->timefinish = 9000; 151 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 152 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 153 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 154 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 155 $attempt->timefinish = 9001; 156 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 157 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001))); 158 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 159 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 160 $this->assertEquals($rule->prevent_new_attempt(4, $attempt), 161 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 162 } 163 164 public function test_with_close_date() { 165 $quiz = new stdClass(); 166 $quiz->attempts = 5; 167 $quiz->timelimit = 0; 168 $quiz->delay1 = 2000; 169 $quiz->delay2 = 1000; 170 $quiz->timeclose = 15000; 171 $cm = new stdClass(); 172 $cm->id = 0; 173 $quizobj = new quiz($quiz, $cm, null); 174 $attempt = new stdClass(); 175 $attempt->timefinish = 13000; 176 177 $rule = new quizaccess_delaybetweenattempts($quizobj, 10000); 178 $this->assertEmpty($rule->description()); 179 $this->assertFalse($rule->prevent_access()); 180 $this->assertFalse($rule->is_finished(0, $attempt)); 181 $this->assertFalse($rule->end_time($attempt)); 182 $this->assertFalse($rule->time_left_display($attempt, 0)); 183 184 $attempt->timefinish = 13000; 185 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 186 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(15000))); 187 $attempt->timefinish = 13001; 188 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 189 get_string('youcannotwait', 'quizaccess_delaybetweenattempts')); 190 $attempt->timefinish = 14000; 191 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 192 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(15000))); 193 $attempt->timefinish = 14001; 194 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 195 get_string('youcannotwait', 'quizaccess_delaybetweenattempts')); 196 197 $rule = new quizaccess_delaybetweenattempts($quizobj, 15000); 198 $attempt->timefinish = 13000; 199 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 200 $attempt->timefinish = 13001; 201 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 202 get_string('youcannotwait', 'quizaccess_delaybetweenattempts')); 203 $attempt->timefinish = 14000; 204 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 205 $attempt->timefinish = 14001; 206 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 207 get_string('youcannotwait', 'quizaccess_delaybetweenattempts')); 208 209 $rule = new quizaccess_delaybetweenattempts($quizobj, 15001); 210 $attempt->timefinish = 13000; 211 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 212 $attempt->timefinish = 13001; 213 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 214 $attempt->timefinish = 14000; 215 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 216 $attempt->timefinish = 14001; 217 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 218 } 219 220 public function test_time_limit_and_overdue() { 221 $quiz = new stdClass(); 222 $quiz->attempts = 5; 223 $quiz->timelimit = 100; 224 $quiz->delay1 = 2000; 225 $quiz->delay2 = 1000; 226 $quiz->timeclose = 0; 227 $cm = new stdClass(); 228 $cm->id = 0; 229 $quizobj = new quiz($quiz, $cm, null); 230 $attempt = new stdClass(); 231 $attempt->timestart = 9900; 232 $attempt->timefinish = 10100; 233 234 $rule = new quizaccess_delaybetweenattempts($quizobj, 10000); 235 $this->assertEmpty($rule->description()); 236 $this->assertFalse($rule->prevent_access()); 237 $this->assertFalse($rule->is_finished(0, $attempt)); 238 $this->assertFalse($rule->end_time($attempt)); 239 $this->assertFalse($rule->time_left_display($attempt, 0)); 240 241 $this->assertFalse($rule->prevent_new_attempt(0, $attempt)); 242 $this->assertFalse($rule->prevent_new_attempt(5, $attempt)); 243 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 244 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(12000))); 245 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 246 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 247 $this->assertEquals($rule->prevent_new_attempt(3, $attempt), 248 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 249 $attempt->timestart = 7950; 250 $attempt->timefinish = 8000; 251 $this->assertFalse($rule->prevent_new_attempt(1, $attempt)); 252 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 253 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 254 $attempt->timestart = 7950; 255 $attempt->timefinish = 8001; 256 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 257 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 258 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 259 $this->assertFalse($rule->prevent_new_attempt(4, $attempt)); 260 $attempt->timestart = 8950; 261 $attempt->timefinish = 9000; 262 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 263 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 264 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 265 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 266 $attempt->timestart = 8950; 267 $attempt->timefinish = 9001; 268 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 269 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001))); 270 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 271 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 272 $this->assertEquals($rule->prevent_new_attempt(4, $attempt), 273 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 274 $attempt->timestart = 8900; 275 $attempt->timefinish = 9100; 276 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 277 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000))); 278 $this->assertFalse($rule->prevent_new_attempt(2, $attempt)); 279 $this->assertFalse($rule->prevent_new_attempt(3, $attempt)); 280 $attempt->timestart = 8901; 281 $attempt->timefinish = 9100; 282 $this->assertEquals($rule->prevent_new_attempt(1, $attempt), 283 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001))); 284 $this->assertEquals($rule->prevent_new_attempt(2, $attempt), 285 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 286 $this->assertEquals($rule->prevent_new_attempt(4, $attempt), 287 get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001))); 288 } 289 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body