diff --git a/calendar/classes/external/calendar_event_exporter.php b/calendar/classes/external/calendar_event_exporter.php index bd1d7515be8..1764d12271d 100644 --- a/calendar/classes/external/calendar_event_exporter.php +++ b/calendar/classes/external/calendar_event_exporter.php @@ -240,11 +240,11 @@ class calendar_event_exporter extends event_exporter_base { } if ($min) { - $values = array_merge($values, $this->get_module_timestamp_min_limit($starttime, $min)); + $values = array_merge($values, $this->get_timestamp_min_limit($starttime, $min)); } if ($max) { - $values = array_merge($values, $this->get_module_timestamp_max_limit($starttime, $max)); + $values = array_merge($values, $this->get_timestamp_max_limit($starttime, $max)); } return $values; @@ -252,12 +252,13 @@ class calendar_event_exporter extends event_exporter_base { /** * Get the correct minimum midnight day limit based on the event start time - * and the module's minimum timestamp limit. + * and the minimum timestamp limit of what the event belongs to. * * @param DateTimeInterface $starttime The event start time * @param array $min The module's minimum limit for the event + * @return array Returns an array with mindaytimestamp and mindayerror keys. */ - protected function get_module_timestamp_min_limit(\DateTimeInterface $starttime, $min) { + protected function get_timestamp_min_limit(\DateTimeInterface $starttime, $min) { // We need to check that the minimum valid time is earlier in the // day than the current event time so that if the user drags and drops // the event to this day (which changes the date but not the time) it @@ -295,15 +296,16 @@ class calendar_event_exporter extends event_exporter_base { /** * Get the correct maximum midnight day limit based on the event start time - * and the module's maximum timestamp limit. + * and the maximum timestamp limit of what the event belongs to. * * @param DateTimeInterface $starttime The event start time * @param array $max The module's maximum limit for the event + * @return array Returns an array with maxdaytimestamp and maxdayerror keys. */ - protected function get_module_timestamp_max_limit(\DateTimeInterface $starttime, $max) { + protected function get_timestamp_max_limit(\DateTimeInterface $starttime, $max) { // We're doing a similar calculation here as we are for the minimum // day timestamp. See the explanation above. - $values; + $values = []; $timestamp = $max[0]; $errorstring = $max[1]; $maxdate = (new \DateTimeImmutable())->setTimestamp($timestamp); @@ -326,4 +328,28 @@ class calendar_event_exporter extends event_exporter_base { $values['maxdayerror'] = $errorstring; return $values; } + + /** + * Get the correct minimum midnight day limit based on the event start time + * and the module's minimum timestamp limit. + * + * @param DateTimeInterface $starttime The event start time + * @param array $min The module's minimum limit for the event + * @return array Returns an array with mindaytimestamp and mindayerror keys. + */ + protected function get_module_timestamp_min_limit(\DateTimeInterface $starttime, $min) { + return $this->get_timestamp_min_limit($starttime, $min); + } + + /** + * Get the correct maximum midnight day limit based on the event start time + * and the module's maximum timestamp limit. + * + * @param DateTimeInterface $starttime The event start time + * @param array $max The module's maximum limit for the event + * @return array Returns an array with maxdaytimestamp and maxdayerror keys. + */ + protected function get_module_timestamp_max_limit(\DateTimeInterface $starttime, $max) { + return $this->get_timestamp_max_limit($starttime, $max); + } } diff --git a/calendar/tests/calendar_event_exporter_test.php b/calendar/tests/calendar_event_exporter_test.php index f5a7b9b55e7..86c815d7f38 100644 --- a/calendar/tests/calendar_event_exporter_test.php +++ b/calendar/tests/calendar_event_exporter_test.php @@ -38,10 +38,10 @@ require_once(__DIR__ . '/helpers.php'); */ class core_calendar_event_exporter_testcase extends advanced_testcase { /** - * Data provider for the module timestamp min limit test case to confirm + * Data provider for the timestamp min limit test case to confirm * that the minimum time limit is set correctly on the boundary cases. */ - public function get_module_timestamp_min_limit_test_cases() { + public function get_timestamp_min_limit_test_cases() { $now = time(); $todaymidnight = usergetmidnight($now); $tomorrowmidnight = $todaymidnight + DAYSECS; @@ -77,16 +77,16 @@ class core_calendar_event_exporter_testcase extends advanced_testcase { } /** - * @dataProvider get_module_timestamp_min_limit_test_cases() + * @dataProvider get_timestamp_min_limit_test_cases() */ - public function test_get_module_timestamp_min_limit($starttime, $min, $expected) { + public function test_get_timestamp_min_limit($starttime, $min, $expected) { $class = \core_calendar\external\calendar_event_exporter::class; $mock = $this->getMockBuilder($class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); $reflector = new ReflectionClass($class); - $method = $reflector->getMethod('get_module_timestamp_min_limit'); + $method = $reflector->getMethod('get_timestamp_min_limit'); $method->setAccessible(true); $result = $method->invoke($mock, $starttime, $min); @@ -95,10 +95,10 @@ class core_calendar_event_exporter_testcase extends advanced_testcase { } /** - * Data provider for the module timestamp min limit test case to confirm - * that the minimum time limit is set correctly on the boundary cases. + * Data provider for the timestamp max limit test case to confirm + * that the maximum time limit is set correctly on the boundary cases. */ - public function get_module_timestamp_max_limit_test_cases() { + public function get_timestamp_max_limit_test_cases() { $now = time(); $todaymidnight = usergetmidnight($now); $yesterdaymidnight = $todaymidnight - DAYSECS; @@ -134,16 +134,16 @@ class core_calendar_event_exporter_testcase extends advanced_testcase { } /** - * @dataProvider get_module_timestamp_max_limit_test_cases() + * @dataProvider get_timestamp_max_limit_test_cases() */ - public function test_get_module_timestamp_max_limit($starttime, $max, $expected) { + public function test_get_timestamp_max_limit($starttime, $max, $expected) { $class = \core_calendar\external\calendar_event_exporter::class; $mock = $this->getMockBuilder($class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); $reflector = new ReflectionClass($class); - $method = $reflector->getMethod('get_module_timestamp_max_limit'); + $method = $reflector->getMethod('get_timestamp_max_limit'); $method->setAccessible(true); $result = $method->invoke($mock, $starttime, $max);