From 4e1dd1d51fe203f0ea4fa30d26afc0203178d203 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 1 May 2025 10:26:13 +0100 Subject: [PATCH] MDL-85262 tool_task: switch next run time comparison in renderer. If a task is "due", then next run time should be considered "ASAP". --- admin/tool/task/renderer.php | 2 +- .../tool/task/tests/behat/adhoc_tasks.feature | 39 +++++++++++++++++++ .../tool/task/tests/behat/delete_task.feature | 21 ---------- admin/tool/task/tests/generator/lib.php | 6 +-- 4 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 admin/tool/task/tests/behat/adhoc_tasks.feature delete mode 100644 admin/tool/task/tests/behat/delete_task.feature diff --git a/admin/tool/task/renderer.php b/admin/tool/task/renderer.php index 6b7886cfed1..4f748bc5c00 100644 --- a/admin/tool/task/renderer.php +++ b/admin/tool/task/renderer.php @@ -287,7 +287,7 @@ class tool_task_renderer extends plugin_renderer_base { $nextruntime = $task->get_next_run_time(); $due = $nextruntime < $now; if ($task->get_attempts_available() > 0) { - $nextrun = $due ? userdate($nextruntime) : get_string('asap', 'tool_task'); + $nextrun = $due ? get_string('asap', 'tool_task') : userdate($nextruntime); } else { $nextrun = get_string('never', 'admin'); } diff --git a/admin/tool/task/tests/behat/adhoc_tasks.feature b/admin/tool/task/tests/behat/adhoc_tasks.feature new file mode 100644 index 00000000000..9d935ababf6 --- /dev/null +++ b/admin/tool/task/tests/behat/adhoc_tasks.feature @@ -0,0 +1,39 @@ +@tool @tool_task @javascript +Feature: Manage adhoc task + In order to manage adhoc tasks + As an admin + I need to be able to view and delete adhoc tasks + + Scenario Outline: View adhoc tasks next run time + Given the following "tool_task > adhoc tasks" exist: + | classname | seconds | hostname | pid | nextruntime | + | \core\task\asynchronous_backup_task | 0 | c69335460f7f | 1915 | | + When I log in as "admin" + And I navigate to "Server > Tasks > Ad hoc tasks" in site administration + Then the following should exist in the "Ad hoc tasks" table: + | Component / Class name | Next run | + | asynchronous_backup_task | | + And I click on "asynchronous_backup_task" "link" in the "Ad hoc tasks" "table" + And the following should exist in the "\core\task\asynchronous_backup_task Ad hoc tasks" table: + | Next run | + | | + Examples: + | nextruntime | nextruntimestr | + | ##yesterday## | ASAP | + | ##tomorrow noon## | ##tomorrow noon##%A, %d %B %Y, %I:%M## | + + Scenario: Delete an existing adhoc task + Given I log in as "admin" + And the following "tool_task > adhoc tasks" exist: + | classname | seconds | hostname | pid | + | \core\task\asynchronous_backup_task | 7201 | c69335460f7f | 1915 | + | \core\task\asynchronous_restore_task | 172800 | c69335460f7f | 1916 | + And I navigate to "Server > Tasks > Ad hoc tasks" in site administration + Then "asynchronous_backup_task" "table_row" should exist + And "asynchronous_restore_task" "table_row" should exist + And I follow "asynchronous_backup_task" + When I follow "Delete" + And I click on "Delete" "button" in the ".modal-dialog" "css_element" + Then I navigate to "Server > Tasks > Ad hoc tasks" in site administration + And "asynchronous_backup_task" "table_row" should not exist + And "asynchronous_restore_task" "table_row" should exist diff --git a/admin/tool/task/tests/behat/delete_task.feature b/admin/tool/task/tests/behat/delete_task.feature deleted file mode 100644 index 18762129a16..00000000000 --- a/admin/tool/task/tests/behat/delete_task.feature +++ /dev/null @@ -1,21 +0,0 @@ -@tool @tool_task @javascript -Feature: Delete an adhoc task - In order to manage adhoc tasks - As an admin - I need to be able to delete adhoc tasks - - Scenario: Delete an existing adhoc task - Given I log in as "admin" - And the following "tool_task > adhoc tasks" exist: - | classname | seconds | hostname | pid | - | \core\task\asynchronous_backup_task | 7201 | c69335460f7f | 1915 | - | \core\task\asynchronous_restore_task | 172800 | c69335460f7f | 1916 | - And I navigate to "Server > Tasks > Ad hoc tasks" in site administration - Then "asynchronous_backup_task" "table_row" should exist - And "asynchronous_restore_task" "table_row" should exist - And I follow "asynchronous_backup_task" - When I follow "Delete" - And I click on "Delete" "button" in the ".modal-dialog" "css_element" - Then I navigate to "Server > Tasks > Ad hoc tasks" in site administration - And "asynchronous_backup_task" "table_row" should not exist - And "asynchronous_restore_task" "table_row" should exist diff --git a/admin/tool/task/tests/generator/lib.php b/admin/tool/task/tests/generator/lib.php index b9324c5db60..8a822d6033f 100644 --- a/admin/tool/task/tests/generator/lib.php +++ b/admin/tool/task/tests/generator/lib.php @@ -43,7 +43,7 @@ class tool_task_generator extends testing_module_generator { global $DB; $conditions = ['classname' => $data['classname']]; $record = $DB->get_record('task_scheduled', $conditions, '*', MUST_EXIST); - $record->timestarted = time() - $data['seconds']; + $record->timestarted = $data['seconds'] > 0 ? time() - $data['seconds'] : 0; $record->hostname = $data['hostname']; $record->pid = $data['pid']; $DB->update_record('task_scheduled', $record); @@ -59,8 +59,8 @@ class tool_task_generator extends testing_module_generator { global $DB; $adhoctask = (object)[ 'classname' => $data['classname'], - 'nextruntime' => 0, - 'timestarted' => time() - $data['seconds'], + 'nextruntime' => $data['nextruntime'] ?? 0, + 'timestarted' => $data['seconds'] > 0 ? time() - $data['seconds'] : 0, 'hostname' => $data['hostname'], 'pid' => $data['pid'], ];