From 679d0839d0a94addfa9c04bc5ab92f8863574cc4 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Fri, 10 May 2024 11:11:46 +0100 Subject: [PATCH] fixup! MDL-70854 core: Alters running tasks page to show progress bars --- .../task/tests/behat/running_tasks.feature | 22 +++++++++++++++++++ lib/behat/classes/behat_core_generator.php | 5 +++++ lib/testing/generator/data_generator.php | 16 ++++++++++++++ lib/tests/behat/behat_general.php | 16 ++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/admin/tool/task/tests/behat/running_tasks.feature b/admin/tool/task/tests/behat/running_tasks.feature index 5725d5c51c435..04f6f7c31a69e 100644 --- a/admin/tool/task/tests/behat/running_tasks.feature +++ b/admin/tool/task/tests/behat/running_tasks.feature @@ -38,3 +38,25 @@ Feature: See running scheduled tasks And I should see "2 days" in the "core\task\asynchronous_restore_task" "table_row" And I should see "c69335460f7f" in the "core\task\asynchronous_restore_task" "table_row" And I should see "1916" in the "core\task\asynchronous_restore_task" "table_row" + + @javascript + Scenario: If a task with a stored progress bar is running, I should be able to observe the progress. + Given the following config values are set as admin: + | progresspollinterval | 1 | + And the following "tool_task > scheduled tasks" exist: + | classname | seconds | hostname | pid | + | \core\task\delete_unconfirmed_users_task | 120 | c69335460f7f | 1917 | + And the following "stored progress bars" exist: + | idnumber | percent | + | core_task_delete_unconfirmed_users_task | 50.00 | + And I navigate to "Server > Tasks > Tasks running now" in site administration + And I should see "2 mins" in the "Delete unconfirmed users" "table_row" + And I should see "c69335460f7f" in the "Delete unconfirmed users" "table_row" + And I should see "1917" in the "Delete unconfirmed users" "table_row" + And I should see "50.0%" in the "Delete unconfirmed users" "table_row" + + When I set the stored progress bar "core_task_delete_unconfirmed_users_task" to "75.00" + # Wait for the progress polling. + And I wait "1" seconds + Then I should not see "50.0%" in the "Delete unconfirmed users" "table_row" + And I should see "75.0%" in the "Delete unconfirmed users" "table_row" diff --git a/lib/behat/classes/behat_core_generator.php b/lib/behat/classes/behat_core_generator.php index 9275712babbc8..2cb62522d757d 100644 --- a/lib/behat/classes/behat_core_generator.php +++ b/lib/behat/classes/behat_core_generator.php @@ -316,6 +316,11 @@ protected function get_creatable_entities(): array { 'required' => ['subject', 'userfrom', 'userto'], 'switchids' => ['userfrom' => 'userfromid', 'userto' => 'usertoid'], ], + 'stored progress bars' => [ + 'singular' => 'stored progress bar', + 'datagenerator' => 'stored_progress_bar', + 'required' => ['idnumber'], + ], ]; return $entities; diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 766ecdc4cc66f..09d40cf5c670c 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -1565,6 +1565,22 @@ public function create_stored_progress( return $record; } + /** + * Generate a stored progress record from an array of fields. + * + * For use as a behat createable entity. Use {@see self::create_stored_progress()} if calling directly. + */ + public function create_stored_progress_bar(array $data): void { + $this->create_stored_progress( + $data['idnumber'] ?? null, + $data['timestart'] ?? null, + $data['lastupdate'] ?? null, + $data['percent'] ?? 0.00, + $data['message'] ?? null, + $data['haserrored'] ?? false, + ); + } + /** * Gets a default generator for a given component. * diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index b38bd60956df5..2a109d437069a 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -2400,4 +2400,20 @@ public function the_page_title_should_contain(string $title): void { ); } } + + /** + * Update a stored progress bar. + * + * @Given I set the stored progress bar :idnumber to :percent + * @param string $idnumber The unique idnumber of the stored progress bar. + * @param float $percent The value to update the progress bar to. + */ + public function i_set_the_stored_progress_bar_to(string $idnumber, float $percent): void { + $progress = \core\stored_progress_bar::get_by_idnumber($idnumber); + if (!$progress) { + throw new invalid_parameter_exception('No progress bar with idnumber ' . $idnumber . 'found.'); + } + $progress->auto_update(false); + $progress->update_full($percent, ''); + } }