mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-60058 choice: implement timestart range callback for calendar UI
This commit is contained in:
parent
c56dd950eb
commit
8c4b939cfe
2 changed files with 256 additions and 21 deletions
|
@ -554,7 +554,10 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
'visible' => 1
|
||||
]);
|
||||
|
||||
$this->assertTrue(mod_choice_core_calendar_validate_event_timestart($event));
|
||||
mod_choice_core_calendar_validate_event_timestart($event);
|
||||
// The function above will throw an exception if the event is
|
||||
// invalid.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -630,7 +633,10 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
'visible' => 1
|
||||
]);
|
||||
|
||||
$this->assertTrue(mod_choice_core_calendar_validate_event_timestart($event));
|
||||
mod_choice_core_calendar_validate_event_timestart($event);
|
||||
// The function above will throw an exception if the event isn't
|
||||
// valid.
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -754,8 +760,16 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
'visible' => 1
|
||||
]);
|
||||
|
||||
// Trigger and capture the event when adding a contact.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
mod_choice_core_calendar_event_timestart_updated($event);
|
||||
|
||||
$triggeredevents = $sink->get_events();
|
||||
$moduleupdatedevents = array_filter($triggeredevents, function($e) {
|
||||
return is_a($e, 'core\event\course_module_updated');
|
||||
});
|
||||
|
||||
$choice = $DB->get_record('choice', ['id' => $choice->id]);
|
||||
// Ensure the timeopen property matches the event timestart.
|
||||
$this->assertEquals($newtimeopen, $choice->timeopen);
|
||||
|
@ -763,6 +777,9 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
$this->assertEquals($timeclose, $choice->timeclose);
|
||||
// Ensure the timemodified property has been changed.
|
||||
$this->assertNotEquals($timemodified, $choice->timemodified);
|
||||
// Confirm that a module updated event is fired when the module
|
||||
// is changed.
|
||||
$this->assertNotEmpty($moduleupdatedevents);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,8 +821,16 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
'visible' => 1
|
||||
]);
|
||||
|
||||
// Trigger and capture the event when adding a contact.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
mod_choice_core_calendar_event_timestart_updated($event);
|
||||
|
||||
$triggeredevents = $sink->get_events();
|
||||
$moduleupdatedevents = array_filter($triggeredevents, function($e) {
|
||||
return is_a($e, 'core\event\course_module_updated');
|
||||
});
|
||||
|
||||
$choice = $DB->get_record('choice', ['id' => $choice->id]);
|
||||
// Ensure the timeclose property matches the event timestart.
|
||||
$this->assertEquals($newtimeclose, $choice->timeclose);
|
||||
|
@ -813,5 +838,140 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
|||
$this->assertEquals($timeopen, $choice->timeopen);
|
||||
// Ensure the timemodified property has been changed.
|
||||
$this->assertNotEquals($timemodified, $choice->timemodified);
|
||||
// Confirm that a module updated event is fired when the module
|
||||
// is changed.
|
||||
$this->assertNotEmpty($moduleupdatedevents);
|
||||
}
|
||||
|
||||
/**
|
||||
* An unkown event type should not have any limits
|
||||
*/
|
||||
public function test_mod_choice_core_calendar_get_valid_event_timestart_range_unknown_event() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . "/calendar/lib.php");
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
$timeopen = time();
|
||||
$timeclose = $timeopen + DAYSECS;
|
||||
$choice = new \stdClass();
|
||||
$choice->timeopen = $timeopen;
|
||||
$choice->timeclose = $timeclose;
|
||||
|
||||
// Create a valid event.
|
||||
$event = new \calendar_event([
|
||||
'name' => 'Test event',
|
||||
'description' => '',
|
||||
'format' => 1,
|
||||
'courseid' => $course->id,
|
||||
'groupid' => 0,
|
||||
'userid' => 2,
|
||||
'modulename' => 'choice',
|
||||
'instance' => 1,
|
||||
'eventtype' => CHOICE_EVENT_TYPE_OPEN . "SOMETHING ELSE",
|
||||
'timestart' => 1,
|
||||
'timeduration' => 86400,
|
||||
'visible' => 1
|
||||
]);
|
||||
|
||||
list ($min, $max) = mod_choice_core_calendar_get_valid_event_timestart_range($event, $choice);
|
||||
$this->assertNull($min);
|
||||
$this->assertNull($max);
|
||||
}
|
||||
|
||||
/**
|
||||
* The open event should be limited by the choice's timeclose property, if it's set.
|
||||
*/
|
||||
public function test_mod_choice_core_calendar_get_valid_event_timestart_range_open_event() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . "/calendar/lib.php");
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
$timeopen = time();
|
||||
$timeclose = $timeopen + DAYSECS;
|
||||
$choice = new \stdClass();
|
||||
$choice->timeopen = $timeopen;
|
||||
$choice->timeclose = $timeclose;
|
||||
|
||||
// Create a valid event.
|
||||
$event = new \calendar_event([
|
||||
'name' => 'Test event',
|
||||
'description' => '',
|
||||
'format' => 1,
|
||||
'courseid' => $course->id,
|
||||
'groupid' => 0,
|
||||
'userid' => 2,
|
||||
'modulename' => 'choice',
|
||||
'instance' => 1,
|
||||
'eventtype' => CHOICE_EVENT_TYPE_OPEN,
|
||||
'timestart' => 1,
|
||||
'timeduration' => 86400,
|
||||
'visible' => 1
|
||||
]);
|
||||
|
||||
// The max limit should be bounded by the timeclose value.
|
||||
list ($min, $max) = mod_choice_core_calendar_get_valid_event_timestart_range($event, $choice);
|
||||
|
||||
$this->assertNull($min);
|
||||
$this->assertEquals($timeclose, $max[0]);
|
||||
|
||||
// No timeclose value should result in no upper limit.
|
||||
$choice->timeclose = 0;
|
||||
list ($min, $max) = mod_choice_core_calendar_get_valid_event_timestart_range($event, $choice);
|
||||
|
||||
$this->assertNull($min);
|
||||
$this->assertNull($max);
|
||||
}
|
||||
|
||||
/**
|
||||
* The close event should be limited by the choice's timeopen property, if it's set.
|
||||
*/
|
||||
public function test_mod_choice_core_calendar_get_valid_event_timestart_range_close_event() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . "/calendar/lib.php");
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
$timeopen = time();
|
||||
$timeclose = $timeopen + DAYSECS;
|
||||
$choice = new \stdClass();
|
||||
$choice->timeopen = $timeopen;
|
||||
$choice->timeclose = $timeclose;
|
||||
|
||||
// Create a valid event.
|
||||
$event = new \calendar_event([
|
||||
'name' => 'Test event',
|
||||
'description' => '',
|
||||
'format' => 1,
|
||||
'courseid' => $course->id,
|
||||
'groupid' => 0,
|
||||
'userid' => 2,
|
||||
'modulename' => 'choice',
|
||||
'instance' => 1,
|
||||
'eventtype' => CHOICE_EVENT_TYPE_CLOSE,
|
||||
'timestart' => 1,
|
||||
'timeduration' => 86400,
|
||||
'visible' => 1
|
||||
]);
|
||||
|
||||
// The max limit should be bounded by the timeclose value.
|
||||
list ($min, $max) = mod_choice_core_calendar_get_valid_event_timestart_range($event, $choice);
|
||||
|
||||
$this->assertEquals($timeopen, $min[0]);
|
||||
$this->assertNull($max);
|
||||
|
||||
// No timeclose value should result in no upper limit.
|
||||
$choice->timeopen = 0;
|
||||
list ($min, $max) = mod_choice_core_calendar_get_valid_event_timestart_range($event, $choice);
|
||||
|
||||
$this->assertNull($min);
|
||||
$this->assertNull($max);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue