MDL-70897 various: uasort callback can not return bool

Co-authored-by: Ruslan Kabalin <ruslan.kabalin@gmail.com>
This commit is contained in:
Marina Glancy 2021-02-15 15:15:35 +01:00 committed by Ruslan Kabalin
parent 0fd37bf5d8
commit 881b4258f7
5 changed files with 12 additions and 11 deletions

View File

@ -225,7 +225,7 @@ class content_item_service {
// Sort by title for return.
usort($exported->content_items, function($a, $b) {
return $a->title > $b->title;
return strcmp($a->title, $b->title);
});
return $exported->content_items;
@ -301,7 +301,7 @@ class content_item_service {
// Sort by title for return.
usort($exported->content_items, function($a, $b) {
return $a->title > $b->title;
return strcmp($a->title, $b->title);
});
return $exported->content_items;

View File

@ -1327,7 +1327,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$conversations = \core_message\api::get_conversations($user1->id);
usort($conversations, function($first, $second){
return $first->id > $second->id;
return $first->id <=> $second->id;
});
// Consider first conversations is self-conversation.

View File

@ -2091,7 +2091,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
$this->assertCount(2, $contacts[0]['conversations']);
// We can't rely on the ordering of conversations within the results, so sort by id first.
usort($contacts[0]['conversations'], function($a, $b) {
return $a['id'] < $b['id'];
return $b['id'] <=> $a['id'];
});
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
@ -2187,7 +2187,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
$this->assertCount(2, $contacts[0]['conversations']);
// We can't rely on the ordering of conversations within the results, so sort by id first.
usort($contacts[0]['conversations'], function($a, $b) {
return $a['id'] < $b['id'];
return $b['id'] <=> $a['id'];
});
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
@ -3538,7 +3538,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
* @return bool
*/
protected static function sort_contacts($a, $b) {
return $a['userid'] > $b['userid'];
return $a['userid'] <=> $b['userid'];
}
/**
@ -3549,7 +3549,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
* @return bool
*/
protected static function sort_contacts_id($a, $b) {
return $a['id'] > $b['id'];
return $a['id'] <=> $b['id'];
}
/**
@ -4422,7 +4422,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
$conversations = $result['conversations'];
usort($conversations, function($first, $second){
return $first['id'] > $second['id'];
return $first['id'] <=> $second['id'];
});
$selfconversation = array_shift($conversations);

View File

@ -2904,7 +2904,7 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
* @return bool
*/
protected static function sort_messages($a, $b) {
return $a->message > $b->message;
return strcmp($a->message, $b->message);
}
/**
@ -2915,7 +2915,8 @@ class core_message_privacy_provider_testcase extends \core_privacy\tests\provide
* @return bool
*/
protected static function sort_contacts($a, $b) {
return $a->contact > $b->contact;
// Contact attribute contains user id.
return $a->contact <=> $b->contact;
}
/**

View File

@ -480,7 +480,7 @@ class manager {
// Sort categories by order.
uasort($categories, function($category1, $category2) {
return $category1->get_order() > $category2->get_order();
return $category1->get_order() <=> $category2->get_order();
});
static::$searchareacategories = $categories;