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.
* @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();
}
/**
$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();
* @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.
* @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;
global $USER;
parent::setUp();
+
+ $this->resetAfterTest();
$this->setAdminUser();
+
+ $this->course = $this->getDataGenerator()->create_course();
$this->template = $this->create_template();
$this->user = $USER;
}
$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();
$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();
* 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);
* @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.
* @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.
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'
);
}
* @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.
* @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.
* 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);
* 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);
* 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();
* 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();
* Test config content is provided successfully.
*/
public function test_config_provided() {
+ $this->resetAfterTest();
+
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
* @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;
defined('MOODLE_INTERNAL') || die();
-require_once(__DIR__ . '/base.php');
+require_once(__DIR__ . '/test_helper_trait.php');
/**
* PHPUnit tests for privacy provider.
* @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();
* 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();
* 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);
}
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;
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,
$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]);
$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]);
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.
* @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.
// 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();
// 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();
$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();
$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();
// 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();
// 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()));
* @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.
* @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.
}
}
+
/**
* 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);
* @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);
* 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);
* 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);
* 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);
* 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);
* 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);
* 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);
* 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"
* 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.";
* 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();
* 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);
* 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);
* 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();
* 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();
* 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();
* 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();
* 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();
* 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();
* @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();
* 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();
* 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);
* 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]);
* @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);
// 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>
* @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;
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;
/** @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