For paging links the 'class' attribute is now always applied to the wrapping tag for consistency. Closes #1759

This commit is contained in:
ADmad 2011-08-14 05:09:57 +05:30
parent b781762903
commit 5d79299362
2 changed files with 74 additions and 68 deletions

View file

@ -463,8 +463,8 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->request->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/admin/users/index/page:2', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/admin/users/index/page:2', 'rel' => 'next'),
'Next',
'/a',
'/span'
@ -566,8 +566,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('next', array('url' => $options));
$expected = array(
'<span',
'a' => array('href' => '/members/posts/index/page:3', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/members/posts/index/page:3', 'rel' => 'next'),
'next',
'/a',
'/span'
@ -576,8 +576,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->prev('prev', array('url' => $options));
$expected = array(
'<span',
'a' => array('href' => '/members/posts/index/page:1', 'class' => 'prev', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/members/posts/index/page:1', 'rel' => 'prev'),
'prev',
'/a',
'/span'
@ -703,8 +703,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'rel' => 'next'),
'Next',
'/a',
'/span'
@ -753,8 +753,8 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->request->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', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'&lt;&lt; Previous',
'/a',
'/span'
@ -763,8 +763,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/index/page:3', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:3', 'rel' => 'next'),
'Next',
'/a',
'/span'
@ -773,8 +773,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next', array('tag' => 'li'));
$expected = array(
'<li',
'a' => array('href' => '/index/page:3', 'class' => 'next', 'rel' => 'next'),
'li' => array('class' => 'next'),
'a' => array('href' => '/index/page:3', 'rel' => 'next'),
'Next',
'/a',
'/li'
@ -783,8 +783,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->prev('<< Previous', array('escape' => true));
$expected = array(
'<span',
'a' => array('href' => '/index/page:1', 'class' => 'prev', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'&lt;&lt; Previous',
'/a',
'/span'
@ -793,8 +793,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->prev('<< Previous', array('escape' => false));
$expected = array(
'<span',
'a' => array('href' => '/index/page:1', 'class' => 'prev', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1', 'rel' => 'prev'),
'preg:/<< Previous/',
'/a',
'/span'
@ -861,10 +861,9 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->request->params['paging']['Client']['prevPage'] = true;
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
$expected = array(
'<span',
'span' => array('class' => 'prev'),
'a' => array(
'href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC',
'class' => 'prev',
'rel' => 'prev'
),
'&lt;&lt; Previous',
@ -875,10 +874,9 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'span' => array('class' => 'next'),
'a' => array(
'href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC',
'class' => 'next',
'rel' => 'next'
),
'Next',
@ -906,8 +904,8 @@ class PaginatorHelperTest extends CakeTestCase {
);
$result = $this->Paginator->prev('Prev');
$expected = array(
'<span',
'a' => array('href' => '/index/page:1/limit:10', 'class' => 'prev', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/page:1/limit:10', 'rel' => 'prev'),
'Prev',
'/a',
'/span'
@ -928,8 +926,8 @@ class PaginatorHelperTest extends CakeTestCase {
$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', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'rel' => 'prev'),
'Prev',
'/a',
'/span'
@ -968,8 +966,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next >>', array('escape' => false));
$expected = array(
'<span',
'a' => array('href' => '/index/page:2', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
'preg:/Next >>/',
'/a',
'/span'
@ -1015,8 +1013,8 @@ class PaginatorHelperTest extends CakeTestCase {
);
$result = $this->Paginator->next('Next', array('model' => 'Client'));
$expected = array(
'<span',
'a' => array('href' => '/index/page:2', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
'Next',
'/a',
'/span'
@ -1542,15 +1540,15 @@ class PaginatorHelperTest extends CakeTestCase {
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers();
$result = $this->Paginator->numbers(array('class' => 'page-link'));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '1', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
);
$this->assertTags($result, $expected);
@ -1780,9 +1778,9 @@ class PaginatorHelperTest extends CakeTestCase {
* @return void
*/
public function testFirstAndLastTag() {
$result = $this->Paginator->first('<<', array('tag' => 'li'));
$result = $this->Paginator->first('<<', array('tag' => 'li', 'class' => 'first'));
$expected = array(
'<li',
'li' => array('class' => 'first'),
'a' => array('href' => '/index/page:1', 'rel' => 'first'),
'&lt;&lt;',
'/a',
@ -1790,15 +1788,14 @@ class PaginatorHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('tag' => 'li'));
$result = $this->Paginator->last(2, array('tag' => 'li', 'class' => 'last'));
$expected = array(
'...',
'<li',
'li' => array('class' => 'last'),
array('a' => array('href' => '/index/page:6')), '6', '/a',
'/li',
' | ',
'<li',
array('li' => array('class' => 'last')),
array('a' => array('href' => '/index/page:7')), '7', '/a',
'/li',
);
@ -2157,10 +2154,9 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'span' => array('class' => 'next'),
'a' => array(
'href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc',
'class' => 'next',
'rel' => 'next'
),
'Next',
@ -2255,8 +2251,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->next('Next');
$expected = array(
'<span',
'a' => array('href' => '/?page=3', 'class' => 'next', 'rel' => 'next'),
'span' => array('class' => 'next'),
'a' => array('href' => '/?page=3', 'rel' => 'next'),
'Next',
'/a',
'/span'
@ -2265,8 +2261,8 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->prev('Prev');
$expected = array(
'<span',
'a' => array('href' => '/?page=1', 'class' => 'prev', 'rel' => 'prev'),
'span' => array('class' => 'prev'),
'a' => array('href' => '/?page=1', 'rel' => 'prev'),
'Prev',
'/a',
'/span'

View file

@ -453,7 +453,7 @@ class PaginatorHelper extends AppHelper {
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);
if ($this->{$check}($model)) {
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'class'))));
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class'));
} else {
unset($options['rel']);
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
@ -636,7 +636,7 @@ class PaginatorHelper extends AppHelper {
}
$defaults = array(
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(),
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
);
$options += $defaults;
@ -651,7 +651,7 @@ class PaginatorHelper extends AppHelper {
extract($options);
unset($options['tag'], $options['before'], $options['after'], $options['model'],
$options['modulus'], $options['separator'], $options['first'], $options['last'],
$options['ellipsis']
$options['ellipsis'], $options['class']
);
$out = '';
@ -672,32 +672,36 @@ class PaginatorHelper extends AppHelper {
if ($first && $start > 1) {
$offset = ($start <= (int)$first) ? $start - 1 : $first;
if ($offset < $start - 1) {
$out .= $this->first($offset, array('tag' => $tag, 'separator' => $separator, 'ellipsis' => $ellipsis));
$out .= $this->first($offset, compact('tag', 'separator', 'ellipsis', 'class'));
} else {
$out .= $this->first($offset, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
$out .= $this->first($offset, compact('tag', 'separator', 'class') + array('after' => $separator));
}
}
$out .= $before;
for ($i = $start; $i < $params['page']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'))
. $separator;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => 'current'));
$currentClass = 'current';
if ($class) {
$currentClass .= ' ' . $class;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
if ($i != $params['pageCount']) {
$out .= $separator;
}
$start = $params['page'] + 1;
for ($i = $start; $i < $end; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'))
. $separator;
}
if ($end != $params['page']) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options));
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options), compact('class'));
}
$out .= $after;
@ -705,9 +709,9 @@ class PaginatorHelper extends AppHelper {
if ($last && $end < $params['pageCount']) {
$offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last;
if ($offset <= $last && $params['pageCount'] - $end > $offset) {
$out .= $this->last($offset, array('tag' => $tag, 'separator' => $separator, 'ellipsis' => $ellipsis));
$out .= $this->last($offset, compact('tag', 'separator', 'ellipsis', 'class'));
} else {
$out .= $this->last($offset, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
$out .= $this->last($offset, compact('tag', 'separator', 'class') + array('before' => $separator));
}
}
@ -716,9 +720,13 @@ class PaginatorHelper extends AppHelper {
for ($i = 1; $i <= $params['pageCount']; $i++) {
if ($i == $params['page']) {
$out .= $this->Html->tag($tag, $i, array('class' => 'current'));
$currentClass = 'current';
if ($class) {
$currentClass .= ' ' . $class;
}
$out .= $this->Html->tag($tag, $i, array('class' => $currentClass));
} else {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
}
if ($i != $params['pageCount']) {
$out .= $separator;
@ -763,7 +771,8 @@ class PaginatorHelper extends AppHelper {
'after' => null,
'model' => $this->defaultModel(),
'separator' => ' | ',
'ellipsis' => '...'
'ellipsis' => '...',
'class' => null
),
(array)$options);
@ -774,7 +783,7 @@ class PaginatorHelper extends AppHelper {
return false;
}
extract($options);
unset($options['tag'], $options['after'], $options['model'], $options['separator'], $options['ellipsis']);
unset($options['tag'], $options['after'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
$out = '';
@ -783,7 +792,7 @@ class PaginatorHelper extends AppHelper {
$after = $ellipsis;
}
for ($i = 1; $i <= $first; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
if ($i != $first) {
$out .= $separator;
}
@ -791,7 +800,7 @@ class PaginatorHelper extends AppHelper {
$out .= $after;
} elseif ($params['page'] > 1 && is_string($first)) {
$options += array('rel' => 'first');
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options), compact('class'))
. $after;
}
return $out;
@ -828,6 +837,7 @@ class PaginatorHelper extends AppHelper {
'model' => $this->defaultModel(),
'separator' => ' | ',
'ellipsis' => '...',
'class' => null
),
(array)$options);
@ -839,7 +849,7 @@ class PaginatorHelper extends AppHelper {
}
extract($options);
unset($options['tag'], $options['before'], $options['model'], $options['separator'], $options['ellipsis']);
unset($options['tag'], $options['before'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
$out = '';
$lower = $params['pageCount'] - $last + 1;
@ -849,7 +859,7 @@ class PaginatorHelper extends AppHelper {
$before = $ellipsis;
}
for ($i = $lower; $i <= $params['pageCount']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
if ($i != $params['pageCount']) {
$out .= $separator;
}
@ -858,8 +868,8 @@ class PaginatorHelper extends AppHelper {
} elseif ($params['page'] < $params['pageCount'] && is_string($last)) {
$options += array('rel' => 'last');
$out = $before . $this->Html->tag(
$tag, $this->link($last, array('page' => $params['pageCount']), $options
));
$tag, $this->link($last, array('page' => $params['pageCount']), $options), compact('class')
);
}
return $out;
}