diff --git a/tests/php/ORM/ManyManyThroughListTest.php b/tests/php/ORM/ManyManyThroughListTest.php index 73b9b1507..3436fff9c 100644 --- a/tests/php/ORM/ManyManyThroughListTest.php +++ b/tests/php/ORM/ManyManyThroughListTest.php @@ -70,8 +70,13 @@ class ManyManyThroughListTest extends SapphireTest $this->assertNotNull($item2->getJoin()); $this->assertEquals('join 2', $item2->getJoin()->Title); $this->assertEquals('join 2', $item2->ManyManyThroughListTest_JoinObject->Title); + } + + public function testSortingOnJoinTable() + { + /** @var ManyManyThroughListTest\TestObject $parent */ + $parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1'); - // Test sorting on join table $items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Sort"'); $this->assertListEquals( [ @@ -89,6 +94,7 @@ class ManyManyThroughListTest extends SapphireTest ], $items ); + $items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Title" DESC'); $this->assertListEquals( [ @@ -97,6 +103,57 @@ class ManyManyThroughListTest extends SapphireTest ], $items ); + + $items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Title" ASC'); + $this->assertListEquals( + [ + ['Title' => 'item 1'], + ['Title' => 'item 2'], + ], + $items + ); + } + + public function testSortingOnJoinTableWithoutTableAlias() + { + /** @var ManyManyThroughListTest\TestObject $parent */ + $parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1'); + + $items = $parent->Items()->sort('"Sort"'); + $this->assertListEquals( + [ + ['Title' => 'item 2'], + ['Title' => 'item 1'], + ], + $items + ); + + $items = $parent->Items()->sort('"Sort" ASC'); + $this->assertListEquals( + [ + ['Title' => 'item 1'], + ['Title' => 'item 2'], + ], + $items + ); + + $items = $parent->Items()->sort('"Title" DESC'); + $this->assertListEquals( + [ + ['Title' => 'item 2'], + ['Title' => 'item 1'], + ], + $items + ); + + $items = $parent->Items()->sort('"Title" ASC'); + $this->assertListEquals( + [ + ['Title' => 'item 1'], + ['Title' => 'item 2'], + ], + $items + ); } public function testAdd()