From 7bc4c9dbc319f4c3d5aacad2468682e9eaaa32fb Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 17 Feb 2023 18:47:20 +1300 Subject: [PATCH 1/2] MNT Tweak some test to account for slightly different sorting logic in PostgreSQL --- tests/php/ORM/DataListTest.php | 31 ++++++++++++++++++++++++++----- tests/php/Security/MemberTest.php | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/php/ORM/DataListTest.php b/tests/php/ORM/DataListTest.php index a50bb6598..99af9d765 100755 --- a/tests/php/ORM/DataListTest.php +++ b/tests/php/ORM/DataListTest.php @@ -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(); diff --git a/tests/php/Security/MemberTest.php b/tests/php/Security/MemberTest.php index 703959946..a600190c0 100644 --- a/tests/php/Security/MemberTest.php +++ b/tests/php/Security/MemberTest.php @@ -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() From 8c396eb1f6178ad7ef2af5e287a603fc0d75ef23 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Fri, 17 Feb 2023 18:53:42 +1300 Subject: [PATCH 2/2] MNT Remove bad PHPDoc comments on test --- tests/php/ORM/DataListTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/php/ORM/DataListTest.php b/tests/php/ORM/DataListTest.php index 99af9d765..294123284 100755 --- a/tests/php/ORM/DataListTest.php +++ b/tests/php/ORM/DataListTest.php @@ -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 @@ -1992,10 +1990,7 @@ 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 {