mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-01 23:29:45 +00:00
Fix sortDir() to read default params.
sortDir() also did not reflect the default paging parameters. This would result in initial links not matching the query used. Fixes #2640
This commit is contained in:
parent
8f72b696a0
commit
dde19f97c7
2 changed files with 37 additions and 0 deletions
lib/Cake
|
@ -384,6 +384,15 @@ class PaginatorHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Paginator->sortKey('Article');
|
$result = $this->Paginator->sortKey('Article');
|
||||||
$this->assertEquals('Article.body', $result);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,6 +464,32 @@ class PaginatorHelperTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $result);
|
$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
|
* testSortAdminLinks method
|
||||||
*
|
*
|
||||||
|
|
|
@ -232,6 +232,8 @@ class PaginatorHelper extends AppHelper {
|
||||||
$dir = strtolower($options['direction']);
|
$dir = strtolower($options['direction']);
|
||||||
} elseif (isset($options['order']) && is_array($options['order'])) {
|
} elseif (isset($options['order']) && is_array($options['order'])) {
|
||||||
$dir = strtolower(current($options['order']));
|
$dir = strtolower(current($options['order']));
|
||||||
|
} elseif (isset($params['order']) && is_array($params['order'])) {
|
||||||
|
$dir = strtolower(current($params['order']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dir == 'desc') {
|
if ($dir == 'desc') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue