mirror of
https://github.com/yiisoft/yii2.git
synced 2026-02-20 00:32:19 +01:00
Fix #19655: Fix LinkPager::getPageRange when maxButtons is 2
This commit is contained in:
@@ -32,6 +32,7 @@ Yii Framework 2 Change Log
|
||||
- Enh #20525: Add `@template` annotations for all actions (max-s-lab)
|
||||
- Bug #20524: Fix PHPStan/Psalm annotations in `Yii::createObject` (max-s-lab)
|
||||
- Bug #20530: Fix notice "Object of class DateTimeImmutable could not be converted to int" in `CookieCollection::has` (max-s-lab)
|
||||
- Bug #19655: Fix `LinkPager::getPageRange` when `maxButtons` is 2 (max-s-lab)
|
||||
- Enh #20539: Update minimum PHP version requirement from `7.3` to `7.4` (terabytesoftw)
|
||||
- Bug #20541: Remove deprecated caching components: `XCache` and `ZendDataCache`, and update related tests and documentation (terabytesoftw)
|
||||
|
||||
|
||||
@@ -264,7 +264,9 @@ class LinkPager extends Widget
|
||||
$currentPage = $this->pagination->getPage();
|
||||
$pageCount = $this->pagination->getPageCount();
|
||||
|
||||
$beginPage = max(0, $currentPage - (int) ($this->maxButtonCount / 2));
|
||||
$beginPageOffset = $this->maxButtonCount > 2 ? (int) ($this->maxButtonCount / 2) : 0;
|
||||
$beginPage = max(0, $currentPage - $beginPageOffset);
|
||||
|
||||
if (($endPage = $beginPage + $this->maxButtonCount - 1) >= $pageCount) {
|
||||
$endPage = $pageCount - 1;
|
||||
$beginPage = max(0, $endPage - $this->maxButtonCount + 1);
|
||||
|
||||
@@ -160,6 +160,99 @@ class LinkPagerTest extends \yiiunit\TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithTwoButtons()
|
||||
{
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(0),
|
||||
'maxButtonCount' => 2,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev disabled"><span>«</span></li>
|
||||
<li class="active"><a href="/?r=test&page=1" data-page="0">1</a></li>
|
||||
<li><a href="/?r=test&page=2" data-page="1">2</a></li>
|
||||
<li class="next"><a href="/?r=test&page=2" data-page="1">»</a></li></ul>
|
||||
HTML,
|
||||
$output,
|
||||
);
|
||||
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(1),
|
||||
'maxButtonCount' => 2,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev"><a href="/?r=test&page=1" data-page="0">«</a></li>
|
||||
<li class="active"><a href="/?r=test&page=2" data-page="1">2</a></li>
|
||||
<li><a href="/?r=test&page=3" data-page="2">3</a></li>
|
||||
<li class="next"><a href="/?r=test&page=3" data-page="2">»</a></li></ul>
|
||||
HTML,
|
||||
$output,
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithOneButton()
|
||||
{
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(0),
|
||||
'maxButtonCount' => 1,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev disabled"><span>«</span></li>
|
||||
<li class="active"><a href="/?r=test&page=1" data-page="0">1</a></li>
|
||||
<li class="next"><a href="/?r=test&page=2" data-page="1">»</a></li></ul>
|
||||
HTML,
|
||||
$output,
|
||||
);
|
||||
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(1),
|
||||
'maxButtonCount' => 1,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev"><a href="/?r=test&page=1" data-page="0">«</a></li>
|
||||
<li class="active"><a href="/?r=test&page=2" data-page="1">2</a></li>
|
||||
<li class="next"><a href="/?r=test&page=3" data-page="2">»</a></li></ul>
|
||||
HTML,
|
||||
$output,
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithNoButtons()
|
||||
{
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(0),
|
||||
'maxButtonCount' => 0,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev disabled"><span>«</span></li>
|
||||
<li class="next"><a href="/?r=test&page=2" data-page="1">»</a></li></ul>
|
||||
HTML,
|
||||
$output
|
||||
);
|
||||
|
||||
$output = LinkPager::widget([
|
||||
'pagination' => $this->getPagination(1),
|
||||
'maxButtonCount' => 0,
|
||||
]);
|
||||
|
||||
$this->assertEqualsWithoutLE(
|
||||
<<<HTML
|
||||
<ul class="pagination"><li class="prev"><a href="/?r=test&page=1" data-page="0">«</a></li>
|
||||
<li class="next"><a href="/?r=test&page=3" data-page="2">»</a></li></ul>
|
||||
HTML,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/15536
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user