2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains the unittests for adhock tasks.
22 * @copyright 2013 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
27 require_once(__DIR__
. '/fixtures/task_fixtures.php');
31 * Test class for adhoc tasks.
35 * @copyright 2013 Damyon Wiese
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class core_adhoc_task_testcase
extends advanced_testcase
{
40 public function test_get_next_adhoc_task() {
41 $this->resetAfterTest(true);
42 // Create an adhoc task.
43 $task = new \core\task\adhoc_test_task
();
46 $task = \core\task\manager
::queue_adhoc_task($task);
49 // Get it from the scheduler.
50 $task = \core\task\manager
::get_next_adhoc_task($now);
51 $this->assertNotNull($task);
54 \core\task\manager
::adhoc_task_failed($task);
55 // Should not get any task.
56 $task = \core\task\manager
::get_next_adhoc_task($now);
57 $this->assertNull($task);
59 // Should get the adhoc task (retry after delay).
60 $task = \core\task\manager
::get_next_adhoc_task($now +
120);
61 $this->assertNotNull($task);
64 \core\task\manager
::adhoc_task_complete($task);
66 // Should not get any task.
67 $task = \core\task\manager
::get_next_adhoc_task($now);
68 $this->assertNull($task);