|
14 | 14 | // You should have received a copy of the GNU General Public License
|
15 | 15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
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; |
26 | 20 |
|
27 | 21 | /**
|
28 | 22 | * Unit tests for observation timeslot notifications.
|
|
32 | 26 | * @copyright Matthew Hilton, Celine Lindeque, Jack Kepper, Jared Hungerford
|
33 | 27 | * @author Matthew Hilton <[email protected]>
|
34 | 28 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 29 | + * @covers \mod_observation\timeslot_manager |
35 | 30 | */
|
36 | 31 | class timeslot_notification_test extends advanced_testcase {
|
37 | 32 |
|
@@ -286,4 +281,27 @@ public function test_deleted_after_slot_deleted() {
|
286 | 281 | $notifications = \mod_observation\timeslot_manager::get_users_notifications($obid, $this->observee->id);
|
287 | 282 | $this->assertEmpty($notifications);
|
288 | 283 | }
|
| 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 | + } |
289 | 307 | }
|
0 commit comments