MDL-62960 calendar: Rename get_module_timestamp_min/max_limit methods

The methods get_module_timestamp_min_limit() and get_module_timestamp_max_limit()
are doing generic stuff and can be used for other calendar event types as well.
I have renamed them to get_timestamp_min_limit() and get_timestamp_max_limit() respectively.
This commit is contained in:
Shamim Rezaie
2018-10-16 13:09:26 +11:00
parent 81e11e98f7
commit 86eff20271
2 changed files with 44 additions and 18 deletions
+33 -7
View File
@@ -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);
}
}
+11 -11
View File
@@ -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);