Skip to content

Commit d66558f

Browse files
committed
added tests and readme
1 parent de58008 commit d66558f

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Magento 2 Custom Option Default Value extension use to set custom option default
3737
* Radio Box
3838
* Checkbox
3939

40+
![Configuration](https://user-images.githubusercontent.com/5670207/73607519-005b9880-45c8-11ea-8b6c-eb7251a8d985.png)
41+
42+
![Setting Custom Option of Product](https://user-images.githubusercontent.com/5670207/73607472-5976fc80-45c7-11ea-8398-b75a3fb593f8.png)
43+
44+
![Product Page](https://user-images.githubusercontent.com/5670207/73607439-1157da00-45c7-11ea-9f4e-4e00763d3e6e.png)
45+
4046
#### Support
4147
If you encounter any problems or bugs, please open an [issue](https://github.com/dmitrykazak/magento2-custom-option-default-value/issues) on GitHub.
4248

Test/Unit/Model/ConfigTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DK\CustomOptionDefaultValue\Test\Unit\Model;
6+
7+
use DK\CustomOptionDefaultValue\Model\Config;
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use PHPUnit\Framework\MockObject\MockObject;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* @internal
14+
* @coversNothing
15+
*/
16+
final class ConfigTest extends TestCase
17+
{
18+
/**
19+
* @var MockObject|ScopeConfigInterface
20+
*/
21+
private $scopeConfig;
22+
23+
/**
24+
* @var Config
25+
*/
26+
private $config;
27+
28+
protected function setUp(): void
29+
{
30+
parent::setUp();
31+
32+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
33+
$this->config = new Config($this->scopeConfig);
34+
}
35+
36+
public function testIsActiveModule(): void
37+
{
38+
$this->scopeConfig
39+
->expects($this->once())
40+
->method('isSetFlag')
41+
->with($this->getConstValue('XML_PATH_GENERAL_ACTIVE')->getValue())
42+
->willReturn(true);
43+
44+
$this->assertTrue($this->config->isActiveModule());
45+
}
46+
47+
private function getConstValue(string $const): \ReflectionClassConstant
48+
{
49+
return new \ReflectionClassConstant(Config::class, $const);
50+
}
51+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DK\CustomOptionDefaultValue\Test\Unit\Plugin\Catalog\Block\Product\View\Options\Type;
6+
7+
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\CheckableFactory;
8+
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\Multiple;
9+
use DK\CustomOptionDefaultValue\Block\Product\View\Options\Type\Select\MultipleFactory;
10+
use DK\CustomOptionDefaultValue\Model\Config;
11+
use DK\CustomOptionDefaultValue\Plugin\Catalog\Block\Product\View\Options\Type\Select;
12+
use Magento\Catalog\Block\Product\View\Options\Type\Select as TypeSelect;
13+
use Magento\Catalog\Model\Product;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* @internal
19+
* @coversNothing
20+
*/
21+
class SelectTest extends TestCase
22+
{
23+
/**
24+
* @var MockObject|MultipleFactory
25+
*/
26+
private $multipleFactory;
27+
28+
/**
29+
* @var CheckableFactory|MockObject
30+
*/
31+
private $checkableFactory;
32+
33+
/**
34+
* @var Config|MockObject
35+
*/
36+
private $config;
37+
38+
/**
39+
* @var Select
40+
*/
41+
private $plugin;
42+
43+
/**
44+
* @var MockObject|TypeSelect
45+
*/
46+
private $typeSelectMock;
47+
48+
protected function setUp(): void
49+
{
50+
parent::setUp();
51+
52+
$this->multipleFactory = $this->createPartialMock(MultipleFactory::class, ['create']);
53+
$this->checkableFactory = $this->createPartialMock(CheckableFactory::class, ['create']);
54+
$this->config = $this->createMock(Config::class);
55+
56+
$this->typeSelectMock = $this->createMock(TypeSelect::class);
57+
58+
$this->plugin = new Select($this->multipleFactory, $this->checkableFactory, $this->config);
59+
}
60+
61+
public function testAroundGetValuesHtml(): void
62+
{
63+
$proceed = function () {
64+
return null;
65+
};
66+
67+
$this->config->expects(self::once())->method('isActiveModule')->willReturn(true);
68+
69+
/** @var \Magento\Catalog\Model\Product\Option|MockObject $option */
70+
$option = $this->createMock(\Magento\Catalog\Model\Product\Option::class);
71+
$option->expects(self::once())->method('getType')->willReturn(\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN);
72+
73+
/** @var MockObject|Product $product */
74+
$product = $this->createMock(Product::class);
75+
76+
$this->typeSelectMock->expects(self::once())->method('getOption')->willReturn($option);
77+
$this->typeSelectMock->expects(self::once())->method('getProduct')->willReturn($product);
78+
79+
$multipleMock = $this->createPartialMock(Multiple::class, [
80+
'setOption', 'setProduct', 'setSkipJsReloadPrice', 'toHtml',
81+
]);
82+
$multipleMock->method('setOption')->willReturn($multipleMock);
83+
$multipleMock->method('setProduct')->willReturn($multipleMock);
84+
$multipleMock->method('setSkipJsReloadPrice')->willReturn($multipleMock);
85+
86+
$this->multipleFactory->expects(self::once())->method('create')->willReturn($multipleMock);
87+
88+
$this->plugin->aroundGetValuesHtml($this->typeSelectMock, $proceed);
89+
}
90+
91+
public function testAroundGetValuesHtmlModuleDisabled(): void
92+
{
93+
$proceed = function () {
94+
return null;
95+
};
96+
97+
$this->config->expects(self::once())->method('isActiveModule')->willReturn(false);
98+
$this->typeSelectMock->expects(self::never())->method('getOption');
99+
100+
$this->plugin->aroundGetValuesHtml($this->typeSelectMock, $proceed);
101+
}
102+
}

0 commit comments

Comments
 (0)