Skip to content

Commit

Permalink
MDL-82119 exemptions: CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite committed Aug 14, 2024
1 parent e23294d commit 3a69d94
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 493 deletions.
4 changes: 3 additions & 1 deletion exemptions/classes/local/entity/exemption.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class exemption {
* @param string $itemtype the type of the item being marked as a exemption. E.g. 'course', 'conversation', etc.
* @param int $itemid the id of the item that is being marked as a exemption. e.g course->id, conversation->id, etc.
* @param int $contextid the id of the context in which this exemption was created.
* @param int $userid the id of user who owns this exemption.
* @param string|null $reason the reason for the exemption.
* @param int|null $reasonformat the format of the reason for the exemption.
* @param int|null $usermodified the id of the user who created the exemption.
*/
public function __construct(string $component, string $itemtype, int $itemid, int $contextid,
?string $reason = null, ?int $reasonformat = null, ?int $usermodified = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(string $component, exemption_repository_interface $r
*
* @param string $itemtype the type of the exempt items.
* @param int $itemid the id of the item to which the exemptions relate
* @param \context $context the context of the items which were exempt.
* @param \context|null $context the context of the items which were exempt.
*/
public function delete_exemptions_by_type_and_item(string $itemtype, int $itemid, ?\context $context = null) {
$criteria = ['component' => $this->component, 'itemtype' => $itemtype, 'itemid' => $itemid] +
Expand Down
4 changes: 2 additions & 2 deletions exemptions/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function get_metadata(collection $collection): collection {
* @param \core_privacy\local\request\contextlist $contextlist
* @param int $userid The id of the user in scope.
* @param string $component the frankenstyle component name.
* @param string $itemtype the type of the exempt items.
* @param string|null $itemtype the type of the exempt items.
*/
public static function add_contexts_for_userid(\core_privacy\local\request\contextlist $contextlist,
int $userid, string $component, ?string $itemtype = null) {
Expand All @@ -121,7 +121,7 @@ public static function add_contexts_for_userid(\core_privacy\local\request\conte
* Add users to a userlist who have exemptions within the specified context.
*
* @param \core_privacy\local\request\userlist $userlist The userlist to add the users to.
* @param string $itemtype the type of the exempt items.
* @param string|null $itemtype the type of the exempt items.
* @return void
*/
public static function add_userids_for_context(\core_privacy\local\request\userlist $userlist, ?string $itemtype = null) {
Expand Down
42 changes: 24 additions & 18 deletions exemptions/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions exemptions/tests/repository_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 3a69d94

Please sign in to comment.