Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 ags_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\ags_info
26
 */
1441 ariadna 27
final class ags_info_test extends \advanced_testcase {
1 efrain 28
 
29
    /**
30
     * Test creation of the object instances.
31
     * @dataProvider instantiation_data_provider
32
     * @param array $args the arguments to the creation method.
33
     * @param array $expectations various expectations for the test cases.
34
     * @covers ::create
35
     */
11 efrain 36
    public function test_creation(array $args, array $expectations): void {
1 efrain 37
        if (!$expectations['valid']) {
38
            $this->expectException($expectations['exception']);
39
            $this->expectExceptionMessage($expectations['exceptionmessage']);
40
            ags_info::create(...array_values($args));
41
        } else {
42
            $agsinfo = ags_info::create(...array_values($args));
43
            $this->assertEquals($args['lineitemsurl'], $agsinfo->get_lineitemsurl());
44
            $this->assertEquals($args['lineitemurl'], $agsinfo->get_lineitemurl());
45
            if (isset($expectations['scopes'])) {
46
                $this->assertEquals($expectations['scopes'], $agsinfo->get_scopes());
47
            } else {
48
                $this->assertEquals($args['scopes'], $agsinfo->get_scopes());
49
            }
50
 
51
            $this->assertEquals($expectations['lineitemscope'], $agsinfo->get_lineitemscope());
52
            $this->assertEquals($expectations['scorescope'], $agsinfo->get_scorescope());
53
            $this->assertEquals($expectations['resultscope'], $agsinfo->get_resultscope());
54
        }
55
    }
56
 
57
    /**
58
     * Data provider for testing object instantiation.
59
     * @return array the data for testing.
60
     */
1441 ariadna 61
    public static function instantiation_data_provider(): array {
1 efrain 62
        return [
63
            'Both lineitems and lineitem URL provided with full list of valid scopes' => [
64
                'args' => [
65
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
66
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
67
                    'scopes' => [
68
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
69
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
70
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
71
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
72
                    ]
73
                ],
74
                'expectations' => [
75
                    'valid' => true,
76
                    'lineitemscope' => [
77
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
78
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly'
79
                    ],
80
                    'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
81
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score'
82
                ]
83
            ],
84
            'Both lineitems and lineitem URL provided with lineitem scopes only' => [
85
                'args' => [
86
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
87
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
88
                    'scopes' => [
89
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
90
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
91
                    ]
92
                ],
93
                'expectations' => [
94
                    'valid' => true,
95
                    'lineitemscope' => [
96
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
97
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
98
                    ],
99
                    'scorescope' => null,
100
                    'resultscope' => null
101
                ]
102
            ],
103
            'Both lineitems and lineitem URL provided with score scope only' => [
104
                'args' => [
105
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
106
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
107
                    'scopes' => [
108
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
109
                    ]
110
                ],
111
                'expectations' => [
112
                    'valid' => true,
113
                    'lineitemscope' => null,
114
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score',
115
                    'resultscope' => null
116
                ]
117
            ],
118
            'Both lineitems and lineitem URL provided with result scope only' => [
119
                'args' => [
120
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
121
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
122
                    'scopes' => [
123
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'
124
                    ]
125
                ],
126
                'expectations' => [
127
                    'valid' => true,
128
                    'lineitemscope' => null,
129
                    'scorescope' => null,
130
                    'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'
131
                ]
132
            ],
133
            'Both lineitems and lineitem URL provided with no scopes' => [
134
                'args' => [
135
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
136
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
137
                    'scopes' => []
138
                ],
139
                'expectations' => [
140
                    'valid' => true,
141
                    'lineitemscope' => null,
142
                    'scorescope' => null,
143
                    'resultscope' => null
144
                ]
145
            ],
146
            'Just lineitems URL, no lineitem URL, with full list of valid scopes' => [
147
                'args' => [
148
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
149
                    'lineitemurl' => null,
150
                    'scopes' => [
151
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
152
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
153
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
154
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
155
                    ]
156
                ],
157
                'expectations' => [
158
                    'valid' => true,
159
                    'lineitemscope' => [
160
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
161
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly'
162
                    ],
163
                    'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
164
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score'
165
                ]
166
            ],
167
            'Just lineitems URL, no lineitem URL, with lineitems scopes only' => [
168
                'args' => [
169
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
170
                    'lineitemurl' => null,
171
                    'scopes' => [
172
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
173
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
174
                    ]
175
                ],
176
                'expectations' => [
177
                    'valid' => true,
178
                    'lineitemscope' => [
179
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
180
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
181
                    ],
182
                    'scorescope' => null,
183
                    'resultscope' => null
184
                ]
185
            ],
186
            'Just lineitems URL, no lineitem URL, with score scope only' => [
187
                'args' => [
188
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
189
                    'lineitemurl' => null,
190
                    'scopes' => [
191
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
192
                    ]
193
                ],
194
                'expectations' => [
195
                    'valid' => true,
196
                    'lineitemscope' => null,
197
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score',
198
                    'resultscope' => null
199
                ]
200
            ],
201
            'Just lineitems URL, no lineitem URL, with result scope only' => [
202
                'args' => [
203
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
204
                    'lineitemurl' => null,
205
                    'scopes' => [
206
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'
207
                    ]
208
                ],
209
                'expectations' => [
210
                    'valid' => true,
211
                    'lineitemscope' => null,
212
                    'scorescope' => null,
213
                    'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'
214
                ]
215
            ],
216
            'Just lineitems URL, no lineitem URL, with no scopes' => [
217
                'args' => [
218
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
219
                    'lineitemurl' => null,
220
                    'scopes' => []
221
                ],
222
                'expectations' => [
223
                    'valid' => true,
224
                    'lineitemscope' => null,
225
                    'scorescope' => null,
226
                    'resultscope' => null
227
                ]
228
            ],
229
            'Both lineitems and lineitem URL provided with non-string scope' => [
230
                'args' => [
231
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
232
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
233
                    'scopes' => [
234
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
235
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
236
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
237
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score',
238
                        12345
239
                    ]
240
                ],
241
                'expectations' => [
242
                    'valid' => false,
243
                    'exception' => \coding_exception::class,
244
                    'exceptionmessage' => 'Scope must be a string value'
245
                ]
246
            ],
247
            'Both lineitems and lineitem URL provided with unsupported scopes' => [
248
                'args' => [
249
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
250
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
251
                    'scopes' => [
252
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
253
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
254
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
255
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score',
256
                        'https://example.com/unsupported/scope'
257
                    ]
258
                ],
259
                'expectations' => [
260
                    'valid' => true,
261
                    'scopes' => [
262
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
263
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
264
                        'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
265
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score',
266
                    ],
267
                    'lineitemscope' => [
268
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
269
                        'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly'
270
                    ],
271
                    'resultscope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly',
272
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score'
273
                ]
274
            ],
275
            'Both lineitems and lineitem URL provided with invalid scope types' => [
276
                'args' => [
277
                    'lineitemsurl' => new \moodle_url('https://platform.example.org/10/lineitems'),
278
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
279
                    'scopes' => [
280
                        12
281
                    ]
282
                ],
283
                'expectations' => [
284
                    'valid' => false,
285
                    'exception' => \coding_exception::class,
286
                    'exceptionmessage' => "Scope must be a string value"
287
                ]
288
            ],
289
            'Claim contains a single lineitem URL only with valid scopes' => [
290
                'args' => [
291
                    'lineitemsurl' => null,
292
                    'lineitemurl' => new \moodle_url('https://platform.example.org/10/lineitems/4/lineitem'),
293
                    'scopes' => [
294
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
295
                    ]
296
                ],
297
                'expectations' => [
298
                    'valid' => true,
299
                    'lineitemscope' => null,
300
                    'scorescope' => 'https://purl.imsglobal.org/spec/lti-ags/scope/score',
301
                    'resultscope' => null
302
                ]
303
            ],
304
            'Claim contains no lineitems URL or lineitem URL' => [
305
                'args' => [
306
                    'lineitemsurl' => null,
307
                    'lineitemurl' => null,
308
                    'scopes' => [
309
                        'https://purl.imsglobal.org/spec/lti-ags/scope/score'
310
                    ]
311
                ],
312
                'expectations' => [
313
                    'valid' => false,
314
                    'exception' => \coding_exception::class,
315
                    'exceptionmessage' => "Missing lineitem or lineitems URL"
316
                ]
317
            ],
318
        ];
319
    }
320
}