|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - https://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. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +namespace mod_reengagement; |
| 18 | + |
| 19 | +use advanced_testcase; |
| 20 | +use mod_reengagement\task\reengagement_adhoc_task; |
| 21 | + |
| 22 | +/** |
| 23 | + * Reengagement adhoc task tests |
| 24 | + * |
| 25 | + * @package mod_reengagement |
| 26 | + * @author Matthew Hilton <[email protected]> |
| 27 | + * @copyright 2025 Catalyst IT {@link http://www.catalyst-au.net} |
| 28 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 29 | + * @covers \mod_reengagement\task\reengagement_adhoc_task |
| 30 | + */ |
| 31 | +class reengagement_adhoc_task_test extends advanced_testcase { |
| 32 | + /** |
| 33 | + * Tests adhoc task exits gracefully without any customdata. |
| 34 | + */ |
| 35 | + public function test_adhoc_task_no_customdata() { |
| 36 | + $task = new reengagement_adhoc_task(); |
| 37 | + $task->execute(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Tests adhoc task exits gracefully with a missing cmid in customdata. |
| 42 | + */ |
| 43 | + public function test_adhoc_task_missing_cmid_customdata() { |
| 44 | + // No cmid is customdata, should exit early and not throw exception. |
| 45 | + $task = new reengagement_adhoc_task(); |
| 46 | + $task->set_custom_data(['cmid' => null]); |
| 47 | + $task->execute(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Tests adhoc task exits gracefully with an invalid cmid in customdata. |
| 52 | + */ |
| 53 | + public function test_adhoc_task_coursemodule_does_not_exist() { |
| 54 | + // This coursemodule does not exist, it should gracefully exit. |
| 55 | + $task = new reengagement_adhoc_task(); |
| 56 | + $task->set_custom_data(['cmid' => 12345]); |
| 57 | + $task->execute(); |
| 58 | + } |
| 59 | +} |
0 commit comments