mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
MDL-58014 core_message: fixed unread message count
This commit is contained in:
parent
9ec952f237
commit
29c3b0b4d2
@ -220,10 +220,12 @@ function message_count_unread_messages($user1=null, $user2=null) {
|
||||
}
|
||||
|
||||
if (!empty($user2)) {
|
||||
return $DB->count_records_select('message', "useridto = ? AND useridfrom = ?",
|
||||
return $DB->count_records_select('message', "useridto = ? AND useridfrom = ? AND notification = 0
|
||||
AND timeusertodeleted = 0",
|
||||
array($user1->id, $user2->id), "COUNT('id')");
|
||||
} else {
|
||||
return $DB->count_records_select('message', "useridto = ?",
|
||||
return $DB->count_records_select('message', "useridto = ? AND notification = 0
|
||||
AND timeusertodeleted = 0",
|
||||
array($user1->id), "COUNT('id')");
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->send_fake_message($sender2, $recipient);
|
||||
|
||||
\core_message\api::mark_all_read_for_user($recipient->id, $sender1->id);
|
||||
$this->assertEquals(message_count_unread_messages($recipient), 6);
|
||||
$this->assertEquals(message_count_unread_messages($recipient), 3);
|
||||
}
|
||||
|
||||
public function test_mark_all_read_for_user_touser_with_type() {
|
||||
|
@ -194,6 +194,59 @@ class core_message_messagelib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(1, message_count_unread_messages($userto, $userfrom1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_count_unread_messages with notifications.
|
||||
*/
|
||||
public function test_message_count_unread_messages_with_notifications() {
|
||||
// Create users to send and receive messages.
|
||||
$userfrom1 = $this->getDataGenerator()->create_user();
|
||||
$userfrom2 = $this->getDataGenerator()->create_user();
|
||||
$userto = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->assertEquals(0, message_count_unread_messages($userto));
|
||||
|
||||
// Send fake messages.
|
||||
$this->send_fake_message($userfrom1, $userto);
|
||||
$this->send_fake_message($userfrom2, $userto);
|
||||
|
||||
// Send fake notifications.
|
||||
$this->send_fake_message($userfrom1, $userto, 'Notification', 1);
|
||||
$this->send_fake_message($userfrom2, $userto, 'Notification', 1);
|
||||
|
||||
// Should only count the messages.
|
||||
$this->assertEquals(2, message_count_unread_messages($userto));
|
||||
$this->assertEquals(1, message_count_unread_messages($userto, $userfrom1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_count_unread_messages with deleted messages.
|
||||
*/
|
||||
public function test_message_count_unread_messages_with_deleted_messages() {
|
||||
global $DB;
|
||||
|
||||
// Create users to send and receive messages.
|
||||
$userfrom1 = $this->getDataGenerator()->create_user();
|
||||
$userfrom2 = $this->getDataGenerator()->create_user();
|
||||
$userto = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->assertEquals(0, message_count_unread_messages($userto));
|
||||
|
||||
// Send fake messages.
|
||||
$messageid = $this->send_fake_message($userfrom1, $userto);
|
||||
$this->send_fake_message($userfrom2, $userto);
|
||||
|
||||
// Send fake notifications.
|
||||
$this->send_fake_message($userfrom1, $userto, 'Notification', 1);
|
||||
$this->send_fake_message($userfrom2, $userto, 'Notification', 1);
|
||||
|
||||
// Delete a message.
|
||||
$message = $DB->get_record('message', array('id' => $messageid));
|
||||
message_delete_message($message, $userto->id);
|
||||
|
||||
// Should only count the messages that weren't deleted by the current user.
|
||||
$this->assertEquals(1, message_count_unread_messages($userto));
|
||||
$this->assertEquals(0, message_count_unread_messages($userto, $userfrom1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_add_contact.
|
||||
|
Loading…
x
Reference in New Issue
Block a user