@@ -160,6 +160,63 @@ public function test_book_core_calendar_provide_event_action() {
160
160
$ this ->assertTrue ($ actionevent ->is_actionable ());
161
161
}
162
162
163
+ public function test_book_core_calendar_provide_event_action_in_hidden_section () {
164
+ // Create the activity.
165
+ $ course = $ this ->getDataGenerator ()->create_course ();
166
+ $ book = $ this ->getDataGenerator ()->create_module ('book ' , array ('course ' => $ course ->id ));
167
+
168
+ // Enrol a student in the course.
169
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
170
+
171
+ // Create a calendar event.
172
+ $ event = $ this ->create_action_event ($ course ->id , $ book ->id ,
173
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
174
+
175
+ // Set sections 0 as hidden.
176
+ set_section_visible ($ course ->id , 0 , 0 );
177
+
178
+ // Now, log out.
179
+ $ this ->setUser ();
180
+
181
+ // Create an action factory.
182
+ $ factory = new \core_calendar \action_factory ();
183
+
184
+ // Decorate action event for the student.
185
+ $ actionevent = mod_book_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
186
+
187
+ // Confirm the event is not shown at all.
188
+ $ this ->assertNull ($ actionevent );
189
+ }
190
+
191
+ public function test_book_core_calendar_provide_event_action_for_user () {
192
+ // Create the activity.
193
+ $ course = $ this ->getDataGenerator ()->create_course ();
194
+ $ book = $ this ->getDataGenerator ()->create_module ('book ' , array ('course ' => $ course ->id ));
195
+
196
+ // Enrol a student in the course.
197
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
198
+
199
+ // Create a calendar event.
200
+ $ event = $ this ->create_action_event ($ course ->id , $ book ->id ,
201
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
202
+
203
+ // Now, log out.
204
+ $ this ->setUser ();
205
+
206
+ // Create an action factory.
207
+ $ factory = new \core_calendar \action_factory ();
208
+
209
+ // Decorate action event for the student.
210
+ $ actionevent = mod_book_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
211
+
212
+ // Confirm the event was decorated.
213
+ $ this ->assertInstanceOf ('\core_calendar\local\event\value_objects\action ' , $ actionevent );
214
+ $ this ->assertEquals (get_string ('view ' ), $ actionevent ->get_name ());
215
+ $ this ->assertInstanceOf ('moodle_url ' , $ actionevent ->get_url ());
216
+ $ this ->assertEquals (1 , $ actionevent ->get_item_count ());
217
+ $ this ->assertTrue ($ actionevent ->is_actionable ());
218
+ }
219
+
163
220
public function test_book_core_calendar_provide_event_action_as_non_user () {
164
221
global $ CFG ;
165
222
@@ -216,6 +273,40 @@ public function test_book_core_calendar_provide_event_action_already_completed()
216
273
$ this ->assertNull ($ actionevent );
217
274
}
218
275
276
+ public function test_book_core_calendar_provide_event_action_already_completed_for_user () {
277
+ global $ CFG ;
278
+
279
+ $ CFG ->enablecompletion = 1 ;
280
+
281
+ // Create the activity.
282
+ $ course = $ this ->getDataGenerator ()->create_course (array ('enablecompletion ' => 1 ));
283
+ $ book = $ this ->getDataGenerator ()->create_module ('book ' , array ('course ' => $ course ->id ),
284
+ array ('completion ' => 2 , 'completionview ' => 1 , 'completionexpected ' => time () + DAYSECS ));
285
+
286
+ // Enrol a student in the course.
287
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
288
+
289
+ // Get some additional data.
290
+ $ cm = get_coursemodule_from_instance ('book ' , $ book ->id );
291
+
292
+ // Create a calendar event.
293
+ $ event = $ this ->create_action_event ($ course ->id , $ book ->id ,
294
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
295
+
296
+ // Mark the activity as completed for the student.
297
+ $ completion = new completion_info ($ course );
298
+ $ completion ->set_module_viewed ($ cm , $ student ->id );
299
+
300
+ // Create an action factory.
301
+ $ factory = new \core_calendar \action_factory ();
302
+
303
+ // Decorate action event for the student.
304
+ $ actionevent = mod_book_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
305
+
306
+ // Ensure result was null.
307
+ $ this ->assertNull ($ actionevent );
308
+ }
309
+
219
310
/**
220
311
* Creates an action event.
221
312
*
0 commit comments