1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace enrol_lti\local\ltiadvantage\task;
|
|
|
18 |
|
|
|
19 |
use enrol_lti\helper;
|
|
|
20 |
use Packback\Lti1p3\LtiAssignmentsGradesService;
|
|
|
21 |
use Packback\Lti1p3\LtiGrade;
|
|
|
22 |
use Packback\Lti1p3\LtiLineitem;
|
|
|
23 |
|
|
|
24 |
defined('MOODLE_INTERNAL') || die();
|
|
|
25 |
|
|
|
26 |
require_once(__DIR__ . '/../lti_advantage_testcase.php');
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Tests for the enrol_lti\local\ltiadvantage\task\sync_grades scheduled task.
|
|
|
30 |
*
|
|
|
31 |
* @package enrol_lti
|
|
|
32 |
* @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
* @coversDefaultClass \enrol_lti\local\ltiadvantage\task\sync_grades
|
|
|
35 |
*/
|
1441 |
ariadna |
36 |
final class sync_grades_test extends \lti_advantage_testcase {
|
1 |
efrain |
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Test confirming task name.
|
|
|
40 |
*
|
|
|
41 |
* @covers ::get_name
|
|
|
42 |
*/
|
11 |
efrain |
43 |
public function test_get_name(): void {
|
1 |
efrain |
44 |
$this->assertEquals(get_string('tasksyncgrades', 'enrol_lti'), (new sync_grades())->get_name());
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Test grade sync when the resource has syncgrades disabled.
|
|
|
49 |
*
|
|
|
50 |
* @covers ::execute
|
|
|
51 |
*/
|
11 |
efrain |
52 |
public function test_sync_grades_gradesync_disabled(): void {
|
1 |
efrain |
53 |
$this->resetAfterTest();
|
|
|
54 |
[$course, $resource] = $this->create_test_environment(true, true, true, helper::MEMBER_SYNC_ENROL_AND_UNENROL,
|
|
|
55 |
false);
|
|
|
56 |
$launchservice = $this->get_tool_launch_service();
|
|
|
57 |
|
|
|
58 |
// Launch the resource for an instructor which will create the domain objects needed for service calls.
|
|
|
59 |
$teachermocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'], false)[0]);
|
|
|
60 |
$instructoruser = $this->getDataGenerator()->create_user();
|
|
|
61 |
$launchservice->user_launches_tool($instructoruser, $teachermocklaunch);
|
|
|
62 |
|
|
|
63 |
$task = new \enrol_lti\local\ltiadvantage\task\sync_grades();
|
|
|
64 |
$this->expectOutputRegex('/Skipping task - There are no resources with grade sync enabled./');
|
|
|
65 |
$task->execute();
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Test the grade sync task when the auth_lti plugin is disabled.
|
|
|
70 |
*
|
|
|
71 |
* @covers ::execute
|
|
|
72 |
*/
|
11 |
efrain |
73 |
public function test_sync_grades_auth_plugin_disabled(): void {
|
1 |
efrain |
74 |
$this->resetAfterTest();
|
|
|
75 |
[$course, $resource] = $this->create_test_environment(false);
|
|
|
76 |
$launchservice = $this->get_tool_launch_service();
|
|
|
77 |
|
|
|
78 |
// Launch the resource for an instructor which will create the domain objects needed for service calls.
|
|
|
79 |
$teachermocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'], false)[0]);
|
|
|
80 |
$instructoruser = $this->getDataGenerator()->create_user();
|
|
|
81 |
$launchservice->user_launches_tool($instructoruser, $teachermocklaunch);
|
|
|
82 |
|
|
|
83 |
$task = new \enrol_lti\local\ltiadvantage\task\sync_grades();
|
|
|
84 |
$this->expectOutputRegex('/Skipping task - ' .
|
|
|
85 |
get_string('pluginnotenabled', 'auth', get_string('pluginname', 'auth_lti')) . '/');
|
|
|
86 |
$task->execute();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Test the grade sync task when the enrol_lti plugin is disabled.
|
|
|
91 |
*
|
|
|
92 |
* @covers ::execute
|
|
|
93 |
*/
|
11 |
efrain |
94 |
public function test_sync_grades_enrol_plugin_disabled(): void {
|
1 |
efrain |
95 |
$this->resetAfterTest();
|
|
|
96 |
[$course, $resource] = $this->create_test_environment(true, false);
|
|
|
97 |
$launchservice = $this->get_tool_launch_service();
|
|
|
98 |
|
|
|
99 |
// Launch the resource for an instructor which will create the domain objects needed for service calls.
|
|
|
100 |
$teachermocklaunch = $this->get_mock_launch($resource, $this->get_mock_launch_users_with_ids(['1'], false)[0]);
|
|
|
101 |
$instructoruser = $this->getDataGenerator()->create_user();
|
|
|
102 |
$launchservice->user_launches_tool($instructoruser, $teachermocklaunch);
|
|
|
103 |
|
|
|
104 |
$task = new \enrol_lti\local\ltiadvantage\task\sync_grades();
|
|
|
105 |
$this->expectOutputRegex('/Skipping task - ' . get_string('enrolisdisabled', 'enrol_lti') . '/');
|
|
|
106 |
$task->execute();
|
|
|
107 |
}
|
|
|
108 |
}
|