Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding default classes to next and prev links.

Switching next() and prev() to use span by default.
  • Loading branch information...
commit 38a4b619e63a20f6aaa934b1cf273fdeb5038ad8 1 parent 533f6e0
@markstory markstory authored
View
9 cake/libs/view/helpers/paginator.php
@@ -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']);
@@ -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)));
}
}
View
54 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -1,6 +1,4 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
* PaginatorHelperTest file
*
@@ -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;
@@ -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'
);
@@ -442,7 +440,7 @@ 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'
);
@@ -450,7 +448,7 @@ function testUrlGenerationWithPrefixes() {
$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'
);
@@ -529,17 +527,17 @@ 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);
@@ -547,7 +545,7 @@ 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'),
+ 'a' => array('href' => '/index/page:1', 'class' => 'prev'),
'&lt;&lt; Previous',
'/a'
);
@@ -555,7 +553,7 @@ function testPagingLinks() {
$result = $this->Paginator->next('Next');
$expected = array(
- 'a' => array('href' => '/index/page:3'),
+ 'a' => array('href' => '/index/page:3', 'class' => 'next'),
'Next',
'/a'
);
@@ -563,7 +561,7 @@ function testPagingLinks() {
$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'
);
@@ -571,7 +569,7 @@ function testPagingLinks() {
$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'
);
@@ -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);
@@ -617,7 +615,7 @@ 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'
);
@@ -625,7 +623,7 @@ function testPagingLinks() {
$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'
);
@@ -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',
);
@@ -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);
}
@@ -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())
));
@@ -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'
);
Please sign in to comment.
Something went wrong with that request. Please try again.