MDL-77091 reportbuilder: set base time in schedule test generator.

The base time allows for the setting of the "current time" for the
purposes of the schedule test against recurrence configuration.

We should ensure the generator method allows this property so that
it can be used when calculating the initial "next send time" of the
schedule upon creation (and avoiding excessive recursion when the
actual current time is used for the calculation).
This commit is contained in:
Paul Holden
2023-02-01 14:39:21 +00:00
parent 880462a168
commit 5b644bfd30
4 changed files with 11 additions and 4 deletions
@@ -43,13 +43,14 @@ class schedule {
* Create report schedule, calculate when it should be next sent
*
* @param stdClass $data
* @param int|null $timenow Time to use as comparison against current date (defaults to current time)
* @return model
*/
public static function create_schedule(stdClass $data): model {
public static function create_schedule(stdClass $data, ?int $timenow = null): model {
$data->name = trim($data->name);
$schedule = (new model(0, $data));
$schedule->set('timenextsend', self::calculate_next_send_time($schedule));
$schedule->set('timenextsend', self::calculate_next_send_time($schedule, $timenow));
return $schedule->create();
}
@@ -228,7 +229,7 @@ class schedule {
* returned value is after the current date
*
* @param model $schedule
* @param int|null $timenow Time to use for calculation (defaults to current time)
* @param int|null $timenow Time to use as comparison against current date (defaults to current time)
* @return int
*/
public static function calculate_next_send_time(model $schedule, ?int $timenow = null): int {
+4 -1
View File
@@ -205,6 +205,9 @@ class core_reportbuilder_generator extends component_generator_base {
$record['timescheduled'] = usergetmidnight(time() + DAYSECS);
}
return schedule_helper::create_schedule((object) $record);
// Time to use as comparison against current date (null means current time).
$timenow = $record['timenow'] ?? null;
return schedule_helper::create_schedule((object) $record, $timenow);
}
}
@@ -404,6 +404,7 @@ class schedule_test extends advanced_testcase {
'name' => 'My schedule',
'recurrence' => $recurrence,
'timescheduled' => $timescheduled,
'timenow' => $timenow,
]);
$this->assertEquals($expected, schedule::calculate_next_send_time($schedule, $timenow));
+2
View File
@@ -10,6 +10,8 @@ Information provided here is intended especially for developers.
- `data-force-table` to force table view
* New optional parameter `pagesize` in external method `core_reportbuilder_reports_get` to set the displayed rows per page.
* Javascript reports repository module method `getReport` updated to accept new pagesize parameter.
* The schedule helper `create_schedule` method accepts a `$timenow` parameter to use for comparisons against current date
during tests
* The `datasource_stress_test_columns` test helper now enables sorting on those columns that support it
* The `create_[column|filter|condition]` test generator methods now allow for setting all persistent properties