mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
c803efec88
commit
028ffae272
2 changed files with 29 additions and 12 deletions
|
@ -140,10 +140,14 @@ class PaginatorHelper extends AppHelper {
|
||||||
$options = am($params['defaults'], $params['options']);
|
$options = am($params['defaults'], $params['options']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['sort'])) {
|
if (isset($options['sort']) && !empty($options['sort'])) {
|
||||||
return $options['sort'];
|
return $options['sort'];
|
||||||
} elseif (isset($options['order']) && is_array($options['order'])) {
|
} elseif (isset($options['order']) && is_array($options['order'])) {
|
||||||
return preg_replace('/.*\./', '', key($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;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -210,9 +214,6 @@ class PaginatorHelper extends AppHelper {
|
||||||
* key the returned link will sort by 'desc'.
|
* key the returned link will sort by 'desc'.
|
||||||
*/
|
*/
|
||||||
function sort($title, $key = null, $options = array()) {
|
function sort($title, $key = null, $options = array()) {
|
||||||
if(!empty($this->options)) {
|
|
||||||
$options = am($this->options, $options);
|
|
||||||
}
|
|
||||||
$options = am(array('url' => array(), 'model' => null), $options);
|
$options = am(array('url' => array(), 'model' => null), $options);
|
||||||
$url = $options['url'];
|
$url = $options['url'];
|
||||||
unset($options['url']);
|
unset($options['url']);
|
||||||
|
|
|
@ -49,18 +49,20 @@ class PaginatorTest extends UnitTestCase {
|
||||||
'nextPage' => true,
|
'nextPage' => true,
|
||||||
'pageCount' => 7,
|
'pageCount' => 7,
|
||||||
'defaults' => array(
|
'defaults' => array(
|
||||||
'order' => 'Article.date DESC',
|
'order' => 'Article.date ASC',
|
||||||
'limit' => 9,
|
'limit' => 9,
|
||||||
'conditions' => array()
|
'conditions' => array()
|
||||||
)
|
),
|
||||||
),
|
'options' => array(
|
||||||
|
'order' => 'Article.date ASC',
|
||||||
'options' => array(
|
'limit' => 9,
|
||||||
'order' => 'Article.date DESC',
|
'page' => 1,
|
||||||
'limit' => 9,
|
'conditions' => array()
|
||||||
'page' => 1
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->paginator->Html =& new HtmlHelper();
|
||||||
|
$this->paginator->Ajax =& new AjaxHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHasPrevious() {
|
function testHasPrevious() {
|
||||||
|
@ -77,6 +79,20 @@ class PaginatorTest extends UnitTestCase {
|
||||||
$this->paginator->params['paging']['Article']['nextPage'] = true;
|
$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() {
|
function tearDown() {
|
||||||
unset($this->paginator);
|
unset($this->paginator);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue