@@ -118,6 +118,91 @@ public function test_folder_core_calendar_provide_event_action() {
118
118
$ this ->assertTrue ($ actionevent ->is_actionable ());
119
119
}
120
120
121
+ public function test_folder_core_calendar_provide_event_action_for_non_user () {
122
+ global $ CFG ;
123
+
124
+ // Create a course.
125
+ $ course = $ this ->getDataGenerator ()->create_course ();
126
+
127
+ // Create the activity.
128
+ $ folder = $ this ->getDataGenerator ()->create_module ('folder ' , array ('course ' => $ course ->id ));
129
+
130
+ // Create a calendar event.
131
+ $ event = $ this ->create_action_event ($ course ->id , $ folder ->id ,
132
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
133
+
134
+ // Now, log out.
135
+ $ CFG ->forcelogin = true ; // We don't want to be logged in as guest, as guest users might still have some capabilities.
136
+ $ this ->setUser ();
137
+
138
+ // Create an action factory.
139
+ $ factory = new \core_calendar \action_factory ();
140
+
141
+ // Decorate action event.
142
+ $ actionevent = mod_folder_core_calendar_provide_event_action ($ event , $ factory );
143
+
144
+ // Confirm the event is not shown at all.
145
+ $ this ->assertNull ($ actionevent );
146
+ }
147
+
148
+ public function test_folder_core_calendar_provide_event_action_in_hidden_section () {
149
+ // Create a course.
150
+ $ course = $ this ->getDataGenerator ()->create_course ();
151
+
152
+ // Create a student.
153
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
154
+
155
+ // Create the activity.
156
+ $ folder = $ this ->getDataGenerator ()->create_module ('folder ' , array ('course ' => $ course ->id ));
157
+
158
+ // Create a calendar event.
159
+ $ event = $ this ->create_action_event ($ course ->id , $ folder ->id ,
160
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
161
+
162
+ // Set sections 0 as hidden.
163
+ set_section_visible ($ course ->id , 0 , 0 );
164
+
165
+ // Create an action factory.
166
+ $ factory = new \core_calendar \action_factory ();
167
+
168
+ // Decorate action event.
169
+ $ actionevent = mod_folder_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
170
+
171
+ // Confirm the event is not shown at all.
172
+ $ this ->assertNull ($ actionevent );
173
+ }
174
+
175
+ public function test_folder_core_calendar_provide_event_action_for_user () {
176
+ // Create a course.
177
+ $ course = $ this ->getDataGenerator ()->create_course ();
178
+
179
+ // Create a student.
180
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
181
+
182
+ // Create the activity.
183
+ $ folder = $ this ->getDataGenerator ()->create_module ('folder ' , array ('course ' => $ course ->id ));
184
+
185
+ // Create a calendar event.
186
+ $ event = $ this ->create_action_event ($ course ->id , $ folder ->id ,
187
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
188
+
189
+ // Now, log out.
190
+ $ this ->setUser ();
191
+
192
+ // Create an action factory.
193
+ $ factory = new \core_calendar \action_factory ();
194
+
195
+ // Decorate action event for the student.
196
+ $ actionevent = mod_folder_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
197
+
198
+ // Confirm the event was decorated.
199
+ $ this ->assertInstanceOf ('\core_calendar\local\event\value_objects\action ' , $ actionevent );
200
+ $ this ->assertEquals (get_string ('view ' ), $ actionevent ->get_name ());
201
+ $ this ->assertInstanceOf ('moodle_url ' , $ actionevent ->get_url ());
202
+ $ this ->assertEquals (1 , $ actionevent ->get_item_count ());
203
+ $ this ->assertTrue ($ actionevent ->is_actionable ());
204
+ }
205
+
121
206
public function test_folder_core_calendar_provide_event_action_already_completed () {
122
207
global $ CFG ;
123
208
@@ -149,6 +234,45 @@ public function test_folder_core_calendar_provide_event_action_already_completed
149
234
$ this ->assertNull ($ actionevent );
150
235
}
151
236
237
+ public function test_folder_core_calendar_provide_event_action_already_completed_for_user () {
238
+ global $ CFG ;
239
+
240
+ $ CFG ->enablecompletion = 1 ;
241
+
242
+ // Create a course.
243
+ $ course = $ this ->getDataGenerator ()->create_course (array ('enablecompletion ' => 1 ));
244
+
245
+ // Create a student.
246
+ $ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
247
+
248
+ // Create the activity.
249
+ $ folder = $ this ->getDataGenerator ()->create_module ('folder ' , array ('course ' => $ course ->id ),
250
+ array ('completion ' => 2 , 'completionview ' => 1 , 'completionexpected ' => time () + DAYSECS ));
251
+
252
+ // Get some additional data.
253
+ $ cm = get_coursemodule_from_instance ('folder ' , $ folder ->id );
254
+
255
+ // Create a calendar event.
256
+ $ event = $ this ->create_action_event ($ course ->id , $ folder ->id ,
257
+ \core_completion \api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED );
258
+
259
+ // Mark the activity as completed for the student.
260
+ $ completion = new completion_info ($ course );
261
+ $ completion ->set_module_viewed ($ cm , $ student ->id );
262
+
263
+ // Now, log out.
264
+ $ this ->setUser ();
265
+
266
+ // Create an action factory.
267
+ $ factory = new \core_calendar \action_factory ();
268
+
269
+ // Decorate action event for the student.
270
+ $ actionevent = mod_folder_core_calendar_provide_event_action ($ event , $ factory , $ student ->id );
271
+
272
+ // Ensure result was null.
273
+ $ this ->assertNull ($ actionevent );
274
+ }
275
+
152
276
/**
153
277
* Creates an action event.
154
278
*
0 commit comments