|
| 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