Skip to content

Commit

Permalink
Links generated by PaginatorHelper::prev and PaginatorHelper::next ar…
Browse files Browse the repository at this point in the history
…e now wrapped in 'span' or the tag specified in options. Fixes #311
  • Loading branch information
ADmad committed Feb 7, 2010
1 parent e6404f2 commit 6f08d86
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
12 changes: 6 additions & 6 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -67,7 +67,7 @@ class PaginatorHelper extends AppHelper {
* - `$options['escape']` Defines if the title field for the link should be escaped (default: true).
* - `$options['update']` DOM id of the element updated with the results of the AJAX call.
* If this key isn't specified Paginator will use plain HTML links.
* - `$options['indicator']` DOM id of the element that will be shown when doing AJAX requests. **Only supported by
* - `$options['indicator']` DOM id of the element that will be shown when doing AJAX requests. **Only supported by
* AjaxHelper**
*
* @var array
Expand Down Expand Up @@ -368,7 +368,7 @@ function link($title, $url = array(), $options = array()) {
* Merges passed URL options with current pagination state to generate a pagination URL.
*
* @param array $options Pagination/URL options array
* @param boolean $asArray Return the url as an array, or a URI string
* @param boolean $asArray Return the url as an array, or a URI string
* @param string $model Which model to paginate on
* @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
* @access public
Expand Down Expand Up @@ -427,7 +427,7 @@ 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, compact('escape', 'class')));
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'class'))));
} else {
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
}
Expand Down Expand Up @@ -514,7 +514,7 @@ function defaultModel() {
*
* - `model` The model to use, defaults to PaginatorHelper::defaultModel();
* - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
* the following placeholders `%page%`, `%pages%`, `%current%`, `%count%`, `%start%`, `%end%` and any
* custom content you would like.
* - `separator` The separator string to use, default to ' of '
Expand Down Expand Up @@ -592,9 +592,9 @@ function counter($options = array()) {
* - `modulus` how many numbers to include on either side of the current page, defaults to 8.
* - `separator` Separator content defaults to ' | '
* - `tag` The tag to wrap links in, defaults to 'span'
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
* links to generate
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
* links to generate
*
* @param mixed $options Options for the numbers, (before, after, model, modulus, separator)
Expand Down
74 changes: 58 additions & 16 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -193,7 +193,7 @@ function testSortLinks() {
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);

$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc'));
Expand Down Expand Up @@ -396,9 +396,11 @@ function testSortAdminLinks() {
$this->Paginator->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/admin/users/index/page:2', 'class' => 'next'),
'Next',
'/a'
'/a',
'/span'
);
$this->assertTags($result, $expected);

Expand Down Expand Up @@ -497,17 +499,21 @@ function testUrlGenerationWithPrefixes() {

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

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

Expand Down Expand Up @@ -587,7 +593,7 @@ function testPassedArgsMergingWithUrlOptions() {
));
$this->Paginator->params['paging'] = array(
'Article' => array(
'page' => 1, 'current' => 3, 'count' => 13,
'page' => 1, 'current' => 3, 'count' => 13,
'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
'defaults' => array(
'limit' => 3, 'step' => 1, 'order' => array(), 'conditions' => array()
Expand Down Expand Up @@ -630,9 +636,11 @@ function testPassedArgsMergingWithUrlOptions() {

$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next'),
'Next',
'/a'
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
Expand Down Expand Up @@ -669,33 +677,51 @@ function testPagingLinks() {
$this->Paginator->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'<span',
'a' => array('href' => '/index/page:1', 'class' => 'prev'),
'&lt;&lt; Previous',
'/a'
'/a',
'/span'
);
$this->assertTags($result, $expected);

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

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

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

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

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

$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC', 'class' => 'next'),
'Next',
'/a'
'/a',
'/span'
);
$this->assertTags($result, $expected);

Expand All @@ -760,15 +790,17 @@ function testPagingLinks() {
));
$result = $this->Paginator->prev('Prev');
$expected = array(
'<span',
'a' => array('href' => '/index/page:1/limit:10', 'class' => 'prev'),
'Prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging'] = array(
'Client' => array(
'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true,
'nextPage' => false, 'pageCount' => 2,
'defaults' => array(),
'options' => array(
Expand All @@ -779,9 +811,11 @@ function testPagingLinks() {
$this->Paginator->options(array('url' => array(12, 'page' => 3)));
$result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar')));
$expected = array(
'<span',
'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'class' => 'prev'),
'Prev',
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
Expand Down Expand Up @@ -815,9 +849,11 @@ function testPagingLinksOptionsReplaceEmptyDisabledOptions() {

$result = $this->Paginator->next('Next >>', array('escape' => false));
$expected = array(
'<span',
'a' => array('href' => '/index/page:2', 'class' => 'next'),
'preg:/Next >>/',
'/a'
'/a',
'/span'
);
$this->assertTags($result, $expected);
}
Expand Down Expand Up @@ -846,7 +882,11 @@ function testPagingLinksNotDefaultModel() {
);
$result = $this->Paginator->next('Next', array('model' => 'Client'));
$expected = array(
'a' => array('href' => '/index/page:2', 'class' => 'next'), 'Next', '/a'
'<span',
'a' => array('href' => '/index/page:2', 'class' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);

Expand Down Expand Up @@ -1784,9 +1824,11 @@ function testNextLinkUsingDotNotation() {

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

0 comments on commit 6f08d86

Please sign in to comment.