|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Bundle\Test\Unit\Pricing\Adjustment; |
| 9 | + |
| 10 | +use Magento\Bundle\Model\Option; |
| 11 | +use Magento\Bundle\Model\Product\Type; |
| 12 | +use Magento\Bundle\Model\ResourceModel\Option\Collection; |
| 13 | +use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection; |
| 14 | +use Magento\Bundle\Pricing\Adjustment\DefaultSelectionPriceListProvider; |
| 15 | +use Magento\Bundle\Pricing\Price\BundleSelectionFactory; |
| 16 | +use Magento\Catalog\Helper\Data as CatalogData; |
| 17 | +use Magento\Catalog\Model\Product; |
| 18 | +use Magento\Framework\DataObject; |
| 19 | +use Magento\Store\Api\Data\StoreInterface; |
| 20 | +use Magento\Store\Api\Data\WebsiteInterface; |
| 21 | +use Magento\Store\Api\WebsiteRepositoryInterface; |
| 22 | +use Magento\Store\Model\StoreManagerInterface; |
| 23 | +use PHPUnit\Framework\MockObject\MockObject; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +/** |
| 27 | + * Test for \Magento\Bundle\Pricing\DefaultSelectionPriceListProvider |
| 28 | + */ |
| 29 | +class DefaultSelectionPriceListProviderTest extends TestCase |
| 30 | +{ |
| 31 | + /** |
| 32 | + * @var BundleSelectionFactory|MockObject |
| 33 | + */ |
| 34 | + private $selectionFactory; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var CatalogData|MockObject |
| 38 | + */ |
| 39 | + private $catalogData; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var StoreManagerInterface|MockObject |
| 43 | + */ |
| 44 | + private $storeManager; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var WebsiteRepositoryInterface|MockObject |
| 48 | + */ |
| 49 | + private $websiteRepository; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var Product|MockObject |
| 53 | + */ |
| 54 | + private $product; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var Collection|MockObject |
| 58 | + */ |
| 59 | + private $optionsCollection; |
| 60 | + |
| 61 | + /** |
| 62 | + * @var Type|MockObject |
| 63 | + */ |
| 64 | + private $typeInstance; |
| 65 | + |
| 66 | + /** |
| 67 | + * @var Option|MockObject |
| 68 | + */ |
| 69 | + private $option; |
| 70 | + |
| 71 | + /** |
| 72 | + * @var SelectionCollection|MockObject |
| 73 | + */ |
| 74 | + private $selectionCollection; |
| 75 | + |
| 76 | + /** |
| 77 | + * @var DataObject|MockObject |
| 78 | + */ |
| 79 | + private $selection; |
| 80 | + |
| 81 | + /** |
| 82 | + * @var StoreInterface|MockObject |
| 83 | + */ |
| 84 | + private $store; |
| 85 | + |
| 86 | + /** |
| 87 | + * @var WebsiteInterface|MockObject |
| 88 | + */ |
| 89 | + private $website; |
| 90 | + |
| 91 | + /** |
| 92 | + * @var DefaultSelectionPriceListProvider |
| 93 | + */ |
| 94 | + private $model; |
| 95 | + |
| 96 | + protected function setUp(): void |
| 97 | + { |
| 98 | + $this->selectionFactory = $this->getMockBuilder(BundleSelectionFactory::class) |
| 99 | + ->disableOriginalConstructor() |
| 100 | + ->getMock(); |
| 101 | + $this->catalogData = $this->getMockBuilder(CatalogData::class) |
| 102 | + ->disableOriginalConstructor() |
| 103 | + ->getMock(); |
| 104 | + $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class) |
| 105 | + ->getMockForAbstractClass(); |
| 106 | + $this->websiteRepository = $this->getMockBuilder(WebsiteRepositoryInterface::class) |
| 107 | + ->getMockForAbstractClass(); |
| 108 | + |
| 109 | + $this->product = $this->getMockBuilder(Product::class) |
| 110 | + ->disableOriginalConstructor() |
| 111 | + ->getMock(); |
| 112 | + $this->optionsCollection = $this->getMockBuilder(Collection::class) |
| 113 | + ->disableOriginalConstructor() |
| 114 | + ->getMock(); |
| 115 | + $this->typeInstance = $this->getMockBuilder(Type::class) |
| 116 | + ->disableOriginalConstructor() |
| 117 | + ->getMock(); |
| 118 | + $this->option = $this->getMockBuilder(Option::class) |
| 119 | + ->disableOriginalConstructor() |
| 120 | + ->getMock(); |
| 121 | + $this->selectionCollection = $this->getMockBuilder(SelectionCollection::class) |
| 122 | + ->disableOriginalConstructor() |
| 123 | + ->getMock(); |
| 124 | + $this->selection = $this->getMockBuilder(DataObject::class) |
| 125 | + ->disableOriginalConstructor() |
| 126 | + ->getMock(); |
| 127 | + $this->store = $this->getMockBuilder(StoreInterface::class) |
| 128 | + ->getMockForAbstractClass(); |
| 129 | + $this->website = $this->getMockBuilder(WebsiteInterface::class) |
| 130 | + ->getMockForAbstractClass(); |
| 131 | + |
| 132 | + $this->model = new DefaultSelectionPriceListProvider( |
| 133 | + $this->selectionFactory, |
| 134 | + $this->catalogData, |
| 135 | + $this->storeManager, |
| 136 | + $this->websiteRepository |
| 137 | + ); |
| 138 | + } |
| 139 | + |
| 140 | + public function testGetPriceList(): void |
| 141 | + { |
| 142 | + $optionId = 1; |
| 143 | + |
| 144 | + $this->typeInstance->expects($this->any()) |
| 145 | + ->method('getOptionsCollection') |
| 146 | + ->with($this->product) |
| 147 | + ->willReturn($this->optionsCollection); |
| 148 | + $this->product->expects($this->any()) |
| 149 | + ->method('getTypeInstance') |
| 150 | + ->willReturn($this->typeInstance); |
| 151 | + $this->optionsCollection->expects($this->once()) |
| 152 | + ->method('getIterator') |
| 153 | + ->willReturn(new \ArrayIterator([$this->option])); |
| 154 | + $this->option->expects($this->once()) |
| 155 | + ->method('getOptionId') |
| 156 | + ->willReturn($optionId); |
| 157 | + $this->typeInstance->expects($this->once()) |
| 158 | + ->method('getSelectionsCollection') |
| 159 | + ->with([$optionId], $this->product) |
| 160 | + ->willReturn($this->selectionCollection); |
| 161 | + $this->option->expects($this->once()) |
| 162 | + ->method('isMultiSelection') |
| 163 | + ->willReturn(true); |
| 164 | + $this->storeManager->expects($this->once()) |
| 165 | + ->method('getStore') |
| 166 | + ->willReturn($this->store); |
| 167 | + $this->store->expects($this->once()) |
| 168 | + ->method('getWebsiteId') |
| 169 | + ->willReturn(0); |
| 170 | + $this->websiteRepository->expects($this->once()) |
| 171 | + ->method('getDefault') |
| 172 | + ->willReturn($this->website); |
| 173 | + $this->website->expects($this->once()) |
| 174 | + ->method('getId') |
| 175 | + ->willReturn(1); |
| 176 | + $this->selectionCollection->expects($this->once()) |
| 177 | + ->method('getIterator') |
| 178 | + ->willReturn(new \ArrayIterator([])); |
| 179 | + |
| 180 | + $this->model->getPriceList($this->product, false, false); |
| 181 | + } |
| 182 | +} |
0 commit comments