From 881b4258f7862be463f81b08a0730993ccecf5af Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 15 Feb 2021 15:15:35 +0100 Subject: [PATCH] MDL-70897 various: uasort callback can not return bool Co-authored-by: Ruslan Kabalin --- course/classes/local/service/content_item_service.php | 4 ++-- message/tests/api_test.php | 2 +- message/tests/externallib_test.php | 10 +++++----- message/tests/privacy_provider_test.php | 5 +++-- search/classes/manager.php | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/course/classes/local/service/content_item_service.php b/course/classes/local/service/content_item_service.php index 832a7eb63f8..a3cf2f4d1a2 100644 --- a/course/classes/local/service/content_item_service.php +++ b/course/classes/local/service/content_item_service.php @@ -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; diff --git a/message/tests/api_test.php b/message/tests/api_test.php index 8654efeed96..3b367fbf7b4 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -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. diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php index b25174b9519..087b27679c7 100644 --- a/message/tests/externallib_test.php +++ b/message/tests/externallib_test.php @@ -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); diff --git a/message/tests/privacy_provider_test.php b/message/tests/privacy_provider_test.php index 245049f45fe..380a7c7cea5 100644 --- a/message/tests/privacy_provider_test.php +++ b/message/tests/privacy_provider_test.php @@ -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; } /** diff --git a/search/classes/manager.php b/search/classes/manager.php index c0a1c5fa3f5..70f81f0be96 100644 --- a/search/classes/manager.php +++ b/search/classes/manager.php @@ -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; -- 2.43.0