@@ -165,7 +165,7 @@ public function testRemoveOptionByCode($code, $option)
165
165
$ this ->model ->addOption ($ option );
166
166
$ this ->assertEquals (1 , count ($ this ->model ->getOptions ()));
167
167
$ this ->model ->removeOption ($ code );
168
- $ actualOptions = $ this ->model ->getOptions ();
168
+ $ actualOptions = $ this ->model ->getOptions ();
169
169
$ actualOption = array_pop ($ actualOptions );
170
170
$ this ->assertTrue ($ actualOption ->isDeleted ());
171
171
}
@@ -185,7 +185,7 @@ public function getOptionsDataProvider()
185
185
->getMock ();
186
186
return [
187
187
['first_key ' , ['code ' => 'first_key ' , 'value ' => 'first_data ' ]],
188
- ['second_key ' ,$ optionMock ],
188
+ ['second_key ' , $ optionMock ],
189
189
['third_key ' , new \Magento \Framework \Object (['code ' => 'third_key ' , 'product ' => $ productMock ])],
190
190
];
191
191
}
@@ -262,4 +262,63 @@ public function testCompareOptionsNegativeOptionsTwoHaveNotOption()
262
262
263
263
$ this ->assertFalse ($ result );
264
264
}
265
+
266
+ public function testSetAndSaveItemOptions ()
267
+ {
268
+ $ this ->assertEmpty ($ this ->model ->getOptions ());
269
+ $ firstOptionMock = $ this ->getMockBuilder ('Magento\Wishlist\Model\Item\Option ' )
270
+ ->disableOriginalConstructor ()
271
+ ->setMethods (['getCode ' , 'isDeleted ' , 'delete ' , '__wakeup ' ])
272
+ ->getMock ();
273
+ $ firstOptionMock ->expects ($ this ->any ())
274
+ ->method ('getCode ' )
275
+ ->willReturn ('first_code ' );
276
+ $ firstOptionMock ->expects ($ this ->any ())
277
+ ->method ('isDeleted ' )
278
+ ->willReturn (true );
279
+ $ firstOptionMock ->expects ($ this ->once ())
280
+ ->method ('delete ' );
281
+
282
+ $ secondOptionMock = $ this ->getMockBuilder ('Magento\Wishlist\Model\Item\Option ' )
283
+ ->disableOriginalConstructor ()
284
+ ->setMethods (['getCode ' , 'save ' , '__wakeup ' ])
285
+ ->getMock ();
286
+ $ secondOptionMock ->expects ($ this ->any ())
287
+ ->method ('getCode ' )
288
+ ->willReturn ('second_code ' );
289
+ $ secondOptionMock ->expects ($ this ->once ())
290
+ ->method ('save ' );
291
+
292
+ $ this ->model ->setOptions ([$ firstOptionMock , $ secondOptionMock ]);
293
+ $ this ->assertNull ($ this ->model ->isOptionsSaved ());
294
+ $ this ->model ->saveItemOptions ();
295
+ $ this ->assertTrue ($ this ->model ->isOptionsSaved ());
296
+ }
297
+
298
+ public function testGetProductWithException ()
299
+ {
300
+ $ this ->setExpectedException ('Magento\Framework\Exception\LocalizedException ' , __ ('Cannot specify product. ' ));
301
+ $ this ->model ->getProduct ();
302
+ }
303
+
304
+ public function testGetProduct ()
305
+ {
306
+ $ productId = 1 ;
307
+ $ storeId = 0 ;
308
+ $ this ->model ->setData ('product_id ' , $ productId );
309
+ $ this ->model ->setData ('store_id ' , $ storeId );
310
+ $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
311
+ ->disableOriginalConstructor ()
312
+ ->getMock ();
313
+ $ productMock ->expects ($ this ->any ())
314
+ ->method ('setFinalPrice ' )
315
+ ->with (null );
316
+ $ productMock ->expects ($ this ->any ())
317
+ ->method ('setCustomOprtions ' )
318
+ ->with ([]);
319
+ $ this ->productRepository ->expects ($ this ->once ())
320
+ ->method ('getById ' )
321
+ ->willReturn ($ productMock );
322
+ $ this ->assertEquals ($ productMock , $ this ->model ->getProduct ());
323
+ }
265
324
}
0 commit comments