Fixing double merging of URL parameters in PaginatorHelper::sort() (Ticket #2692)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5291 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-06-17 17:01:18 +00:00
parent c803efec88
commit 028ffae272
2 changed files with 29 additions and 12 deletions

View file

@ -140,10 +140,14 @@ class PaginatorHelper extends AppHelper {
$options = am($params['defaults'], $params['options']);
}
if (isset($options['sort'])) {
if (isset($options['sort']) && !empty($options['sort'])) {
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
return preg_replace('/.*\./', '', key($options['order']));
} elseif (isset($options['order']) && is_string($options['order'])) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
return $result[1];
}
}
return null;
}
@ -210,9 +214,6 @@ class PaginatorHelper extends AppHelper {
* key the returned link will sort by 'desc'.
*/
function sort($title, $key = null, $options = array()) {
if(!empty($this->options)) {
$options = am($this->options, $options);
}
$options = am(array('url' => array(), 'model' => null), $options);
$url = $options['url'];
unset($options['url']);

View file

@ -49,18 +49,20 @@ class PaginatorTest extends UnitTestCase {
'nextPage' => true,
'pageCount' => 7,
'defaults' => array(
'order' => 'Article.date DESC',
'order' => 'Article.date ASC',
'limit' => 9,
'conditions' => array()
)
),
'options' => array(
'order' => 'Article.date DESC',
'limit' => 9,
'page' => 1
),
'options' => array(
'order' => 'Article.date ASC',
'limit' => 9,
'page' => 1,
'conditions' => array()
)
)
);
$this->paginator->Html =& new HtmlHelper();
$this->paginator->Ajax =& new AjaxHelper();
}
function testHasPrevious() {
@ -77,6 +79,20 @@ class PaginatorTest extends UnitTestCase {
$this->paginator->params['paging']['Article']['nextPage'] = true;
}
function testSortLinks() {
Router::reload();
Router::setRequestInfo(array(
array ('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0, 'webservices' => null),
array ('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null)
));
$this->paginator->options(array('url' => array('param')));
$result = $this->paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc"\s*>Title<\/a>$/', $result);
$result = $this->paginator->sort('date');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc"\s*>Date<\/a>$/', $result);
}
function tearDown() {
unset($this->paginator);
}