Skip to content

Commit

Permalink
Adding default classes to next and prev links.
Browse files Browse the repository at this point in the history
Switching next() and prev() to use span by default.
  • Loading branch information
markstory committed Aug 27, 2009
1 parent 533f6e0 commit 38a4b61
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
9 changes: 6 additions & 3 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -312,7 +312,10 @@ function url($options = array(), $asArray = false, $model = null) {
*/
function __pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
$check = 'has' . $which;
$_defaults = array('url' => array(), 'step' => 1, 'escape' => true, 'model' => null, 'tag' => 'div');
$_defaults = array(
'url' => array(), 'step' => 1, 'escape' => true,
'model' => null, 'tag' => 'span', 'class' => strtolower($which)
);
$options = array_merge($_defaults, (array)$options);
$paging = $this->params($options['model']);

Expand All @@ -332,9 +335,9 @@ function __pagingLink($which, $title = null, $options = array(), $disabledTitle
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);

if ($this->{$check}($model)) {
return $this->link($title, $url, array_merge($options, array('escape' => $escape)));
return $this->link($title, $url, array_merge($options, array('escape' => $escape, 'class' => $class)));
} else {
return $this->Html->tag($tag, $title, $options, $escape);
return $this->Html->tag($tag, $title, array_merge($options, array('class' => $class, 'escape' => $escape)));
}
}

Expand Down
54 changes: 26 additions & 28 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -1,6 +1,4 @@
<?php
/* SVN FILE: $Id$ */

/**
* PaginatorHelperTest file
*
Expand Down Expand Up @@ -119,7 +117,7 @@ function testDisabledLink() {
$this->Paginator->params['paging']['Article']['nextPage'] = false;
$this->Paginator->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next', array(), true);
$expected = '<div>Next</div>';
$expected = '<span class="next">Next</span>';
$this->assertEqual($result, $expected);

$this->Paginator->params['paging']['Article']['prevPage'] = false;
Expand Down Expand Up @@ -344,7 +342,7 @@ function testSortAdminLinks() {
$this->Paginator->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next');
$expected = array(
'a' => array('href' => '/admin/users/index/page:2'),
'a' => array('href' => '/admin/users/index/page:2', 'class' => 'next'),
'Next',
'/a'
);
Expand Down Expand Up @@ -442,15 +440,15 @@ function testUrlGenerationWithPrefixes() {

$result = $this->Paginator->next('next', array('url' => $options));
$expected = array(
'a' => array('href' => '/members/posts/index/page:3'),
'a' => array('href' => '/members/posts/index/page:3', 'class' => 'next'),
'next',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('prev', array('url' => $options));
$expected = array(
'a' => array('href' => '/members/posts/index/page:1'),
'a' => array('href' => '/members/posts/index/page:1', 'class' => 'prev'),
'prev',
'/a'
);
Expand Down Expand Up @@ -529,49 +527,49 @@ function testPagingLinks() {
);
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'div' => array('class' => 'disabled'),
'span' => array('class' => 'disabled'),
'&lt;&lt; Previous',
'/div'
'/span'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'span'));
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'div'));
$expected = array(
'span' => array('class' => 'disabled'),
'div' => array('class' => 'disabled'),
'&lt;&lt; Previous',
'/span'
'/div'
);
$this->assertTags($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'));
$expected = array(
'a' => array('href' => '/index/page:1'),
'a' => array('href' => '/index/page:1', 'class' => 'prev'),
'&lt;&lt; Previous',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->next('Next');
$expected = array(
'a' => array('href' => '/index/page:3'),
'a' => array('href' => '/index/page:3', 'class' => 'next'),
'Next',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('<< Previous', array('escape' => true));
$expected = array(
'a' => array('href' => '/index/page:1'),
'a' => array('href' => '/index/page:1', 'class' => 'prev'),
'&lt;&lt; Previous',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('<< Previous', array('escape' => false));
$expected = array(
'a' => array('href' => '/index/page:1'),
'a' => array('href' => '/index/page:1', 'class' => 'prev'),
'preg:/<< Previous/',
'/a'
);
Expand All @@ -585,25 +583,25 @@ function testPagingLinks() {

$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
$expected = array(
'<div',
'span' => array('class' => 'prev'),
'&lt;strong&gt;Disabled&lt;/strong&gt;',
'/div'
'/span'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
$expected = array(
'<div',
'span' => array('class' => 'prev'),
'&lt;strong&gt;Disabled&lt;/strong&gt;',
'/div'
'/span'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
$expected = array(
'<div',
'span' => array('class' => 'prev'),
'<strong', 'Disabled', '/strong',
'/div'
'/span'
);
$this->assertTags($result, $expected);

Expand All @@ -617,15 +615,15 @@ function testPagingLinks() {
$this->Paginator->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'a' => array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC'),
'a' => array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC', 'class' => 'prev'),
'&lt;&lt; Previous',
'/a'
);
$this->assertTags($result, $expected, true);

$result = $this->Paginator->next('Next');
$expected = array(
'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC'),
'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC', 'class' => 'next'),
'Next',
'/a'
);
Expand All @@ -638,7 +636,7 @@ function testPagingLinks() {
));
$result = $this->Paginator->prev('Prev');
$expected = array(
'a' => array('href' => '/index/page:1/limit:10'),
'a' => array('href' => '/index/page:1/limit:10', 'class' => 'prev'),
'Prev',
'/a',
);
Expand Down Expand Up @@ -669,13 +667,13 @@ function testPagingLinksNotDefaultModel() {
);
$result = $this->Paginator->next('Next', array('model' => 'Client'));
$expected = array(
'a' => array('href' => '/index/page:2'), 'Next', '/a'
'a' => array('href' => '/index/page:2', 'class' => 'next'), 'Next', '/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
$expected = array(
'<div', 'No Next', '/div'
'span' => array('class' => 'next'), 'No Next', '/span'
);
$this->assertTags($result, $expected);
}
Expand Down Expand Up @@ -1591,7 +1589,7 @@ function testNextLinkUsingDotNotation() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
));

Expand All @@ -1607,7 +1605,7 @@ function testNextLinkUsingDotNotation() {

$result = $this->Paginator->next('Next');
$expected = array(
'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc'),
'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc', 'class' => 'next'),
'Next',
'/a'
);
Expand Down

0 comments on commit 38a4b61

Please sign in to comment.