Skip to content

Commit

Permalink
Fixing more boundary issues with first() and last(). When you entered…
Browse files Browse the repository at this point in the history
… a first/last range a wonky page link would be generated. Tests added.
  • Loading branch information
markstory committed Dec 28, 2010
1 parent 85baa18 commit eb38b8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -782,7 +782,7 @@ public function first($first = '<< first', $options = array()) {
}
}
$out .= $after;
} elseif ($params['page'] > 1) {
} elseif ($params['page'] > 1 && is_string($first)) {
$options += array('rel' => 'first');
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
. $after;
Expand Down Expand Up @@ -848,7 +848,7 @@ public function last($last = 'last >>', $options = array()) {
}
}
$out = $before . $out;
} elseif ($params['page'] < $params['pageCount']) {
} 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
Expand Down
7 changes: 7 additions & 0 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -1878,6 +1878,10 @@ function testFirstBoundaries() {
'/span'
);
$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');
}

/**
Expand Down Expand Up @@ -1922,6 +1926,9 @@ function testLast() {
'/span',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->last(3);
$this->assertEquals('', $result, 'When inside the last links range, no links should be made');
}

/**
Expand Down

0 comments on commit eb38b8b

Please sign in to comment.