Skip to content

Commit

Permalink
Adds two simple tests to prove secondary column sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Mar 11, 2018
1 parent a0e3d9c commit b889769
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/PHPUnit/Unit/DataTable/Filter/SortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,34 @@ public function testFilter_shouldPickStringSearchEvenIfFirstLabelIsNumeric()
$this->assertTrue(DataTable::isEqual($table, $expectedtableReverse));
}

public function testSecondarySort()
{
$table = new DataTable();
$table->addRowsFromArray(array(
array(Row::COLUMNS => array('label' => 'ask', 'count' => 10, 'count2' => 10)),
array(Row::COLUMNS => array('label' => 'nintendo', 'count' => 10, 'count2' => 5)),
array(Row::COLUMNS => array('label' => 'yahoo', 'count' => 10, 'count2' => 100)
)));
$filter = new Sort($table, 'count', 'desc', true, true, function(){return 'count2';});
$filter->filter($table);
$expectedOrder = array('yahoo', 'ask', 'nintendo');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}

public function testSecondarySort2()
{
$table = new DataTable();
$table->addRowsFromArray(array(
array(Row::COLUMNS => array('label' => 'ask', 'count' => 1, 'count2' => 10)),
array(Row::COLUMNS => array('label' => 'nintendo', 'count' => 10, 'count2' => 5)),
array(Row::COLUMNS => array('label' => 'yahoo', 'count' => 10, 'count2' => 100)
)));
$filter = new Sort($table, 'count', 'desc', true, true, function(){return 'count2';});
$filter->filter($table);
$expectedOrder = array('yahoo', 'nintendo', 'ask');
$this->assertEquals($expectedOrder, $table->getColumn('label'));
}

private function createDataTable($rows)
{
$table = new DataTable();
Expand Down

0 comments on commit b889769

Please sign in to comment.