-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Merge Pull Request #25337 from chickenland/magento2:2.3-develop - Merged commits: 1. c57d98c 2. 3f4642e 3. 2860283 4. 94e8685 5. 9c4991a
- Loading branch information
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/code/Magento/Theme/Test/Unit/Block/Html/PagerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Theme\Test\Unit\Block\Html; | ||
|
||
use Magento\Framework\App\Config; | ||
use Magento\Framework\Data\Collection; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Theme\Block\Html\Pager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test For Page class | ||
*/ | ||
class PagerTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Pager $pager | ||
*/ | ||
private $pager; | ||
|
||
/** | ||
* @var Context $context | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var Config $scopeConfig | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var UrlInterface $urlBuilderMock | ||
*/ | ||
private $urlBuilderMock; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->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); | ||
} | ||
} |