@@ -146,4 +146,121 @@ public function calculateSpecialPrice()
146
146
[10 , 100 , 1 , true , 10 ],
147
147
];
148
148
}
149
+
150
+ public function testGetTotalBundleItemsPriceWithNoCustomOptions ()
151
+ {
152
+ $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
153
+ ->disableOriginalConstructor ()
154
+ ->getMock ();
155
+
156
+ $ productMock ->expects ($ this ->once ())
157
+ ->method ('hasCustomOptions ' )
158
+ ->willReturn (false );
159
+
160
+ $ this ->assertEquals (0 , $ this ->model ->getTotalBundleItemsPrice ($ productMock ));
161
+ }
162
+
163
+ /**
164
+ * @param string|null $value
165
+ * @dataProvider dataProviderWithEmptyOptions
166
+ */
167
+ public function testGetTotalBundleItemsPriceWithEmptyOptions ($ value )
168
+ {
169
+ $ dataObjectMock = $ this ->getMockBuilder ('Magento\Framework\DataObject ' )
170
+ ->setMethods (['getValue ' ])
171
+ ->disableOriginalConstructor ()
172
+ ->getMock ();
173
+
174
+ $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
175
+ ->disableOriginalConstructor ()
176
+ ->getMock ();
177
+
178
+ $ productMock ->expects ($ this ->once ())
179
+ ->method ('hasCustomOptions ' )
180
+ ->willReturn (true );
181
+ $ productMock ->expects ($ this ->once ())
182
+ ->method ('getCustomOption ' )
183
+ ->with ('bundle_selection_ids ' )
184
+ ->willReturn ($ dataObjectMock );
185
+
186
+ $ dataObjectMock ->expects ($ this ->once ())
187
+ ->method ('getValue ' )
188
+ ->willReturn ($ value );
189
+
190
+ $ this ->assertEquals (0 , $ this ->model ->getTotalBundleItemsPrice ($ productMock ));
191
+ }
192
+
193
+ /**
194
+ * @return array
195
+ */
196
+ public function dataProviderWithEmptyOptions ()
197
+ {
198
+ return [
199
+ ['a:0:{} ' ],
200
+ ['' ],
201
+ [null ],
202
+ ];
203
+ }
204
+
205
+ public function testGetTotalBundleItemsPriceWithNoItems ()
206
+ {
207
+ $ storeId = 1 ;
208
+
209
+ $ dataObjectMock = $ this ->getMockBuilder ('Magento\Framework\DataObject ' )
210
+ ->setMethods (['getValue ' ])
211
+ ->disableOriginalConstructor ()
212
+ ->getMock ();
213
+
214
+ $ productMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product ' )
215
+ ->disableOriginalConstructor ()
216
+ ->getMock ();
217
+
218
+ $ productTypeMock = $ this ->getMockBuilder ('Magento\Bundle\Model\Product\Type ' )
219
+ ->disableOriginalConstructor ()
220
+ ->getMock ();
221
+
222
+ $ selectionsMock = $ this ->getMockBuilder ('Magento\Bundle\Model\ResourceModel\Selection\Collection ' )
223
+ ->disableOriginalConstructor ()
224
+ ->getMock ();
225
+
226
+ $ productMock ->expects ($ this ->once ())
227
+ ->method ('hasCustomOptions ' )
228
+ ->willReturn (true );
229
+ $ productMock ->expects ($ this ->once ())
230
+ ->method ('getCustomOption ' )
231
+ ->with ('bundle_selection_ids ' )
232
+ ->willReturn ($ dataObjectMock );
233
+ $ productMock ->expects ($ this ->once ())
234
+ ->method ('getTypeInstance ' )
235
+ ->willReturn ($ productTypeMock );
236
+ $ productMock ->expects ($ this ->once ())
237
+ ->method ('getStoreId ' )
238
+ ->willReturn ($ storeId );
239
+
240
+ $ dataObjectMock ->expects ($ this ->once ())
241
+ ->method ('getValue ' )
242
+ ->willReturn ('a:1:{i:0;s:1:"1";} ' );
243
+
244
+ $ productTypeMock ->expects ($ this ->once ())
245
+ ->method ('getSelectionsByIds ' )
246
+ ->with ([1 ], $ productMock )
247
+ ->willReturn ($ selectionsMock );
248
+
249
+ $ selectionsMock ->expects ($ this ->once ())
250
+ ->method ('addTierPriceData ' )
251
+ ->willReturnSelf ();
252
+ $ selectionsMock ->expects ($ this ->once ())
253
+ ->method ('getItems ' )
254
+ ->willReturn ([]);
255
+
256
+ $ this ->eventManagerMock ->expects ($ this ->once ())
257
+ ->method ('dispatch ' )
258
+ ->with (
259
+ 'prepare_catalog_product_collection_prices ' ,
260
+ ['collection ' => $ selectionsMock , 'store_id ' => $ storeId ]
261
+ )
262
+ ->willReturnSelf ();
263
+
264
+ $ this ->assertEquals (0 , $ this ->model ->getTotalBundleItemsPrice ($ productMock ));
265
+ }
149
266
}
0 commit comments