mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-68656-master' of https://github.com/catalyst/moodle
This commit is contained in:
commit
4c6a9740f7
@ -26,11 +26,10 @@
|
||||
use quizaccess_seb\access_manager;
|
||||
use quizaccess_seb\quiz_settings;
|
||||
use quizaccess_seb\settings_provider;
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for the access manager.
|
||||
@ -38,14 +37,18 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizacces_seb_access_manager_testcase extends quizaccess_seb_testcase {
|
||||
class quizacces_seb_access_manager_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -289,7 +292,7 @@ class quizacces_seb_access_manager_testcase extends quizaccess_seb_testcase {
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$quizsettings = 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__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
$accessmanager = $this->get_access_manager();
|
@ -23,11 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for backup and restore functionality.
|
||||
@ -35,7 +34,9 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_backup_restore_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_backup_restore_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
|
||||
/** @var \quizaccess_seb\template $template A test template. */
|
||||
protected $template;
|
||||
@ -47,7 +48,11 @@ class quizaccess_seb_backup_restore_testcase extends quizaccess_seb_testcase {
|
||||
global $USER;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->template = $this->create_template();
|
||||
$this->user = $USER;
|
||||
}
|
||||
@ -202,7 +207,7 @@ class quizaccess_seb_backup_restore_testcase extends quizaccess_seb_testcase {
|
||||
|
||||
$expected = \quizaccess_seb\quiz_settings::get_record(['quizid' => $this->quiz->id]);
|
||||
$expected->set('requiresafeexambrowser', \quizaccess_seb\settings_provider::USE_SEB_UPLOAD_CONFIG);
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$expected->save();
|
||||
|
||||
@ -271,7 +276,7 @@ class quizaccess_seb_backup_restore_testcase extends quizaccess_seb_testcase {
|
||||
$this->assertEquals(1, quizaccess_seb\quiz_settings::count_records());
|
||||
$this->assertEquals(1, quizaccess_seb\template::count_records());
|
||||
|
||||
$newxml = file_get_contents($CFG->dirroot . '/mod/quiz/accessrule/seb/tests/phpunit/sample_data/simpleunencrypted.seb');
|
||||
$newxml = file_get_contents($CFG->dirroot . '/mod/quiz/accessrule/seb/tests/fixtures/simpleunencrypted.seb');
|
||||
$this->template->set('content', $newxml);
|
||||
$this->template->save();
|
||||
|
@ -56,8 +56,8 @@ class quizaccess_seb_config_key_testcase extends advanced_testcase {
|
||||
* Check that the Config Key hash is not altered if the originatorVersion is present in the XML or not.
|
||||
*/
|
||||
public function test_presence_of_originator_version_does_not_effect_hash() {
|
||||
$xmlwithoriginatorversion = file_get_contents(__DIR__ . '/sample_data/simpleunencrypted.seb');
|
||||
$xmlwithoutoriginatorversion = file_get_contents(__DIR__ . '/sample_data/simpleunencryptedwithoutoriginator.seb');
|
||||
$xmlwithoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencrypted.seb');
|
||||
$xmlwithoutoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencryptedwithoutoriginator.seb');
|
||||
$hashwithorigver = config_key::generate($xmlwithoriginatorversion)->get_hash();
|
||||
$hashwithoutorigver = config_key::generate($xmlwithoutoriginatorversion)->get_hash();
|
||||
$this->assertEquals($hashwithorigver, $hashwithoutorigver);
|
@ -23,11 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for all plugin events.
|
||||
@ -35,7 +34,18 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_event_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_event_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating the access_prevented event.
|
@ -50,7 +50,7 @@ class quizaccess_seb_generator extends component_generator_base {
|
||||
|
||||
if (!isset($data['content'])) {
|
||||
$data['content'] = file_get_contents(
|
||||
$CFG->dirroot . '/mod/quiz/accessrule/seb/tests/phpunit/sample_data/unencrypted.seb'
|
||||
$CFG->dirroot . '/mod/quiz/accessrule/seb/tests/fixtures/unencrypted.seb'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for helper class.
|
||||
@ -35,7 +34,8 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_helper_testhelpertrait extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Test that we can check valid seb string.
|
||||
@ -80,6 +80,8 @@ class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
* Test that the course module must exist to get a seb config file content.
|
||||
*/
|
||||
public function test_can_not_get_config_content_with_invalid_cmid() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
@ -104,6 +106,8 @@ class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
* Test that the user must be enrolled to get seb config content.
|
||||
*/
|
||||
public function test_can_not_get_config_content_when_user_not_enrolled_in_course() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$quiz = $this->create_test_quiz($course, \quizaccess_seb\settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
@ -120,7 +124,7 @@ class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
* Test that if SEB quiz settings can't be found, a seb config content won't be provided.
|
||||
*/
|
||||
public function test_can_not_get_config_content_if_config_not_found_for_cmid() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
@ -139,7 +143,7 @@ class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
* That that if config is empty for a quiz, a seb config content won't be provided.
|
||||
*/
|
||||
public function test_can_not_get_config_content_if_config_empty() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -159,6 +163,8 @@ class quizaccess_seb_helper_testcase extends quizaccess_seb_testcase {
|
||||
* Test config content is provided successfully.
|
||||
*/
|
||||
public function test_config_provided() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
@ -23,7 +23,6 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
use core_privacy\local\request\approved_userlist;
|
||||
use core_privacy\local\request\userlist;
|
||||
use core_privacy\local\request\writer;
|
||||
@ -33,7 +32,7 @@ use quizaccess_seb\quiz_settings;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for privacy provider.
|
||||
@ -41,13 +40,18 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_provider_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_provider_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Setup the user, the quiz and ensure that the user is the last user to modify the SEB quiz settings.
|
||||
*/
|
||||
public function setup_test_data() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course, \quizaccess_seb\settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
|
||||
$this->user = $this->getDataGenerator()->create_user();
|
||||
@ -79,6 +83,8 @@ class quizaccess_seb_provider_testcase extends quizaccess_seb_testcase {
|
||||
* That that no module context is found for a user who has not modified any quiz settings.
|
||||
*/
|
||||
public function test_get_no_contexts_for_userid() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$contexts = provider::get_contexts_for_userid($user->id);
|
||||
$contextids = $contexts->get_contextids();
|
@ -244,11 +244,11 @@ class quizaccess_seb_property_list_testcase extends advanced_testcase {
|
||||
* Test that the xml is exported to JSON from a real SEB config file. Expected JSON extracted from SEB logs.
|
||||
*/
|
||||
public function test_export_to_json_full_file() {
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted_mac_001.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted_mac_001.seb');
|
||||
$plist = new property_list($xml);
|
||||
$plist->delete_element('originatorVersion'); // JSON should not contain originatorVersion key.
|
||||
$generatedjson = $plist->to_json();
|
||||
$json = trim(file_get_contents(__DIR__ . '/sample_data/JSON_unencrypted_mac_001.txt'));
|
||||
$json = trim(file_get_contents(__DIR__ . '/fixtures/JSON_unencrypted_mac_001.txt'));
|
||||
$this->assertEquals($json, $generatedjson);
|
||||
}
|
||||
|
@ -25,18 +25,19 @@
|
||||
|
||||
use quizaccess_seb\quiz_settings;
|
||||
use quizaccess_seb\settings_provider;
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for quiz_settings class.
|
||||
*
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_quiz_settings_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_quiz_settings_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/** @var context_module $context Test context. */
|
||||
protected $context;
|
||||
@ -50,7 +51,10 @@ class quizaccess_seb_quiz_settings_testcase extends quizaccess_seb_testcase {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', [
|
||||
'course' => $this->course->id,
|
||||
'seb_requiresafeexambrowser' => settings_provider::USE_SEB_CONFIG_MANUALLY,
|
||||
@ -493,7 +497,7 @@ class quizaccess_seb_quiz_settings_testcase extends quizaccess_seb_testcase {
|
||||
$this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_TEMPLATE, $templateid);
|
||||
|
||||
// Case for USE_SEB_UPLOAD_CONFIG, ensure template id reverts to 0.
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$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]);
|
||||
@ -693,7 +697,7 @@ class quizaccess_seb_quiz_settings_testcase extends quizaccess_seb_testcase {
|
||||
$this->assertNull($quizsettings->get_config());
|
||||
|
||||
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$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]);
|
@ -25,11 +25,10 @@
|
||||
|
||||
use quizaccess_seb\quiz_settings;
|
||||
use quizaccess_seb\settings_provider;
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for plugin rule class.
|
||||
@ -37,7 +36,19 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_rule__testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to get SEB download link for testing.
|
||||
@ -374,7 +385,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
// Set quiz setting to require seb and save BEK.
|
||||
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
|
||||
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
|
||||
@ -476,7 +487,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
// Set quiz setting to require seb and save BEK.
|
||||
$quizsettings = quiz_settings::get_record(['quizid' => $this->quiz->id]);
|
||||
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
|
||||
@ -535,7 +546,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
$quizsettings = 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__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
|
||||
@ -635,7 +646,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
$quizsettings = 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__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
|
||||
@ -755,7 +766,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
// Set quiz setting to require seb.
|
||||
$quizsettings = 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__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
|
||||
@ -1017,7 +1028,7 @@ class quizaccess_seb_rule_testcase extends quizaccess_seb_testcase {
|
||||
|
||||
// Should see links when using uploaded config.
|
||||
$quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG);
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$this->create_module_test_file($xml, $this->quiz->cmid);
|
||||
$quizsettings->save();
|
||||
$this->assertContains($this->get_seb_launch_link(), $method->invoke($this->make_rule()));
|
@ -23,13 +23,12 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use quizaccess_seb\tests\phpunit\quizaccess_seb_testcase;
|
||||
use quizaccess_seb\quiz_settings;
|
||||
use quizaccess_seb\settings_provider;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/base.php');
|
||||
require_once(__DIR__ . '/test_helper_trait.php');
|
||||
|
||||
/**
|
||||
* PHPUnit tests for settings_provider.
|
||||
@ -37,7 +36,8 @@ require_once(__DIR__ . '/base.php');
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase {
|
||||
class quizaccess_seb_settings_provider_testcase extends advanced_testcase {
|
||||
use quizaccess_seb_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Mocked quiz form instance.
|
||||
@ -586,11 +586,14 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test can check if can manage SEB settings respecting settings structure.
|
||||
*/
|
||||
public function test_can_manage_seb_config_setting() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -632,7 +635,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* @dataProvider settings_capability_data_provider
|
||||
*/
|
||||
public function test_get_requiresafeexambrowser_options($settingcapability) {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -698,7 +703,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test SEB usage options with conflicting permissions.
|
||||
*/
|
||||
public function test_get_requiresafeexambrowser_options_with_conflicting_permissions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -723,7 +730,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that SEB options and templates are frozen if conflicting permissions.
|
||||
*/
|
||||
public function test_form_elements_are_frozen_if_conflicting_permissions() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -755,6 +764,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that All settings are frozen if quiz was attempted and use seb with manual settings.
|
||||
*/
|
||||
public function test_form_elements_are_locked_when_quiz_attempted_manual() {
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
|
||||
@ -781,7 +793,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that All settings are frozen if a quiz was attempted and use template.
|
||||
*/
|
||||
public function test_form_elements_are_locked_when_quiz_attempted_template() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -816,7 +830,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test Show Safe Exam Browser download button setting in the form.
|
||||
*/
|
||||
public function test_showsebdownloadlink_in_form() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -841,7 +857,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test Allowed Browser Exam Keys setting in the form.
|
||||
*/
|
||||
public function test_allowedbrowserexamkeys_in_form() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
@ -865,6 +883,8 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test the validation of a seb config file.
|
||||
*/
|
||||
public function test_validate_draftarea_configfile_success() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
@ -880,6 +900,8 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test the validation of a missing seb config file.
|
||||
*/
|
||||
public function test_validate_draftarea_configfile_failure() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
$xml = "This is not a config file.";
|
||||
@ -892,10 +914,12 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test obtaining the draftarea content.
|
||||
*/
|
||||
public function test_get_current_user_draft_file() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$itemid = $this->create_test_draftarea_file($xml);
|
||||
$file = settings_provider::get_current_user_draft_file($itemid);
|
||||
$content = $file->get_content();
|
||||
@ -907,11 +931,13 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test saving files from the user draft area into the quiz context area storage.
|
||||
*/
|
||||
public function test_save_filemanager_sebconfigfile_draftarea() {
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->set_up_user_and_role();
|
||||
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
|
||||
$draftitemid = $this->create_test_draftarea_file($xml);
|
||||
|
||||
@ -927,11 +953,13 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test deleting the $this->quiz->cmid itemid from the file area.
|
||||
*/
|
||||
public function test_delete_uploaded_config_file() {
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->set_up_user_and_role();
|
||||
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$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);
|
||||
@ -951,14 +979,16 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test getting the file from the context module id file area.
|
||||
*/
|
||||
public function test_get_module_context_sebconfig_file() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
|
||||
$this->set_up_user_and_role();
|
||||
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb');
|
||||
$draftitemid = $this->create_test_draftarea_file($xml);
|
||||
|
||||
$fs = get_file_storage();
|
||||
@ -992,6 +1022,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that users can or can not configure seb settings.
|
||||
*/
|
||||
public function test_can_configure_seb() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1010,6 +1043,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that users can or can not use seb template.
|
||||
*/
|
||||
public function test_can_use_seb_template() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1028,6 +1064,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that users can or can not upload seb config file.
|
||||
*/
|
||||
public function test_can_upload_seb_file() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1046,6 +1085,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that users can or can not change Show Safe Exam Browser download button setting.
|
||||
*/
|
||||
public function test_can_change_seb_showsebdownloadlink() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1063,6 +1105,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that users can or can not change Allowed Browser Exam Keys setting.
|
||||
*/
|
||||
public function test_can_change_seb_allowedbrowserexamkeys() {
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1084,6 +1129,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* @dataProvider settings_capability_data_provider
|
||||
*/
|
||||
public function test_can_configure_manually($settingcapability) {
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$this->quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $this->course->id]);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
$this->setAdminUser();
|
||||
@ -1102,6 +1150,9 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that we can check if the seb settings are locked.
|
||||
*/
|
||||
public function test_is_seb_settings_locked() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course);
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
@ -1115,8 +1166,10 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that we can check identify conflicting permissions if set to use template.
|
||||
*/
|
||||
public function test_is_conflicting_permissions_for_manage_templates() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
|
||||
@ -1141,13 +1194,15 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* Test that we can check identify conflicting permissions if set to use own seb file.
|
||||
*/
|
||||
public function test_is_conflicting_permissions_for_upload_seb_file() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
|
||||
// Save file.
|
||||
$xml = file_get_contents(__DIR__ . '/sample_data/unencrypted.seb');
|
||||
$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]);
|
||||
@ -1170,8 +1225,10 @@ class quizaccess_seb_settings_provider_testcase extends quizaccess_seb_testcase
|
||||
* @dataProvider settings_capability_data_provider
|
||||
*/
|
||||
public function test_is_conflicting_permissions_for_configure_manually($settingcapability) {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
|
||||
$this->context = context_module::instance($this->quiz->cmid);
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Base class for tests. All tests should extend it to get common helper methods.
|
||||
* A test helper trait.
|
||||
*
|
||||
* @package quizaccess_seb
|
||||
* @author Andrew Madden <andrewmadden@catalyst-au.net>
|
||||
@ -23,8 +23,6 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace quizaccess_seb\tests\phpunit;
|
||||
|
||||
use quizaccess_seb\access_manager;
|
||||
use quizaccess_seb\settings_provider;
|
||||
|
||||
@ -35,12 +33,12 @@ require_once($CFG->dirroot . "/mod/quiz/accessrule/seb/rule.php"); // Include pl
|
||||
require_once($CFG->dirroot . "/mod/quiz/mod_form.php"); // Include plugin rule class.
|
||||
|
||||
/**
|
||||
* Base class for tests. All tests should extend it to get common helper methods.
|
||||
* A test helper trait. It has some common helper methods.
|
||||
*
|
||||
* @copyright 2020 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class quizaccess_seb_testcase extends \advanced_testcase {
|
||||
trait quizaccess_seb_test_helper_trait {
|
||||
|
||||
/** @var \stdClass $course Test course to contain quiz. */
|
||||
protected $course;
|
||||
@ -51,16 +49,6 @@ abstract class quizaccess_seb_testcase extends \advanced_testcase {
|
||||
/** @var \stdClass $user A test logged-in user. */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a capability to $USER
|
||||
* The function creates a student $USER if $USER->id is empty
|
Loading…
x
Reference in New Issue
Block a user