|
5 | 5 | namespace Magento\Bundle\Model\Product;
|
6 | 6 |
|
7 | 7 | use Magento\Bundle\Model\Resource\Option\Collection;
|
| 8 | +use Magento\Bundle\Model\Resource\Selection\Collection as SelectionCollection; |
8 | 9 | use Magento\Catalog\Model\Product\Option\Type\DefaultType;
|
9 | 10 | use Magento\Framework\Model\Exception;
|
10 | 11 |
|
@@ -120,7 +121,17 @@ public function testPrepareForCartAdvancedSelectRequiredOptions()
|
120 | 121 | ->getMock();
|
121 | 122 | /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */
|
122 | 123 | $option = $this->getMockBuilder('Magento\Catalog\Model\Product\Option')
|
123 |
| - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired']) |
| 124 | + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) |
| 125 | + ->disableOriginalConstructor() |
| 126 | + ->getMock(); |
| 127 | + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ |
| 128 | + $selectionCollection = $this->getMockBuilder('Magento\Bundle\Model\Resource\Selection\Collection') |
| 129 | + ->setMethods(['getItems']) |
| 130 | + ->disableOriginalConstructor() |
| 131 | + ->getMock(); |
| 132 | + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Object $buyRequest */ |
| 133 | + $selection = $this->getMockBuilder('Magento\Framework\Object') |
| 134 | + ->setMethods(['__wakeup', 'isSalable', 'getOptionId']) |
124 | 135 | ->disableOriginalConstructor()
|
125 | 136 | ->getMock();
|
126 | 137 | /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */
|
@@ -148,44 +159,64 @@ public function testPrepareForCartAdvancedSelectRequiredOptions()
|
148 | 159 | ->getMock();
|
149 | 160 | /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */
|
150 | 161 | $optionCollection = $this->getMockBuilder('Magento\Bundle\Model\Resource\Option\Collection')
|
151 |
| - ->setMethods(['getItems']) |
| 162 | + ->setMethods(['getItems', 'getItemById']) |
152 | 163 | ->disableOriginalConstructor()
|
153 | 164 | ->getMock();
|
154 | 165 |
|
155 | 166 | $this->parentClass($group, $option, $buyRequest, $product);
|
156 | 167 |
|
157 |
| - $product->expects($this->at(0)) |
| 168 | + $product->expects($this->any()) |
158 | 169 | ->method('getSkipCheckRequiredOption')
|
159 | 170 | ->willReturn(true);
|
160 |
| - $product->expects($this->at(1)) |
161 |
| - ->method('getSkipCheckRequiredOption') |
162 |
| - ->willReturn(false); |
163 | 171 | $product->expects($this->once())
|
164 | 172 | ->method('getTypeInstance')
|
165 | 173 | ->willReturn($productType);
|
166 | 174 | $product->expects($this->once())
|
167 | 175 | ->method('hasData')
|
168 | 176 | ->willReturn(true);
|
169 |
| - $product->expects($this->once()) |
| 177 | + $product->expects($this->any()) |
170 | 178 | ->method('getData')
|
171 |
| - ->willReturn($optionCollection); |
| 179 | + ->willReturnCallback(function($key) use ($optionCollection, $selectionCollection){ |
| 180 | + $resultValue = null; |
| 181 | + switch($key) { |
| 182 | + case '_cache_instance_options_collection': |
| 183 | + $resultValue = $optionCollection; |
| 184 | + break; |
| 185 | + case '_cache_instance_used_selections': |
| 186 | + $resultValue = $selectionCollection; |
| 187 | + break; |
| 188 | + case '_cache_instance_used_selections_ids': |
| 189 | + $resultValue = [0 => 5]; |
| 190 | + break; |
| 191 | + } |
| 192 | + return $resultValue; |
| 193 | + }); |
| 194 | + $optionCollection->expects($this->once()) |
| 195 | + ->method('getItemById') |
| 196 | + ->willReturn($option); |
172 | 197 | $productType->expects($this->once())
|
173 | 198 | ->method('setStoreFilter');
|
174 | 199 | $buyRequest->expects($this->once())
|
175 | 200 | ->method('getBundleOption')
|
176 |
| - ->willReturn([1]); |
177 |
| - $optionCollection->expects($this->once()) |
| 201 | + ->willReturn([3 => 5]); |
| 202 | + $selectionCollection->expects($this->once()) |
178 | 203 | ->method('getItems')
|
179 |
| - ->willReturn([$option]); |
| 204 | + ->willReturn([$selection]); |
| 205 | + $selection->expects($this->once()) |
| 206 | + ->method('isSalable') |
| 207 | + ->willReturn(false); |
| 208 | + $option->expects($this->at(3)) |
| 209 | + ->method('getId') |
| 210 | + ->willReturn(3); |
180 | 211 | $option->expects($this->once())
|
181 | 212 | ->method('getRequired')
|
182 | 213 | ->willReturn(true);
|
183 |
| - $option->expects($this->at(1)) |
184 |
| - ->method('getId') |
185 |
| - ->willReturn(3); |
| 214 | + $option->expects($this->once()) |
| 215 | + ->method('isMultiSelection') |
| 216 | + ->willReturn(true); |
186 | 217 |
|
187 | 218 | $result = $this->model->prepareForCartAdvanced($buyRequest, $product);
|
188 |
| - $this->assertEquals('Please select all required options.', $result); |
| 219 | + $this->assertEquals('The required options you selected are not available.', $result); |
189 | 220 | }
|
190 | 221 |
|
191 | 222 | public function testPrepareForCartAdvancedParentClassReturnString()
|
|
0 commit comments