forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,28 +14,22 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Privacy tests for core_exemptions. | ||
* | ||
* @package core_exemptions | ||
* @category test | ||
* @author Alexander Van der Bellen <[email protected]> | ||
* @copyright 2018 Jake Dallimore <[email protected]> | ||
* @copyright 2024 Catalyst IT Australia | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @coversDefaultClass \core_exemptions\privacy\provider | ||
*/ | ||
namespace core_exemptions\privacy; | ||
|
||
use core_privacy\tests\provider_testcase; | ||
use core_exemptions\privacy\provider; | ||
use core_privacy\local\request\transform; | ||
|
||
/** | ||
* Unit tests for exemptions/classes/privacy/provider | ||
* Privacy tests for core_exemptions. | ||
* | ||
* @package core_exemptions | ||
* @category test | ||
* @author Alexander Van der Bellen <[email protected]> | ||
* @copyright 2018 Jake Dallimore <[email protected]> | ||
* @copyright 2024 Catalyst IT Australia | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @coversDefaultClass \core_exemptions\privacy\provider | ||
*/ | ||
final class provider_test extends provider_testcase { | ||
|
||
|
@@ -61,9 +55,11 @@ protected function set_up_courses_and_users() { | |
|
||
/** | ||
* Test confirming that contexts of exempt items can be added to the contextlist. | ||
* | ||
* @covers ::add_contexts_for_userid | ||
*/ | ||
public function test_add_contexts_for_userid(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 courses for user1 and 1 course for user2, all at the site context. | ||
$ufservice1 = \core_exemptions\service_factory::get_service_for_user_context($user1context); | ||
|
@@ -93,9 +89,11 @@ public function test_add_contexts_for_userid(): void { | |
|
||
/** | ||
* Test deletion of user exemptions based on an approved_contextlist and component area. | ||
* | ||
* @covers ::delete_exemptions_for_user | ||
*/ | ||
public function test_delete_exemptions_for_user(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 courses for user1 and 1 course for user2, all at the user context. | ||
$ufservice1 = \core_exemptions\service_factory::get_service_for_user_context($user1context); | ||
|
@@ -117,9 +115,11 @@ public function test_delete_exemptions_for_user(): void { | |
|
||
/** | ||
* Test deletion of all exemptions for a specified context, component area and item type. | ||
* | ||
* @covers ::delete_exemptions_for_all_users | ||
*/ | ||
public function test_delete_exemptions_for_all_users(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 course modules for user1 and 1 course module for user2 all in course 1 context. | ||
$ufservice1 = \core_exemptions\service_factory::get_service_for_user_context($user1context); | ||
|
@@ -144,9 +144,11 @@ public function test_delete_exemptions_for_all_users(): void { | |
|
||
/** | ||
* Test confirming that user ID's of exempt items can be added to the userlist. | ||
* | ||
* @covers ::add_userids_for_context | ||
*/ | ||
public function test_add_userids_for_context(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 courses for user1 and 1 course for user2, all at the site context. | ||
$ufservice1 = \core_exemptions\service_factory::get_service_for_user_context($user1context); | ||
|
@@ -189,9 +191,11 @@ public function test_add_userids_for_context(): void { | |
|
||
/** | ||
* Test deletion of user exemptions based on an approved_userlist, component area and item type. | ||
* | ||
* @covers ::delete_exemptions_for_userlist | ||
*/ | ||
public function test_delete_exemptions_for_userlist(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 courses for user1 and 1 course for user2. | ||
$systemcontext = \context_system::instance(); | ||
|
@@ -256,9 +260,11 @@ public function test_delete_exemptions_for_userlist(): void { | |
|
||
/** | ||
* Test fetching the exemptions data for a specified user in a specified component, item type and item ID. | ||
* | ||
* @covers ::get_exemptions_info_for_user | ||
*/ | ||
public function test_get_exemptions_info_for_user(): void { | ||
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users(); | ||
[$user1, $user2, $user1context, $user2context, $course1context, $course2context] = $this->set_up_courses_and_users(); | ||
|
||
// Exempt 2 courses for user1 and 1 course for user2. | ||
$ufservice1 = \core_exemptions\service_factory::get_service_for_user_context($user1context); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
* @copyright 2018 Jake Dallimore <[email protected]> | ||
* @copyright 2024 Catalyst IT Australia | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @covers \core_exemptions\local\repository\exemption_repository | ||
*/ | ||
final class repository_test extends \advanced_testcase { | ||
|
||
|
@@ -54,6 +55,8 @@ protected function setup_users_and_courses() { | |
|
||
/** | ||
* Verify the basic create operation can create records, and is validated. | ||
* | ||
* @covers ::add | ||
*/ | ||
public function test_add(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -95,6 +98,8 @@ public function test_add(): void { | |
|
||
/** | ||
* Tests that incomplete exemptions cannot be saved. | ||
* | ||
* @covers ::add | ||
*/ | ||
public function test_add_incomplete_exemption(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -114,6 +119,11 @@ public function test_add_incomplete_exemption(): void { | |
$exemptionsrepo->add($exemcourse); | ||
} | ||
|
||
/** | ||
* Tests that exemptions can be saved in bulk. | ||
* | ||
* @covers ::add_all | ||
*/ | ||
public function test_add_all_basic(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
||
|
@@ -163,6 +173,8 @@ public function test_add_all_basic(): void { | |
|
||
/** | ||
* Tests reading from the repository by instance id. | ||
* | ||
* @covers ::find | ||
*/ | ||
public function test_find(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -190,6 +202,8 @@ public function test_find(): void { | |
|
||
/** | ||
* Test verifying that find_all() returns all exemptions, or an empty array. | ||
* | ||
* @covers ::find_all | ||
*/ | ||
public function test_find_all(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -227,6 +241,8 @@ public function test_find_all(): void { | |
|
||
/** | ||
* Testing the pagination of the find_all method. | ||
* | ||
* @covers ::find_all | ||
*/ | ||
public function test_find_all_pagination(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -265,6 +281,8 @@ public function test_find_all_pagination(): void { | |
|
||
/** | ||
* Test retrieval of a user's exemptions for a given criteria, in this case, area. | ||
* | ||
* @covers ::find_by | ||
*/ | ||
public function test_find_by(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -311,6 +329,8 @@ public function test_find_by(): void { | |
|
||
/** | ||
* Testing the pagination of the find_by method. | ||
* | ||
* @covers ::find_by | ||
*/ | ||
public function test_find_by_pagination(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -353,6 +373,8 @@ public function test_find_by_pagination(): void { | |
|
||
/** | ||
* Test the count_by() method. | ||
* | ||
* @covers ::count_by | ||
*/ | ||
public function test_count_by(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -382,6 +404,8 @@ public function test_count_by(): void { | |
|
||
/** | ||
* Test the exists() function. | ||
* | ||
* @covers ::exists | ||
*/ | ||
public function test_exists(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -405,6 +429,8 @@ public function test_exists(): void { | |
|
||
/** | ||
* Test the exists_by() method. | ||
* | ||
* @covers ::exists_by | ||
*/ | ||
public function test_exists_by(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -457,6 +483,8 @@ public function test_exists_by(): void { | |
|
||
/** | ||
* Test the update() method, by simulating a user changing the ordering of a exemption. | ||
* | ||
* @covers ::update | ||
*/ | ||
public function test_update(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -479,6 +507,11 @@ public function test_update(): void { | |
$this->assertEquals('1', $exemption1->ordering); | ||
} | ||
|
||
/** | ||
* Test the delete() method. | ||
* | ||
* @covers ::delete | ||
*/ | ||
public function test_delete(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
||
|
@@ -502,6 +535,8 @@ public function test_delete(): void { | |
|
||
/** | ||
* Test the delete_by() method. | ||
* | ||
* @covers ::delete_by | ||
*/ | ||
public function test_delete_by(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -558,6 +593,8 @@ public function test_delete_by(): void { | |
|
||
/** | ||
* Test the find_exemption() method for an existing exemption. | ||
* | ||
* @covers ::find_exemption | ||
*/ | ||
public function test_find_exemption_basic(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
@@ -586,6 +623,8 @@ public function test_find_exemption_basic(): void { | |
|
||
/** | ||
* Test confirming the repository throws an exception in find_exemption if the exemption can't be found. | ||
* | ||
* @covers ::find_exemption | ||
*/ | ||
public function test_find_exemption_nonexistent_exemption(): void { | ||
[$user1context, $user2context, $course1context, $course2context] = $this->setup_users_and_courses(); | ||
|
Oops, something went wrong.