-
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.
#27089 Fix issue with returning non-available default limit, coverage…
… with Unit Tests
- Loading branch information
1 parent
a3c2af0
commit 17236cc
Showing
2 changed files
with
118 additions
and
63 deletions.
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
74 changes: 74 additions & 0 deletions
74
app/code/Magento/Catalog/Test/Unit/Helper/Product/ProductListTest.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,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Test\Unit\Helper\Product; | ||
|
||
|
||
use Magento\Catalog\Helper\Product\ProductList; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ProductListTest extends TestCase | ||
{ | ||
const STUB_VIEW_MODE = 'grid'; | ||
/** | ||
* @var ScopeConfigInterface|MockObject | ||
*/ | ||
private $scopeConfigMock; | ||
|
||
/** | ||
* @var ProductList | ||
*/ | ||
private $productListHelper; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); | ||
$this->productListHelper = $objectManager->getObject(ProductList::class, [ | ||
'scopeConfig' => $this->scopeConfigMock | ||
]); | ||
} | ||
|
||
/** | ||
* @dataProvider defaultAvailableLimitsDataProvider | ||
*/ | ||
public function testGetDefaultLimitPerPageValueReturnsOneOfAvailableLimits( | ||
string $availableValues, | ||
int $defaultValue, | ||
int $expectedReturn | ||
) { | ||
$this->scopeConfigMock->method('getValue') | ||
->willReturnMap([ | ||
[sprintf('catalog/frontend/%s_per_page_values', self::STUB_VIEW_MODE), $availableValues], | ||
[sprintf('catalog/frontend/%s_per_page', self::STUB_VIEW_MODE), $defaultValue] | ||
]); | ||
|
||
$returnedValue = $this->productListHelper->getDefaultLimitPerPageValue(self::STUB_VIEW_MODE); | ||
|
||
$this->assertSame($expectedReturn, $returnedValue); | ||
} | ||
|
||
public function defaultAvailableLimitsDataProvider(): array | ||
{ | ||
return [ | ||
'limit-available' => [ | ||
'values' => '10,20,30', | ||
'default' => 10, | ||
'expected' => 10 | ||
], | ||
'limit-not-available' => [ | ||
'values' => '10,20,30', | ||
'default' => 1, | ||
'expected' => 10 | ||
] | ||
]; | ||
} | ||
} |