@@ -850,7 +850,18 @@ public function testSetOptionsWithNull()
850
850
private function createOptionMock ($ optionCode , $ optionData = [])
851
851
{
852
852
$ optionMock = $ this ->getMockBuilder (\Magento \Quote \Model \Quote \Item \Option::class)
853
- ->setMethods (['setData ' , 'setItem ' , 'getCode ' , '__wakeup ' , 'isDeleted ' , 'getValue ' , 'getProduct ' ])
853
+ ->setMethods ([
854
+ 'setData ' ,
855
+ 'setItem ' ,
856
+ 'getItem ' ,
857
+ 'getCode ' ,
858
+ '__wakeup ' ,
859
+ 'isDeleted ' ,
860
+ 'delete ' ,
861
+ 'getValue ' ,
862
+ 'getProduct ' ,
863
+ 'save '
864
+ ])
854
865
->disableOriginalConstructor ()
855
866
->getMock ();
856
867
$ optionMock ->expects ($ this ->any ())
@@ -1189,4 +1200,33 @@ public function testRemoveErrorInfosByParamsAllErrorsRemoved()
1189
1200
$ this ->assertFalse ($ this ->model ->getHasError ());
1190
1201
$ this ->assertEquals ('' , $ this ->model ->getMessage ());
1191
1202
}
1203
+
1204
+ /**
1205
+ * Test method \Magento\Quote\Model\Quote\Item::saveItemOptions
1206
+ */
1207
+ public function testSaveItemOptions ()
1208
+ {
1209
+ $ optionMockDeleted = $ this ->createOptionMock (100 );
1210
+ $ optionMockDeleted ->expects (self ::once ())->method ('isDeleted ' )->willReturn (true );
1211
+ $ optionMockDeleted ->expects (self ::once ())->method ('delete ' );
1212
+
1213
+ $ optionMock1 = $ this ->createOptionMock (200 );
1214
+ $ optionMock1 ->expects (self ::once ())->method ('isDeleted ' )->willReturn (false );
1215
+ $ quoteItemMock1 = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Item::class, ['getId ' ]);
1216
+ $ quoteItemMock1 ->expects (self ::once ())->method ('getId ' )->willReturn (null );
1217
+ $ optionMock1 ->expects (self ::exactly (2 ))->method ('getItem ' )->willReturn ($ quoteItemMock1 );
1218
+ $ optionMock1 ->expects (self ::exactly (2 ))->method ('setItem ' )->with ($ this ->model );
1219
+ $ optionMock1 ->expects (self ::once ())->method ('save ' );
1220
+
1221
+ $ optionMock2 = $ this ->createOptionMock (300 );
1222
+ $ optionMock2 ->expects (self ::once ())->method ('isDeleted ' )->willReturn (false );
1223
+ $ quoteItemMock2 = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Item::class, ['getId ' ]);
1224
+ $ quoteItemMock2 ->expects (self ::once ())->method ('getId ' )->willReturn (11 );
1225
+ $ optionMock2 ->expects (self ::exactly (2 ))->method ('getItem ' )->willReturn ($ quoteItemMock2 );
1226
+ $ optionMock2 ->expects (self ::once ())->method ('setItem ' )->with ($ this ->model );
1227
+ $ optionMock2 ->expects (self ::once ())->method ('save ' );
1228
+
1229
+ $ this ->model ->setOptions ([$ optionMockDeleted , $ optionMock1 , $ optionMock2 ]);
1230
+ $ this ->model ->saveItemOptions ();
1231
+ }
1192
1232
}
0 commit comments