Skip to content

Commit

Permalink
MDL-68656 quizaccess_seb: refactor test to use helper trait
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed May 14, 2020
1 parent 355cf68 commit 142a023
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 31 deletions.
8 changes: 6 additions & 2 deletions mod/quiz/accessrule/seb/tests/access_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@

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();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions mod/quiz/accessrule/seb/tests/backup_restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@

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;
Expand All @@ -46,7 +48,11 @@ public function setUp() {
global $USER;

parent::setUp();

$this->resetAfterTest();
$this->setAdminUser();

$this->course = $this->getDataGenerator()->create_course();
$this->template = $this->create_template();
$this->user = $USER;
}
Expand Down
15 changes: 13 additions & 2 deletions mod/quiz/accessrule/seb/tests/event_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@

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.
Expand Down
15 changes: 11 additions & 4 deletions mod/quiz/accessrule/seb/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@

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.
Expand Down Expand Up @@ -79,6 +80,8 @@ public function test_get_seb_file_headers() {
* 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);
Expand All @@ -103,6 +106,8 @@ public function test_can_not_get_config_content_with_invalid_cmid() {
* 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);
Expand All @@ -119,7 +124,7 @@ public function test_can_not_get_config_content_when_user_not_enrolled_in_course
* 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();
Expand All @@ -138,7 +143,7 @@ public function test_can_not_get_config_content_if_config_not_found_for_cmid() {
* 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();

Expand All @@ -158,6 +163,8 @@ public function test_can_not_get_config_content_if_config_empty() {
* Test config content is provided successfully.
*/
public function test_config_provided() {
$this->resetAfterTest();

$this->setAdminUser();

$course = $this->getDataGenerator()->create_course();
Expand Down
11 changes: 9 additions & 2 deletions mod/quiz/accessrule/seb/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@

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();
Expand Down Expand Up @@ -78,6 +83,8 @@ public function test_get_contexts_for_userid() {
* 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();
Expand Down
9 changes: 7 additions & 2 deletions mod/quiz/accessrule/seb/tests/quiz_settings_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@

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;
Expand All @@ -49,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,
Expand Down
16 changes: 14 additions & 2 deletions mod/quiz/accessrule/seb/tests/rule_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,27 @@

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.
Expand Down
Loading

0 comments on commit 142a023

Please sign in to comment.