Skip to content

Commit 2241fdb

Browse files
Merge pull request #130 from catalyst/129-handle-removed-users
[#129] Handle users being removed from timeslots when processing noti…
2 parents ea9bbf2 + 7903306 commit 2241fdb

9 files changed

+73
-76
lines changed

classes/timeslot_manager.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,18 @@ public static function process_notifications() {
665665
foreach ($notifications as $n) {
666666
$notifytime = $n->start_time - $n->time_before;
667667

668-
if ($notifytime < time()) {
669-
// Process it !
670-
self::send_reminder_message($n->obs_id, $n->timeslot_id, $n->userid);
668+
// Not ready yet - skip.
669+
if (time() < $notifytime) {
670+
continue;
671+
}
671672

672-
// Delete notification record.
673-
$DB->delete_records('observation_notifications', ['id' => $n->notification_id]);
673+
// If user is still linked to the timeslot, send the reminder message.
674+
if (!empty($n->userid)) {
675+
self::send_reminder_message($n->obs_id, $n->timeslot_id, $n->userid);
674676
}
677+
678+
// Delete the record.
679+
$DB->delete_records('observation_notifications', ['id' => $n->notification_id]);
675680
}
676681
}
677682

tests/backup_test.php

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
namespace mod_observation;
18+
19+
use advanced_testcase;
20+
1721
/**
1822
* Unit tests for observation backups.
1923
*
@@ -22,6 +26,8 @@
2226
* @copyright Catalyst IT Australia
2327
* @author Matthew Hilton
2428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \backup_observation_activity_task
30+
* @covers \restore_observation_activity_task
2531
*/
2632
class backup_test extends advanced_testcase {
2733
/**

tests/observation_point_test.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the observation point manager class.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for the observation point manager class.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\observation_manager
3530
*/
3631
class observation_point_test extends advanced_testcase {
3732

tests/observation_session_test.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the observation session class.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for the observation session manager class.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\observation_manager
3530
*/
3631
class observation_session_test extends advanced_testcase {
3732

tests/privacy_test.php tests/provider_test.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,23 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the block_community implementation of the privacy API.
19-
*
20-
* @package mod_observation
21-
* @copyright Catalyst IT
22-
* @author Matthew Hilton <[email protected]>
23-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24-
*/
25-
26-
defined('MOODLE_INTERNAL') || die();
17+
namespace mod_observation;
2718

28-
use \core_privacy\local\metadata\collection;
29-
use \core_privacy\local\request\writer;
30-
use \core_privacy\local\request\approved_contextlist;
31-
use \mod_observation\privacy\provider;
19+
use core_privacy\local\metadata\collection;
20+
use core_privacy\local\request\writer;
21+
use core_privacy\local\request\approved_contextlist;
22+
use mod_observation\privacy\provider;
3223

3324
/**
3425
* Unit tests for the mod_observation implementation of the privacy API.
3526
*
3627
* @copyright Catalyst IT
28+
* @package mod_observation
3729
* @author Matthew Hilton <[email protected]>
3830
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31+
* @covers \mod_observation\privacy\provider
3932
*/
40-
class mod_observation_privacy_testcase extends \core_privacy\tests\provider_testcase {
33+
class provider_test extends \core_privacy\tests\provider_testcase {
4134
/**
4235
* Set up for tests.
4336
*/
@@ -359,7 +352,7 @@ public function test_export_user_data() {
359352
]);
360353

361354
// Export the user data for this user.
362-
$cmcontext = context_module::instance($this->instance->cmid);
355+
$cmcontext = \context_module::instance($this->instance->cmid);
363356
$writer = writer::with_context($cmcontext);
364357
$contextlist = new approved_contextlist($this->observee, 'mod_observation' , [$cmcontext->id]);
365358

tests/timeslot_joining_test.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the observation timeslot joining.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Jack Kepper <[email protected]>, Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for the observation timeslot joining.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Jack Kepper <[email protected]>, Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\timeslot_manager
3530
*/
3631
class timeslot_joining_test extends advanced_testcase {
3732

tests/timeslot_notification_test.php

+27-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the observation timeslot joining.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for observation timeslot notifications.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\timeslot_manager
3530
*/
3631
class timeslot_notification_test extends advanced_testcase {
3732

@@ -286,4 +281,27 @@ public function test_deleted_after_slot_deleted() {
286281
$notifications = \mod_observation\timeslot_manager::get_users_notifications($obid, $this->observee->id);
287282
$this->assertEmpty($notifications);
288283
}
284+
285+
/**
286+
* Tests that process_notifications handles correctly a notification with no observee to send it to.
287+
* In this case, it should just ignore it and delete the notification processing record.
288+
*/
289+
public function test_process_notifications_after_user_removed() {
290+
global $DB;
291+
292+
// Create notification.
293+
$this->setUser($this->observee);
294+
\mod_observation\timeslot_manager::create_notification($this->instance->id, $this->slot1id, $this->observee->id,
295+
(object) self::NOTIFY_DATA);
296+
297+
$this->assertEquals(1, $DB->count_records('observation_notifications'));
298+
299+
// Remove them from the timeslot.
300+
\mod_observation\timeslot_manager::remove_observee($this->instance->id, $this->slot1id, $this->observee->id);
301+
302+
// Process their notifications. This should just remove the notification,
303+
// since the user is not longer assigned to the timeslot.
304+
\mod_observation\timeslot_manager::process_notifications();
305+
$this->assertEquals(0, $DB->count_records('observation_notifications'));
306+
}
289307
}

tests/timeslots_test.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for timeslots.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for timeslots.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\timeslot_manager
3530
*/
3631
class timeslots_test extends advanced_testcase {
3732

@@ -224,7 +219,7 @@ public function test_negative_start_time() {
224219
* Creates data for valid interval timeslot
225220
*/
226221
private function create_valid_interval_timeslot() {
227-
$data = new stdClass();
222+
$data = new \stdClass();
228223

229224
$data->interval_amount = 30;
230225
// In form the multiplier is a string, so simulate that here.

tests/unenrol_test.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* Unit tests for the observation session class.
19-
*
20-
* @package mod_observation
21-
* @category test
22-
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
23-
* @author Jack Kepper <[email protected]>, Matthew Hilton <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
17+
namespace mod_observation;
18+
19+
use advanced_testcase;
2620

2721
/**
2822
* Unit tests for unenrollment functions.
@@ -32,6 +26,7 @@
3226
* @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
3327
* @author Jack Kepper <[email protected]>, Matthew Hilton <[email protected]>
3428
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
* @covers \mod_observation\timeslot_manager
3530
*/
3631
class unenrol_test extends advanced_testcase {
3732

0 commit comments

Comments
 (0)