Skip to content

Commit

Permalink
MDL-54751 behat: Support for adhoc module and section deletion in behat
Browse files Browse the repository at this point in the history
Introduced new behat step for running all pending adhoc tasks and
modified the relavant behat tests.
  • Loading branch information
snake committed Nov 6, 2016
1 parent 3704ff8 commit ff4230d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions admin/tool/recyclebin/tests/behat/backup_user_data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Feature: Backup user data
And I follow "Course 1"
And I turn editing mode on
And I delete "Quiz 1" activity
And I run all adhoc tasks
And I navigate to "Recycle bin" node in "Course administration"
And I should see "Quiz 1"
And I click on "Restore" "link" in the "region-main" "region"
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/recyclebin/tests/behat/basic_functionality.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Feature: Basic recycle bin functionality
| Assignment name | Test assign |
| Description | Test |
And I delete "Test assign" activity
And I run all adhoc tasks
And I navigate to "Recycle bin" node in "Course administration"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected item from the recycle bin?"
Expand All @@ -92,6 +93,7 @@ Feature: Basic recycle bin functionality
| Description | Test 2 |
And I delete "Test assign 1" activity
And I delete "Test assign 2" activity
And I run all adhoc tasks
And I navigate to "Recycle bin" node in "Course administration"
And I should see "Test assign 1"
And I should see "Test assign 2"
Expand Down
3 changes: 2 additions & 1 deletion backup/util/loggers/base_logger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ abstract protected function action($message, $level, $options = null); // To imp

public final function process($message, $level, $options = null) {
$result = true;
if ($this->level != backup::LOG_NONE && $this->level >= $level) { // Perform action conditionally
if ($this->level != backup::LOG_NONE && $this->level >= $level
&& !(defined('BEHAT_TEST') && BEHAT_TEST)) { // Perform action conditionally.
$result = $this->action($message, $level, $options);
}
if ($result === false) { // Something was wrong, stop the chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Feature: View structural changes in recent activity block
And I follow "Course 1"
And I turn editing mode on
And I delete "ForumUpdated" activity
And I run all adhoc tasks
And I log out
And I wait "1" seconds
# Students 1 and 2 see that forum was deleted
Expand Down
37 changes: 37 additions & 0 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,43 @@ public function i_run_the_scheduled_task($taskname) {
}
}

/**
* 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.
*
Expand Down

0 comments on commit ff4230d

Please sign in to comment.