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->courseid
= $courseid;
537 $subscription->groupid
= $groupid;
539 // Trigger and capture the event.
540 $sink = $this->redirectEvents();
541 $id = calendar_add_subscription($subscription);
543 $events = $sink->get_events();
544 $event = reset($events);
545 // Check that the event data is valid.
546 $this->assertInstanceOf('\core\event\calendar_subscription_created', $event);
547 $this->assertEquals($id, $event->objectid
);
548 $this->assertEquals($courseid, $event->other
['courseid']);
549 $this->assertEquals($groupid, $event->other
['groupid']);
550 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
551 $this->assertArrayNotHasKey('categoryid', $event->other
);
552 $this->assertDebuggingNotCalled();
557 * Tests for calendar_subscription_updated event for a site subscription.
559 public function test_calendar_subscription_updated_site() {
561 require_once($CFG->dirroot
. '/calendar/lib.php');
562 $this->resetAfterTest(true);
564 // Create a mock subscription.
565 $subscription = new stdClass();
566 $subscription->eventtype
= 'site';
567 $subscription->name
= 'test';
568 $subscription->courseid
= $this->course
->id
;
569 $subscription->id
= calendar_add_subscription($subscription);
571 $subscription->name
= 'awesome';
573 // Trigger and capture the event.
574 $sink = $this->redirectEvents();
575 calendar_update_subscription($subscription);
576 $events = $sink->get_events();
577 $event = reset($events);
578 // Check that the event data is valid.
579 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
580 $this->assertEquals($subscription->id
, $event->objectid
);
581 $this->assertEquals($subscription->courseid
, $event->other
['courseid']);
582 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
583 $this->assertArrayNotHasKey('categoryid', $event->other
);
584 $this->assertArrayNotHasKey('groupid', $event->other
);
585 $this->assertDebuggingNotCalled();
590 * Tests for calendar_subscription_updated event for a category subscription.
592 public function test_calendar_subscription_updated_category() {
594 require_once($CFG->dirroot
. '/calendar/lib.php');
595 $this->resetAfterTest(true);
597 $categoryid = $this->course
->category
;
599 // Create a mock subscription.
600 $subscription = new stdClass();
601 $subscription->eventtype
= 'category';
602 $subscription->name
= 'test';
603 $subscription->categoryid
= $categoryid;
604 $subscription->id
= calendar_add_subscription($subscription);
606 $subscription->name
= 'awesome';
608 // Trigger and capture the event.
609 $sink = $this->redirectEvents();
610 calendar_update_subscription($subscription);
611 $events = $sink->get_events();
612 $event = reset($events);
613 // Check that the event data is valid.
614 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
615 $this->assertEquals($subscription->id
, $event->objectid
);
616 $this->assertEquals($categoryid, $event->other
['categoryid']);
617 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
618 $this->assertArrayNotHasKey('courseid', $event->other
);
619 $this->assertArrayNotHasKey('groupid', $event->other
);
620 $this->assertDebuggingNotCalled();
625 * Tests for calendar_subscription_updated event for a group subscription.
627 public function test_calendar_subscription_updated_course() {
629 require_once($CFG->dirroot
. '/calendar/lib.php');
630 $this->resetAfterTest(true);
632 // Create a mock subscription.
633 $subscription = new stdClass();
634 $subscription->eventtype
= 'course';
635 $subscription->name
= 'test';
636 $subscription->courseid
= $this->course
->id
;
637 $subscription->id
= calendar_add_subscription($subscription);
639 $subscription->name
= 'awesome';
641 // Trigger and capture the event.
642 $sink = $this->redirectEvents();
643 calendar_update_subscription($subscription);
644 $events = $sink->get_events();
645 $event = reset($events);
646 // Check that the event data is valid.
647 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
648 $this->assertEquals($subscription->id
, $event->objectid
);
649 $this->assertEquals($this->course
->id
, $event->other
['courseid']);
650 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
651 $this->assertArrayNotHasKey('categoryid', $event->other
);
652 $this->assertArrayNotHasKey('groupid', $event->other
);
653 $this->assertDebuggingNotCalled();
658 * Tests for calendar_subscription_updated event for a course subscription.
660 public function test_calendar_subscription_updated_group() {
662 require_once($CFG->dirroot
. '/calendar/lib.php');
663 $this->resetAfterTest(true);
665 $courseid = $this->course
->id
;
668 // Create a mock subscription.
669 $subscription = new stdClass();
670 $subscription->eventtype
= 'group';
671 $subscription->name
= 'test';
672 $subscription->courseid
= $courseid;
673 $subscription->groupid
= $groupid;
675 $subscription->id
= calendar_add_subscription($subscription);
677 $subscription->name
= 'awesome';
679 // Trigger and capture the event.
680 $sink = $this->redirectEvents();
681 calendar_update_subscription($subscription);
682 $events = $sink->get_events();
683 $event = reset($events);
684 // Check that the event data is valid.
685 $this->assertInstanceOf('\core\event\calendar_subscription_updated', $event);
686 $this->assertEquals($subscription->id
, $event->objectid
);
687 $this->assertEquals($this->course
->id
, $event->other
['courseid']);
688 $this->assertEquals($groupid, $event->other
['groupid']);
689 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
690 $this->assertArrayNotHasKey('categoryid', $event->other
);
691 $this->assertDebuggingNotCalled();
696 * Tests for calendar_subscription_deleted event for a site subscription.
698 public function test_calendar_subscription_deleted_site() {
700 require_once($CFG->dirroot
. '/calendar/lib.php');
701 $this->resetAfterTest(true);
703 // Create a mock subscription.
704 $subscription = new stdClass();
705 $subscription->eventtype
= 'site';
706 $subscription->name
= 'test';
707 $subscription->courseid
= $this->course
->id
;
708 $subscription->id
= calendar_add_subscription($subscription);
710 // Trigger and capture the event.
711 $sink = $this->redirectEvents();
712 calendar_delete_subscription($subscription);
713 $events = $sink->get_events();
714 $event = reset($events);
715 // Check that the event data is valid.
716 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
717 $this->assertEquals($subscription->id
, $event->objectid
);
718 $this->assertEquals($subscription->courseid
, $event->other
['courseid']);
719 $this->assertDebuggingNotCalled();
725 * Tests for calendar_subscription_deleted event for a category subscription.
727 public function test_calendar_subscription_deleted_category() {
729 require_once($CFG->dirroot
. '/calendar/lib.php');
730 $this->resetAfterTest(true);
732 $categoryid = $this->course
->category
;
734 // Create a mock subscription.
735 $subscription = new stdClass();
736 $subscription->eventtype
= 'category';
737 $subscription->name
= 'test';
738 $subscription->categoryid
= $categoryid;
739 $subscription->id
= calendar_add_subscription($subscription);
741 // Trigger and capture the event.
742 $sink = $this->redirectEvents();
743 calendar_delete_subscription($subscription);
744 $events = $sink->get_events();
745 $event = reset($events);
746 // Check that the event data is valid.
747 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
748 $this->assertEquals($subscription->id
, $event->objectid
);
749 $this->assertEquals($categoryid, $event->other
['categoryid']);
750 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
751 $this->assertArrayNotHasKey('courseid', $event->other
);
752 $this->assertArrayNotHasKey('groupid', $event->other
);
753 $this->assertDebuggingNotCalled();
758 * Tests for calendar_subscription_deleted event for a course.
760 public function test_calendar_subscription_deleted_course() {
762 require_once($CFG->dirroot
. '/calendar/lib.php');
763 $this->resetAfterTest(true);
765 // Create a mock subscription.
766 $subscription = new stdClass();
767 $subscription->eventtype
= 'course';
768 $subscription->name
= 'test';
769 $subscription->courseid
= $this->course
->id
;
770 $subscription->id
= calendar_add_subscription($subscription);
772 // Trigger and capture the event.
773 $sink = $this->redirectEvents();
774 calendar_delete_subscription($subscription);
775 $events = $sink->get_events();
776 $event = reset($events);
777 // Check that the event data is valid.
778 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
779 $this->assertEquals($subscription->id
, $event->objectid
);
780 $this->assertEquals($this->course
->id
, $event->other
['courseid']);
781 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
782 $this->assertArrayNotHasKey('categoryid', $event->other
);
783 $this->assertArrayNotHasKey('groupid', $event->other
);
784 $this->assertDebuggingNotCalled();
789 * Tests for calendar_subscription_deleted event for a group.
791 public function test_calendar_subscription_deleted_group() {
793 require_once($CFG->dirroot
. '/calendar/lib.php');
794 $this->resetAfterTest(true);
796 $courseid = $this->course
->id
;
799 // Create a mock subscription.
800 $subscription = new stdClass();
801 $subscription->eventtype
= 'group';
802 $subscription->name
= 'test';
803 $subscription->groupid
= $groupid;
804 $subscription->courseid
= $courseid;
805 $subscription->id
= calendar_add_subscription($subscription);
807 // Trigger and capture the event.
808 $sink = $this->redirectEvents();
809 calendar_delete_subscription($subscription);
810 $events = $sink->get_events();
811 $event = reset($events);
812 // Check that the event data is valid.
813 $this->assertInstanceOf('\core\event\calendar_subscription_deleted', $event);
814 $this->assertEquals($subscription->id
, $event->objectid
);
815 $this->assertEquals($this->course
->id
, $event->other
['courseid']);
816 $this->assertEquals($groupid, $event->other
['groupid']);
817 $this->assertEquals($subscription->eventtype
, $event->other
['eventtype']);
818 $this->assertArrayNotHasKey('categoryid', $event->other
);
819 $this->assertDebuggingNotCalled();