Fixing more boundary issues with first() and last(). When you entered a first/last range a wonky page link would be generated. Tests added.

This commit is contained in:
mark_story 2010-12-27 23:40:10 -05:00
parent 85baa180d9
commit eb38b8b60c
2 changed files with 9 additions and 2 deletions

View file

@ -782,7 +782,7 @@ class PaginatorHelper extends AppHelper {
} }
} }
$out .= $after; $out .= $after;
} elseif ($params['page'] > 1) { } elseif ($params['page'] > 1 && is_string($first)) {
$options += array('rel' => '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))
. $after; . $after;
@ -848,7 +848,7 @@ class PaginatorHelper extends AppHelper {
} }
} }
$out = $before . $out; $out = $before . $out;
} elseif ($params['page'] < $params['pageCount']) { } elseif ($params['page'] < $params['pageCount'] && is_string($last)) {
$options += array('rel' => 'last'); $options += array('rel' => 'last');
$out = $before . $this->Html->tag( $out = $before . $this->Html->tag(
$tag, $this->link($last, array('page' => $params['pageCount']), $options $tag, $this->link($last, array('page' => $params['pageCount']), $options

View file

@ -1878,6 +1878,10 @@ class PaginatorHelperTest extends CakeTestCase {
'/span' '/span'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['page'] = 2;
$result = $this->Paginator->first(3);
$this->assertEquals('', $result, 'When inside the first links range, no links should be made');
} }
/** /**
@ -1922,6 +1926,9 @@ class PaginatorHelperTest extends CakeTestCase {
'/span', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Paginator->last(3);
$this->assertEquals('', $result, 'When inside the last links range, no links should be made');
} }
/** /**