MDL-54751 behat: Support for adhoc module and section deletion in behat

Introduced new behat step for running all pending adhoc tasks and
modified the relavant behat tests.
This commit is contained in:
Jake Dallimore
2016-11-07 07:41:59 +08:00
parent 3704ff8cde
commit ff4230d88e
5 changed files with 43 additions and 1 deletions
+37
View File
@@ -1001,6 +1001,43 @@ class behat_general extends behat_base {
}
}
/**
* Runs all ad-hoc tasks in the queue.
*
* This is faster and more reliable than running cron (running cron won't
* work more than once in the same test, for instance). However it is
* a little less 'realistic'.
*
* While the task is running, we suppress mtrace output because it makes
* the Behat result look ugly.
*
* @Given /^I run all adhoc tasks$/
* @throws DriverException
*/
public function i_run_all_adhoc_tasks() {
// Do setup for cron task.
cron_setup_user();
// Run tasks. Locking is handled by get_next_adhoc_task.
$now = time();
ob_start(); // Discard task output as not appropriate for Behat output!
while (($task = \core\task\manager::get_next_adhoc_task($now)) !== null) {
try {
$task->execute();
// Mark task complete.
\core\task\manager::adhoc_task_complete($task);
} catch (Exception $e) {
// Mark task failed and throw exception.
\core\task\manager::adhoc_task_failed($task);
ob_end_clean();
throw new DriverException('An adhoc task failed', 0, $e);
}
}
ob_end_clean();
}
/**
* Checks that an element and selector type exists in another element and selector type on the current page.
*