7
7
8
8
namespace Magento \Wishlist \Test \Unit \Pricing \ConfiguredPrice ;
9
9
10
+ use Magento \Catalog \Api \Data \ProductInterface ;
10
11
use Magento \Catalog \Model \Product ;
11
12
use Magento \Framework \Pricing \Adjustment \CalculatorInterface ;
12
13
use Magento \Framework \Pricing \Price \PriceInterface ;
@@ -46,6 +47,11 @@ class ConfigurableProductTest extends TestCase
46
47
*/
47
48
private $ priceInfoMock ;
48
49
50
+ /**
51
+ * @var ProductInterface|MockObject
52
+ */
53
+ private $ productCustomOption ;
54
+
49
55
protected function setUp (): void
50
56
{
51
57
$ this ->priceInfoMock = $ this ->getMockBuilder (PriceInfoInterface::class)
@@ -65,6 +71,9 @@ protected function setUp(): void
65
71
$ this ->priceCurrency = $ this ->getMockBuilder (PriceCurrencyInterface::class)
66
72
->getMockForAbstractClass ();
67
73
74
+ $ this ->productCustomOption = $ this ->getMockBuilder (ProductInterface::class)
75
+ ->getMockForAbstractClass ();
76
+
68
77
$ this ->model = new ConfigurableProduct (
69
78
$ this ->saleableItem ,
70
79
null ,
@@ -143,4 +152,76 @@ public function testGetValueWithNoCustomOption()
143
152
144
153
$ this ->assertEquals (100 , $ this ->model ->getValue ());
145
154
}
155
+
156
+ public function testGetValueWithCustomOption () {
157
+ $ priceValue = 10 ;
158
+ $ customOptionPrice = 5 ;
159
+
160
+ $ priceMock = $ this ->getMockBuilder (PriceInterface::class)
161
+ ->getMockForAbstractClass ();
162
+
163
+ $ priceMock ->expects ($ this ->once ())
164
+ ->method ('getValue ' )
165
+ ->willReturn ($ priceValue );
166
+
167
+ $ this ->priceInfoMock = $ this ->getMockBuilder (Base::class)
168
+ ->disableOriginalConstructor ()
169
+ ->getMock ();
170
+ $ this ->priceInfoMock ->expects ($ this ->once ())
171
+ ->method ('getPrice ' )
172
+ ->with (ConfigurableProduct::PRICE_CODE )
173
+ ->willReturn ($ priceMock );
174
+
175
+ $ productMock = $ this ->getMockBuilder (Product::class)
176
+ ->disableOriginalConstructor ()
177
+ ->getMock ();
178
+ $ productMock ->expects ($ this ->once ())
179
+ ->method ('getPriceInfo ' )
180
+ ->willReturn ($ this ->priceInfoMock );
181
+
182
+ $ wishlistItemOptionMock = $ this ->getMockBuilder (Option::class)
183
+ ->disableOriginalConstructor ()
184
+ ->getMock ();
185
+ $ wishlistItemOptionMock ->expects ($ this ->once ())
186
+ ->method ('getProduct ' )
187
+ ->willReturn ($ productMock );
188
+
189
+ $ this ->saleableItem ->expects ($ this ->once ())
190
+ ->method ('getCustomOption ' )
191
+ ->with ('simple_product ' )
192
+ ->willReturn ($ wishlistItemOptionMock );
193
+
194
+ $ productOptionMock = $ this ->getMockBuilder ('Magento\Catalog\Model\ResourceModel\Product\Option\Collection ' )
195
+ ->disableOriginalConstructor ()
196
+ ->addMethods (['getValues ' ])
197
+ ->onlyMethods (['getIterator ' ,'getData ' ])
198
+ ->getMock ();
199
+
200
+ $ productValMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product\Option\Value ' )
201
+ ->disableOriginalConstructor ()
202
+ ->addMethods (['getIterator ' ])
203
+ ->onlyMethods (['getPrice ' ])
204
+ ->getMock ();
205
+
206
+ $ productMock ->expects ($ this ->atLeastOnce ())
207
+ ->method ('getProductOptionsCollection ' )
208
+ ->willReturn ($ productOptionMock );
209
+
210
+ $ productOptionMock ->expects ($ this ->any ())->method ('getIterator ' )
211
+ ->willReturn (new \ArrayIterator ([$ productOptionMock ]));
212
+
213
+ $ productOptionMock ->expects ($ this ->any ())
214
+ ->method ('getValues ' )
215
+ ->willReturn ($ productValMock );
216
+
217
+ $ productValMock ->expects ($ this ->any ())->method ('getIterator ' )
218
+ ->willReturn (new \ArrayIterator ([$ productValMock ]));
219
+
220
+ $ productValMock ->expects ($ this ->any ())
221
+ ->method ('getPrice ' )
222
+ ->willReturn ($ customOptionPrice );
223
+
224
+ $ totalPrice = $ priceValue + $ customOptionPrice ;
225
+ $ this ->assertEquals ($ totalPrice , $ this ->model ->getValue ());
226
+ }
146
227
}
0 commit comments