Skip to content

Commit

Permalink
Removed unused test and simplified validateSort
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafikart committed Jan 29, 2014
1 parent aec9564 commit fb68446
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
32 changes: 15 additions & 17 deletions src/Controller/Component/PaginatorComponent.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -305,28 +305,26 @@ public function validateSort(Table $object, array $options) {
return $options; return $options;
} }


if (is_array($options['order'])) { $tableAlias = $object->alias();
$tableAlias = $object->alias(); $order = [];
$order = [];


foreach ($options['order'] as $key => $value) { foreach ($options['order'] as $key => $value) {
$field = $key; $field = $key;
$alias = $tableAlias; $alias = $tableAlias;
if (is_numeric($key)){ if (is_numeric($key)){
$order[] = $value; $order[] = $value;
}else{ }else{
if (strpos($key, '.') !== false) { if (strpos($key, '.') !== false) {
list($alias, $field) = explode('.', $key); list($alias, $field) = explode('.', $key);
} }
$correctAlias = ($tableAlias == $alias); $correctAlias = ($tableAlias == $alias);


if ($correctAlias && $object->hasField($field)) { if ($correctAlias && $object->hasField($field)) {
$order[$tableAlias . '.' . $field] = $value; $order[$tableAlias . '.' . $field] = $value;
}
} }
} }
$options['order'] = $order;
} }
$options['order'] = $order;


return $options; return $options;
} }
Expand Down
21 changes: 0 additions & 21 deletions tests/TestCase/Controller/Component/PaginatorComponentTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -508,27 +508,6 @@ public function testValidateSortWithString() {
$this->assertEquals($expected, $result['order']); $this->assertEquals($expected, $result['order']);
} }


/**
* test that numeric array order are used by paginator
*
* @return void
*/
public function testValidateSortWithNumericArray() {
$model = $this->getMock('Cake\ORM\Table');
$model->expects($this->any())
->method('alias')
->will($this->returnValue('model'));
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));

$options = array(
'order' => array('model.author_id DESC')
);
$result = $this->Paginator->validateSort($model, $options);
$expected = array('model.author_id DESC');

$this->assertEquals($expected, $result['order']);
}

/** /**
* Test that no sort doesn't trigger an error. * Test that no sort doesn't trigger an error.
* *
Expand Down

0 comments on commit fb68446

Please sign in to comment.