Skip to content

Commit

Permalink
raisedtest coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
n.plaschke committed Dec 14, 2015
1 parent 46645fd commit d3c3ad6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/OpenSkill/Datatable/Providers/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,18 @@ public function setupOrder()
*/
$this->defaultGlobalOrderFunction = function (array $first, array $second, array $orderColumn) {
foreach($orderColumn as $order) {
$value = strnatcmp($first[$order->columnName()], $second[$order->columnName()]);
if($value == 0) {
continue;
}
if (!$order->isAscending()) {
return $value * -1;
if(array_key_exists($order->columnName(), $first)) {
$value = strnatcmp($first[$order->columnName()], $second[$order->columnName()]);
if($value == 0) {
continue;
}
if (!$order->isAscending()) {
return $value * -1;
}
return $value;
}
return $value;
}
return 0;
};
}
}
29 changes: 29 additions & 0 deletions tests/OpenSkill/Datatable/Providers/CollectionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,35 @@ public function testDefaultOrder()
$this->assertSame(2, $first['id']);
}

public function testNoOrder()
{
$data = [
['id' => 1, 'name' => 'foo'],
['id' => 2, 'name' => 'foo'],
];

$queryConfiguration = QueryConfigurationBuilder::create()
->start(0)
->length(2)
->drawCall(1)
->columnOrder('name', 'asc')
->build();

$columnConfiguration = ColumnConfigurationBuilder::create()
->name('name')
->build();

$provider = new CollectionProvider(new Collection($data));

$provider->prepareForProcessing($queryConfiguration, [$columnConfiguration]);
$data = $provider->process();

$this->assertSame(2, $data->data()->count());
$first = $data->data()->first();

$this->assertSame('foo', $first['name']);
}

public function testDefaultOrder2()
{
$data = [
Expand Down

0 comments on commit d3c3ad6

Please sign in to comment.