MDL-29627 quiz access: move the unit tests into the relevant plugins.
This commit is contained in:
@@ -83,7 +83,7 @@ class quiz_access_manager {
|
||||
$this->quizobj, $this->timenow);
|
||||
$this->rules[] = $this->securewindowrule;
|
||||
} else if ($quiz->popup == 2) {
|
||||
$this->safebrowserrule = new quizaccess_securebrowser(
|
||||
$this->safebrowserrule = new quizaccess_safebrowser(
|
||||
$this->quizobj, $this->timenow);
|
||||
$this->rules[] = $this->safebrowserrule;
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_delaybetweenattempts plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage delaybetweenattempts
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/delaybetweenattempts/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_delaybetweenattempts plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_delaybetweenattempts_test extends UnitTestCase {
|
||||
public function test_just_first_delay() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 3;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 1000;
|
||||
$quiz->delay2 = 0;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
}
|
||||
|
||||
public function test_just_second_delay() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 0;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
|
||||
public function test_just_both_delays() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(12000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timefinish = 8000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 8001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
|
||||
public function test_with_close_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 15000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 13000;
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(15000)));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(15000)));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 15000);
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 15001);
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
}
|
||||
|
||||
public function test_time_limit_and_overdue() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 100;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timestart = 9900;
|
||||
$attempt->timefinish = 10100;
|
||||
|
||||
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(12000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timestart = 7950;
|
||||
$attempt->timefinish = 8000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 7950;
|
||||
$attempt->timefinish = 8001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
|
||||
$attempt->timestart = 8950;
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 8950;
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$attempt->timestart = 8900;
|
||||
$attempt->timefinish = 9100;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 8901;
|
||||
$attempt->timefinish = 9100;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_ipaddress plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage ipaddress
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/ipaddress/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_ipaddress plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_ipaddress_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/ipaddress/rule.php');
|
||||
|
||||
public function test_ipaddress_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$attempt = new stdClass();
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
|
||||
// Test the allowed case by getting the user's IP address. However, this
|
||||
// does not always work, for example using the mac install package on my laptop.
|
||||
$quiz->subnet = getremoteaddr(null);
|
||||
if (!empty($quiz->subnet)) {
|
||||
$quiz->questions = '';
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_ipaddress($quizobj, 0);
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
|
||||
$quiz->subnet = '0.0.0.0';
|
||||
$quiz->questions = '';
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_ipaddress($quizobj, 0);
|
||||
|
||||
$this->assertTrue($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_numattempts plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage numattempts
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/numattempts/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_numattempts plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_numattempts_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/numattempts/rule.php');
|
||||
|
||||
public function test_num_attempts_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 3;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_numattempts($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertEqual($rule->description(), get_string('attemptsallowedn', 'quiz', 3));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('nomoreattempts', 'quiz'));
|
||||
$this->assertEqual($rule->prevent_new_attempt(666, $attempt),
|
||||
get_string('nomoreattempts', 'quiz'));
|
||||
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(2, $attempt));
|
||||
$this->assertTrue($rule->is_finished(3, $attempt));
|
||||
$this->assertTrue($rule->is_finished(666, $attempt));
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_openclosedate plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage openclosedate
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/openclosedate/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_openclosedate plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_openclosedate_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/openclosedate/rule.php');
|
||||
|
||||
public function test_no_dates() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 0;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 10000));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 0);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
}
|
||||
|
||||
public function test_start_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 10000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 9999);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quiznotavailable', 'quiz', userdate(10000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 10000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
}
|
||||
|
||||
public function test_close_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 0;
|
||||
$quiz->timeclose = 20000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 20000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 20001);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizclosed', 'quiz', userdate(20000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertTrue($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
}
|
||||
|
||||
public function test_both_dates() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 10000;
|
||||
$quiz->timeclose = 20000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 9999);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quiznotavailable', 'quiz', userdate(10000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 10000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000)),
|
||||
get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 20000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000)),
|
||||
get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new quizaccess_openclosedate($quizobj, 20001);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizclosed', 'quiz', userdate(20000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertTrue($rule->is_finished(0, $attempt));
|
||||
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_password plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage password
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/password/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_password plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_password_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/password/rule.php');
|
||||
|
||||
public function test_password_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->password = 'frog';
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_password($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertEqual($rule->description(), get_string('requirepasswordmessage', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
@@ -35,9 +35,9 @@ require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php');
|
||||
* @copyright 2009 Oliver Rahs
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class safebrowser_access_rule extends quiz_access_rule_base {
|
||||
class quizaccess_safebrowser extends quiz_access_rule_base {
|
||||
public function prevent_access() {
|
||||
if (!$this->quizobj->is_preview_user() && !quiz_check_safe_browser()) {
|
||||
if (!$this->check_safe_browser()) {
|
||||
return get_string('safebrowsererror', 'quiz');
|
||||
} else {
|
||||
return false;
|
||||
@@ -47,4 +47,13 @@ class safebrowser_access_rule extends quiz_access_rule_base {
|
||||
public function description() {
|
||||
return get_string("safebrowsernotice", "quiz");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if browser is safe browser
|
||||
*
|
||||
* @return true, if browser is safe browser else false
|
||||
*/
|
||||
function check_safe_browser() {
|
||||
return strpos($_SERVER['HTTP_USER_AGENT'], "SEB") !== false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_safebrowser plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage safebrowser
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/safebrowser/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_safebrowser plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_safebrowser_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/safebrowser/rule.php');
|
||||
|
||||
// Nothing very testable in this class, just test that it obeys the general access rule contact.
|
||||
public function test_safebrowser_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->popup = 1;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_safebrowser($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
// This next test assumes the unit tests are not being run using Safe Exam Browser!
|
||||
$this->assertEqual(get_string('safebrowsererror', 'quiz'), $rule->prevent_access());
|
||||
|
||||
$this->assertEqual(get_string('safebrowsernotice', 'quiz'), $rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_securewindow plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage securewindow
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/securewindow/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_securewindow plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_securewindow_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/securewindow/rule.php');
|
||||
|
||||
// Nothing very testable in this class, just test that it obeys the general access rule contact.
|
||||
public function test_securewindow_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->popup = 1;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_securewindow($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_timelimit plugin.
|
||||
*
|
||||
* @package quizaccess
|
||||
* @subpackage timelimit
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrule/timelimit/rule.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the quizaccess_timelimit plugin.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_timelimit_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/accessrule/timelimit/rule.php');
|
||||
|
||||
public function test_time_limit_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timelimit = 3600;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new quizaccess_timelimit($quizobj, 10000);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertEqual($rule->description(),
|
||||
get_string('quiztimelimit', 'quiz', format_time(3600)));
|
||||
|
||||
$attempt->timestart = 10000;
|
||||
$this->assertEqual($rule->time_left($attempt, 10000), 3600);
|
||||
$this->assertEqual($rule->time_left($attempt, 12000), 1600);
|
||||
$this->assertEqual($rule->time_left($attempt, 14000), -400);
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
}
|
||||
}
|
||||
@@ -656,7 +656,7 @@ $string['reviewresponsetoq'] = 'Review response (question {$a})';
|
||||
$string['reviewthisattempt'] = 'Review your responses to this attempt';
|
||||
$string['rqp'] = 'Remote question';
|
||||
$string['rqps'] = 'Remote questions';
|
||||
$string['safebrowsererror'] = 'This quiz has been set up so that it may only be attempted using the Safe Exam Browser. You cannot attempt it form this web browser.';
|
||||
$string['safebrowsererror'] = 'This quiz has been set up so that it may only be attempted using the Safe Exam Browser. You cannot attempt it from this web browser.';
|
||||
$string['safebrowsernotice'] = 'This quiz has been configured so that students may only attempt it using the Safe Exam Browser.';
|
||||
$string['sameasoverall'] = 'Same as for overall grades';
|
||||
$string['save'] = 'Save';
|
||||
|
||||
+1
-10
@@ -33,7 +33,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessrules.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/accessmanager.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/renderer.php');
|
||||
require_once($CFG->dirroot . '/mod/quiz/attemptlib.php');
|
||||
require_once($CFG->dirroot . '/question/editlib.php');
|
||||
@@ -1283,15 +1283,6 @@ function quiz_attempt_submitted_handler($event) {
|
||||
get_context_instance(CONTEXT_MODULE, $cm->id), $cm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if browser is safe browser
|
||||
*
|
||||
* @return true, if browser is safe browser else false
|
||||
*/
|
||||
function quiz_check_safe_browser() {
|
||||
return strpos($_SERVER['HTTP_USER_AGENT'], "SEB") !== false;
|
||||
}
|
||||
|
||||
function quiz_get_js_module() {
|
||||
global $PAGE;
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for the access manager class.
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage quiz
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for the access manager class
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quiz_access_manager_test extends UnitTestCase {
|
||||
public function test_cannot_review_message() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->reviewattempt = 0x10010;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->attempts = 0;
|
||||
$quiz->questions = '1,2,0,3,4,0';
|
||||
|
||||
$cm = new stdClass();
|
||||
$cm->id = 123;
|
||||
|
||||
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
|
||||
|
||||
$am = new quiz_access_manager($quizobj, time(), false);
|
||||
|
||||
$this->assertEqual('',
|
||||
$am->cannot_review_message(mod_quiz_display_options::DURING));
|
||||
$this->assertEqual('',
|
||||
$am->cannot_review_message(mod_quiz_display_options::IMMEDIATELY_AFTER));
|
||||
$this->assertEqual(get_string('noreview', 'quiz'),
|
||||
$am->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
|
||||
$this->assertEqual(get_string('noreview', 'quiz'),
|
||||
$am->cannot_review_message(mod_quiz_display_options::AFTER_CLOSE));
|
||||
|
||||
$closetime = time() + 10000;
|
||||
$quiz->timeclose = $closetime;
|
||||
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
|
||||
$am = new quiz_access_manager($quizobj, time(), false);
|
||||
|
||||
$this->assertEqual(get_string('noreviewuntil', 'quiz', userdate($closetime)),
|
||||
$am->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
|
||||
}
|
||||
}
|
||||
@@ -1,614 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) mod/quiz/accessrules.php.
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage quiz
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for (some of) mod/quiz/accessrules.php.
|
||||
*
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class simple_rules_test extends UnitTestCase {
|
||||
public static $includecoverage = array('mod/quiz/locallib.php');
|
||||
public function test_num_attempts_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 3;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new num_attempts_access_rule($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertEqual($rule->description(), get_string('attemptsallowedn', 'quiz', 3));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('nomoreattempts', 'quiz'));
|
||||
$this->assertEqual($rule->prevent_new_attempt(666, $attempt),
|
||||
get_string('nomoreattempts', 'quiz'));
|
||||
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(2, $attempt));
|
||||
$this->assertTrue($rule->is_finished(3, $attempt));
|
||||
$this->assertTrue($rule->is_finished(666, $attempt));
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
|
||||
public function test_ipaddress_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$attempt = new stdClass();
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
|
||||
// Test the allowed case by getting the user's IP address. However, this
|
||||
// does not always work, for example using the mac install package on my laptop.
|
||||
$quiz->subnet = getremoteaddr(null);
|
||||
if (!empty($quiz->subnet)) {
|
||||
$quiz->questions = '';
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new ipaddress_access_rule($quizobj, 0);
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
|
||||
$quiz->subnet = '0.0.0.0';
|
||||
$quiz->questions = '';
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new ipaddress_access_rule($quizobj, 0);
|
||||
$this->assertTrue($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
|
||||
public function test_time_limit_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timelimit = 3600;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new time_limit_access_rule($quizobj, 10000);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertEqual($rule->description(),
|
||||
get_string('quiztimelimit', 'quiz', format_time(3600)));
|
||||
|
||||
$attempt->timestart = 10000;
|
||||
$this->assertEqual($rule->time_left($attempt, 10000), 3600);
|
||||
$this->assertEqual($rule->time_left($attempt, 12000), 1600);
|
||||
$this->assertEqual($rule->time_left($attempt, 14000), -400);
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class open_close_date_access_rule_test extends UnitTestCase {
|
||||
public function test_no_dates() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 0;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 10000));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 0);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
}
|
||||
|
||||
public function test_start_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 10000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 9999);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quiznotavailable', 'quiz', userdate(10000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 10000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
}
|
||||
|
||||
public function test_close_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 0;
|
||||
$quiz->timeclose = 20000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 20000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 20001);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizclosed', 'quiz', userdate(20000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertTrue($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
}
|
||||
|
||||
public function test_both_dates() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->timeopen = 10000;
|
||||
$quiz->timeclose = 20000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->preview = 0;
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 9999);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quiznotavailable', 'quiz', userdate(10000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 10000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000)),
|
||||
get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 20000);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizopenedon', 'quiz', userdate(10000)),
|
||||
get_string('quizcloseson', 'quiz', userdate(20000))));
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
|
||||
$rule = new open_close_date_access_rule($quizobj, 20001);
|
||||
$this->assertEqual($rule->description(),
|
||||
array(get_string('quizclosed', 'quiz', userdate(20000))));
|
||||
$this->assertEqual($rule->prevent_access(),
|
||||
get_string('notavailable', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertTrue($rule->is_finished(0, $attempt));
|
||||
|
||||
$this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
|
||||
$this->assertEqual($rule->time_left($attempt, 19900), 100);
|
||||
$this->assertEqual($rule->time_left($attempt, 20000), 0);
|
||||
$this->assertEqual($rule->time_left($attempt, 20100), -100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class inter_attempt_delay_access_rule_test extends UnitTestCase {
|
||||
public function test_just_first_delay() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 3;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 1000;
|
||||
$quiz->delay2 = 0;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
}
|
||||
|
||||
public function test_just_second_delay() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 0;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
|
||||
public function test_just_both_delays() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 10000;
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(12000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timefinish = 8000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 8001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
|
||||
public function test_with_close_date() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 0;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 15000;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timefinish = 13000;
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(15000)));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(15000)));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 15000);
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youcannotwait', 'quiz'));
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 15001);
|
||||
$attempt->timefinish = 13000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 13001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$attempt->timefinish = 14000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$attempt->timefinish = 14001;
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
}
|
||||
|
||||
public function test_time_limit_and_overdue() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->attempts = 5;
|
||||
$quiz->timelimit = 100;
|
||||
$quiz->delay1 = 2000;
|
||||
$quiz->delay2 = 1000;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$attempt = new stdClass();
|
||||
$attempt->timestart = 9900;
|
||||
$attempt->timefinish = 10100;
|
||||
|
||||
$rule = new inter_attempt_delay_access_rule($quizobj, 10000);
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 0));
|
||||
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(12000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(3, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$attempt->timestart = 7950;
|
||||
$attempt->timefinish = 8000;
|
||||
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 7950;
|
||||
$attempt->timefinish = 8001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
|
||||
$attempt->timestart = 8950;
|
||||
$attempt->timefinish = 9000;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 8950;
|
||||
$attempt->timefinish = 9001;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$attempt->timestart = 8900;
|
||||
$attempt->timefinish = 9100;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11000)));
|
||||
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
|
||||
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
|
||||
$attempt->timestart = 8901;
|
||||
$attempt->timefinish = 9100;
|
||||
$this->assertEqual($rule->prevent_new_attempt(1, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(11001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(2, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
$this->assertEqual($rule->prevent_new_attempt(4, $attempt),
|
||||
get_string('youmustwait', 'quiz', userdate(10001)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class password_access_rule_test extends UnitTestCase {
|
||||
public function test_password_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->password = 'frog';
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new password_access_rule($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertEqual($rule->description(), get_string('requirepasswordmessage', 'quiz'));
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class securewindow_access_rule_test extends UnitTestCase {
|
||||
// Nothing very testable in this class, just test that it obeys the general access rule contact.
|
||||
|
||||
public function test_securewindow_access_rule() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->popup = 1;
|
||||
$quiz->questions = '';
|
||||
$cm = new stdClass();
|
||||
$cm->id = 0;
|
||||
$quizobj = new quiz($quiz, $cm, null);
|
||||
$rule = new securewindow_access_rule($quizobj, 0);
|
||||
$attempt = new stdClass();
|
||||
|
||||
$this->assertFalse($rule->prevent_access());
|
||||
$this->assertFalse($rule->description());
|
||||
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
|
||||
$this->assertFalse($rule->is_finished(0, $attempt));
|
||||
$this->assertFalse($rule->time_left($attempt, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @copyright 2008 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quiz_access_manager_test extends UnitTestCase {
|
||||
public function test_cannot_review_message() {
|
||||
$quiz = new stdClass();
|
||||
$quiz->reviewattempt = 0x10010;
|
||||
$quiz->timeclose = 0;
|
||||
$quiz->attempts = 0;
|
||||
$quiz->questions = '1,2,0,3,4,0';
|
||||
|
||||
$cm = new stdClass();
|
||||
$cm->id = 123;
|
||||
|
||||
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
|
||||
|
||||
$am = new quiz_access_manager($quizobj, time(), false);
|
||||
|
||||
$this->assertEqual('',
|
||||
$am->cannot_review_message(mod_quiz_display_options::DURING));
|
||||
$this->assertEqual('',
|
||||
$am->cannot_review_message(mod_quiz_display_options::IMMEDIATELY_AFTER));
|
||||
$this->assertEqual(get_string('noreview', 'quiz'),
|
||||
$am->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
|
||||
$this->assertEqual(get_string('noreview', 'quiz'),
|
||||
$am->cannot_review_message(mod_quiz_display_options::AFTER_CLOSE));
|
||||
|
||||
$closetime = time() + 10000;
|
||||
$quiz->timeclose = $closetime;
|
||||
$quizobj = new quiz($quiz, $cm, new stdClass(), false);
|
||||
$am = new quiz_access_manager($quizobj, time(), false);
|
||||
|
||||
$this->assertEqual(get_string('noreviewuntil', 'quiz', userdate($closetime)),
|
||||
$am->cannot_review_message(mod_quiz_display_options::LATER_WHILE_OPEN));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user