MDL-49294 logging: Improve cleanup tests
[moodle.git] / lib / tests / adhoc_task_test.php
blob174e54c28524cd42b5b2a5b01b846cb6baf6dd02
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * This file contains the unittests for adhock tasks.
20 * @package core
21 * @category phpunit
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');
30 /**
31 * Test class for adhoc tasks.
33 * @package core
34 * @category task
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();
45 // Queue it.
46 $task = \core\task\manager::queue_adhoc_task($task);
48 $now = time();
49 // Get it from the scheduler.
50 $task = \core\task\manager::get_next_adhoc_task($now);
51 $this->assertNotNull($task);
52 $task->execute();
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);
62 $task->execute();
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);