From c57d98c67343794530cd9e9d7405c095bc31fad8 Mon Sep 17 00:00:00 2001 From: Douglas Radburn Date: Mon, 28 Oct 2019 21:27:10 +0000 Subject: [PATCH 1/4] Updated page 1 to not include p1 in URL link --- app/code/Magento/Theme/Block/Html/Pager.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/Block/Html/Pager.php b/app/code/Magento/Theme/Block/Html/Pager.php index ad3f4aad676eb..e86310b66bb4b 100644 --- a/app/code/Magento/Theme/Block/Html/Pager.php +++ b/app/code/Magento/Theme/Block/Html/Pager.php @@ -450,7 +450,9 @@ public function getLastPageUrl() */ public function getPageUrl($page) { - return $this->getPagerUrl([$this->getPageVarName() => $page]); + return $this->getPagerUrl([ + $this->getPageVarName() => $page > 1 ? $page : null, + ]); } /** From 3f4642ed3529467baafad828dd415749f0395176 Mon Sep 17 00:00:00 2001 From: Douglas Radburn Date: Wed, 11 Dec 2019 15:32:16 +0000 Subject: [PATCH 2/4] Updated code test --- app/code/Magento/Theme/Block/Html/Pager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Theme/Block/Html/Pager.php b/app/code/Magento/Theme/Block/Html/Pager.php index e86310b66bb4b..866203c72b83b 100644 --- a/app/code/Magento/Theme/Block/Html/Pager.php +++ b/app/code/Magento/Theme/Block/Html/Pager.php @@ -450,9 +450,11 @@ public function getLastPageUrl() */ public function getPageUrl($page) { - return $this->getPagerUrl([ - $this->getPageVarName() => $page > 1 ? $page : null, - ]); + return $this->getPagerUrl( + [ + $this->getPageVarName() => $page > 1 ? $page : null, + ] + ); } /** From 2860283bd1797bab573925501964712e0c177ed8 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Mon, 6 Jan 2020 11:29:20 +0200 Subject: [PATCH 3/4] Cover changes with unit test --- .../Theme/Test/Unit/Block/Html/PagerTest.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php diff --git a/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php new file mode 100644 index 0000000000000..79a06e64479c7 --- /dev/null +++ b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php @@ -0,0 +1,109 @@ +context = $this->createMock(Context::class); + $this->urlBuilderMock = $this->createMock(UrlInterface::class); + $this->context->expects($this->any()) + ->method('getUrlBuilder') + ->willReturn($this->urlBuilderMock); + $this->scopeConfig = $this->createMock(Config::class); + $this->pager = (new ObjectManager($this))->getObject( + Pager::class, + ['context' => $this->context] + ); + } + + /** + * Verify current page Url + * + * @return void + */ + public function testGetPageUrl(): void + { + $expectedPageUrl = 'page-url'; + $this->urlBuilderMock->expects($this->once()) + ->method('getUrl') + ->willReturn($expectedPageUrl); + $this->assertEquals($expectedPageUrl, $this->pager->getPageUrl(0)); + } + + /** + * Verify get pages method. + * + * @return void + */ + public function testGetPages(): void + { + $expectedPages = range(1, 5); + $collectionMock = $this->createMock(Collection::class); + $collectionMock->expects($this->exactly(2)) + ->method('getCurPage') + ->willReturn(2); + $collectionMock->expects($this->any()) + ->method('getLastPageNumber') + ->willReturn(10); + $this->setCollectionProperty($collectionMock); + $this->assertEquals($expectedPages, $this->pager->getPages()); + } + + /** + * Set Collection + * + * @return void + */ + private function setCollectionProperty($collection): void + { + $reflection = new \ReflectionClass($this->pager); + $reflection_property = $reflection->getProperty('_collection'); + $reflection_property->setAccessible(true); + $reflection_property->setValue($this->pager, $collection); + } +} From 9c4991a5828b34c98e753ecc62dda592a6ff54fc Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Mon, 6 Jan 2020 11:51:45 +0200 Subject: [PATCH 4/4] fix static test --- app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php index 79a06e64479c7..2fa1c637f1838 100644 --- a/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php +++ b/app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php @@ -34,11 +34,6 @@ class PagerTest extends TestCase */ private $scopeConfig; - /** - * @var ObjectManager $objectManager - */ - private $objectManager; - /** * @var UrlInterface $urlBuilderMock */