Refactor sorting tests to use a dataprovider

This commit is contained in:
Robbie Averill 2018-09-27 17:18:19 +02:00
parent c7d522ff6d
commit 0c7ced1513

View File

@ -72,88 +72,83 @@ class ManyManyThroughListTest extends SapphireTest
$this->assertEquals('join 2', $item2->ManyManyThroughListTest_JoinObject->Title); $this->assertEquals('join 2', $item2->ManyManyThroughListTest_JoinObject->Title);
} }
public function testSortingOnJoinTable() /**
* @param string $sort
* @param array $expected
* @dataProvider sortingProvider
*/
public function testSorting($sort, $expected)
{ {
/** @var ManyManyThroughListTest\TestObject $parent */ /** @var ManyManyThroughListTest\TestObject $parent */
$parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1'); $parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1');
$items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Sort"'); $items = $parent->Items()->sort($sort);
$this->assertListEquals( $this->assertListEquals($expected, $items);
[
['Title' => 'item 2'],
['Title' => 'item 1'],
],
$items
);
$items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Sort" ASC');
$this->assertListEquals(
[
['Title' => 'item 1'],
['Title' => 'item 2'],
],
$items
);
$items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Title" DESC');
$this->assertListEquals(
[
['Title' => 'item 2'],
['Title' => 'item 1'],
],
$items
);
$items = $parent->Items()->sort('"ManyManyThroughListTest_JoinObject"."Title" ASC');
$this->assertListEquals(
[
['Title' => 'item 1'],
['Title' => 'item 2'],
],
$items
);
} }
public function testSortingOnJoinTableWithoutTableAlias() /**
* @return array[]
*/
public function sortingProvider()
{ {
/** @var ManyManyThroughListTest\TestObject $parent */ return [
$parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1'); 'table with default column' => [
'"ManyManyThroughListTest_JoinObject"."Sort"',
$items = $parent->Items()->sort('"Sort"');
$this->assertListEquals(
[ [
['Title' => 'item 2'], ['Title' => 'item 2'],
['Title' => 'item 1'], ['Title' => 'item 1'],
]
], ],
$items 'table with default column ascending' => [
); '"ManyManyThroughListTest_JoinObject"."Sort" ASC',
$items = $parent->Items()->sort('"Sort" ASC');
$this->assertListEquals(
[ [
['Title' => 'item 1'], ['Title' => 'item 1'],
['Title' => 'item 2'], ['Title' => 'item 2'],
]
], ],
$items 'table with column descending' => [
); '"ManyManyThroughListTest_JoinObject"."Title" DESC',
$items = $parent->Items()->sort('"Title" DESC');
$this->assertListEquals(
[ [
['Title' => 'item 2'], ['Title' => 'item 2'],
['Title' => 'item 1'], ['Title' => 'item 1'],
]
], ],
$items 'table with column ascending' => [
); '"ManyManyThroughListTest_JoinObject"."Title" ASC',
$items = $parent->Items()->sort('"Title" ASC');
$this->assertListEquals(
[ [
['Title' => 'item 1'], ['Title' => 'item 1'],
['Title' => 'item 2'], ['Title' => 'item 2'],
]
], ],
$items 'default column' => [
); '"Sort"',
[
['Title' => 'item 2'],
['Title' => 'item 1'],
]
],
'default column ascending' => [
'"Sort" ASC',
[
['Title' => 'item 1'],
['Title' => 'item 2'],
]
],
'column descending' => [
'"Title" DESC',
[
['Title' => 'item 2'],
['Title' => 'item 1'],
]
],
'column ascending' => [
'"Title" ASC',
[
['Title' => 'item 1'],
['Title' => 'item 2'],
]
],
];
} }
public function testAdd() public function testAdd()