Merge pull request #10693 from creative-commoners/pulls/5.0/tweak-test-for-postgresql

MNT Tweak some test to account for slightly different sorting logic in PostgreSQL
This commit is contained in:
Daniel Hensby 2023-02-18 10:32:28 +05:30 committed by GitHub
commit bf058ee968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -1958,8 +1958,6 @@ class DataListTest extends SapphireTest
/**
* Test passing scalar values to sort()
*
* Explicity tests that sort(null) will wipe any existing sort on a DataList
*
* @dataProvider provideSortScalarValues
*/
public function testSortScalarValues(mixed $emtpyValue, string $type): void
@ -1967,16 +1965,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 +1980,6 @@ class DataListTest extends SapphireTest
public function provideSortScalarValues(): array
{
return [
[null, 'wipes-existing'],
['', 'empty-scalar'],
[[], 'empty-scalar'],
[false, 'invalid-scalar'],
@ -1994,6 +1989,27 @@ class DataListTest extends SapphireTest
];
}
/**
* 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()