2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This file contains the class that handles testing of the calendar events.
20 * @package core_calendar
21 * @copyright 2014 Ankit Agarwal <ankit.agrr@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/calendar/tests/externallib_test.php');
30 * This file contains the class that handles testing of the calendar events.
32 * @package core_calendar
33 * @copyright 2014 Ankit Agarwal <ankit.agrr@gmail.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class core_calendar_events_testcase extends advanced_testcase {
51 protected function setUp() {
53 // The user we are going to test this on.
54 $this->setAdminUser();
56 $this->course = self::getDataGenerator()->create_course();
60 * Tests for calendar_event_created event.
62 public function test_calendar_event_created() {
64 $this->resetAfterTest();
67 $sink = $this->redirectEvents();
69 // Create a calendar event.
70 $record = new stdClass();
71 $record->courseid = 0;
73 $calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
74 $record); // User event.
77 $events = $sink->get_events();
80 // Validate the event.
82 $this->assertInstanceOf('\core\event\calendar_event_created', $event);
83 $this->assertEquals('event', $event->objecttable);
84 $this->assertEquals(0, $event->courseid);
85 $this->assertEquals($calevent->context, $event->get_context());
86 $expectedlog = array(0, 'calendar', 'add', 'event.php?action=edit&id=' . $calevent->id , $calevent->name);
87 $other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'event');
88 $this->assertEquals($other, $event->other);
89 $this->assertEventLegacyLogData($expectedlog, $event);
90 $this->assertEventContextNotUsed($event);
92 // Now we create a repeated course event.
93 $record = new stdClass();
94 $record->courseid = $this->course->id;
95 $calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, $time,
97 $events = $sink->get_events();
100 $this->assertEquals(10, count($events));
101 foreach ($events as $event) {
102 $this->assertInstanceOf('\core\event\calendar_event_created', $event);
103 $this->assertEquals('event', $event->objecttable);
104 $this->assertEquals($this->course->id, $event->courseid);
105 $this->assertEquals($calevent->context, $event->get_context());
110 * Tests for event validations related to calendar_event_created event.
112 public function test_calendar_event_created_validations() {
113 $this->resetAfterTest();
114 $context = context_user::instance($this->user->id);
116 // Test not setting other['repeatid'].
118 \core\event\calendar_event_created::create(array(
119 'context' => $context,
122 'timestart' => time(),
126 $this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
128 } catch (coding_exception $e) {
129 $this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
132 // Test not setting other['name'].
134 \core\event\calendar_event_created::create(array(
135 'context' => $context,
139 'timestart' => time(),
142 $this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
144 } catch (coding_exception $e) {
145 $this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
148 // Test not setting other['timestart'].
150 \core\event\calendar_event_created::create(array(
151 'context' => $context,
158 $this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
159 other['timestart']");
160 } catch (coding_exception $e) {
161 $this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
166 * Tests for calendar_event_updated event.
168 public function test_calendar_event_updated() {
170 $this->resetAfterTest();
172 // Create a calendar event.
173 $record = new stdClass();
174 $record->courseid = 0;
176 $calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
177 $record); // User event.
180 $sink = $this->redirectEvents();
181 $prop = new stdClass();
182 $prop->name = 'new event';
183 $calevent->update($prop); // Update calender event.
184 // Capture the event.
185 $events = $sink->get_events();
187 // Validate the event.
189 $this->assertInstanceOf('\core\event\calendar_event_updated', $event);
190 $this->assertEquals('event', $event->objecttable);
191 $this->assertEquals(0, $event->courseid);
192 $this->assertEquals($calevent->context, $event->get_context());
193 $expectedlog = array(0, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id , $calevent->name);
194 $this->assertEventLegacyLogData($expectedlog, $event);
195 $other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'new event');
196 $this->assertEquals($other, $event->other);
197 $this->assertEventContextNotUsed($event);
199 // Now we create a repeated course event and update it.
200 $record = new stdClass();
201 $record->courseid = $this->course->id;
202 $calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, time(),
206 $prop = new stdClass();
207 $prop->name = 'new event';
208 $prop->repeateditall = true;
209 $calevent->update($prop); // Update calender event.
210 $events = $sink->get_events();
213 $this->assertEquals(10, count($events));
214 foreach ($events as $event) {
215 $this->assertInstanceOf('\core\event\calendar_event_updated', $event);
216 $this->assertEquals('event', $event->objecttable);
217 $this->assertEquals($this->course->id, $event->courseid);
218 $this->assertEquals($calevent->context, $event->get_context());
223 * Tests for calendar_event_updated event.
225 public function test_calendar_event_updated_toggle_visibility() {
228 $this->resetAfterTest();
230 // Create a calendar event.
232 $calevent = core_calendar_externallib_testcase::create_calendar_event('Some wickedly awesome event yo!',
233 $this->user->id, 'user', 0, $time);
235 // Updated the visibility of the calendar event.
236 $sink = $this->redirectEvents();
237 $calevent->toggle_visibility();
238 $dbrecord = $DB->get_record('event', array('id' => $calevent->id), '*', MUST_EXIST);
239 $events = $sink->get_events();
241 // Validate the calendar_event_updated event.
243 $this->assertInstanceOf('\core\event\calendar_event_updated', $event);
244 $this->assertEquals('event', $event->objecttable);
245 $this->assertEquals($SITE->id, $event->courseid);
246 $this->assertEquals($calevent->context, $event->get_context());
247 $expectedlog = array($SITE->id, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id ,
249 $this->assertEventLegacyLogData($expectedlog, $event);
250 $other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'Some wickedly awesome event yo!');
251 $this->assertEquals($other, $event->other);
252 $this->assertEventContextNotUsed($event);
253 $this->assertEquals($dbrecord, $event->get_record_snapshot('event', $event->objectid));
258 * Tests for event validations related to calendar_event_created event.
260 public function test_calendar_event_updated_validations() {
261 $this->resetAfterTest();
262 $context = context_user::instance($this->user->id);
264 // Test not setting other['repeatid'].
266 \core\event\calendar_event_updated::create(array(
267 'context' => $context,
270 'timestart' => time(),
274 $this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
276 } catch (coding_exception $e) {
277 $this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
280 // Test not setting other['name'].
282 \core\event\calendar_event_updated::create(array(
283 'context' => $context,
287 'timestart' => time(),
290 $this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
292 } catch (coding_exception $e) {
293 $this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
296 // Test not setting other['timestart'].
298 \core\event\calendar_event_updated::create(array(
299 'context' => $context,
306 $this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
307 other['timestart']");
308 } catch (coding_exception $e) {
309 $this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
314 * Tests for calendar_event_deleted event.
316 public function test_calendar_event_deleted() {
319 $this->resetAfterTest();
321 // Create a calendar event.
322 $record = new stdClass();
323 $record->courseid = 0;
324 $record->repeatid = 0;
326 $calevent = core_calendar_externallib_testcase::create_calendar_event('event', $this->user->id, 'user', 0, $time,
327 $record); // User event.
328 $dbrecord = $DB->get_record('event', array('id' => $calevent->id), '*', MUST_EXIST);
331 $sink = $this->redirectEvents();
332 $calevent->delete(false);
333 $events = $sink->get_events();
335 // Validate the event.
337 $this->assertInstanceOf('\core\event\calendar_event_deleted', $event);
338 $this->assertEquals('event', $event->objecttable);
339 $this->assertEquals(0, $event->courseid);
340 $this->assertEquals($calevent->context, $event->get_context());
341 $other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'event');
342 $this->assertEquals($other, $event->other);
343 $this->assertEventContextNotUsed($event);
344 $this->assertEquals($dbrecord, $event->get_record_snapshot('event', $event->objectid));
346 // Now we create a repeated course event and delete it.
347 $record = new stdClass();
348 $record->courseid = $this->course->id;
349 $calevent = core_calendar_externallib_testcase::create_calendar_event('course', $this->user->id, 'course', 10, time(),
353 $prop = new stdClass();
354 $prop->name = 'new event';
355 $prop->repeateditall = true;
356 $calevent->delete(true);
357 $events = $sink->get_events();
360 $this->assertEquals(10, count($events));
361 foreach ($events as $event) {
362 $this->assertInstanceOf('\core\event\calendar_event_deleted', $event);
363 $this->assertEquals('event', $event->objecttable);
364 $this->assertEquals($this->course->id, $event->courseid);
365 $this->assertEquals($calevent->context, $event->get_context());
370 * Tests for event validations related to calendar_event_deleted event.
372 public function test_calendar_event_deleted_validations() {
373 $this->resetAfterTest();
374 $context = context_user::instance($this->user->id);
376 // Test not setting other['repeatid'].
378 \core\event\calendar_event_deleted::create(array(
379 'context' => $context,
382 'timestart' => time(),
386 $this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
388 } catch (coding_exception $e) {
389 $this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
392 // Test not setting other['name'].
394 \core\event\calendar_event_deleted::create(array(
395 'context' => $context,
399 'timestart' => time(),
402 $this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
404 } catch (coding_exception $e) {
405 $this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
408 // Test not setting other['timestart'].
410 \core\event\calendar_event_deleted::create(array(
411 'context' => $context,
418 $this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
419 other['timestart']");
420 } catch (coding_exception $e) {
421 $this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
426 * Tests for calendar_subscription_added event for a site subscription.
428 public function test_calendar_subscription_created_site() {
430 require_once($CFG->dirroot . '/calendar/lib.php');
431 $this->resetAfterTest(true);
433 // Create a mock subscription.
434 $subscription = new stdClass();
435 $subscription->eventtype = 'site';
436 $subscription->name = 'test';
437 $subscription->courseid = $this->course->id;
439 // Trigger and capture the event.
440 $sink = $this->redirectEvents();
441 $id = calendar_add_subscription($subscription);
443 $events = $sink->get_events();
444 $event = reset($events);
445 // Check that the event data is valid.
446 $this->assertInstanceOf('\core\event\calendar_subscription_created', $event);
447 $this->assertEquals($id, $event->objectid);
448 $this->assertEquals($subscription->courseid, $event->other['courseid']);
449 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
450 $this->assertArrayNotHasKey('categoryid', $event->other);
451 $this->assertArrayNotHasKey('groupid', $event->other);
452 $this->assertDebuggingNotCalled();
457 * Tests for calendar_subscription_added event for a category subscription.
459 public function test_calendar_subscription_created_category() {
461 require_once($CFG->dirroot . '/calendar/lib.php');
462 $this->resetAfterTest(true);
464 $categoryid = $this->course->category;
466 // Create a mock subscription.
467 $subscription = new stdClass();
468 $subscription->eventtype = 'category';
469 $subscription->name = 'test';
470 $subscription->categoryid = $categoryid;
472 // Trigger and capture the event.
473 $sink = $this->redirectEvents();
474 $id = calendar_add_subscription($subscription);
476 $events = $sink->get_events();
477 $event = reset($events);
478 // Check that the event data is valid.
479 $this->assertInstanceOf('\core\event\calendar_subscription_created', $event);
480 $this->assertEquals($id, $event->objectid);
481 $this->assertEquals($categoryid, $event->other['categoryid']);
482 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
483 $this->assertArrayNotHasKey('courseid', $event->other);
484 $this->assertArrayNotHasKey('groupid', $event->other);
485 $this->assertDebuggingNotCalled();
490 * Tests for calendar_subscription_added event for a course subscription.
492 public function test_calendar_subscription_created_course() {
494 require_once($CFG->dirroot . '/calendar/lib.php');
495 $this->resetAfterTest(true);
497 // Create a mock subscription.
498 $subscription = new stdClass();
499 $subscription->eventtype = 'course';
500 $subscription->name = 'test';
501 $subscription->courseid = $this->course->id;
503 // Trigger and capture the event.
504 $sink = $this->redirectEvents();
505 $id = calendar_add_subscription($subscription);
507 $events = $sink->get_events();
508 $event = reset($events);
509 // Check that the event data is valid.
510 $this->assertInstanceOf('\core\event\calendar_subscription_created', $event);
511 $this->assertEquals($id, $event->objectid);
512 $this->assertEquals($subscription->courseid, $event->other['courseid']);
513 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
514 $this->assertArrayNotHasKey('categoryid', $event->other);
515 $this->assertArrayNotHasKey('groupid', $event->other);
516 $this->assertDebuggingNotCalled();
522 * Tests for calendar_subscription_added event for a group subscription.
524 public function test_calendar_subscription_created_group() {
526 require_once($CFG->dirroot . '/calendar/lib.php');
527 $this->resetAfterTest(true);
529 $courseid = $this->course->id;
532 // Create a mock subscription.
533 $subscription = new stdClass();
534 $subscription->eventtype = 'group';
535 $subscription->name = 'test';
536 $subscription->groupid = "{$courseid}-{$groupid}";
538 // Trigger and capture the event.
539 $sink = $this->redirectEvents();
540 $id = calendar_add_subscription($subscription);
542 $events = $sink->get_events();
543 $event = reset($events);
544 // Check that the event data is valid.
545 $this->assertInstanceOf('\core\event\calendar_subscription_created', $event);
546 $this->assertEquals($id, $event->objectid);
547 $this->assertEquals($courseid, $event->other['courseid']);
548 $this->assertEquals($groupid, $event->other['groupid']);
549 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
550 $this->assertArrayNotHasKey('categoryid', $event->other);
551 $this->assertDebuggingNotCalled();
556 * Tests for calendar_subscription_updated event for a site subscription.
558 public function test_calendar_subscription_updated_site() {
560 require_once($CFG->dirroot . '/calendar/lib.php');
561 $this->resetAfterTest(true);
563 // Create a mock subscription.
564 $subscription = new stdClass();
565 $subscription->eventtype = 'site';
566 $subscription->name = 'test';
567 $subscription->courseid = $this->course->id;
568 $subscription->id = calendar_add_subscription($subscription);
570 $subscription->name = 'awesome';
572 // Trigger and capture the event.
573 $sink = $this->redirectEvents();
574 calendar_update_subscription($subscription);
575 $events = $sink->get_events();
576 $event = reset($events);
577 // Check that the event data is valid.
578 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
579 $this->assertEquals($subscription->id, $event->objectid);
580 $this->assertEquals($subscription->courseid, $event->other['courseid']);
581 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
582 $this->assertArrayNotHasKey('categoryid', $event->other);
583 $this->assertArrayNotHasKey('groupid', $event->other);
584 $this->assertDebuggingNotCalled();
589 * Tests for calendar_subscription_updated event for a category subscription.
591 public function test_calendar_subscription_updated_category() {
593 require_once($CFG->dirroot . '/calendar/lib.php');
594 $this->resetAfterTest(true);
596 $categoryid = $this->course->category;
598 // Create a mock subscription.
599 $subscription = new stdClass();
600 $subscription->eventtype = 'category';
601 $subscription->name = 'test';
602 $subscription->categoryid = $categoryid;
603 $subscription->id = calendar_add_subscription($subscription);
605 $subscription->name = 'awesome';
607 // Trigger and capture the event.
608 $sink = $this->redirectEvents();
609 calendar_update_subscription($subscription);
610 $events = $sink->get_events();
611 $event = reset($events);
612 // Check that the event data is valid.
613 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
614 $this->assertEquals($subscription->id, $event->objectid);
615 $this->assertEquals($categoryid, $event->other['categoryid']);
616 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
617 $this->assertArrayNotHasKey('courseid', $event->other);
618 $this->assertArrayNotHasKey('groupid', $event->other);
619 $this->assertDebuggingNotCalled();
624 * Tests for calendar_subscription_updated event for a group subscription.
626 public function test_calendar_subscription_updated_course() {
628 require_once($CFG->dirroot . '/calendar/lib.php');
629 $this->resetAfterTest(true);
631 // Create a mock subscription.
632 $subscription = new stdClass();
633 $subscription->eventtype = 'course';
634 $subscription->name = 'test';
635 $subscription->courseid = $this->course->id;
636 $subscription->id = calendar_add_subscription($subscription);
638 $subscription->name = 'awesome';
640 // Trigger and capture the event.
641 $sink = $this->redirectEvents();
642 calendar_update_subscription($subscription);
643 $events = $sink->get_events();
644 $event = reset($events);
645 // Check that the event data is valid.
646 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
647 $this->assertEquals($subscription->id, $event->objectid);
648 $this->assertEquals($this->course->id, $event->other['courseid']);
649 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
650 $this->assertArrayNotHasKey('categoryid', $event->other);
651 $this->assertArrayNotHasKey('groupid', $event->other);
652 $this->assertDebuggingNotCalled();
657 * Tests for calendar_subscription_updated event for a course subscription.
659 public function test_calendar_subscription_updated_group() {
661 require_once($CFG->dirroot . '/calendar/lib.php');
662 $this->resetAfterTest(true);
664 $courseid = $this->course->id;
667 // Create a mock subscription.
668 $subscription = new stdClass();
669 $subscription->eventtype = 'group';
670 $subscription->name = 'test';
671 $subscription->groupid = "{$courseid}-{$groupid}";
672 $subscription->id = calendar_add_subscription($subscription);
674 $subscription->name = 'awesome';
676 // Trigger and capture the event.
677 $sink = $this->redirectEvents();
678 calendar_update_subscription($subscription);
679 $events = $sink->get_events();
680 $event = reset($events);
681 // Check that the event data is valid.
682 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
683 $this->assertEquals($subscription->id, $event->objectid);
684 $this->assertEquals($this->course->id, $event->other['courseid']);
685 $this->assertEquals($groupid, $event->other['groupid']);
686 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
687 $this->assertArrayNotHasKey('categoryid', $event->other);
688 $this->assertDebuggingNotCalled();
693 * Tests for calendar_subscription_deleted event for a site subscription.
695 public function test_calendar_subscription_deleted_site() {
697 require_once($CFG->dirroot . '/calendar/lib.php');
698 $this->resetAfterTest(true);
700 // Create a mock subscription.
701 $subscription = new stdClass();
702 $subscription->eventtype = 'site';
703 $subscription->name = 'test';
704 $subscription->courseid = $this->course->id;
705 $subscription->id = calendar_add_subscription($subscription);
707 // Trigger and capture the event.
708 $sink = $this->redirectEvents();
709 calendar_delete_subscription($subscription);
710 $events = $sink->get_events();
711 $event = reset($events);
712 // Check that the event data is valid.
713 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
714 $this->assertEquals($subscription->id, $event->objectid);
715 $this->assertEquals($subscription->courseid, $event->other['courseid']);
716 $this->assertDebuggingNotCalled();
722 * Tests for calendar_subscription_deleted event for a category subscription.
724 public function test_calendar_subscription_deleted_category() {
726 require_once($CFG->dirroot . '/calendar/lib.php');
727 $this->resetAfterTest(true);
729 $categoryid = $this->course->category;
731 // Create a mock subscription.
732 $subscription = new stdClass();
733 $subscription->eventtype = 'category';
734 $subscription->name = 'test';
735 $subscription->categoryid = $categoryid;
736 $subscription->id = calendar_add_subscription($subscription);
738 // Trigger and capture the event.
739 $sink = $this->redirectEvents();
740 calendar_delete_subscription($subscription);
741 $events = $sink->get_events();
742 $event = reset($events);
743 // Check that the event data is valid.
744 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
745 $this->assertEquals($subscription->id, $event->objectid);
746 $this->assertEquals($categoryid, $event->other['categoryid']);
747 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
748 $this->assertArrayNotHasKey('courseid', $event->other);
749 $this->assertArrayNotHasKey('groupid', $event->other);
750 $this->assertDebuggingNotCalled();
755 * Tests for calendar_subscription_deleted event for a course.
757 public function test_calendar_subscription_deleted_course() {
759 require_once($CFG->dirroot . '/calendar/lib.php');
760 $this->resetAfterTest(true);
762 // Create a mock subscription.
763 $subscription = new stdClass();
764 $subscription->eventtype = 'course';
765 $subscription->name = 'test';
766 $subscription->courseid = $this->course->id;
767 $subscription->id = calendar_add_subscription($subscription);
769 // Trigger and capture the event.
770 $sink = $this->redirectEvents();
771 calendar_delete_subscription($subscription);
772 $events = $sink->get_events();
773 $event = reset($events);
774 // Check that the event data is valid.
775 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
776 $this->assertEquals($subscription->id, $event->objectid);
777 $this->assertEquals($this->course->id, $event->other['courseid']);
778 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
779 $this->assertArrayNotHasKey('categoryid', $event->other);
780 $this->assertArrayNotHasKey('groupid', $event->other);
781 $this->assertDebuggingNotCalled();
786 * Tests for calendar_subscription_deleted event for a group.
788 public function test_calendar_subscription_deleted_group() {
790 require_once($CFG->dirroot . '/calendar/lib.php');
791 $this->resetAfterTest(true);
793 $courseid = $this->course->id;
796 // Create a mock subscription.
797 $subscription = new stdClass();
798 $subscription->eventtype = 'group';
799 $subscription->name = 'test';
800 $subscription->groupid = "{$courseid}-{$groupid}";
801 $subscription->id = calendar_add_subscription($subscription);
803 // Trigger and capture the event.
804 $sink = $this->redirectEvents();
805 calendar_delete_subscription($subscription);
806 $events = $sink->get_events();
807 $event = reset($events);
808 // Check that the event data is valid.
809 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
810 $this->assertEquals($subscription->id, $event->objectid);
811 $this->assertEquals($this->course->id, $event->other['courseid']);
812 $this->assertEquals($groupid, $event->other['groupid']);
813 $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
814 $this->assertArrayNotHasKey('categoryid', $event->other);
815 $this->assertDebuggingNotCalled();