Skip to content

Commit

Permalink
Fix url option in first() and last()
Browse files Browse the repository at this point in the history
Correct URL generation when the title is a string and the `url` option
is used.

Fixes #14155
  • Loading branch information
markstory committed Jan 11, 2020
1 parent c6f7c14 commit 0f91177
Show file tree
Hide file tree
Showing 2 changed files with 23 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
21 changes: 21 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,17 @@ 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 0f91177

Please sign in to comment.