MDL-76614 quizaccess_seb: rename access_manager & quiz_settings classes

This is to avoid confusion between the main mod_quiz classes and SEB's own.
This commit is contained in:
Tim Hunt 2022-12-20 12:22:04 +00:00
parent 58e4bc9a3e
commit ca7fb1eb02
24 changed files with 202 additions and 166 deletions

View File

@ -58,7 +58,7 @@ class backup_quizaccess_seb_subplugin extends backup_mod_quiz_access_subplugin {
$subplugintemplatesettings = new backup_nested_element('quizaccess_seb_template', null, $templatekeys);
// Get quiz settings keys to save.
$settings = new \quizaccess_seb\quiz_settings();
$settings = new \quizaccess_seb\seb_quiz_settings();
$blanksettingsarray = (array) $settings->to_record();
unset($blanksettingsarray['id']); // We don't need to save reference to settings record in current instance.
// We don't need to save the data about who last modified the settings as they will be overwritten on restore. Also
@ -77,7 +77,7 @@ class backup_quizaccess_seb_subplugin extends backup_mod_quiz_access_subplugin {
$subpluginquizsettings->add_child($subplugintemplatesettings);
// Set source to populate the settings data by referencing the ID of quiz being backed up.
$subpluginquizsettings->set_source_table(quizaccess_seb\quiz_settings::TABLE, ['quizid' => $quizid]);
$subpluginquizsettings->set_source_table(quizaccess_seb\seb_quiz_settings::TABLE, ['quizid' => $quizid]);
$subpluginquizsettings->annotate_files('quizaccess_seb', 'filemanager_sebconfigfile', null);
@ -86,4 +86,4 @@ class backup_quizaccess_seb_subplugin extends backup_mod_quiz_access_subplugin {
return $subplugin;
}
}
}

View File

@ -24,7 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use quizaccess_seb\quiz_settings;
use quizaccess_seb\seb_quiz_settings;
defined('MOODLE_INTERNAL') || die();
@ -73,7 +73,7 @@ class restore_quizaccess_seb_subplugin extends restore_mod_quiz_access_subplugin
unset($data->id);
$data->timecreated = $data->timemodified = time();
$data->usermodified = $USER->id;
$DB->insert_record(quizaccess_seb\quiz_settings::TABLE, $data);
$DB->insert_record(quizaccess_seb\seb_quiz_settings::TABLE, $data);
// Process attached files.
$this->add_related_files('quizaccess_seb', 'filemanager_sebconfigfile', null);
@ -112,7 +112,7 @@ class restore_quizaccess_seb_subplugin extends restore_mod_quiz_access_subplugin
}
// Update the restored quiz settings to use restored template.
$DB->set_field(\quizaccess_seb\quiz_settings::TABLE, 'templateid', $template->get('id'), ['quizid' => $quizid]);
$DB->set_field(\quizaccess_seb\seb_quiz_settings::TABLE, 'templateid', $template->get('id'), ['quizid' => $quizid]);
}
}

View File

