MDL-57503 calendar: add api function for action events by course
[moodle.git] / calendar / tests / api_test.php
CommitLineData
3607961d
DP
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/**
12cbce0a 18 * Contains the class containing unit tests for the calendar API.
3607961d
DP
19 *
20 * @package core_calendar
12cbce0a 21 * @copyright 2017 Mark Nelson <markn@moodle.com>
3607961d
DP
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
3607961d 26
1575194a
RW
27require_once(__DIR__ . '/helpers.php');
28
29use \core_calendar\api;
30
3607961d 31/**
12cbce0a 32 * Class contaning unit tests for the calendar API.
3607961d
DP
33 *
34 * @package core_calendar
12cbce0a 35 * @copyright 2017 Mark Nelson <markn@moodle.com>
3607961d
DP
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
12cbce0a 38class core_calendar_api_testcase extends advanced_testcase {
3607961d 39
12cbce0a
MN
40 /**
41 * Tests set up
42 */
b8ad1728 43 protected function setUp() {
12cbce0a 44 $this->resetAfterTest();
b8ad1728 45 }
3607961d 46
12cbce0a 47 public function test_get_course_cached() {
3607961d
DP
48 // Setup some test courses.
49 $course1 = $this->getDataGenerator()->create_course();
50 $course2 = $this->getDataGenerator()->create_course();
51 $course3 = $this->getDataGenerator()->create_course();
52
53 // Load courses into cache.
54 $coursecache = null;
12cbce0a
MN
55 \core_calendar\api::get_course_cached($coursecache, $course1->id);
56 \core_calendar\api::get_course_cached($coursecache, $course2->id);
57 \core_calendar\api::get_course_cached($coursecache, $course3->id);
3607961d
DP
58
59 // Verify the cache.
60 $this->assertArrayHasKey($course1->id, $coursecache);
61 $cachedcourse1 = $coursecache[$course1->id];
62 $this->assertEquals($course1->id, $cachedcourse1->id);
63 $this->assertEquals($course1->shortname, $cachedcourse1->shortname);
64 $this->assertEquals($course1->fullname, $cachedcourse1->fullname);
65
66 $this->assertArrayHasKey($course2->id, $coursecache);
67 $cachedcourse2 = $coursecache[$course2->id];
68 $this->assertEquals($course2->id, $cachedcourse2->id);
69 $this->assertEquals($course2->shortname, $cachedcourse2->shortname);
70 $this->assertEquals($course2->fullname, $cachedcourse2->fullname);
71
72 $this->assertArrayHasKey($course3->id, $coursecache);
73 $cachedcourse3 = $coursecache[$course3->id];
74 $this->assertEquals($course3->id, $cachedcourse3->id);
75 $this->assertEquals($course3->shortname, $cachedcourse3->shortname);
76 $this->assertEquals($course3->fullname, $cachedcourse3->fullname);
77 }
b8ad1728
JPG
78
79 /**
12cbce0a 80 * Test that the get_events() function only returns activity events that are enabled.
b8ad1728 81 */
12cbce0a 82 public function test_get_events_with_disabled_module() {
cbbca0d0
AG
83 global $DB;
84
f52459bb
JP
85 $generator = $this->getDataGenerator();
86 $course = $generator->create_course();
87 $student = $generator->create_user();
88 $generator->enrol_user($student->id, $course->id, 'student');
89 $this->setUser($student);
f52459bb
JP
90 $events = [
91 [
92 'name' => 'Start of assignment',
93 'description' => '',
94 'format' => 1,
95 'courseid' => $course->id,
96 'groupid' => 0,
97 'userid' => 2,
98 'modulename' => 'assign',
99 'instance' => 1,
100 'eventtype' => 'due',
101 'timestart' => time(),
102 'timeduration' => 86400,
103 'visible' => 1
104 ], [
f52459bb
JP
105 'name' => 'Start of lesson',
106 'description' => '',
107 'format' => 1,
108 'courseid' => $course->id,
109 'groupid' => 0,
110 'userid' => 2,
111 'modulename' => 'lesson',
112 'instance' => 1,
113 'eventtype' => 'end',
114 'timestart' => time(),
115 'timeduration' => 86400,
116 'visible' => 1
117 ]
118 ];
cbbca0d0 119 foreach ($events as $event) {
e057f279 120 \core_calendar\event::create($event, false);
cbbca0d0 121 }
cbbca0d0
AG
122 $timestart = time() - 60;
123 $timeend = time() + 60;
cbbca0d0 124 // Get all events.
12cbce0a 125 $events = \core_calendar\api::get_events($timestart, $timeend, true, 0, true);
cbbca0d0 126 $this->assertCount(2, $events);
cbbca0d0
AG
127 // Disable the lesson module.
128 $modulerecord = $DB->get_record('modules', ['name' => 'lesson']);
129 $modulerecord->visible = 0;
130 $DB->update_record('modules', $modulerecord);
cbbca0d0 131 // Check that we only return the assign event.
12cbce0a 132 $events = \core_calendar\api::get_events($timestart, $timeend, true, 0, true);
cbbca0d0
AG
133 $this->assertCount(1, $events);
134 $event = reset($events);
135 $this->assertEquals('assign', $event->modulename);
136 }
f52459bb
JP
137
138 /**
139 * Test for calendar_get_events() when there are user and group overrides.
140 */
141 public function test_calendar_get_events_with_overrides() {
142 global $DB;
f52459bb
JP
143 $generator = $this->getDataGenerator();
144 $course = $generator->create_course();
145 $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
146 if (!isset($params['course'])) {
147 $params['course'] = $course->id;
148 }
149 $instance = $plugingenerator->create_instance($params);
f52459bb
JP
150 // Create users.
151 $useroverridestudent = $generator->create_user();
152 $group1student = $generator->create_user();
153 $group2student = $generator->create_user();
154 $group12student = $generator->create_user();
155 $nogroupstudent = $generator->create_user();
f52459bb
JP
156 // Enrol users.
157 $generator->enrol_user($useroverridestudent->id, $course->id, 'student');
158 $generator->enrol_user($group1student->id, $course->id, 'student');
159 $generator->enrol_user($group2student->id, $course->id, 'student');
160 $generator->enrol_user($group12student->id, $course->id, 'student');
161 $generator->enrol_user($nogroupstudent->id, $course->id, 'student');
f52459bb
JP
162 // Create groups.
163 $group1 = $generator->create_group(['courseid' => $course->id]);
164 $group2 = $generator->create_group(['courseid' => $course->id]);
f52459bb
JP
165 // Add members to groups.
166 $generator->create_group_member(['groupid' => $group1->id, 'userid' => $group1student->id]);
167 $generator->create_group_member(['groupid' => $group2->id, 'userid' => $group2student->id]);
168 $generator->create_group_member(['groupid' => $group1->id, 'userid' => $group12student->id]);
169 $generator->create_group_member(['groupid' => $group2->id, 'userid' => $group12student->id]);
f52459bb
JP
170 $now = time();
171 // Events with the same module name, instance and event type.
172 $events = [
173 [
174 'name' => 'Assignment 1 due date',
175 'description' => '',
176 'format' => 0,
177 'courseid' => $course->id,
178 'groupid' => 0,
179 'userid' => 2,
180 'modulename' => 'assign',
181 'instance' => $instance->id,
182 'eventtype' => 'due',
183 'timestart' => $now,
184 'timeduration' => 0,
185 'visible' => 1
186 ], [
187 'name' => 'Assignment 1 due date - User override',
188 'description' => '',
189 'format' => 1,
190 'courseid' => 0,
191 'groupid' => 0,
192 'userid' => $useroverridestudent->id,
193 'modulename' => 'assign',
194 'instance' => $instance->id,
195 'eventtype' => 'due',
196 'timestart' => $now + 86400,
197 'timeduration' => 0,
198 'visible' => 1,
199 'priority' => CALENDAR_EVENT_USER_OVERRIDE_PRIORITY
200 ], [
201 'name' => 'Assignment 1 due date - Group A override',
202 'description' => '',
203 'format' => 1,
204 'courseid' => $course->id,
205 'groupid' => $group1->id,
206 'userid' => 2,
207 'modulename' => 'assign',
208 'instance' => $instance->id,
209 'eventtype' => 'due',
210 'timestart' => $now + (2 * 86400),
211 'timeduration' => 0,
212 'visible' => 1,
213 'priority' => 1,
214 ], [
215 'name' => 'Assignment 1 due date - Group B override',
216 'description' => '',
217 'format' => 1,
218 'courseid' => $course->id,
219 'groupid' => $group2->id,
220 'userid' => 2,
221 'modulename' => 'assign',
222 'instance' => $instance->id,
223 'eventtype' => 'due',
224 'timestart' => $now + (3 * 86400),
225 'timeduration' => 0,
226 'visible' => 1,
227 'priority' => 2,
228 ],
229 ];
f52459bb 230 foreach ($events as $event) {
12cbce0a 231 \core_calendar\event::create($event, false);
f52459bb 232 }
f52459bb
JP
233 $timestart = $now - 100;
234 $timeend = $now + (3 * 86400);
f52459bb 235 $groups = [$group1->id, $group2->id];
f52459bb
JP
236 // Get user override events.
237 $this->setUser($useroverridestudent);
12cbce0a 238 $events = \core_calendar\api::get_events($timestart, $timeend, $useroverridestudent->id, $groups, $course->id);
f52459bb
JP
239 $this->assertCount(1, $events);
240 $event = reset($events);
241 $this->assertEquals('Assignment 1 due date - User override', $event->name);
f52459bb 242 // Get event for user with override but with the timestart and timeend parameters only covering the original event.
12cbce0a 243 $events = \core_calendar\api::get_events($timestart, $now, $useroverridestudent->id, $groups, $course->id);
f52459bb 244 $this->assertCount(0, $events);
f52459bb
JP
245 // Get events for user that does not belong to any group and has no user override events.
246 $this->setUser($nogroupstudent);
12cbce0a 247 $events = \core_calendar\api::get_events($timestart, $timeend, $nogroupstudent->id, $groups, $course->id);
f52459bb
JP
248 $this->assertCount(1, $events);
249 $event = reset($events);
250 $this->assertEquals('Assignment 1 due date', $event->name);
f52459bb
JP
251 // Get events for user that belongs to groups A and B and has no user override events.
252 $this->setUser($group12student);
12cbce0a 253 $events = \core_calendar\api::get_events($timestart, $timeend, $group12student->id, $groups, $course->id);
f52459bb
JP
254 $this->assertCount(1, $events);
255 $event = reset($events);
256 $this->assertEquals('Assignment 1 due date - Group B override', $event->name);
f52459bb
JP
257 // Get events for user that belongs to group A and has no user override events.
258 $this->setUser($group1student);
12cbce0a 259 $events = \core_calendar\api::get_events($timestart, $timeend, $group1student->id, $groups, $course->id);
f52459bb
JP
260 $this->assertCount(1, $events);
261 $event = reset($events);
262 $this->assertEquals('Assignment 1 due date - Group A override', $event->name);
f52459bb
JP
263 // Add repeating events.
264 $repeatingevents = [
265 [
266 'name' => 'Repeating site event',
267 'description' => '',
268 'format' => 1,
269 'courseid' => SITEID,
270 'groupid' => 0,
271 'userid' => 2,
272 'repeatid' => 1,
273 'modulename' => '0',
274 'instance' => 0,
275 'eventtype' => 'site',
276 'timestart' => $now + 86400,
277 'timeduration' => 0,
278 'visible' => 1,
279 ],
280 [
281 'name' => 'Repeating site event',
282 'description' => '',
283 'format' => 1,
284 'courseid' => SITEID,
285 'groupid' => 0,
286 'userid' => 2,
287 'repeatid' => 1,
288 'modulename' => '0',
289 'instance' => 0,
290 'eventtype' => 'site',
291 'timestart' => $now + (2 * 86400),
292 'timeduration' => 0,
293 'visible' => 1,
294 ],
295 ];
296 foreach ($repeatingevents as $event) {
12cbce0a 297 \core_calendar\event::create($event, false);
f52459bb 298 }
f52459bb 299 // Make sure repeating events are not filtered out.
12cbce0a 300 $events = \core_calendar\api::get_events($timestart, $timeend, true, true, true);
f52459bb
JP
301 $this->assertCount(3, $events);
302 }
12cbce0a
MN
303
304 /**
305 * Test the update_subscription() function.
306 */
307 public function test_update_subscription() {
308 $this->resetAfterTest(true);
309
310 $subscription = new stdClass();
311 $subscription->eventtype = 'site';
312 $subscription->name = 'test';
313 $id = \core_calendar\api::add_subscription($subscription);
314
315 $subscription = \core_calendar\api::get_subscription($id);
316 $subscription->name = 'awesome';
317 \core_calendar\api::update_subscription($subscription);
318 $sub = \core_calendar\api::get_subscription($id);
319 $this->assertEquals($subscription->name, $sub->name);
320
321 $subscription = \core_calendar\api::get_subscription($id);
322 $subscription->name = 'awesome2';
323 $subscription->pollinterval = 604800;
324 \core_calendar\api::update_subscription($subscription);
325 $sub = \core_calendar\api::get_subscription($id);
326 $this->assertEquals($subscription->name, $sub->name);
327 $this->assertEquals($subscription->pollinterval, $sub->pollinterval);
328
329 $subscription = new stdClass();
330 $subscription->name = 'awesome4';
331 $this->expectException('coding_exception');
332 \core_calendar\api::update_subscription($subscription);
333 }
334
335 public function test_add_subscription() {
336 global $DB, $CFG;
337
338 require_once($CFG->dirroot . '/lib/bennu/bennu.inc.php');
339
340 $this->resetAfterTest(true);
341
342 // Test for Microsoft Outlook 2010.
343 $subscription = new stdClass();
344 $subscription->name = 'Microsoft Outlook 2010';
345 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
346 $subscription->eventtype = 'site';
347 $id = \core_calendar\api::add_subscription($subscription);
348
349 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
350 $ical = new iCalendar();
351 $ical->unserialize($calendar);
352 $this->assertEquals($ical->parser_errors, array());
353
354 $sub = \core_calendar\api::get_subscription($id);
355 \core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
356 $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
357 $this->assertEquals($count, 1);
358
359 // Test for OSX Yosemite.
360 $subscription = new stdClass();
361 $subscription->name = 'OSX Yosemite';
362 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
363 $subscription->eventtype = 'site';
364 $id = \core_calendar\api::add_subscription($subscription);
365
366 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
367 $ical = new iCalendar();
368 $ical->unserialize($calendar);
369 $this->assertEquals($ical->parser_errors, array());
370
371 $sub = \core_calendar\api::get_subscription($id);
372 \core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
373 $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
374 $this->assertEquals($count, 1);
375
376 // Test for Google Gmail.
377 $subscription = new stdClass();
378 $subscription->name = 'Google Gmail';
379 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
380 $subscription->eventtype = 'site';
381 $id = \core_calendar\api::add_subscription($subscription);
382
383 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
384 $ical = new iCalendar();
385 $ical->unserialize($calendar);
386 $this->assertEquals($ical->parser_errors, array());
387
388 $sub = \core_calendar\api::get_subscription($id);
389 \core_calendar\api::import_icalendar_events($ical, $sub->courseid, $sub->id);
390 $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
391 $this->assertEquals($count, 1);
392 }
1575194a
RW
393
394 /**
395 * Requesting calendar events from a given time should return all events with a sort
396 * time at or after the requested time. All events prior to that time should not
397 * be return.
398 *
399 * If there are no events on or after the given time then an empty result set should
400 * be returned.
401 */
402 function test_get_calendar_action_events_by_timesort_after_time() {
c91b4c02 403 $this->setAdminUser();
1575194a
RW
404
405 $params = [
406 'type' => CALENDAR_EVENT_TYPE_ACTION,
c91b4c02
MN
407 'courseid' => 1,
408 'modulename' => 'xyz',
409 'instance' => 1,
410 'userid' => 1,
1575194a
RW
411 'eventtype' => 'user',
412 'repeats' => 0,
413 'timestart' => 1,
414 ];
415
416 $event1 = create_event(array_merge($params, ['name' => 'Event 1', 'timesort' => 1]));
417 $event2 = create_event(array_merge($params, ['name' => 'Event 2', 'timesort' => 2]));
418 $event3 = create_event(array_merge($params, ['name' => 'Event 3', 'timesort' => 3]));
419 $event4 = create_event(array_merge($params, ['name' => 'Event 4', 'timesort' => 4]));
420 $event5 = create_event(array_merge($params, ['name' => 'Event 5', 'timesort' => 5]));
421 $event6 = create_event(array_merge($params, ['name' => 'Event 6', 'timesort' => 6]));
422 $event7 = create_event(array_merge($params, ['name' => 'Event 7', 'timesort' => 7]));
423 $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
424
425 $result = api::get_action_events_by_timesort(5);
426
427 $this->assertCount(4, $result);
428 $this->assertEquals('Event 5', $result[0]->name);
429 $this->assertEquals('Event 6', $result[1]->name);
430 $this->assertEquals('Event 7', $result[2]->name);
431 $this->assertEquals('Event 8', $result[3]->name);
432
433 $result = api::get_action_events_by_timesort(9);
434
435 $this->assertEmpty($result);
436 }
437
438 /**
439 * Requesting calendar events before a given time should return all events with a sort
440 * time at or before the requested time (inclusive). All events after that time
441 * should not be returned.
442 *
443 * If there are no events before the given time then an empty result set should be
444 * returned.
445 */
446 function test_get_calendar_action_events_by_timesort_before_time() {
c91b4c02 447 $this->setAdminUser();
1575194a
RW
448
449 $params = [
450 'type' => CALENDAR_EVENT_TYPE_ACTION,
c91b4c02
MN
451 'courseid' => 1,
452 'modulename' => 'xyz',
453 'instance' => 1,
454 'userid' => 1,
1575194a
RW
455 'eventtype' => 'user',
456 'repeats' => 0,
457 'timestart' => 1,
458 ];
459
460 $event1 = create_event(array_merge($params, ['name' => 'Event 1', 'timesort' => 2]));
461 $event2 = create_event(array_merge($params, ['name' => 'Event 2', 'timesort' => 3]));
462 $event3 = create_event(array_merge($params, ['name' => 'Event 3', 'timesort' => 4]));
463 $event4 = create_event(array_merge($params, ['name' => 'Event 4', 'timesort' => 5]));
464 $event5 = create_event(array_merge($params, ['name' => 'Event 5', 'timesort' => 6]));
465 $event6 = create_event(array_merge($params, ['name' => 'Event 6', 'timesort' => 7]));
466 $event7 = create_event(array_merge($params, ['name' => 'Event 7', 'timesort' => 8]));
467 $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 9]));
468
469 $result = api::get_action_events_by_timesort(null, 5);
470
471 $this->assertCount(4, $result);
472 $this->assertEquals('Event 1', $result[0]->name);
473 $this->assertEquals('Event 2', $result[1]->name);
474 $this->assertEquals('Event 3', $result[2]->name);
475 $this->assertEquals('Event 4', $result[3]->name);
476
477 $result = api::get_action_events_by_timesort(null, 1);
478
479 $this->assertEmpty($result);
480 }
481
482 /**
483 * Requesting calendar events within a given time range should return all events with
484 * a sort time between the lower and upper time bound (inclusive).
485 *
486 * If there are no events in the given time range then an empty result set should be
487 * returned.
488 */
489 function test_get_calendar_action_events_by_timesort_time_range() {
c91b4c02 490 $this->setAdminUser();
1575194a
RW
491
492 $params = [
493 'type' => CALENDAR_EVENT_TYPE_ACTION,
c91b4c02
MN
494 'courseid' => 1,
495 'modulename' => 'xyz',
496 'instance' => 1,
497 'userid' => 1,
1575194a
RW
498 'eventtype' => 'user',
499 'repeats' => 0,
500 'timestart' => 1,
501 ];
502
503 $event1 = create_event(array_merge($params, ['name' => 'Event 1', 'timesort' => 1]));
504 $event2 = create_event(array_merge($params, ['name' => 'Event 2', 'timesort' => 2]));
505 $event3 = create_event(array_merge($params, ['name' => 'Event 3', 'timesort' => 3]));
506 $event4 = create_event(array_merge($params, ['name' => 'Event 4', 'timesort' => 4]));
507 $event5 = create_event(array_merge($params, ['name' => 'Event 5', 'timesort' => 5]));
508 $event6 = create_event(array_merge($params, ['name' => 'Event 6', 'timesort' => 6]));
509 $event7 = create_event(array_merge($params, ['name' => 'Event 7', 'timesort' => 7]));
510 $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
511
512 $result = api::get_action_events_by_timesort(3, 6);
513
514 $this->assertCount(4, $result);
515 $this->assertEquals('Event 3', $result[0]->name);
516 $this->assertEquals('Event 4', $result[1]->name);
517 $this->assertEquals('Event 5', $result[2]->name);
518 $this->assertEquals('Event 6', $result[3]->name);
519
520 $result = api::get_action_events_by_timesort(10, 15);
521
522 $this->assertEmpty($result);
523 }
524
525 /**
526 * Requesting calendar events within a given time range and a limit and offset should return
527 * the number of events up to the given limit value that have a sort time between the lower
528 * and uppper time bound (inclusive) where the result set is shifted by the offset value.
529 *
530 * If there are no events in the given time range then an empty result set should be
531 * returned.
532 */
533 function test_get_calendar_action_events_by_timesort_time_limit_offset() {
c91b4c02 534 $this->setAdminUser();
1575194a
RW
535
536 $params = [
537 'type' => CALENDAR_EVENT_TYPE_ACTION,
c91b4c02
MN
538 'courseid' => 1,
539 'modulename' => 'xyz',
540 'instance' => 1,
541 'userid' => 1,
1575194a
RW
542 'eventtype' => 'user',
543 'repeats' => 0,
544 'timestart' => 1,
545 ];
546
547 $event1 = create_event(array_merge($params, ['name' => 'Event 1', 'timesort' => 1]));
548 $event2 = create_event(array_merge($params, ['name' => 'Event 2', 'timesort' => 2]));
549 $event3 = create_event(array_merge($params, ['name' => 'Event 3', 'timesort' => 3]));
550 $event4 = create_event(array_merge($params, ['name' => 'Event 4', 'timesort' => 4]));
551 $event5 = create_event(array_merge($params, ['name' => 'Event 5', 'timesort' => 5]));
552 $event6 = create_event(array_merge($params, ['name' => 'Event 6', 'timesort' => 6]));
553 $event7 = create_event(array_merge($params, ['name' => 'Event 7', 'timesort' => 7]));
554 $event8 = create_event(array_merge($params, ['name' => 'Event 8', 'timesort' => 8]));
555
556 $result = api::get_action_events_by_timesort(2, 7, $event3->id, 2);
557
558 $this->assertCount(2, $result);
559 $this->assertEquals('Event 4', $result[0]->name);
560 $this->assertEquals('Event 5', $result[1]->name);
561
562 $result = api::get_action_events_by_timesort(2, 7, $event5->id, 2);
563
564 $this->assertCount(2, $result);
565 $this->assertEquals('Event 6', $result[0]->name);
566 $this->assertEquals('Event 7', $result[1]->name);
567
568 $result = api::get_action_events_by_timesort(2, 7, $event7->id, 2);
569
570 $this->assertEmpty($result);
571 }
3607961d 572}