Array handling fix for Paginator and additional test cases

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6132 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-12-08 08:46:01 +00:00
parent c2db2a3936
commit 0b9f2c1b9d
2 changed files with 19 additions and 7 deletions

View file

@ -174,9 +174,8 @@ class PaginatorHelper extends AppHelper {
if ($dir == 'desc') {
return 'desc';
} else {
return 'asc';
}
return 'asc';
}
/**
* Generates a "previous" link for a set of paged records
@ -273,11 +272,8 @@ class PaginatorHelper extends AppHelper {
*/
function __pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
$check = 'has' . $which;
$_defaults = array(
'url' => array(), 'step' => 1,
'escape' => true, 'model' => null
);
$options = array_merge($_defaults, $options);
$_defaults = array('url' => array(), 'step' => 1, 'escape' => true, 'model' => null);
$options = array_merge($_defaults, (array)$options);
$paging = $this->params($options['model']);
if (!$this->{$check}() && (!empty($disabledTitle) || !empty($disabledOptions))) {

View file

@ -126,6 +126,22 @@ class PaginatorTest extends UnitTestCase {
$this->assertPattern('/\/sort:controller\//', $result);
}
function testPagingLinks() {
$this->Paginator->params['paging'] = array('Client' => array(
'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
);
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = '<div class="disabled">&lt;&lt; Previous</div>';
$this->assertEqual($result, $expected);
$this->Paginator->params['paging']['Client']['page'] = 2;
$this->Paginator->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$this->assertPattern('/^<a[^<>]+>&lt;&lt; Previous<\/a>$/', $result);
}
function tearDown() {
unset($this->Paginator);
}