@ -26,7 +26,7 @@
namespace quizaccess_seb\event;
use core\event\base;
use quizaccess_seb\access_manager;
use quizaccess_seb\seb_access_manager;
defined('MOODLE_INTERNAL') || die();
@ -44,13 +44,13 @@ class access_prevented extends base {
* Define strict parameters to create event with instead of relying on internal validation of array. Better code practice.
* Easier for consumers of this class to know what data must be supplied and observers can have more trust in event data.
*
* @param access_manager $accessmanager Access manager.
* @param seb_access_manager $accessmanager Access manager.
* @param string $reason Reason that access was prevented.
* @param string|null $configkey A Safe Exam Browser config key.
* @param string|null $browserexamkey A Safe Exam Browser browser exam key.
* @return base
*/
public static function create_strict(access_manager $accessmanager, string $reason,
public static function create_strict(seb_access_manager $accessmanager, string $reason,
?string $configkey = null, ?string $browserexamkey = null) : base {
global $USER;

View File

@ -27,7 +27,7 @@ use external_value;
use invalid_parameter_exception;
use mod_quiz\quiz_settings;
use quizaccess_seb\event\access_prevented;
use quizaccess_seb\access_manager;
use quizaccess_seb\seb_access_manager;
require_once($CFG->libdir . '/externallib.php');
@ -95,7 +95,7 @@ class validate_quiz_keys extends external_api {
$result = ['configkey' => true, 'browserexamkey' => true];
$accessmanager = new access_manager(quiz_settings::create($quizid));
$accessmanager = new seb_access_manager(quiz_settings::create($quizid));
// Check if there is a valid config key.
if (!$accessmanager->validate_config_key($configkey, $url)) {

View File

@ -121,7 +121,7 @@ class helper {
require_login($cm->course, false, $cm);
// Retrieve the config for quiz.
$config = quiz_settings::get_config_by_quiz_id($cm->instance);
$config = seb_quiz_settings::get_config_by_quiz_id($cm->instance);
if (empty($config)) {
throw new \moodle_exception('noconfigfound', 'quizaccess_seb', '', $cm->id);
}

View File

@ -33,7 +33,7 @@ use core_privacy\local\request\contextlist;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use core_privacy\local\request\writer;
use quizaccess_seb\quiz_settings;
use quizaccess_seb\seb_quiz_settings;
use quizaccess_seb\template;
defined('MOODLE_INTERNAL') || die();
@ -162,7 +162,7 @@ class provider implements
$index++;
$subcontext = [
get_string('pluginname', 'quizaccess_seb'),
quiz_settings::TABLE,
seb_quiz_settings::TABLE,
$index
];

View File

@ -39,7 +39,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class access_manager {
class seb_access_manager {
/** Header sent by Safe Exam Browser containing the Config Key hash. */
private const CONFIG_KEY_HEADER = 'HTTP_X_SAFEEXAMBROWSER_CONFIGKEYHASH';
@ -50,7 +50,7 @@ class access_manager {
/** @var quiz_settings $quiz A quiz object containing all information pertaining to current quiz. */
private $quiz;
/** @var quiz_settings $quizsettings A quiz settings persistent object containing plugin settings */
/** @var seb_quiz_settings $quizsettings A quiz settings persistent object containing plugin settings */
private $quizsettings;
/** @var context_module $context Context of this quiz activity. */
@ -67,8 +67,8 @@ class access_manager {
public function __construct(quiz_settings $quiz) {
$this->quiz = $quiz;
$this->context = context_module::instance($quiz->get_cmid());
$this->quizsettings = quiz_settings::get_by_quiz_id($quiz->get_quizid());
$this->validconfigkey = quiz_settings::get_config_key_by_quiz_id($quiz->get_quizid());
$this->quizsettings = seb_quiz_settings::get_by_quiz_id($quiz->get_quizid());
$this->validconfigkey = seb_quiz_settings::get_config_key_by_quiz_id($quiz->get_quizid());
}
/**

View File

@ -43,7 +43,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_settings extends persistent {
class seb_quiz_settings extends persistent {
/** Table name for the persistent. */
const TABLE = 'quizaccess_seb_quizsettings';
@ -193,7 +193,7 @@ class quiz_settings extends persistent {
* This method gets data from cache before doing any DB calls.
*
* @param int $quizid Quiz id.
* @return false|\quizaccess_seb\quiz_settings
* @return false|\quizaccess_seb\seb_quiz_settings
*/
public static function get_by_quiz_id(int $quizid) {
if ($data = self::get_quiz_settings_cache()->get($quizid)) {
@ -567,7 +567,7 @@ class quiz_settings extends persistent {
}
/**
* Sets the quitURL if found in the mod_quiz\quiz_settings.
* Sets the quitURL if found in the seb_quiz_settings.
*/
private function process_quit_url_from_settings() {
$settings = $this->to_record();

View File

@ -395,7 +395,7 @@ class settings_provider {
self::freeze_element($quizform, $mform, 'seb_showsebdownloadlink');
self::freeze_element($quizform, $mform, 'seb_allowedbrowserexamkeys');
$quizsettings = quiz_settings::get_by_quiz_id((int) $quizform->get_instance());
$quizsettings = seb_quiz_settings::get_by_quiz_id((int) $quizform->get_instance());
// If the file has been uploaded, then replace it with the link to download the file.
if (!empty($quizsettings) && $quizsettings->get('requiresafeexambrowser') == self::USE_SEB_UPLOAD_CONFIG) {
@ -528,7 +528,7 @@ class settings_provider {
return false;
}
$settings = quiz_settings::get_record(['cmid' => (int) $context->instanceid]);
$settings = seb_quiz_settings::get_record(['cmid' => (int) $context->instanceid]);
if (empty($settings)) {
return false;

View File

@ -125,7 +125,7 @@ class template extends persistent {
$result = true;
if ($this->get('id')) {
$settings = quiz_settings::get_records(['templateid' => $this->get('id')]);
$settings = seb_quiz_settings::get_records(['templateid' => $this->get('id')]);
$result = empty($settings);
}

View File

@ -0,0 +1,31 @@
<?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/>.
/**
* This file contains mappings for classes that have been renamed.
*
* @package quizaccess_seb
* @copyright 2022 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$renamedclasses = [
// Since Moodle 4.2.
'quizaccess_seb\quiz_settings' => 'quizaccess_seb\seb_quiz_settings',
'quizaccess_seb\access_manager' => 'quizaccess_seb\seb_access_manager',
];

View File

@ -16,8 +16,8 @@
use mod_quiz\local\access_rule_base;
use mod_quiz\quiz_attempt;
use quizaccess_seb\access_manager;
use quizaccess_seb\quiz_settings;
use quizaccess_seb\seb_access_manager;
use quizaccess_seb\seb_quiz_settings;
use quizaccess_seb\settings_provider;
use quizaccess_seb\event\access_prevented;
@ -32,7 +32,7 @@ use quizaccess_seb\event\access_prevented;
*/
class quizaccess_seb extends access_rule_base {
/** @var access_manager $accessmanager Instance to manage the access to the quiz for this plugin. */
/** @var seb_access_manager $accessmanager Instance to manage the access to the quiz for this plugin. */
private $accessmanager;
/**
@ -40,9 +40,9 @@ class quizaccess_seb extends access_rule_base {
*
* @param \mod_quiz\quiz_settings $quizobj information about the quiz in question.
* @param int $timenow the time that should be considered as 'now'.
* @param access_manager $accessmanager the quiz accessmanager.
* @param seb_access_manager $accessmanager the quiz accessmanager.
*/
public function __construct(\mod_quiz\quiz_settings $quizobj, int $timenow, access_manager $accessmanager) {
public function __construct(\mod_quiz\quiz_settings $quizobj, int $timenow, seb_access_manager $accessmanager) {
parent::__construct($quizobj, $timenow);
$this->accessmanager = $accessmanager;
}
@ -58,7 +58,7 @@ class quizaccess_seb extends access_rule_base {
* @return access_rule_base|null the rule, if applicable, else null.
*/
public static function make(\mod_quiz\quiz_settings $quizobj, $timenow, $canignoretimelimits) {
$accessmanager = new access_manager($quizobj);
$accessmanager = new seb_access_manager($quizobj);
// If Safe Exam Browser is not required, this access rule is not applicable.
if (!$accessmanager->seb_required()) {
return null;
@ -110,7 +110,7 @@ class quizaccess_seb extends access_rule_base {
$settings = settings_provider::filter_plugin_settings((object) $data);
// Validate basic settings using persistent class.
$quizsettings = (new quiz_settings())->from_record($settings);
$quizsettings = (new seb_quiz_settings())->from_record($settings);
// Set non-form fields.
$quizsettings->set('quizid', $quizid);
$quizsettings->set('cmid', $cmid);
@ -176,9 +176,9 @@ class quizaccess_seb extends access_rule_base {
$settings->cmid = $cm->id;
// Get existing settings or create new settings if none exist.
$quizsettings = quiz_settings::get_by_quiz_id($quiz->id);
$quizsettings = seb_quiz_settings::get_by_quiz_id($quiz->id);
if (empty($quizsettings)) {
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
} else {
$settings->id = $quizsettings->get('id');
$quizsettings->from_record($settings);
@ -208,7 +208,7 @@ class quizaccess_seb extends access_rule_base {
* which is the id of the quiz being deleted.
*/
public static function delete_settings($quiz) {
$quizsettings = quiz_settings::get_by_quiz_id($quiz->id);
$quizsettings = seb_quiz_settings::get_by_quiz_id($quiz->id);
// Check that there are existing settings.
if ($quizsettings !== false) {
$quizsettings->delete();

View File

@ -27,7 +27,7 @@ require_once(__DIR__ . '/test_helper_trait.php');
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \quizaccess_seb\access_manager
* @covers \quizaccess_seb\seb_access_manager
*/
class access_manager_test extends \advanced_testcase {
use \quizaccess_seb_test_helper_trait;
@ -53,7 +53,7 @@ class access_manager_test extends \advanced_testcase {
$this->assertFalse($accessmanager->seb_required());
$reflection = new \ReflectionClass('\quizaccess_seb\access_manager');
$reflection = new \ReflectionClass('\quizaccess_seb\seb_access_manager');
$property = $reflection->getProperty('quizsettings');
$property->setAccessible(true);
@ -153,7 +153,7 @@ class access_manager_test extends \advanced_testcase {
$accessmanager = $this->get_access_manager();
$configkey = quiz_settings::get_record(['quizid' => $this->quiz->id])->get_config_key();
$configkey = seb_quiz_settings::get_record(['quizid' => $this->quiz->id])->get_config_key();
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
@ -171,7 +171,7 @@ class access_manager_test extends \advanced_testcase {
$url = 'https://www.example.com/moodle';
$accessmanager = $this->get_access_manager();
$configkey = quiz_settings::get_record(['quizid' => $this->quiz->id])->get_config_key();
$configkey = seb_quiz_settings::get_record(['quizid' => $this->quiz->id])->get_config_key();
$fullconfigkey = hash('sha256', $url . $configkey);
$this->assertTrue($accessmanager->validate_config_key($fullconfigkey, $url));
@ -202,7 +202,7 @@ class access_manager_test extends \advanced_testcase {
public function test_no_browser_exam_keys_cause_check_to_be_successful() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('allowedbrowserexamkeys', '');
$settings->save();
$accessmanager = $this->get_access_manager();
@ -216,7 +216,7 @@ class access_manager_test extends \advanced_testcase {
public function test_access_keys_fail_if_browser_exam_key_header_does_not_exist() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('allowedbrowserexamkeys', hash('sha256', 'one') . "\n" . hash('sha256', 'two'));
$settings->save();
$accessmanager = $this->get_access_manager();
@ -229,7 +229,7 @@ class access_manager_test extends \advanced_testcase {
public function test_access_keys_fail_if_browser_exam_key_header_does_not_match_provided_hash() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('allowedbrowserexamkeys', hash('sha256', 'one') . "\n" . hash('sha256', 'two'));
$settings->save();
$accessmanager = $this->get_access_manager();
@ -244,7 +244,7 @@ class access_manager_test extends \advanced_testcase {
global $FULLME;
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$browserexamkey = hash('sha256', 'browserexamkey');
$settings->set('allowedbrowserexamkeys', $browserexamkey); // Add a hashed BEK.
$settings->save();
@ -263,7 +263,7 @@ class access_manager_test extends \advanced_testcase {
public function test_browser_exam_keys_match_provided_browser_exam_key() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
$url = 'https://www.example.com/moodle';
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$browserexamkey = hash('sha256', 'browserexamkey');
$fullbrowserexamkey = hash('sha256', $url . $browserexamkey);
$settings->set('allowedbrowserexamkeys', $browserexamkey); // Add a hashed BEK.
@ -315,7 +315,7 @@ class access_manager_test extends \advanced_testcase {
// Use template.
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $this->create_template()->get('id'));
$quizsettings->save();
@ -324,7 +324,7 @@ class access_manager_test extends \advanced_testcase {
// Use uploaded config.
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); // Doesn't check basic header.
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
@ -362,7 +362,7 @@ class access_manager_test extends \advanced_testcase {
* @dataProvider should_validate_basic_header_data_provider
*/
public function test_should_validate_basic_header($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
$accessmanager = $this->getMockBuilder(seb_access_manager::class)
->disableOriginalConstructor()
->onlyMethods(['get_seb_use_type'])
->getMock();
@ -396,7 +396,7 @@ class access_manager_test extends \advanced_testcase {
* @dataProvider should_validate_config_key_data_provider
*/
public function test_should_validate_config_key($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
$accessmanager = $this->getMockBuilder(seb_access_manager::class)
->disableOriginalConstructor()
->onlyMethods(['get_seb_use_type'])
->getMock();
@ -429,7 +429,7 @@ class access_manager_test extends \advanced_testcase {
* @dataProvider should_validate_browser_exam_key_data_provider
*/
public function test_should_validate_browser_exam_key($type, $expected) {
$accessmanager = $this->getMockBuilder(access_manager::class)
$accessmanager = $this->getMockBuilder(seb_access_manager::class)
->disableOriginalConstructor()
->onlyMethods(['get_seb_use_type'])
->getMock();
@ -457,7 +457,7 @@ class access_manager_test extends \advanced_testcase {
$this->assertTrue($accessmanager->validate_config_key());
// Change settings (but don't save) and check that still can validate config key.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('showsebtaskbar', 0);
$this->assertNotEquals($quizsettings->get_config_key(), $configkey);
$this->assertTrue($accessmanager->validate_config_key());
@ -479,7 +479,7 @@ class access_manager_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
$accessmanager = $this->get_access_manager();
$this->assertEmpty(quiz_settings::get_record(['quizid' => $this->quiz->id]));
$this->assertEmpty(seb_quiz_settings::get_record(['quizid' => $this->quiz->id]));
$this->assertNull($accessmanager->get_valid_config_key());
}

View File

@ -54,11 +54,11 @@ class backup_restore_test extends \advanced_testcase {
/**
* A helper method to create a quiz with template usage of SEB.
*
* @return quiz_settings
* @return seb_quiz_settings
*/
protected function create_quiz_with_template() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $this->template->get('id'));
$quizsettings->save();
@ -129,10 +129,10 @@ class backup_restore_test extends \advanced_testcase {
* @param cm_info $newcm Restored course_module object.
*/
protected function validate_backup_restore(\cm_info $newcm) {
$this->assertEquals(2, quiz_settings::count_records());
$actual = quiz_settings::get_record(['quizid' => $newcm->instance]);
$this->assertEquals(2, seb_quiz_settings::count_records());
$actual = seb_quiz_settings::get_record(['quizid' => $newcm->instance]);
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals($expected->get('templateid'), $actual->get('templateid'));
$this->assertEquals($expected->get('requiresafeexambrowser'), $actual->get('requiresafeexambrowser'));
$this->assertEquals($expected->get('showsebdownloadlink'), $actual->get('showsebdownloadlink'));
@ -152,10 +152,10 @@ class backup_restore_test extends \advanced_testcase {
*/
public function test_backup_restore_no_seb() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
$this->assertEquals(0, quiz_settings::count_records());
$this->assertEquals(0, seb_quiz_settings::count_records());
$this->backup_and_restore_quiz();
$this->assertEquals(0, quiz_settings::count_records());
$this->assertEquals(0, seb_quiz_settings::count_records());
}
/**
@ -164,12 +164,12 @@ class backup_restore_test extends \advanced_testcase {
public function test_backup_restore_manual_config() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected->set('showsebdownloadlink', 0);
$expected->set('quitpassword', '123');
$expected->save();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$newcm = $this->backup_and_restore_quiz();
$this->validate_backup_restore($newcm);
@ -181,13 +181,13 @@ class backup_restore_test extends \advanced_testcase {
public function test_backup_restore_template_config() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$template = $this->create_template();
$expected->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$expected->set('templateid', $template->get('id'));
$expected->save();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$newcm = $this->backup_and_restore_quiz();
$this->validate_backup_restore($newcm);
@ -199,13 +199,13 @@ class backup_restore_test extends \advanced_testcase {
public function test_backup_restore_uploaded_config() {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
$expected->save();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$newcm = $this->backup_and_restore_quiz();
$this->validate_backup_restore($newcm);
@ -224,14 +224,14 @@ class backup_restore_test extends \advanced_testcase {
$this->create_quiz_with_template();
$backupid = $this->backup_quiz();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$this->assertEquals(1, template::count_records());
$this->change_site();
$this->restore_quiz($backupid);
// Should see additional setting record, but no new template record.
$this->assertEquals(2, quiz_settings::count_records());
$this->assertEquals(2, seb_quiz_settings::count_records());
$this->assertEquals(1, template::count_records());
}
@ -243,7 +243,7 @@ class backup_restore_test extends \advanced_testcase {
$this->create_quiz_with_template();
$backupid = $this->backup_quiz();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$this->assertEquals(1, template::count_records());
$this->template->set('name', 'New name for template');
@ -253,7 +253,7 @@ class backup_restore_test extends \advanced_testcase {
$this->restore_quiz($backupid);
// Should see additional setting record, and new template record.
$this->assertEquals(2, quiz_settings::count_records());
$this->assertEquals(2, seb_quiz_settings::count_records());
$this->assertEquals(2, template::count_records());
}
@ -267,7 +267,7 @@ class backup_restore_test extends \advanced_testcase {
$this->create_quiz_with_template();
$backupid = $this->backup_quiz();
$this->assertEquals(1, quiz_settings::count_records());
$this->assertEquals(1, seb_quiz_settings::count_records());
$this->assertEquals(1, template::count_records());
$newxml = file_get_contents($CFG->dirroot . '/mod/quiz/accessrule/seb/tests/fixtures/simpleunencrypted.seb');
@ -278,7 +278,7 @@ class backup_restore_test extends \advanced_testcase {
$this->restore_quiz($backupid);
// Should see additional setting record, and new template record.
$this->assertEquals(2, quiz_settings::count_records());
$this->assertEquals(2, seb_quiz_settings::count_records());
$this->assertEquals(2, template::count_records());
}

View File

@ -53,7 +53,7 @@ class events_test extends \advanced_testcase {
$this->setAdminUser();
$quiz = $this->create_test_quiz($this->course, \quizaccess_seb\settings_provider::USE_SEB_CONFIG_MANUALLY);
$accessmanager = new \quizaccess_seb\access_manager(new quiz_settings($quiz,
$accessmanager = new \quizaccess_seb\seb_access_manager(new quiz_settings($quiz,
get_coursemodule_from_id('quiz', $quiz->cmid), $this->course));
// Set up event with data.
@ -103,7 +103,7 @@ class events_test extends \advanced_testcase {
$this->setAdminUser();
$quiz = $this->create_test_quiz($this->course, \quizaccess_seb\settings_provider::USE_SEB_CONFIG_MANUALLY);
$accessmanager = new \quizaccess_seb\access_manager(new quiz_settings($quiz,
$accessmanager = new \quizaccess_seb\seb_access_manager(new quiz_settings($quiz,
get_coursemodule_from_id('quiz', $quiz->cmid), $this->course));
// Set up event with data.

View File

@ -20,7 +20,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
use quizaccess_seb\quiz_settings;
use quizaccess_seb\seb_quiz_settings;
require_once($CFG->libdir . '/externallib.php');
@ -164,7 +164,7 @@ class validate_quiz_access_test extends \advanced_testcase {
$url = 'https://www.example.com/moodle';
// Create the quiz settings.
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$quizsettings->save();
$fullconfigkey = hash('sha256', $url . $quizsettings->get_config_key());
@ -188,7 +188,7 @@ class validate_quiz_access_test extends \advanced_testcase {
]);
// Create the quiz settings.
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$quizsettings->save();
$result = validate_quiz_keys::execute($this->quiz->cmid, 'https://www.example.com/moodle', 'badconfigkey');
@ -217,7 +217,7 @@ class validate_quiz_access_test extends \advanced_testcase {
]);
// Create the quiz settings.
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$quizsettings->save();
$fullbrowserexamkey = hash('sha256', $url . $validbrowserexamkey);
@ -243,7 +243,7 @@ class validate_quiz_access_test extends \advanced_testcase {
]);
// Create the quiz settings.
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$quizsettings->save();
$result = validate_quiz_keys::execute($this->quiz->cmid, 'https://www.example.com/moodle', null,

View File

@ -31,7 +31,7 @@ use core_privacy\local\request\writer;
use core_privacy\tests\request\approved_contextlist;
use core_privacy\tests\provider_testcase;
use quizaccess_seb\privacy\provider;
use quizaccess_seb\quiz_settings;
use quizaccess_seb\seb_quiz_settings;
defined('MOODLE_INTERNAL') || die();
@ -62,7 +62,7 @@ class provider_test extends provider_testcase {
$template = $this->create_template();
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
// Modify settings so usermodified is updated. This is the user data we are testing for.
$quizsettings->set('requiresafeexambrowser', \quizaccess_seb\settings_provider::USE_SEB_TEMPLATE);
@ -126,7 +126,7 @@ class provider_test extends provider_testcase {
$index = '1'; // Get first data returned from the quizsettings table metadata.
$data = $writer->get_data([
get_string('pluginname', 'quizaccess_seb'),
quiz_settings::TABLE,
seb_quiz_settings::TABLE,
$index,
]);
$this->assertNotEmpty($data);
@ -142,7 +142,7 @@ class provider_test extends provider_testcase {
$index = '2'; // There should not be more than one instance with data.
$data = $writer->get_data([
get_string('pluginname', 'quizaccess_seb'),
quiz_settings::TABLE,
seb_quiz_settings::TABLE,
$index,
]);
$this->assertEmpty($data);
@ -180,11 +180,11 @@ class provider_test extends provider_testcase {
'quizaccess_seb', [$this->user->id]);
// Test data exists.
$this->assertNotEmpty(quiz_settings::get_record(['quizid' => $this->quiz->id]));
$this->assertNotEmpty(seb_quiz_settings::get_record(['quizid' => $this->quiz->id]));
// Test data is deleted.
provider::delete_data_for_users($approveduserlist);
$record = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$record = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEmpty($record->get('usermodified'));
$template = \quizaccess_seb\template::get_record(['id' => $record->get('templateid')]);
@ -202,11 +202,11 @@ class provider_test extends provider_testcase {
'quizaccess_seb', [$context->id]);
// Test data exists.
$this->assertNotEmpty(quiz_settings::get_record(['quizid' => $this->quiz->id]));
$this->assertNotEmpty(seb_quiz_settings::get_record(['quizid' => $this->quiz->id]));
// Test data is deleted.
provider::delete_data_for_user($approvedcontextlist);
$record = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$record = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEmpty($record->get('usermodified'));
$template = \quizaccess_seb\template::get_record(['id' => $record->get('templateid')]);
@ -222,7 +222,7 @@ class provider_test extends provider_testcase {
$context = \context_module::instance($this->quiz->cmid);
// Test data exists.
$record = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$record = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$template = \quizaccess_seb\template::get_record(['id' => $record->get('templateid')]);
$this->assertNotEmpty($record->get('usermodified'));
$this->assertNotEmpty($template->get('usermodified'));
@ -230,7 +230,7 @@ class provider_test extends provider_testcase {
// Test data is deleted.
provider::delete_data_for_all_users_in_context($context);
$record = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$record = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$template = \quizaccess_seb\template::get_record(['id' => $record->get('templateid')]);
$this->assertEmpty($record->get('usermodified'));
$this->assertEmpty($template->get('usermodified'));

View File

@ -16,12 +16,15 @@
namespace quizaccess_seb;
use context_module;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/test_helper_trait.php');
/**
* PHPUnit tests for mod_quiz\quiz_settings class.
* PHPUnit tests for seb_quiz_settings class.
*
* @package quizaccess_seb
* @author Andrew Madden <andrewmadden@catalyst-au.net>
@ -66,7 +69,7 @@ class quiz_settings_test extends \advanced_testcase {
]);
// Obtain the existing record that is created when using a generator.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
// Update the settings with values from the test function.
$quizsettings->from_record($settings);
@ -100,7 +103,7 @@ class quiz_settings_test extends \advanced_testcase {
]);
// Obtain the existing record that is created when using a generator.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
// Update the settings with values from the test function.
$quizsettings->from_record($settings);
@ -145,7 +148,7 @@ class quiz_settings_test extends \advanced_testcase {
public function test_config_key_is_created_from_quiz_settings() {
$settings = $this->get_test_settings();
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$configkey = $quizsettings->get_config_key();
$this->assertEquals("65ff7a3b8aec80e58fbe2e7968826c33cbf0ac444a748055ebe665829cbf4201",
$configkey
@ -158,7 +161,7 @@ class quiz_settings_test extends \advanced_testcase {
public function test_config_key_is_updated_from_quiz_settings() {
$settings = $this->get_test_settings();
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$configkey = $quizsettings->get_config_key();
$this->assertEquals("65ff7a3b8aec80e58fbe2e7968826c33cbf0ac444a748055ebe665829cbf4201",
$configkey);
@ -178,7 +181,7 @@ class quiz_settings_test extends \advanced_testcase {
* @dataProvider filter_rules_provider
*/
public function test_filter_rules_added_to_config(\stdClass $settings, string $expectedxml) {
$quizsettings = new quiz_settings(0, $settings);
$quizsettings = new seb_quiz_settings(0, $settings);
$config = $quizsettings->get_config();
$this->assertEquals($expectedxml, $config);
}
@ -187,7 +190,7 @@ class quiz_settings_test extends \advanced_testcase {
* Test that browser keys are validated and retrieved as an array instead of string.
*/
public function test_browser_exam_keys_are_retrieved_as_array() {
$quizsettings = new quiz_settings();
$quizsettings = new seb_quiz_settings();
$quizsettings->set('allowedbrowserexamkeys', "one two,three\nfour");
$retrievedkeys = $quizsettings->get('allowedbrowserexamkeys');
$this->assertEquals(['one', 'two', 'three', 'four'], $retrievedkeys);
@ -202,7 +205,7 @@ class quiz_settings_test extends \advanced_testcase {
* @dataProvider bad_browser_exam_key_provider
*/
public function test_browser_exam_keys_validation_errors($bek, $expectederrorstring) {
$quizsettings = new quiz_settings();
$quizsettings = new seb_quiz_settings();
$quizsettings->set('allowedbrowserexamkeys', $bek);
$quizsettings->validate();
$errors = $quizsettings->get_errors();
@ -220,7 +223,7 @@ class quiz_settings_test extends \advanced_testcase {
. "<key>allowWlan</key><false/><key>startURL</key><string>$url</string>"
. "<key>sendBrowserExamKey</key><true/><key>browserWindowWebView</key><integer>3</integer></dict></plist>\n";
$itemid = $this->create_module_test_file($xml, $this->quiz->cmid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings->save();
$config = $quizsettings->get_config();
@ -231,7 +234,7 @@ class quiz_settings_test extends \advanced_testcase {
* Test test_no_config_file_uploaded
*/
public function test_no_config_file_uploaded() {
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$cmid = $quizsettings->get('cmid');
$this->expectException(\moodle_exception::class);
@ -279,7 +282,7 @@ class quiz_settings_test extends \advanced_testcase {
$this->assertStringContainsString("<key>allowQuit</key><true/>", $template->get('content'));
$this->assertStringContainsString("<key>hashedQuitPassword</key><string>password</string>", $template->get('content'));
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $template->get('id'));
$quizsettings->set('allowuserquitseb', 1);
@ -318,7 +321,7 @@ class quiz_settings_test extends \advanced_testcase {
$this->assertStringNotContainsString("<key>allowQuit</key><true/>", $template->get('content'));
$this->assertStringNotContainsString("<key>hashedQuitPassword</key><string>password</string>", $template->get('content'));
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $template->get('id'));
$quizsettings->set('allowuserquitseb', 1);
@ -347,7 +350,7 @@ class quiz_settings_test extends \advanced_testcase {
$xml = $this->get_config_xml(true, 'password');
$this->create_module_test_file($xml, $this->quiz->cmid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings->set('allowuserquitseb', 0);
$quizsettings->set('quitpassword', '');
@ -384,7 +387,7 @@ class quiz_settings_test extends \advanced_testcase {
$xml = $this->get_config_xml();
$this->create_module_test_file($xml, $this->quiz->cmid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings->set('allowuserquitseb', 1);
$quizsettings->set('quitpassword', '');
@ -424,7 +427,7 @@ class quiz_settings_test extends \advanced_testcase {
$template = $this->create_template($xml);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $template->get('id'));
@ -446,7 +449,7 @@ class quiz_settings_test extends \advanced_testcase {
. "<key>sendBrowserExamKey</key><true/></dict></plist>\n";
$itemid = $this->create_module_test_file($xml, $this->quiz->cmid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$this->assertEmpty($quizsettings->get('linkquitseb'));
@ -460,7 +463,7 @@ class quiz_settings_test extends \advanced_testcase {
* Test template id set correctly.
*/
public function test_templateid_set_correctly_when_save_settings() {
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(0, $quizsettings->get('templateid'));
$template = $this->create_template();
@ -468,12 +471,12 @@ class quiz_settings_test extends \advanced_testcase {
// Initially set to USE_SEB_TEMPLATE with a template id.
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_TEMPLATE, $templateid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals($templateid, $quizsettings->get('templateid'));
// Case for USE_SEB_NO, ensure template id reverts to 0.
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_NO);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(0, $quizsettings->get('templateid'));
// Reverting back to USE_SEB_TEMPLATE.
@ -481,7 +484,7 @@ class quiz_settings_test extends \advanced_testcase {
// Case for USE_SEB_CONFIG_MANUALLY, ensure template id reverts to 0.
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(0, $quizsettings->get('templateid'));
// Reverting back to USE_SEB_TEMPLATE.
@ -489,7 +492,7 @@ class quiz_settings_test extends \advanced_testcase {
// Case for USE_SEB_CLIENT_CONFIG, ensure template id reverts to 0.
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_CLIENT_CONFIG);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(0, $quizsettings->get('templateid'));
// Reverting back to USE_SEB_TEMPLATE.
@ -499,19 +502,19 @@ class quiz_settings_test extends \advanced_testcase {
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(0, $quizsettings->get('templateid'));
// Case for USE_SEB_TEMPLATE, ensure template id is correct.
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_TEMPLATE, $templateid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals($templateid, $quizsettings->get('templateid'));
}
/**
* Helper function in tests to set USE_SEB_TEMPLATE and a template id on the quiz settings.
*
* @param quiz_settings $quizsettings Given quiz settings instance.
* @param seb_quiz_settings $quizsettings Given quiz settings instance.
* @param int $savetype Type of SEB usage.
* @param int $templateid Template ID.
*/
@ -695,13 +698,13 @@ class quiz_settings_test extends \advanced_testcase {
* Test that config and config key are null when expected.
*/
public function test_generates_config_values_as_null_when_expected() {
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertNotNull($quizsettings->get_config());
$this->assertNotNull($quizsettings->get_config_key());
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_NO);
$quizsettings->save();
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertNull($quizsettings->get_config());
$this->assertNull($quizsettings->get_config());
@ -709,20 +712,20 @@ class quiz_settings_test extends \advanced_testcase {
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
$quizsettings->save();
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertNotNull($quizsettings->get_config());
$this->assertNotNull($quizsettings->get_config_key());
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_CLIENT_CONFIG);
$quizsettings->save();
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertNull($quizsettings->get_config());
$this->assertNull($quizsettings->get_config_key());
$template = $this->create_template();
$templateid = $template->get('id');
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_TEMPLATE, $templateid);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertNotNull($quizsettings->get_config());
$this->assertNotNull($quizsettings->get_config_key());
}
@ -731,7 +734,7 @@ class quiz_settings_test extends \advanced_testcase {
* Test that quizsettings cache exists after creation.
*/
public function test_quizsettings_cache_exists_after_creation() {
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals($expected->to_record(), \cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
}
@ -741,30 +744,30 @@ class quiz_settings_test extends \advanced_testcase {
public function test_quizsettings_cache_purged_after_deletion() {
$this->assertNotEmpty(\cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->delete();
$this->assertFalse(\cache::make('quizaccess_seb', 'quizsettings')->get($this->quiz->id));
}
/**
* Test that we can get mod_quiz\quiz_settings by quiz id.
* Test that we can get seb_quiz_settings by quiz id.
*/
public function test_get_quiz_settings_by_quiz_id() {
$expected = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals($expected->to_record(), quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
$this->assertEquals($expected->to_record(), seb_quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
// Check that data is getting from cache.
$expected->set('showsebtaskbar', 0);
$this->assertNotEquals($expected->to_record(), quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
$this->assertNotEquals($expected->to_record(), seb_quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
// Now save and check that cached as been updated.
$expected->save();
$this->assertEquals($expected->to_record(), quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
$this->assertEquals($expected->to_record(), seb_quiz_settings::get_by_quiz_id($this->quiz->id)->to_record());
// Returns false for non existing quiz.
$this->assertFalse(quiz_settings::get_by_quiz_id(7777777));
$this->assertFalse(seb_quiz_settings::get_by_quiz_id(7777777));
}
/**
@ -780,7 +783,7 @@ class quiz_settings_test extends \advanced_testcase {
public function test_config_cache_purged_after_deletion() {
$this->assertNotEmpty(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->delete();
$this->assertFalse(\cache::make('quizaccess_seb', 'config')->get($this->quiz->id));
@ -790,21 +793,21 @@ class quiz_settings_test extends \advanced_testcase {
* Test that we can get SEB config by quiz id.
*/
public function test_get_config_by_quiz_id() {
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = $quizsettings->get_config();
$this->assertEquals($expected, quiz_settings::get_config_by_quiz_id($this->quiz->id));
$this->assertEquals($expected, seb_quiz_settings::get_config_by_quiz_id($this->quiz->id));
// Check that data is getting from cache.
$quizsettings->set('showsebtaskbar', 0);
$this->assertNotEquals($quizsettings->get_config(), quiz_settings::get_config_by_quiz_id($this->quiz->id));
$this->assertNotEquals($quizsettings->get_config(), seb_quiz_settings::get_config_by_quiz_id($this->quiz->id));
// Now save and check that cached as been updated.
$quizsettings->save();
$this->assertEquals($quizsettings->get_config(), quiz_settings::get_config_by_quiz_id($this->quiz->id));
$this->assertEquals($quizsettings->get_config(), seb_quiz_settings::get_config_by_quiz_id($this->quiz->id));
// Returns null for non existing quiz.
$this->assertNull(quiz_settings::get_config_by_quiz_id(7777777));
$this->assertNull(seb_quiz_settings::get_config_by_quiz_id(7777777));
}
/**
@ -820,7 +823,7 @@ class quiz_settings_test extends \advanced_testcase {
public function test_config_key_cache_purged_after_deletion() {
$this->assertNotEmpty(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->delete();
$this->assertFalse(\cache::make('quizaccess_seb', 'configkey')->get($this->quiz->id));
@ -830,21 +833,21 @@ class quiz_settings_test extends \advanced_testcase {
* Test that we can get SEB config key by quiz id.
*/
public function test_get_config_key_by_quiz_id() {
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$expected = $quizsettings->get_config_key();
$this->assertEquals($expected, quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
$this->assertEquals($expected, seb_quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
// Check that data is getting from cache.
$quizsettings->set('showsebtaskbar', 0);
$this->assertNotEquals($quizsettings->get_config_key(), quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
$this->assertNotEquals($quizsettings->get_config_key(), seb_quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
// Now save and check that cached as been updated.
$quizsettings->save();
$this->assertEquals($quizsettings->get_config_key(), quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
$this->assertEquals($quizsettings->get_config_key(), seb_quiz_settings::get_config_key_by_quiz_id($this->quiz->id));
// Returns null for non existing quiz.
$this->assertNull(quiz_settings::get_config_key_by_quiz_id(7777777));
$this->assertNull(seb_quiz_settings::get_config_key_by_quiz_id(7777777));
}
}

View File

@ -285,7 +285,7 @@ class rule_test extends \advanced_testcase {
$this->quiz->seb_requiresafeexambrowser = settings_provider::USE_SEB_NO;
quizaccess_seb::save_settings($this->quiz);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$this->assertEquals(settings_provider::USE_SEB_CONFIG_MANUALLY, $quizsettings->get('requiresafeexambrowser'));
}
@ -388,7 +388,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb and save BEK.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
@ -414,7 +414,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb and save BEK.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $this->create_template()->get('id'));
$quizsettings->save();
@ -442,7 +442,7 @@ class rule_test extends \advanced_testcase {
$this->setUser($user);
// Set quiz setting to require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
// Set up dummy request.
$FULLME = 'https://example.com/moodle/mod/quiz/attempt.php?attemptid=123&page=4';
@ -463,7 +463,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb and save BEK.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $this->create_template()->get('id'));
$quizsettings->save();
@ -490,7 +490,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb and save BEK.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
@ -522,7 +522,7 @@ class rule_test extends \advanced_testcase {
// Set quiz setting to require seb and save BEK.
$browserexamkey = hash('sha256', 'testkey');
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_CLIENT_CONFIG); // Doesn't check config key.
$quizsettings->set('allowedbrowserexamkeys', $browserexamkey);
$quizsettings->save();
@ -548,7 +548,7 @@ class rule_test extends \advanced_testcase {
// Set quiz setting to require seb and save BEK.
$browserexamkey = hash('sha256', 'testkey');
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings->set('allowedbrowserexamkeys', $browserexamkey);
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
@ -643,7 +643,7 @@ class rule_test extends \advanced_testcase {
// Set quiz setting to require seb and save BEK.
$browserexamkey = hash('sha256', 'testkey');
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_CLIENT_CONFIG); // Doesn't check config key.
$quizsettings->set('allowedbrowserexamkeys', $browserexamkey);
$quizsettings->save();
@ -666,7 +666,7 @@ class rule_test extends \advanced_testcase {
// Set quiz setting to require seb and save BEK.
$browserexamkey = hash('sha256', 'testkey');
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$quizsettings->set('allowedbrowserexamkeys', $browserexamkey);
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
@ -698,7 +698,7 @@ class rule_test extends \advanced_testcase {
// Set quiz setting to require seb and save BEK.
$browserexamkey = hash('sha256', 'testkey');
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('allowedbrowserexamkeys', $browserexamkey);
$quizsettings->set('templateid', $this->create_template()->get('id'));
@ -730,7 +730,7 @@ class rule_test extends \advanced_testcase {
$this->setUser($user);
// Set quiz setting to require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_CLIENT_CONFIG); // Doesn't check config key.
$quizsettings->save();
@ -752,7 +752,7 @@ class rule_test extends \advanced_testcase {
$this->setUser($user);
// Set quiz setting to require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_CLIENT_CONFIG); // Doesn't check config key.
$quizsettings->save();
@ -795,7 +795,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); // Doesn't check basic header.
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$this->create_module_test_file($xml, $this->quiz->cmid);
@ -824,7 +824,7 @@ class rule_test extends \advanced_testcase {
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
// Set quiz setting to require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$quizsettings->set('templateid', $this->create_template()->get('id'));
$quizsettings->save();
@ -853,7 +853,7 @@ class rule_test extends \advanced_testcase {
$this->setUser($user);
// Set quiz setting to not require seb.
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_NO);
$quizsettings->save();
@ -1044,7 +1044,7 @@ class rule_test extends \advanced_testcase {
$method = $reflection->getMethod('get_action_buttons');
$method->setAccessible(true);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
// Should see link when using manually.
$this->assertStringContainsString($this->get_seb_launch_link(), $method->invoke($this->make_rule()));
@ -1161,7 +1161,7 @@ class rule_test extends \advanced_testcase {
$this->setAdminUser();
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$user = $this->getDataGenerator()->create_user();
$roleid = $this->getDataGenerator()->create_role();
@ -1268,7 +1268,7 @@ class rule_test extends \advanced_testcase {
$this->setAdminUser();
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$quizsettings->save();
// Set access for Moodle session.
$SESSION->quizaccess_seb_access = [$this->quiz->cmid => true];

View File

@ -111,7 +111,7 @@ class settings_provider_test extends \advanced_testcase {
* Test that settings types to be added to quiz settings, are part of quiz_settings persistent class.
*/
public function test_setting_elements_are_part_of_quiz_settings_table() {
$dbsettings = (array) (new quiz_settings())->to_record();
$dbsettings = (array) (new seb_quiz_settings())->to_record();
$settingelements = settings_provider::get_seb_config_elements();
$settingelements = (array) $this->strip_all_prefixes((object) $settingelements);
@ -704,7 +704,7 @@ class settings_provider_test extends \advanced_testcase {
$template = $this->create_template();
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('templateid', $template->get('id'));
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$settings->save();
@ -731,7 +731,7 @@ class settings_provider_test extends \advanced_testcase {
// Setup conflicting permissions.
$template = $this->create_template();
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('templateid', $template->get('id'));
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$settings->save();
@ -794,7 +794,7 @@ class settings_provider_test extends \advanced_testcase {
$template = $this->create_template();
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('templateid', $template->get('id'));
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$settings->save();
@ -989,7 +989,7 @@ class settings_provider_test extends \advanced_testcase {
settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$settings->save();
@ -1167,7 +1167,7 @@ class settings_provider_test extends \advanced_testcase {
// Create a template.
$template = $this->create_template();
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('templateid', $template->get('id'));
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_TEMPLATE);
$settings->save();
@ -1197,7 +1197,7 @@ class settings_provider_test extends \advanced_testcase {
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
$draftitemid = $this->create_test_draftarea_file($xml);
settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid);
$settings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
$settings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
$settings->save();

View File

@ -108,7 +108,7 @@ class template_test extends \advanced_testcase {
$template->save();
$this->assertTrue($template->can_delete());
$DB->insert_record(quiz_settings::TABLE, (object) [
$DB->insert_record(seb_quiz_settings::TABLE, (object) [
'quizid' => 1,
'cmid' => 1,
'templateid' => $template->get('id'),

View File

@ -25,7 +25,7 @@
use mod_quiz\local\access_rule_base;
use mod_quiz\quiz_attempt;
use quizaccess_seb\access_manager;
use quizaccess_seb\seb_access_manager;
use quizaccess_seb\settings_provider;
defined('MOODLE_INTERNAL') || die();
@ -239,10 +239,10 @@ trait quizaccess_seb_test_helper_trait {
/**
* Get access manager for testing.
*
* @return \quizaccess_seb\access_manager
* @return \quizaccess_seb\seb_access_manager
*/
protected function get_access_manager() {
return new access_manager(new mod_quiz\quiz_settings($this->quiz,
return new seb_access_manager(new mod_quiz\quiz_settings($this->quiz,
get_coursemodule_from_id('quiz', $this->quiz->cmid), $this->course));
}

View File

@ -292,7 +292,7 @@ class quiz_attempt {
}
/**
* Get the {@see quiz_settings} object for this quiz.
* Get the {@see seb_quiz_settings} object for this quiz.
*
* @return quiz_settings
*/

View File

@ -54,6 +54,8 @@ This files describes API changes in the quiz code.
- quiz_review_nav_panel => mod_quiz\output\navigation_panel_review
- quiz_attempt => mod_quiz\quiz_attempt
- quiz => mod_quiz\quiz_settings
- quizaccess_seb\quiz_settings => quizaccess_seb\seb_quiz_settings
- quizaccess_seb\access_manager => quizaccess_seb\seb_access_manager
* The following classes have been deprecated:
- mod_quiz_overdue_attempt_updater - merged into mod_quiz\task\update_overdue_attempts