@@ -141,6 +141,101 @@ public function test_glossary_core_calendar_provide_event_action() {
141
141
$ this ->assertTrue ($ actionevent ->is_actionable ());
142
142
}
143
143
144
+ public function test_glossary_core_calendar_provide_event_action_as_non_user () {
145
+ global $ CFG ;
146
+
147
+ $ this ->resetAfterTest ();
148
+ $ this ->setAdminUser ();
149
+
150
+ // Create the activity.
151
+ $ course = $ this ->getDataGenerator ()->create_course ();
152
+ $ glossary = $ this ->getDataGenerator ()->create_module ('glossary ' , array ('course ' => $ course ->id ));
153
+
154
+ // Create a calendar event.
155
+ $ event = $ this ->create_action_event ($ course ->id , $ glossary ->id ,
156
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
157
+
158
+ // Now log out.
159
+ $ CFG ->forcelogin = true ; // We don't want to be logged in as guest, as guest users might still have some capabilities.
160
+ $ this ->setUser ();
161
+
162
+ // Create an action factory.
163
+ $ factory = new \core_calendar \action_factory ();
164
+
165
+ // Decorate action event for the student.
166
+ $ actionevent = mod_glossary_core_calendar_provide_event_action ($ event , $ factory );
167
+
168
+ // Confirm the event is not shown at all.
169
+ $ this ->assertNull ($ actionevent );
170
+ }
171
+
172
+ public function test_glossary_core_calendar_provide_event_action_for_user () {
173
+ global $ CFG ;
174
+
175
+ $ this ->resetAfterTest ();
176
+ $ this ->setAdminUser ();
177
+
178
+ // Create a course.
179
+ $ course = $ this ->getDataGenerator ()->create_course ();
180
+
181
+ // Create a student.
182
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
183
+
184
+ // Create the activity.
185
+ $ glossary = $ this ->getDataGenerator ()->create_module ('glossary ' , array ('course ' => $ course ->id ));
186
+
187
+ // Create a calendar event.
188
+ $ event = $ this ->create_action_event ($ course ->id , $ glossary ->id ,
189
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
190
+
191
+ // Now log out.
192
+ $ CFG ->forcelogin = true ; // We don't want to be logged in as guest, as guest users might still have some capabilities.
193
+ $ this ->setUser ();
194
+
195
+ // Create an action factory.
196
+ $ factory = new \core_calendar \action_factory ();
197
+
198
+ // Decorate action event for the student.
199
+ $ actionevent = mod_glossary_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
200
+
201
+ // Confirm the event was decorated.
202
+ $ this ->assertInstanceOf ('\core_calendar\local\event\value_objects\action ' , $ actionevent );
203
+ $ this ->assertEquals (get_string ('view ' ), $ actionevent ->get_name ());
204
+ $ this ->assertInstanceOf ('moodle_url ' , $ actionevent ->get_url ());
205
+ $ this ->assertEquals (1 , $ actionevent ->get_item_count ());
206
+ $ this ->assertTrue ($ actionevent ->is_actionable ());
207
+ }
208
+
209
+ public function test_glossary_core_calendar_provide_event_action_in_hidden_section () {
210
+ $ this ->resetAfterTest ();
211
+ $ this ->setAdminUser ();
212
+
213
+ // Create a course.
214
+ $ course = $ this ->getDataGenerator ()->create_course ();
215
+
216
+ // Create a student.
217
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
218
+
219
+ // Create the activity.
220
+ $ glossary = $ this ->getDataGenerator ()->create_module ('glossary ' , array ('course ' => $ course ->id ));
221
+
222
+ // Create a calendar event.
223
+ $ event = $ this ->create_action_event ($ course ->id , $ glossary ->id ,
224
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
225
+
226
+ // Set sections 0 as hidden.
227
+ set_section_visible ($ course ->id , 0 , 0 );
228
+
229
+ // Create an action factory.
230
+ $ factory = new \core_calendar \action_factory ();
231
+
232
+ // Decorate action event for the student.
233
+ $ actionevent = mod_glossary_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
234
+
235
+ // Confirm the event is not shown at all.
236
+ $ this ->assertNull ($ actionevent );
237
+ }
238
+
144
239
public function test_glossary_core_calendar_provide_event_action_already_completed () {
145
240
global $ CFG ;
146
241
@@ -175,6 +270,45 @@ public function test_glossary_core_calendar_provide_event_action_already_complet
175
270
$ this ->assertNull ($ actionevent );
176
271
}
177
272
273
+ public function test_glossary_core_calendar_provide_event_action_already_completed_for_user () {
274
+ global $ CFG ;
275
+
276
+ $ this ->resetAfterTest ();
277
+ $ this ->setAdminUser ();
278
+
279
+ $ CFG ->enablecompletion = 1 ;
280
+
281
+ // Create a course.
282
+ $ course = $ this ->getDataGenerator ()->create_course (array ('enablecompletion ' => 1 ));
283
+
284
+ // Create a student.
285
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
286
+
287
+ // Create the activity.
288
+ $ glossary = $ this ->getDataGenerator ()->create_module ('glossary ' , array ('course ' => $ course ->id ),
289
+ array ('completion ' => 2 , 'completionview ' => 1 , 'completionexpected ' => time () + DAYSECS ));
290
+
291
+ // Get some additional data.
292
+ $ cm = get_coursemodule_from_instance ('glossary ' , $ glossary ->id );
293
+
294
+ // Create a calendar event.
295
+ $ event = $ this ->create_action_event ($ course ->id , $ glossary ->id ,
296
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
297
+
298
+ // Mark the activity as completed for the user.
299
+ $ completion = new completion_info ($ course );
300
+ $ completion ->set_module_viewed ($ cm , $ student ->id );
301
+
302
+ // Create an action factory.
303
+ $ factory = new \core_calendar \action_factory ();
304
+
305
+ // Decorate action event.
306
+ $ actionevent = mod_glossary_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
307
+
308
+ // Ensure result was null.
309
+ $ this ->assertNull ($ actionevent );
310
+ }
311
+
178
312
/**
179
313
* Creates an action event.
180
314
*
0 commit comments