@@ -87,6 +87,11 @@ class WishlistTest extends \PHPUnit_Framework_TestCase
87
87
*/
88
88
protected $ productRepository ;
89
89
90
+ /**
91
+ * @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject
92
+ */
93
+ protected $ serializer ;
94
+
90
95
protected function setUp ()
91
96
{
92
97
$ context = $ this ->getMockBuilder (\Magento \Framework \Model \Context::class)
@@ -134,6 +139,9 @@ protected function setUp()
134
139
->disableOriginalConstructor ()
135
140
->getMock ();
136
141
$ this ->productRepository = $ this ->getMock (\Magento \Catalog \Api \ProductRepositoryInterface::class);
142
+ $ this ->serializer = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
143
+ ->disableOriginalConstructor ()
144
+ ->getMock ();
137
145
138
146
$ context ->expects ($ this ->once ())
139
147
->method ('getEventDispatcher ' )
@@ -154,7 +162,9 @@ protected function setUp()
154
162
$ this ->mathRandom ,
155
163
$ this ->dateTime ,
156
164
$ this ->productRepository ,
157
- false
165
+ false ,
166
+ [],
167
+ $ this ->serializer
158
168
);
159
169
}
160
170
@@ -286,7 +296,61 @@ public function testUpdateItem($itemId, $buyRequest, $param)
286
296
public function updateItemDataProvider ()
287
297
{
288
298
return [
289
- '0 ' => [1 , new \Magento \Framework \DataObject (), null ],
299
+ '0 ' => [1 , new \Magento \Framework \DataObject (), null ]
290
300
];
291
301
}
302
+
303
+ public function testAddNewItem ()
304
+ {
305
+ $ productId = 1 ;
306
+ $ storeId = 1 ;
307
+ $ buyRequest = json_encode ([
308
+ 'number ' => 42 ,
309
+ 'string ' => 'string_value ' ,
310
+ 'boolean ' => true ,
311
+ 'collection ' => [1 , 2 , 3 ],
312
+ 'product ' => 1 ,
313
+ 'form_key ' => 'abc '
314
+ ]);
315
+ $ result = 'product ' ;
316
+
317
+ $ instanceType = $ this ->getMockBuilder (\Magento \Catalog \Model \Product \Type \AbstractType::class)
318
+ ->disableOriginalConstructor ()
319
+ ->getMock ();
320
+ $ instanceType ->expects ($ this ->once ())
321
+ ->method ('processConfiguration ' )
322
+ ->willReturn ('product ' );
323
+
324
+ $ productMock = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class)
325
+ ->disableOriginalConstructor ()
326
+ ->setMethods (['getId ' , 'hasWishlistStoreId ' , 'getStoreId ' , 'getTypeInstance ' ])
327
+ ->getMock ();
328
+ $ productMock ->expects ($ this ->once ())
329
+ ->method ('getId ' )
330
+ ->willReturn ($ productId );
331
+ $ productMock ->expects ($ this ->once ())
332
+ ->method ('hasWishlistStoreId ' )
333
+ ->willReturn (false );
334
+ $ productMock ->expects ($ this ->once ())
335
+ ->method ('getStoreId ' )
336
+ ->willReturn ($ storeId );
337
+ $ productMock ->expects ($ this ->once ())
338
+ ->method ('getTypeInstance ' )
339
+ ->willReturn ($ instanceType );
340
+
341
+ $ this ->productRepository ->expects ($ this ->once ())
342
+ ->method ('getById ' )
343
+ ->with ($ productId , false , $ storeId )
344
+ ->willReturn ($ productMock );
345
+
346
+ $ this ->serializer ->expects ($ this ->once ())
347
+ ->method ('unserialize ' )
348
+ ->willReturnCallback (
349
+ function ($ value ) {
350
+ return json_decode ($ value , true );
351
+ }
352
+ );
353
+
354
+ $ this ->assertEquals ($ result , $ this ->wishlist ->addNewItem ($ productMock , $ buyRequest ));
355
+ }
292
356
}
0 commit comments