Add tests for sorting many many through list without a table alias

This commit is contained in:
Robbie Averill 2018-09-27 14:34:37 +02:00
parent 89df5515ae
commit 3321c6b39d

View File

@ -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()