/** * Test marking all message as read. */ public function test_mark_all_messages_as_read() { global $DB; $this->resetAfterTest(true); $sender1 = $this->getDataGenerator()->create_user(); $sender2 = $this->getDataGenerator()->create_user(); $sender3 = $this->getDataGenerator()->create_user(); $recipient = $this->getDataGenerator()->create_user(); $this->setUser($recipient); $this->send_message($sender1, $recipient, 'Message'); $this->send_message($sender1, $recipient, 'Message'); $this->send_message($sender2, $recipient, 'Message'); $this->send_message($sender2, $recipient, 'Message'); $this->send_message($sender3, $recipient, 'Message'); $this->send_message($sender3, $recipient, 'Message'); core_message_external::mark_all_messages_as_read($recipient->id, $sender1->id); $readnotifications = $DB->get_records('message_read', array('useridto' => $recipient->id)); $unreadnotifications = $DB->get_records('message', array('useridto' => $recipient->id)); $this->assertCount(2, $readnotifications); $this->assertCount(4, $unreadnotifications); core_message_external::mark_all_messages_as_read($recipient->id, 0); $readnotifications = $DB->get_records('message_read', array('useridto' => $recipient->id)); $unreadnotifications = $DB->get_records('message', array('useridto' => $recipient->id)); $this->assertCount(6, $readnotifications); $this->assertCount(0, $unreadnotifications); }