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 context.
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\context
26
 */
1441 ariadna 27
final class context_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_creation(array $args, array $expectations): void {
1 efrain 38
        if (!$expectations['valid']) {
39
            $this->expectException($expectations['exception']);
40
            $this->expectExceptionMessage($expectations['exceptionmessage']);
41
            context::create(...array_values($args));
42
        } else {
43
            $context = context::create(...array_values($args));
44
            $this->assertEquals($args['deploymentid'], $context->get_deploymentid());
45
            $this->assertEquals($args['contextid'], $context->get_contextid());
46
            $this->assertEquals($args['types'], $context->get_types());
47
            $this->assertEquals($args['id'], $context->get_id());
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
            'Creation of a course section context' => [
58
                'args' => [
59
                    'deploymentid' => 24,
60
                    'contextid' => 'context-123',
61
                    'types' => [
62
                        'http://purl.imsglobal.org/vocab/lis/v2/course#CourseSection'
63
                    ],
64
                    'id' => null
65
                ],
66
                'expectations' => [
67
                    'valid' => true,
68
                ]
69
            ],
70
            'Creation of a course offering context' => [
71
                'args' => [
72
                    'deploymentid' => 24,
73
                    'contextid' => 'context-123',
74
                    'types' => [
75
                        'http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering'
76
                    ],
77
                    'id' => null
78
                ],
79
                'expectations' => [
80
                    'valid' => true,
81
                ]
82
            ],
83
            'Creation of a course template context' => [
84
                'args' => [
85
                    'deploymentid' => 24,
86
                    'contextid' => 'context-123',
87
                    'types' => [
88
                        'http://purl.imsglobal.org/vocab/lis/v2/course#CourseTemplate'
89
                    ],
90
                    'id' => null
91
                ],
92
                'expectations' => [
93
                    'valid' => true,
94
                ]
95
            ],
96
            'Creation of a course group context' => [
97
                'args' => [
98
                    'deploymentid' => 24,
99
                    'contextid' => 'context-123',
100
                    'types' => [
101
                        'http://purl.imsglobal.org/vocab/lis/v2/course#Group'
102
                    ],
103
                    'id' => null
104
                ],
105
                'expectations' => [
106
                    'valid' => true,
107
                ]
108
            ],
109
            'Creation of an invalid context' => [
110
                'args' => [
111
                    'deploymentid' => 24,
112
                    'contextid' => 'context-123',
113
                    'types' => [
114
                        'http://example.com/invalid/context'
115
                    ],
116
                    'id' => null
117
                ],
118
                'expectations' => [
119
                    'valid' => false,
120
                    'exception' => \coding_exception::class,
121
                    'exceptionmessage' => "Cannot set invalid context type 'http://example.com/invalid/context'."
122
                ]
123
            ],
124
            'Creation of a simple name context with type CourseTemplate' => [
125
                'args' => [
126
                    'deploymentid' => 24,
127
                    'contextid' => 'context-123',
128
                    'types' => [
129
                        'CourseTemplate'
130
                    ],
131
                    'id' => null
132
                ],
133
                'expectations' => [
134
                    'valid' => true,
135
                ]
136
            ],
137
            'Creation of a simple name context with type CourseOffering' => [
138
                'args' => [
139
                    'deploymentid' => 24,
140
                    'contextid' => 'context-123',
141
                    'types' => [
142
                        'CourseOffering'
143
                    ],
144
                    'id' => null
145
                ],
146
                'expectations' => [
147
                    'valid' => true,
148
                ]
149
            ],
150
            'Creation of a simple name context with type CourseSection' => [
151
                'args' => [
152
                    'deploymentid' => 24,
153
                    'contextid' => 'context-123',
154
                    'types' => [
155
                        'CourseSection'
156
                    ],
157
                    'id' => null
158
                ],
159
                'expectations' => [
160
                    'valid' => true,
161
                ]
162
            ],
163
            'Creation of a simple name context with type Group' => [
164
                'args' => [
165
                    'deploymentid' => 24,
166
                    'contextid' => 'context-123',
167
                    'types' => [
168
                        'Group'
169
                    ],
170
                    'id' => null
171
                ],
172
                'expectations' => [
173
                    'valid' => true,
174
                ]
175
            ],
176
            'Creation of a context with id' => [
177
                'args' => [
178
                    'deploymentid' => 24,
179
                    'contextid' => 'context-123',
180
                    'types' => [
181
                        'Group'
182
                    ],
183
                    'id' => 24
184
                ],
185
                'expectations' => [
186
                    'valid' => true,
187
                ]
188
            ],
189
            'Creation of a context with invalid id' => [
190
                'args' => [
191
                    'deploymentid' => 24,
192
                    'contextid' => 'context-123',
193
                    'types' => [
194
                        'Group'
195
                    ],
196
                    'id' => 0
197
                ],
198
                'expectations' => [
199
                    'valid' => false,
200
                    'exception' => \coding_exception::class,
201
                    'exceptionmessage' => "id must be a positive int"
202
                ]
203
            ],
204
        ];
205
    }
206
}