Skip to content

Commit

Permalink
provide integration test for sync task.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Aug 12, 2024
1 parent 29e8be8 commit 51e65ea
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 78 deletions.
2 changes: 0 additions & 2 deletions classes/ilios.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
*/
class ilios {



/**
* @var string The API base path.
*/
Expand Down
60 changes: 0 additions & 60 deletions classes/manager.php

This file was deleted.

10 changes: 5 additions & 5 deletions tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Competency data generator.
* The data generator for this plugin.
*
* @package tool_ilioscategoryassignment
* @category test
* @copyright 2015 Frédéric Massart - FMCorz.net
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\invalid_persistent_exception;
use Firebase\JWT\JWT;
use tool_ilioscategoryassignment\sync_job;
Expand All @@ -35,14 +34,15 @@
/**
* Test data generator class for this plugin.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_ilioscategoryassignment_generator extends component_generator_base {

/** @var int Number of created sync jobs. */
protected $syncjobcount = 0;
protected int $syncjobcount = 0;

/**
* Resets internal instance counter.
Expand Down
8 changes: 5 additions & 3 deletions tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Test fixtures generator testcase.
* Tests fixtures generator.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_ilioscategoryassignment;

use advanced_testcase;
use coding_exception;
use Firebase\JWT\JWT;
use moodle_exception;

/**
* Tests the fixture generator for tests.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \tool_ilioscategoryassignment_generator
* @covers \tool_ilioscategoryassignment_generator
*/
final class generator_test extends advanced_testcase {

Expand Down
16 changes: 12 additions & 4 deletions tests/ilios_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Test coverage for the Ilios API client.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_ilioscategoryassignment;

use advanced_testcase;
use core\di;
use core\http_client;
use DateTime;
use Firebase\JWT\JWT;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use moodle_exception;

/**
* Sync task test.
* Tests the Ilios API client.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \tool_ilioscategoryassignment\ilios
* @covers \tool_ilioscategoryassignment\ilios
*/
final class ilios_test extends advanced_testcase {

Expand Down
33 changes: 29 additions & 4 deletions tests/sync_job_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides test coverage for the sync job model.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_ilioscategoryassignment;

use advanced_testcase;
Expand All @@ -23,10 +32,11 @@
/**
* Test case for the sync_job class.
*
* @category test
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \tool_ilioscategoryassignment\sync_job
* @covers \tool_ilioscategoryassignment\sync_job
*/
final class sync_job_test extends advanced_testcase {

Expand Down Expand Up @@ -71,19 +81,34 @@ public function test_before_delete(): void {
$roleid = $dg->create_role();
$user1 = $dg->create_user();
$user2 = $dg->create_user();
$user3 = $dg->create_user();
$syncjob = $lpg->create_sync_job(['coursecatid' => $category->id, 'schoolid' => 1, 'roleid' => $roleid]);

$context = $category->get_context();

// These users have role assignments made by this plugin.
role_assign($roleid, $user1->id, $context->id, 'tool_ilioscategoryassignment');
role_assign($roleid, $user2->id, $context->id, 'tool_ilioscategoryassignment');
// This user is "manually" assigned.
role_assign($roleid, $user3->id, $context->id);

$this->assertTrue(user_has_role_assignment($user1->id, $roleid, $context->id));
$this->assertTrue(user_has_role_assignment($user1->id, $roleid, $context->id));
$this->assertTrue(user_has_role_assignment($user2->id, $roleid, $context->id));
$this->assertTrue(user_has_role_assignment($user3->id, $roleid, $context->id));

$syncjob->delete();

$this->assertFalse(user_has_role_assignment($user1->id, $roleid, $context->id));
$this->assertFalse(user_has_role_assignment($user1->id, $roleid, $context->id));
$this->assertFalse(
user_has_role_assignment($user1->id, $roleid, $context->id),
'The plugin-managed role assignment for user1 has been removed'
);
$this->assertFalse(
user_has_role_assignment($user2->id, $roleid, $context->id),
'The plugin-managed role assignment for user2 has been removed'
);
$this->assertTrue(
user_has_role_assignment($user3->id, $roleid, $context->id),
'The out-of-band managed role assignment for user3 persists.'
);
}
}
Loading

0 comments on commit 51e65ea

Please sign in to comment.