10
10
use Magento \Catalog \Model \Product ;
11
11
use Magento \Framework \DataObject ;
12
12
use Magento \Framework \Model \AbstractModel ;
13
+ use Magento \Quote \Model \Quote ;
13
14
use Magento \Quote \Model \Quote \Item ;
14
15
use Magento \Quote \Model \Quote \Item \AbstractItem ;
15
16
use Magento \Rule \Model \Condition \Context ;
@@ -36,6 +37,9 @@ class SubselectTest extends TestCase
36
37
/** @var Product|MockObject */
37
38
private $ productMock ;
38
39
40
+ /** @var Quote|MockObject */
41
+ private $ quoteMock ;
42
+
39
43
/** @var Item|MockObject */
40
44
private $ quoteItemMock ;
41
45
@@ -51,13 +55,18 @@ protected function setUp(): void
51
55
->getMock ();
52
56
$ this ->abstractModel = $ this ->getMockBuilder (AbstractModel::class)
53
57
->disableOriginalConstructor ()
54
- ->addMethods (['getAllItems ' , 'getProduct ' ])
58
+ ->addMethods (['getQuote ' , ' getAllItems ' , 'getProduct ' ])
55
59
->getMockForAbstractClass ();
56
60
$ this ->productMock = $ this ->getMockBuilder (Product::class)
57
61
->onlyMethods (['getData ' , 'getResource ' , 'hasData ' ])
58
62
->addMethods (['getOperatorForValidate ' , 'getValueParsed ' ])
59
63
->disableOriginalConstructor ()
60
64
->getMock ();
65
+ $ this ->quoteMock = $ this ->getMockBuilder (Quote::class)
66
+ ->disableOriginalConstructor ()
67
+ ->addMethods (['getIsMultiShipping ' ])
68
+ ->onlyMethods (['getAllVisibleItems ' ])
69
+ ->getMock ();
61
70
$ this ->quoteItemMock = $ this ->getMockBuilder (Item::class)
62
71
->addMethods (['getHasChildren ' , 'getProductId ' ])
63
72
->onlyMethods (
@@ -66,12 +75,19 @@ protected function setUp(): void
66
75
'getProduct ' ,
67
76
'getProductType ' ,
68
77
'getChildren ' ,
78
+ 'getQuote ' ,
69
79
'getAddress ' ,
70
80
'getOptionByCode '
71
81
]
72
82
)
73
83
->disableOriginalConstructor ()
74
84
->getMock ();
85
+ $ this ->quoteMock ->expects ($ this ->any ())
86
+ ->method ('getAllVisibleItems ' )
87
+ ->willReturn ([$ this ->quoteItemMock ]);
88
+ $ this ->abstractModel ->expects ($ this ->any ())
89
+ ->method ('getQuote ' )
90
+ ->willReturn ($ this ->quoteMock );
75
91
$ this ->abstractModel ->expects ($ this ->any ())
76
92
->method ('getAllItems ' )
77
93
->willReturn ([$ this ->quoteItemMock ]);
@@ -90,6 +106,7 @@ protected function setUp(): void
90
106
*
91
107
* @param array|null $attributeDetails
92
108
* @param array $productDetails
109
+ * @param bool $isMultiShipping
93
110
* @param bool $expectedResult
94
111
* @return void
95
112
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -98,6 +115,7 @@ protected function setUp(): void
98
115
public function testValidateForFixedBundleProduct (
99
116
?array $ attributeDetails ,
100
117
array $ productDetails ,
118
+ bool $ isMultiShipping ,
101
119
bool $ expectedResult
102
120
): void {
103
121
$ attributeResource = new DataObject ();
@@ -130,6 +148,9 @@ public function testValidateForFixedBundleProduct(
130
148
$ this ->ruleConditionMock ->expects ($ this ->any ())->method ('getOperatorForValidate ' )
131
149
->willReturn ($ attributeDetails ['attributeOperator ' ]);
132
150
}
151
+ $ this ->quoteMock ->expects ($ this ->any ())
152
+ ->method ('getIsMultiShipping ' )
153
+ ->willReturn ($ isMultiShipping );
133
154
$ this ->quoteItemMock ->expects ($ this ->any ())
134
155
->method ('getProductType ' )
135
156
->willReturn ($ productDetails ['type ' ]);
@@ -185,7 +206,7 @@ public function testValidateForFixedBundleProduct(
185
206
public static function dataProviderForFixedBundleProduct (): array
186
207
{
187
208
return [
188
- 'validate true for bundle product data with conditions ' =>
209
+ 'validate true for bundle product data with conditions with multi shipping ' =>
189
210
[
190
211
[
191
212
'id ' => 'attribute_set_id ' ,
@@ -202,9 +223,10 @@ public static function dataProviderForFixedBundleProduct(): array
202
223
'baseRowTotal ' => 100 ,
203
224
'valueParsed ' => 100
204
225
],
226
+ true ,
205
227
true
206
228
],
207
- 'validate false for bundle product data with conditions ' =>
229
+ 'validate false for bundle product data with conditions w/o multi shipping ' =>
208
230
[
209
231
[
210
232
'id ' => 'attribute_set_id ' ,
@@ -221,9 +243,10 @@ public static function dataProviderForFixedBundleProduct(): array
221
243
'baseRowTotal ' => 100 ,
222
244
'valueParsed ' => 50
223
245
],
246
+ false ,
224
247
false
225
248
],
226
- 'validate product data without conditions with bundle product ' =>
249
+ 'validate product data without conditions with bundle product w/o multi shipping ' =>
227
250
[
228
251
null ,
229
252
[
@@ -235,9 +258,11 @@ public static function dataProviderForFixedBundleProduct(): array
235
258
'baseRowTotal ' => 100 ,
236
259
'valueParsed ' => 100
237
260
],
261
+ false ,
238
262
false
239
263
],
240
- 'validate true for bundle product data with conditions for attribute base_row_total ' =>
264
+ 'validate true for bundle product
265
+ data with conditions for attribute base_row_total w/o multi shipping ' =>
241
266
[
242
267
[
243
268
'id ' => 'attribute_set_id ' ,
@@ -254,9 +279,10 @@ public static function dataProviderForFixedBundleProduct(): array
254
279
'baseRowTotal ' => 200 ,
255
280
'valueParsed ' => 200
256
281
],
282
+ false ,
257
283
false
258
284
],
259
- 'validate true for simple product data with conditions ' =>
285
+ 'validate true for simple product data with conditions with multi shipping ' =>
260
286
[
261
287
[
262
288
'id ' => 'attribute_set_id ' ,
@@ -273,9 +299,10 @@ public static function dataProviderForFixedBundleProduct(): array
273
299
'baseRowTotal ' => 100 ,
274
300
'valueParsed ' => 100
275
301
],
302
+ true ,
276
303
true
277
304
],
278
- 'validate false for simple product data with conditions ' =>
305
+ 'validate false for simple product data with conditions w/o multi shipping ' =>
279
306
[
280
307
[
281
308
'id ' => 'attribute_set_id ' ,
@@ -292,6 +319,7 @@ public static function dataProviderForFixedBundleProduct(): array
292
319
'baseRowTotal ' => 100 ,
293
320
'valueParsed ' => 50
294
321
],
322
+ false ,
295
323
false
296
324
]
297
325
];
@@ -302,6 +330,7 @@ public static function dataProviderForFixedBundleProduct(): array
302
330
*
303
331
* @param array|null $attributeDetails
304
332
* @param array $productDetails
333
+ * @param bool $isMultiShipping
305
334
* @param bool $expectedResult
306
335
* @return void
307
336
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -310,6 +339,7 @@ public static function dataProviderForFixedBundleProduct(): array
310
339
public function testValidateForBaseTotalInclTax (
311
340
?array $ attributeDetails ,
312
341
array $ productDetails ,
342
+ bool $ isMultiShipping ,
313
343
bool $ expectedResult
314
344
):void {
315
345
$ attributeResource = new DataObject ();
@@ -343,6 +373,9 @@ public function testValidateForBaseTotalInclTax(
343
373
->willReturn ($ attributeDetails ['attributeOperator ' ]);
344
374
}
345
375
376
+ $ this ->quoteMock ->expects ($ this ->any ())
377
+ ->method ('getIsMultiShipping ' )
378
+ ->willReturn ($ isMultiShipping );
346
379
/* @var AbstractItem|MockObject $quoteItemMock */
347
380
$ this ->productMock ->expects ($ this ->any ())
348
381
->method ('getResource ' )
@@ -368,7 +401,8 @@ public function testValidateForBaseTotalInclTax(
368
401
public static function dataProviderForBaseTotalInclTax (): array
369
402
{
370
403
return [
371
- 'validate true for product data with conditions for attribute base_row_total_incl_tax ' =>
404
+ 'validate true for product data with conditions
405
+ for attribute base_row_total_incl_tax w/o multi shipping ' =>
372
406
[
373
407
[
374
408
'id ' => 'attribute_set_id ' ,
@@ -385,6 +419,7 @@ public static function dataProviderForBaseTotalInclTax(): array
385
419
'baseRowTotalInclTax ' => 200 ,
386
420
'valueParsed ' => 200
387
421
],
422
+ false ,
388
423
false
389
424
]
390
425
];
0 commit comments