Skip to content

Commit

Permalink
MDL-56090 core_message: added API unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 21, 2016
1 parent 919b9df commit 1f64514
Show file tree
Hide file tree
Showing 5 changed files with 820 additions and 16 deletions.
14 changes: 7 additions & 7 deletions message/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public static function get_profile($userid, $otheruserid) {
if (isset($userfields['lastaccess'])) {
$data->isonline = helper::is_online($userfields['lastaccess']);
} else {
$data->isonline = 0;
$data->isonline = false;
}
} else {
// Technically the access checks in user_get_user_details are correct,
Expand All @@ -362,12 +362,12 @@ public static function get_profile($userid, $otheruserid) {
$data->email = '';
$data->profileimageurl = '';
$data->profileimageurlsmall = '';
$data->isonline = 0;
$data->isonline = false;
}
// Check if the contact has been blocked.
$contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
if ($contact) {
$data->isblocked = $contact->blocked;
$data->isblocked = (bool) $contact->blocked;
$data->iscontact = true;
} else {
$data->isblocked = false;
Expand All @@ -383,14 +383,14 @@ public static function get_profile($userid, $otheruserid) {
*
* @param int $userid The user id of who we want to delete the messages for (this may be done by the admin
* but will still seem as if it was by the user)
* @return bool Returns true if a user can delete the message, false otherwise.
* @return bool Returns true if a user can delete the conversation, false otherwise.
*/
public static function can_delete_conversation($userid) {
global $USER;

$systemcontext = \context_system::instance();

// Let's check if the user is allowed to delete this message.
// Let's check if the user is allowed to delete this conversation.
if (has_capability('moodle/site:deleteanymessage', $systemcontext) ||
((has_capability('moodle/site:deleteownmessage', $systemcontext) &&
$USER->id == $userid))) {
Expand All @@ -411,7 +411,7 @@ public static function can_delete_conversation($userid) {
* @return bool
*/
public static function delete_conversation($userid, $otheruserid) {
global $DB, $USER;
global $DB;

// We need to update the tables to mark all messages as deleted from and to the other user. This seems worse than it
// is, that's because our DB structure splits messages into two tables (great idea, huh?) which causes code like this.
Expand Down Expand Up @@ -457,7 +457,7 @@ public static function delete_conversation($userid, $otheruserid) {

// Trigger event for deleting the message.
\core\event\message_deleted::create_from_ids($message->useridfrom, $message->useridto,
$USER->id, $messagetable, $message->id)->trigger();
$userid, $messagetable, $message->id)->trigger();
}
}

Expand Down
4 changes: 2 additions & 2 deletions message/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public static function create_contact($contact, $prefix = '') {
}
// Check if the user is online.
$data->isonline = self::is_online($userfields->lastaccess);
$data->isblocked = isset($contact->blocked) ? $contact->blocked : 0;
$data->isread = isset($contact->isread) ? $contact->isread : 0;
$data->isblocked = isset($contact->blocked) ? (bool) $contact->blocked : false;
$data->isread = isset($contact->isread) ? (bool) $contact->isread : false;
$data->unreadcount = isset($contact->unreadcount) ? $contact->unreadcount : null;

return $data;
Expand Down
Loading

0 comments on commit 1f64514

Please sign in to comment.