Skip to content

Commit c1b027e

Browse files
authored
Merge pull request #196 from catalyst/195-fix-task-400
195 fix task 400
2 parents a97d8b9 + f9d032f commit c1b027e

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ jobs:
99
# Required if you plan to publish (uncomment the below)
1010
secrets:
1111
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}
12-
with:
13-
disable_phpunit: true

classes/task/reengagement_adhoc_task.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function execute() {
5050
return;
5151
}
5252

53+
// Ensure the coursemodule still exists, otherwise exit early.
54+
if (empty($data->cmid) || !$DB->record_exists('course_modules', ['id' => $data->cmid])) {
55+
return;
56+
}
57+
5358
// Get a list of users who are eligible to start this module.
5459
$startusers = reengagement_get_startusers($data);
5560

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)