@@ -142,6 +142,11 @@ class QuoteTest extends \PHPUnit\Framework\TestCase
142
142
*/
143
143
private $ customerDataFactoryMock ;
144
144
145
+ /**
146
+ * @var \PHPUnit_Framework_MockObject_MockObject
147
+ */
148
+ private $ itemProcessor ;
149
+
145
150
/**
146
151
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
147
152
*/
@@ -223,7 +228,9 @@ protected function setUp()
223
228
$ this ->filterBuilderMock = $ this ->getMockBuilder (\Magento \Framework \Api \FilterBuilder::class)
224
229
->disableOriginalConstructor ()
225
230
->getMock ();
226
-
231
+ $ this ->itemProcessor = $ this ->getMockBuilder (\Magento \Quote \Model \Quote \Item \Processor::class)
232
+ ->disableOriginalConstructor ()
233
+ ->getMock ();
227
234
$ this ->extensionAttributesJoinProcessorMock = $ this ->createMock (\Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface::class);
228
235
$ this ->customerDataFactoryMock = $ this ->createPartialMock (\Magento \Customer \Api \Data \CustomerInterfaceFactory::class, ['create ' ]);
229
236
$ this ->quote = (new ObjectManager ($ this ))
@@ -249,6 +256,7 @@ protected function setUp()
249
256
'objectCopyService ' => $ this ->objectCopyServiceMock ,
250
257
'extensionAttributesJoinProcessor ' => $ this ->extensionAttributesJoinProcessorMock ,
251
258
'customerDataFactory ' => $ this ->customerDataFactoryMock ,
259
+ 'itemProcessor ' => $ this ->itemProcessor ,
252
260
'data ' => [
253
261
'reserved_order_id ' => 1000001
254
262
]
@@ -853,6 +861,69 @@ public function testAddProductItemPreparation()
853
861
$ this ->assertEquals ($ expectedResult , $ result );
854
862
}
855
863
864
+ public function testAddProductItemNew ()
865
+ {
866
+ $ itemMock = $ this ->createMock (\Magento \Quote \Model \Quote \Item::class);
867
+
868
+ $ expectedResult = $ itemMock ;
869
+ $ requestMock = $ this ->createMock (
870
+ \Magento \Framework \DataObject::class
871
+ );
872
+ $ this ->objectFactoryMock ->expects ($ this ->once ())
873
+ ->method ('create ' )
874
+ ->with ($ this ->equalTo (['qty ' => 1 ]))
875
+ ->will ($ this ->returnValue ($ requestMock ));
876
+
877
+ $ typeInstanceMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product \Type \Simple::class, [
878
+ 'prepareForCartAdvanced '
879
+ ]);
880
+
881
+ $ productMock = $ this ->createPartialMock (\Magento \Catalog \Model \Product::class, [
882
+ 'getParentProductId ' ,
883
+ 'setStickWithinParent ' ,
884
+ '__wakeup '
885
+ ]);
886
+
887
+ $ collectionMock = $ this ->createMock (\Magento \Quote \Model \ResourceModel \Quote \Item \Collection::class);
888
+
889
+ $ itemMock ->expects ($ this ->any ())
890
+ ->method ('representProduct ' )
891
+ ->will ($ this ->returnValue (false ));
892
+
893
+ $ iterator = new \ArrayIterator ([$ itemMock ]);
894
+ $ collectionMock ->expects ($ this ->any ())
895
+ ->method ('getIterator ' )
896
+ ->will ($ this ->returnValue ($ iterator ));
897
+
898
+ $ this ->quoteItemCollectionFactoryMock ->expects ($ this ->once ())
899
+ ->method ('create ' )
900
+ ->will ($ this ->returnValue ($ collectionMock ));
901
+
902
+ $ this ->productMock ->expects ($ this ->once ())
903
+ ->method ('isSalable ' )
904
+ ->willReturn (true );
905
+ $ this ->itemProcessor
906
+ ->expects ($ this ->once ())
907
+ ->method ('init ' )
908
+ ->willReturn ($ itemMock );
909
+ $ itemMock ->expects ($ this ->once ())
910
+ ->method ('setProduct ' );
911
+ $ itemMock ->expects ($ this ->once ())
912
+ ->method ('setOptions ' );
913
+ $ itemMock ->expects ($ this ->any ())
914
+ ->method ('setQuote ' )
915
+ ->with ($ this ->quote );
916
+ $ typeInstanceMock ->expects ($ this ->once ())
917
+ ->method ('prepareForCartAdvanced ' )
918
+ ->will ($ this ->returnValue ([$ productMock ]));
919
+ $ this ->productMock ->expects ($ this ->once ())
920
+ ->method ('getTypeInstance ' )
921
+ ->will ($ this ->returnValue ($ typeInstanceMock ));
922
+
923
+ $ result = $ this ->quote ->addProduct ($ this ->productMock , null );
924
+ $ this ->assertEquals ($ expectedResult , $ result );
925
+ }
926
+
856
927
public function testValidateMiniumumAmount ()
857
928
{
858
929
$ storeId = 1 ;
0 commit comments