77
88namespace Magento \Wishlist \Test \Unit \Pricing \ConfiguredPrice ;
99
10+ use Magento \Catalog \Api \Data \ProductInterface ;
1011use Magento \Catalog \Model \Product ;
1112use Magento \Framework \Pricing \Adjustment \CalculatorInterface ;
1213use Magento \Framework \Pricing \Price \PriceInterface ;
@@ -46,6 +47,11 @@ class ConfigurableProductTest extends TestCase
4647 */
4748 private $ priceInfoMock ;
4849
50+ /**
51+ * @var ProductInterface|MockObject
52+ */
53+ private $ productCustomOption ;
54+
4955 protected function setUp (): void
5056 {
5157 $ this ->priceInfoMock = $ this ->getMockBuilder (PriceInfoInterface::class)
@@ -65,6 +71,9 @@ protected function setUp(): void
6571 $ this ->priceCurrency = $ this ->getMockBuilder (PriceCurrencyInterface::class)
6672 ->getMockForAbstractClass ();
6773
74+ $ this ->productCustomOption = $ this ->getMockBuilder (ProductInterface::class)
75+ ->getMockForAbstractClass ();
76+
6877 $ this ->model = new ConfigurableProduct (
6978 $ this ->saleableItem ,
7079 null ,
@@ -143,4 +152,76 @@ public function testGetValueWithNoCustomOption()
143152
144153 $ this ->assertEquals (100 , $ this ->model ->getValue ());
145154 }
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+ }
146227}
0 commit comments