Skip to content
Snippets Groups Projects
Commit a88b687f authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3453511 by eiriksm: Make sure getting user teams return teams in a somewhat consistent order

parent d5877d47
No related branches found
No related tags found
1 merge request!62Make sure teams are same order
Pipeline #194965 passed with warnings
......@@ -79,6 +79,10 @@ class TeamManager {
->condition('field_team_members', $user->id())
->condition('field_team_admins', $user->id());
$nids_q->condition($or);
// Make sure they are somewhat consistent.
$nids_q->sort('nid');
$nids = $nids_q->execute();
return $node_storage->loadMultiple($nids);
}
......
......@@ -52,6 +52,35 @@ class TeamManagerTest extends KernelTestBase {
self::assertEquals($node->id(), $team_node_result->id());
}
/**
* Test that we get the same teams back from every call to the team manager.
*/
public function testGetSeverealTeamsFromUser() {
/** @var \Drupal\violinist_teams\TeamNode $node1 */
$node1 = Node::create([
'type' => $this->nodeType->id(),
'title' => 'test1',
]);
/** @var \Drupal\violinist_teams\TeamNode $node2 */
$node2 = Node::create([
'type' => $this->nodeType->id(),
'title' => 'test2',
]);
$user = User::create([
'name' => 'test',
'mail' => 'test@example.com',
]);
$user->save();
$node1->appendMember($user)->save();
$node2->appendMember($user)->save();
$teams = $this->teamManager->getTeamsByUser($user);
self::assertCount(2, $teams);
$team_ids = array_values(array_map(function (TeamNode $team) {
return $team->id();
}, $teams));
self::assertEquals([$node1->id(), $node2->id()], $team_ids);
}
/**
* Test that we can get teams from user.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment