Skip to content

Commit

Permalink
Merge pull request #14157 from cakephp/issue-14155
Browse files Browse the repository at this point in the history
Fix url option in first() and last()
  • Loading branch information
markstory committed Jan 12, 2020
2 parents df57f6e + 40b915f commit df21a65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/View/Helper/PaginatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ public function first($first = '<< first', array $options = []): string
} elseif ($params['page'] > 1 && is_string($first)) {
$first = $options['escape'] ? h($first) : $first;
$out .= $this->templater()->format('first', [
'url' => $this->generateUrl(['page' => 1], $options['model']),
'url' => $this->generateUrl(['page' => 1], $options['model'], $options['url']),
'text' => $first,
]);
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public function last($last = 'last >>', array $options = []): string
} elseif ($params['page'] < $params['pageCount'] && is_string($last)) {
$last = $options['escape'] ? h($last) : $last;
$out .= $this->templater()->format('last', [
'url' => $this->generateUrl(['page' => $params['pageCount']], $options['model']),
'url' => $this->generateUrl(['page' => $params['pageCount']], $options['model'], $options['url']),
'text' => $last,
]);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/View/Helper/PaginatorHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,16 @@ public function testFirstAndLastTag()
'/li',
];
$this->assertHtml($expected, $result);

$result = $this->Paginator->first('first', ['url' => ['action' => 'paged']]);
$expected = [
'li' => ['class' => 'first'],
'a' => ['href' => '/paged'],
'first',
'/a',
'/li',
];
$this->assertHtml($expected, $result);
}

/**
Expand Down Expand Up @@ -2860,6 +2870,16 @@ public function testLast()

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

$result = $this->Paginator->last('lastest', ['url' => ['action' => 'paged']]);
$expected = [
'li' => ['class' => 'last'],
'a' => ['href' => '/paged?page=7'],
'lastest',
'/a',
'/li',
];
$this->assertHtml($expected, $result);
}

/**
Expand Down

0 comments on commit df21a65

Please sign in to comment.