MDL-57545 core_calendar: trigger update event when toggling visibility

Part of MDL-55611 epic.
This commit is contained in:
Mark Nelson 2017-01-05 16:34:20 +08:00 committed by Damyon Wiese
parent 10a8ea172b
commit c45266d115
3 changed files with 64 additions and 4 deletions

View file

@ -192,7 +192,8 @@ class core_calendar_events_testcase extends advanced_testcase {
$this->assertEquals($calevent->context, $event->get_context());
$expectedlog = array(0, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id , $calevent->name);
$this->assertEventLegacyLogData($expectedlog, $event);
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'new event');
$other = array('repeatid' => 0, 'timestart' => $time, 'name' => 'new event', 'visible' => (bool) $calevent->visible,
'visibilitytoggled' => false);
$this->assertEquals($other, $event->other);
$this->assertEventContextNotUsed($event);
@ -219,6 +220,39 @@ class core_calendar_events_testcase extends advanced_testcase {
}
}
/**
* Tests for calendar_event_updated event.
*/
public function test_calendar_event_updated_toggle_visibility() {
global $SITE;
$this->resetAfterTest();
// Create a calendar event.
$time = time();
$calevent = core_calendar_externallib_testcase::create_calendar_event('Some wickedly awesome event yo!',
$this->user->id, 'user', 0, $time);
// Updated the visibility of the calendar event.
$sink = $this->redirectEvents();
$calevent->toggle_visibility();
$events = $sink->get_events();
// Validate the calendar_event_updated event.
$event = $events[0];
$this->assertInstanceOf('\core\event\calendar_event_updated', $event);
$this->assertEquals('event', $event->objecttable);
$this->assertEquals($SITE->id, $event->courseid);
$this->assertEquals($calevent->context, $event->get_context());
$expectedlog = array($SITE->id, 'calendar', 'edit', 'event.php?action=edit&id=' . $calevent->id ,
$calevent->name);
$this->assertEventLegacyLogData($expectedlog, $event);
$other = array('repeatid' => 0, 'timestart' => time(), 'name' => 'Some wickedly awesome event yo!',
'visible' => (bool) $calevent->visible, 'visibilitytoggled' => true);
$this->assertEquals($other, $event->other);
$this->assertEventContextNotUsed($event);
}
/**
* Tests for event validations related to calendar_event_created event.
*/