-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de58008
commit d66558f
Showing
3 changed files
with
159 additions
and
0 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
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DK\CustomOptionDefaultValue\Test\Unit\Model; | ||
|
||
use DK\CustomOptionDefaultValue\Model\Config; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
final class ConfigTest extends TestCase | ||
{ | ||
/** | ||
* @var MockObject|ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class); | ||
$this->config = new Config($this->scopeConfig); | ||
} | ||
|
||
public function testIsActiveModule(): void | ||
{ | ||
$this->scopeConfig | ||
->expects($this->once()) | ||
->method('isSetFlag') | ||
->with($this->getConstValue('XML_PATH_GENERAL_ACTIVE')->getValue()) | ||
->willReturn(true); | ||
|
||
$this->assertTrue($this->config->isActiveModule()); | ||
} | ||
|
||
private function getConstValue(string $const): \ReflectionClassConstant | ||
{ | ||
return new \ReflectionClassConstant(Config::class, $const); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
Test/Unit/Plugin/Catalog/Block/Product/View/Options/Type/SelectTest.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,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DK\CustomOptionDefaultValue\Test\Unit\Plugin\Catalog\Block\Product\View\Options\Type; | ||
|
||
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\CheckableFactory; | ||
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\Multiple; | ||
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\MultipleFactory; | ||
use DK\CustomOptionDefaultValue\Model\Config; | ||
use DK\CustomOptionDefaultValue\Plugin\Catalog\Block\Product\View\Options\Type\Select; | ||
use Magento\Catalog\Block\Product\View\Options\Type\Select as TypeSelect; | ||
use Magento\Catalog\Model\Product; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class SelectTest extends TestCase | ||
{ | ||
/** | ||
* @var MockObject|MultipleFactory | ||
*/ | ||
private $multipleFactory; | ||
|
||
/** | ||
* @var CheckableFactory|MockObject | ||
*/ | ||
private $checkableFactory; | ||
|
||
/** | ||
* @var Config|MockObject | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var Select | ||
*/ | ||
private $plugin; | ||
|
||
/** | ||
* @var MockObject|TypeSelect | ||
*/ | ||
private $typeSelectMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->multipleFactory = $this->createPartialMock(MultipleFactory::class, ['create']); | ||
$this->checkableFactory = $this->createPartialMock(CheckableFactory::class, ['create']); | ||
$this->config = $this->createMock(Config::class); | ||
|
||
$this->typeSelectMock = $this->createMock(TypeSelect::class); | ||
|
||
$this->plugin = new Select($this->multipleFactory, $this->checkableFactory, $this->config); | ||
} | ||
|
||
public function testAroundGetValuesHtml(): void | ||
{ | ||
$proceed = function () { | ||
return null; | ||
}; | ||
|
||
$this->config->expects(self::once())->method('isActiveModule')->willReturn(true); | ||
|
||
/** @var \Magento\Catalog\Model\Product\Option|MockObject $option */ | ||
$option = $this->createMock(\Magento\Catalog\Model\Product\Option::class); | ||
$option->expects(self::once())->method('getType')->willReturn(\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN); | ||
|
||
/** @var MockObject|Product $product */ | ||
$product = $this->createMock(Product::class); | ||
|
||
$this->typeSelectMock->expects(self::once())->method('getOption')->willReturn($option); | ||
$this->typeSelectMock->expects(self::once())->method('getProduct')->willReturn($product); | ||
|
||
$multipleMock = $this->createPartialMock(Multiple::class, [ | ||
'setOption', 'setProduct', 'setSkipJsReloadPrice', 'toHtml', | ||
]); | ||
$multipleMock->method('setOption')->willReturn($multipleMock); | ||
$multipleMock->method('setProduct')->willReturn($multipleMock); | ||
$multipleMock->method('setSkipJsReloadPrice')->willReturn($multipleMock); | ||
|
||
$this->multipleFactory->expects(self::once())->method('create')->willReturn($multipleMock); | ||
|
||
$this->plugin->aroundGetValuesHtml($this->typeSelectMock, $proceed); | ||
} | ||
|
||
public function testAroundGetValuesHtmlModuleDisabled(): void | ||
{ | ||
$proceed = function () { | ||
return null; | ||
}; | ||
|
||
$this->config->expects(self::once())->method('isActiveModule')->willReturn(false); | ||
$this->typeSelectMock->expects(self::never())->method('getOption'); | ||
|
||
$this->plugin->aroundGetValuesHtml($this->typeSelectMock, $proceed); | ||
} | ||
} |