Merge branch '2.0' into 2.1

This commit is contained in:
mark_story 2012-03-03 23:20:18 -05:00
commit 50e7f4c995
2 changed files with 60 additions and 5 deletions

View file

@ -53,6 +53,8 @@ class PaginatorHelperTest extends CakeTestCase {
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'order' => null,
'limit' => 20,
'options' => array(
'page' => 1,
'conditions' => array()
@ -369,6 +371,30 @@ class PaginatorHelperTest extends CakeTestCase {
$this->assertEquals($result, 'Article');
}
/**
* Test that sortKey falls back to the default sorting options set
* in the $params which are the default pagination options.
*
* @return void
*/
public function testSortKeyFallbackToParams() {
$this->Paginator->request->params['paging']['Article']['order'] = 'Article.body';
$result = $this->Paginator->sortKey();
$this->assertEquals('Article.body', $result);
$result = $this->Paginator->sortKey('Article');
$this->assertEquals('Article.body', $result);
$this->Paginator->request->params['paging']['Article']['order'] = array(
'Article.body' => 'DESC'
);
$result = $this->Paginator->sortKey();
$this->assertEquals('Article.body', $result);
$result = $this->Paginator->sortKey('Article');
$this->assertEquals('Article.body', $result);
}
/**
* testSortDir method
*
@ -438,6 +464,32 @@ class PaginatorHelperTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that sortDir falls back to the default sorting options set
* in the $params which are the default pagination options.
*
* @return void
*/
public function testSortDirFallbackToParams() {
$this->Paginator->request->params['paging']['Article']['order'] = array(
'Article.body' => 'ASC'
);
$result = $this->Paginator->sortDir();
$this->assertEquals('asc', $result);
$result = $this->Paginator->sortDir('Article');
$this->assertEquals('asc', $result);
$this->Paginator->request->params['paging']['Article']['order'] = array(
'Article.body' => 'DESC'
);
$result = $this->Paginator->sortDir();
$this->assertEquals('desc', $result);
$result = $this->Paginator->sortDir('Article');
$this->assertEquals('desc', $result);
}
/**
* testSortAdminLinks method
*

View file

@ -199,13 +199,14 @@ class PaginatorHelper extends AppHelper {
$params = $this->params($model);
$options = $params['options'];
}
if (isset($options['sort']) && !empty($options['sort'])) {
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
return key($options['order']);
} elseif (isset($options['order']) && is_string($options['order'])) {
return $options['order'];
}
if (isset($options['order'])) {
return is_array($options['order']) ? key($options['order']) : $options['order'];
}
if (isset($params['order'])) {
return is_array($params['order']) ? key($params['order']) : $params['order'];
}
return null;
}
@ -231,6 +232,8 @@ class PaginatorHelper extends AppHelper {
$dir = strtolower($options['direction']);
} elseif (isset($options['order']) && is_array($options['order'])) {
$dir = strtolower(current($options['order']));
} elseif (isset($params['order']) && is_array($params['order'])) {
$dir = strtolower(current($params['order']));
}
if ($dir == 'desc') {