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\entity;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Tests for nrps_info.
|
|
|
21 |
*
|
|
|
22 |
* @package enrol_lti
|
|
|
23 |
* @copyright 2021 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
* @coversDefaultClass \enrol_lti\local\ltiadvantage\entity\nrps_info
|
|
|
26 |
*/
|
1441 |
ariadna |
27 |
final class nrps_info_test extends \advanced_testcase {
|
1 |
efrain |
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Test creation of the object instances.
|
|
|
31 |
*
|
|
|
32 |
* @dataProvider instantiation_data_provider
|
|
|
33 |
* @param array $args the arguments to the creation method.
|
|
|
34 |
* @param array $expectations various expectations for the test cases.
|
|
|
35 |
* @covers ::create
|
|
|
36 |
*/
|
11 |
efrain |
37 |
public function test_create(array $args, array $expectations): void {
|
1 |
efrain |
38 |
if (!$expectations['valid']) {
|
|
|
39 |
$this->expectException($expectations['exception']);
|
|
|
40 |
$this->expectExceptionMessage($expectations['exceptionmessage']);
|
|
|
41 |
nrps_info::create(...array_values($args));
|
|
|
42 |
} else {
|
|
|
43 |
$nrpsinfo = nrps_info::create(...array_values($args));
|
|
|
44 |
$this->assertEquals($args['contextmembershipsurl'], $nrpsinfo->get_context_memberships_url());
|
|
|
45 |
$this->assertEquals($expectations['serviceversions'], $nrpsinfo->get_service_versions());
|
|
|
46 |
$this->assertEquals('https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly',
|
|
|
47 |
$nrpsinfo->get_service_scope());
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Data provider for testing object instantiation.
|
|
|
53 |
* @return array the data for testing.
|
|
|
54 |
*/
|
1441 |
ariadna |
55 |
public static function instantiation_data_provider(): array {
|
1 |
efrain |
56 |
return [
|
|
|
57 |
'Valid creation' => [
|
|
|
58 |
'args' => [
|
|
|
59 |
'contextmembershipsurl' => new \moodle_url('https://lms.example.com/45/memberships'),
|
|
|
60 |
'serviceversions' => ['1.0', '2.0'],
|
|
|
61 |
],
|
|
|
62 |
'expectations' => [
|
|
|
63 |
'valid' => true,
|
|
|
64 |
'serviceversions' => ['1.0', '2.0']
|
|
|
65 |
]
|
|
|
66 |
],
|
|
|
67 |
'Missing service version' => [
|
|
|
68 |
'args' => [
|
|
|
69 |
'contextmembershipsurl' => new \moodle_url('https://lms.example.com/45/memberships'),
|
|
|
70 |
'serviceversions' => [],
|
|
|
71 |
],
|
|
|
72 |
'expectations' => [
|
|
|
73 |
'valid' => false,
|
|
|
74 |
'exception' => \coding_exception::class,
|
|
|
75 |
'exceptionmessage' => 'Service versions array cannot be empty'
|
|
|
76 |
]
|
|
|
77 |
],
|
|
|
78 |
'Invalid service version' => [
|
|
|
79 |
'args' => [
|
|
|
80 |
'contextmembershipsurl' => new \moodle_url('https://lms.example.com/45/memberships'),
|
|
|
81 |
'serviceversions' => ['1.1'],
|
|
|
82 |
],
|
|
|
83 |
'expectations' => [
|
|
|
84 |
'valid' => false,
|
|
|
85 |
'exception' => \coding_exception::class,
|
|
|
86 |
'exceptionmessage' => "Invalid Names and Roles service version '1.1'"
|
|
|
87 |
]
|
|
|
88 |
],
|
|
|
89 |
'Duplicate service version' => [
|
|
|
90 |
'args' => [
|
|
|
91 |
'contextmembershipsurl' => new \moodle_url('https://lms.example.com/45/memberships'),
|
|
|
92 |
'serviceversions' => ['1.0', '1.0'],
|
|
|
93 |
],
|
|
|
94 |
'expectations' => [
|
|
|
95 |
'valid' => true,
|
|
|
96 |
'serviceversions' => ['1.0']
|
|
|
97 |
]
|
|
|
98 |
]
|
|
|
99 |
];
|
|
|
100 |
}
|
1441 |
ariadna |
101 |
|
|
|
102 |
/**
|
|
|
103 |
* Verify that the contextmembershipurl property can be gotten and is immutable.
|
|
|
104 |
*
|
|
|
105 |
* @covers ::get_context_memberships_url
|
|
|
106 |
*/
|
|
|
107 |
public function test_get_context_memberships_url(): void {
|
|
|
108 |
$nrpsendpoint = 'https://lms.example.com/45/memberships';
|
|
|
109 |
$nrpsinfo = nrps_info::create(new \moodle_url($nrpsendpoint));
|
|
|
110 |
$membershipsurlcopy = $nrpsinfo->get_context_memberships_url();
|
|
|
111 |
$this->assertEquals($nrpsendpoint, $membershipsurlcopy->out(false));
|
|
|
112 |
$rlid = '01234567-1234-5678-90ab-123456789abc';
|
|
|
113 |
$membershipsurlcopy->param('rlid', $rlid);
|
|
|
114 |
$this->assertEquals($nrpsendpoint . '?rlid=' . $rlid, $membershipsurlcopy->out(false));
|
|
|
115 |
$this->assertEquals($nrpsendpoint, $nrpsinfo->get_context_memberships_url()->out(false));
|
|
|
116 |
}
|
|
|
117 |
|
1 |
efrain |
118 |
}
|