-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-6477: [Catalog] covered product ViewModel AddToCompareAvailabi…
…lity by Unit Test #26050
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
...code/Magento/Catalog/Test/Unit/ViewModel/Product/Checker/AddToCompareAvailabilityTest.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,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Test\Unit\ViewModel\Product\Checker; | ||
|
||
use Magento\Catalog\ViewModel\Product\Checker\AddToCompareAvailability; | ||
use Magento\CatalogInventory\Api\StockConfigurationInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
/** | ||
* Unit test for Magento\Catalog\ViewModel\Product\Checker\AddToCompareAvailability. | ||
*/ | ||
class AddToCompareAvailabilityTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
/** | ||
* @var AddToCompareAvailability | ||
*/ | ||
private $viewModel; | ||
|
||
/** | ||
* @var StockConfigurationInterface|MockObject | ||
*/ | ||
protected $stockConfigurationMock; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
|
||
$objectManager = new ObjectManager($this); | ||
|
||
$this->stockConfigurationMock = | ||
$this->getMockBuilder(StockConfigurationInterface::class) | ||
->getMock(); | ||
|
||
$this->viewModel = $objectManager->getObject( | ||
AddToCompareAvailability::class, | ||
[ | ||
'stockConfiguration' => $this->stockConfigurationMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test IsAvailableForCompare() with data provider | ||
* | ||
* @param bool $status | ||
* @param bool $isSalable | ||
* @param array $isInStock | ||
* @param bool $isShowOutOfStock | ||
* @param bool $expectedBool | ||
* @return void | ||
* @dataProvider isAvailableForCompareDataProvider | ||
*/ | ||
public function testIsAvailableForCompare($status, $isSalable, $isInStock, $isShowOutOfStock, $expectedBool): void | ||
{ | ||
$productMock = $this->getMockBuilder(Product::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$productMock->expects($this->once()) | ||
->method('getStatus') | ||
->willReturn($status); | ||
|
||
$productMock->expects($this->any()) | ||
->method('isSalable') | ||
->willReturn($isSalable); | ||
|
||
$productMock->expects($this->any()) | ||
->method('getQuantityAndStockStatus') | ||
->willReturn($isInStock); | ||
|
||
$this->stockConfigurationMock->expects($this->any()) | ||
->method('isShowOutOfStock') | ||
->willReturn($isShowOutOfStock); | ||
|
||
$this->assertEquals($expectedBool, $this->viewModel->isAvailableForCompare($productMock)); | ||
} | ||
|
||
/** | ||
* Data provider for isAvailableForCompare() | ||
* | ||
* @return array | ||
*/ | ||
public function isAvailableForCompareDataProvider(): array | ||
{ | ||
return [ | ||
[Status::STATUS_ENABLED, true, ['is_in_stock' => true], false, true], | ||
[Status::STATUS_ENABLED, true, ['is_in_stock' => false], true, true], | ||
[Status::STATUS_ENABLED, true, [], false, true], | ||
[Status::STATUS_ENABLED, false, [], false, false], | ||
[Status::STATUS_DISABLED, true, ['is_in_stock' => true], false, false] | ||
]; | ||
} | ||
} |