MNT Tweak some test to account for slightly different sorting logic in PostgreSQL

This commit is contained in:
Maxime Rainville 2023-02-17 18:47:20 +13:00
parent 6a6a7849c0
commit 7bc4c9dbc3
2 changed files with 27 additions and 6 deletions

View File

@ -1967,16 +1967,14 @@ class DataListTest extends SapphireTest
$this->assertSame(['Subteam 1'], Team::get()->limit(1)->column('Title'));
$list = Team::get()->sort('Title DESC');
$this->assertSame(['Team 3'], $list->limit(1)->column('Title'));
if ($type !== 'wipes-existing') {
$this->expectException(InvalidArgumentException::class);
}
$this->expectException(InvalidArgumentException::class);
if ($type === 'invalid-scalar') {
$this->expectExceptionMessage('sort() arguments must either be a string, an array, or null');
}
if ($type === 'empty-scalar') {
$this->expectExceptionMessage('Invalid sort parameter');
}
// $type === 'wipes-existing' is valid
$list = $list->sort($emtpyValue);
$this->assertSame(['Subteam 1'], $list->limit(1)->column('Title'));
}
@ -1984,7 +1982,6 @@ class DataListTest extends SapphireTest
public function provideSortScalarValues(): array
{
return [
[null, 'wipes-existing'],
['', 'empty-scalar'],
[[], 'empty-scalar'],
[false, 'invalid-scalar'],
@ -1994,6 +1991,30 @@ class DataListTest extends SapphireTest
];
}
/**
* Test passing scalar values to sort()
*
* Explicity tests that sort(null) will wipe any existing sort on a DataList
*
*/
public function testSortNull(): void
{
$list = Team::get()->sort('Title DESC');
$query = $list->dataQuery()->getFinalisedQuery();
$this->assertSame(
['"DataObjectTest_Team"."Title"' => 'DESC'],
$query->getOrderBy(),
'Calling sort on a DataList sets an Orderby on the underlying query.'
);
$list = $list->sort(null);
$query = $list->dataQuery()->getFinalisedQuery();
$this->assertEmpty(
$query->getOrderBy(),
'Calling sort with null on a DataList unsets the orderby on the underlying query.'
);
}
public function testShuffle()
{
$list = Team::get()->shuffle();

View File

@ -1831,7 +1831,7 @@ class MemberTest extends FunctionalTest
$result = Member::mapInCMSGroups($groups);
$this->assertInstanceOf(Map::class, $result);
$this->assertSame($expectedUsers, $result->keys());
$this->assertEqualsCanonicalizing($expectedUsers, $result->keys());
}
public function provideMapInCMSGroups()