mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-64412 core_message: get_member_info() respects provided ordering
This change makes sure the function returns the member information in the same order as those users provided in the $userids param.
This commit is contained in:
parent
38a1b4f203
commit
9e6734a790
@ -589,6 +589,9 @@ class helper {
|
||||
}
|
||||
}
|
||||
|
||||
// Return member information in the same order as the userids originally provided.
|
||||
$members = array_replace(array_flip($userids), $members);
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
|
70
message/tests/helper_test.php
Normal file
70
message/tests/helper_test.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains a test class for the message helper.
|
||||
*
|
||||
* @package core_message
|
||||
* @category test
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/message/tests/messagelib_test.php');
|
||||
|
||||
/**
|
||||
* Tests for the message helper class.
|
||||
*
|
||||
* @package core_message
|
||||
* @category test
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_message_helper_testcase extends advanced_testcase {
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
public function test_get_member_info_ordering() {
|
||||
// Create a conversation with several users.
|
||||
$user1 = self::getDataGenerator()->create_user();
|
||||
$user2 = self::getDataGenerator()->create_user();
|
||||
$user3 = self::getDataGenerator()->create_user();
|
||||
$user4 = self::getDataGenerator()->create_user();
|
||||
|
||||
\core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[
|
||||
$user1->id,
|
||||
$user2->id,
|
||||
$user3->id,
|
||||
$user4->id,
|
||||
],
|
||||
'Group conversation'
|
||||
);
|
||||
|
||||
// Verify that the member information comes back in the same order that we specified in the input array.
|
||||
$memberinfo = \core_message\helper::get_member_info($user1->id, [$user3->id, $user4->id, $user2->id]);
|
||||
$this->assertEquals($user3->id, array_shift($memberinfo)->id);
|
||||
$this->assertEquals($user4->id, array_shift($memberinfo)->id);
|
||||
$this->assertEquals($user2->id, array_shift($memberinfo)->id);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user