1010use Magento \Catalog \Model \Product ;
1111use Magento \Framework \DataObject ;
1212use Magento \Framework \Model \AbstractModel ;
13+ use Magento \Quote \Model \Quote ;
1314use Magento \Quote \Model \Quote \Item ;
1415use Magento \Quote \Model \Quote \Item \AbstractItem ;
1516use Magento \Rule \Model \Condition \Context ;
@@ -36,6 +37,9 @@ class SubselectTest extends TestCase
3637 /** @var Product|MockObject */
3738 private $ productMock ;
3839
40+ /** @var Quote|MockObject */
41+ private $ quoteMock ;
42+
3943 /** @var Item|MockObject */
4044 private $ quoteItemMock ;
4145
@@ -51,13 +55,18 @@ protected function setUp(): void
5155 ->getMock ();
5256 $ this ->abstractModel = $ this ->getMockBuilder (AbstractModel::class)
5357 ->disableOriginalConstructor ()
54- ->addMethods (['getAllItems ' , 'getProduct ' ])
58+ ->addMethods (['getQuote ' , ' getAllItems ' , 'getProduct ' ])
5559 ->getMockForAbstractClass ();
5660 $ this ->productMock = $ this ->getMockBuilder (Product::class)
5761 ->onlyMethods (['getData ' , 'getResource ' , 'hasData ' ])
5862 ->addMethods (['getOperatorForValidate ' , 'getValueParsed ' ])
5963 ->disableOriginalConstructor ()
6064 ->getMock ();
65+ $ this ->quoteMock = $ this ->getMockBuilder (Quote::class)
66+ ->disableOriginalConstructor ()
67+ ->addMethods (['getIsMultiShipping ' ])
68+ ->onlyMethods (['getAllVisibleItems ' ])
69+ ->getMock ();
6170 $ this ->quoteItemMock = $ this ->getMockBuilder (Item::class)
6271 ->addMethods (['getHasChildren ' , 'getProductId ' ])
6372 ->onlyMethods (
@@ -66,12 +75,19 @@ protected function setUp(): void
6675 'getProduct ' ,
6776 'getProductType ' ,
6877 'getChildren ' ,
78+ 'getQuote ' ,
6979 'getAddress ' ,
7080 'getOptionByCode '
7181 ]
7282 )
7383 ->disableOriginalConstructor ()
7484 ->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 );
7591 $ this ->abstractModel ->expects ($ this ->any ())
7692 ->method ('getAllItems ' )
7793 ->willReturn ([$ this ->quoteItemMock ]);
@@ -90,6 +106,7 @@ protected function setUp(): void
90106 *
91107 * @param array|null $attributeDetails
92108 * @param array $productDetails
109+ * @param bool $isMultiShipping
93110 * @param bool $expectedResult
94111 * @return void
95112 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -98,6 +115,7 @@ protected function setUp(): void
98115 public function testValidateForFixedBundleProduct (
99116 ?array $ attributeDetails ,
100117 array $ productDetails ,
118+ bool $ isMultiShipping ,
101119 bool $ expectedResult
102120 ): void {
103121 $ attributeResource = new DataObject ();
@@ -130,6 +148,9 @@ public function testValidateForFixedBundleProduct(
130148 $ this ->ruleConditionMock ->expects ($ this ->any ())->method ('getOperatorForValidate ' )
131149 ->willReturn ($ attributeDetails ['attributeOperator ' ]);
132150 }
151+ $ this ->quoteMock ->expects ($ this ->any ())
152+ ->method ('getIsMultiShipping ' )
153+ ->willReturn ($ isMultiShipping );
133154 $ this ->quoteItemMock ->expects ($ this ->any ())
134155 ->method ('getProductType ' )
135156 ->willReturn ($ productDetails ['type ' ]);
@@ -185,7 +206,7 @@ public function testValidateForFixedBundleProduct(
185206 public static function dataProviderForFixedBundleProduct (): array
186207 {
187208 return [
188- 'validate true for bundle product data with conditions ' =>
209+ 'validate true for bundle product data with conditions with multi shipping ' =>
189210 [
190211 [
191212 'id ' => 'attribute_set_id ' ,
@@ -202,9 +223,10 @@ public static function dataProviderForFixedBundleProduct(): array
202223 'baseRowTotal ' => 100 ,
203224 'valueParsed ' => 100
204225 ],
226+ true ,
205227 true
206228 ],
207- 'validate false for bundle product data with conditions ' =>
229+ 'validate false for bundle product data with conditions w/o multi shipping ' =>
208230 [
209231 [
210232 'id ' => 'attribute_set_id ' ,
@@ -221,9 +243,10 @@ public static function dataProviderForFixedBundleProduct(): array
221243 'baseRowTotal ' => 100 ,
222244 'valueParsed ' => 50
223245 ],
246+ false ,
224247 false
225248 ],
226- 'validate product data without conditions with bundle product ' =>
249+ 'validate product data without conditions with bundle product w/o multi shipping ' =>
227250 [
228251 null ,
229252 [
@@ -235,9 +258,11 @@ public static function dataProviderForFixedBundleProduct(): array
235258 'baseRowTotal ' => 100 ,
236259 'valueParsed ' => 100
237260 ],
261+ false ,
238262 false
239263 ],
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 ' =>
241266 [
242267 [
243268 'id ' => 'attribute_set_id ' ,
@@ -254,9 +279,10 @@ public static function dataProviderForFixedBundleProduct(): array
254279 'baseRowTotal ' => 200 ,
255280 'valueParsed ' => 200
256281 ],
282+ false ,
257283 false
258284 ],
259- 'validate true for simple product data with conditions ' =>
285+ 'validate true for simple product data with conditions with multi shipping ' =>
260286 [
261287 [
262288 'id ' => 'attribute_set_id ' ,
@@ -273,9 +299,10 @@ public static function dataProviderForFixedBundleProduct(): array
273299 'baseRowTotal ' => 100 ,
274300 'valueParsed ' => 100
275301 ],
302+ true ,
276303 true
277304 ],
278- 'validate false for simple product data with conditions ' =>
305+ 'validate false for simple product data with conditions w/o multi shipping ' =>
279306 [
280307 [
281308 'id ' => 'attribute_set_id ' ,
@@ -292,6 +319,7 @@ public static function dataProviderForFixedBundleProduct(): array
292319 'baseRowTotal ' => 100 ,
293320 'valueParsed ' => 50
294321 ],
322+ false ,
295323 false
296324 ]
297325 ];
@@ -302,6 +330,7 @@ public static function dataProviderForFixedBundleProduct(): array
302330 *
303331 * @param array|null $attributeDetails
304332 * @param array $productDetails
333+ * @param bool $isMultiShipping
305334 * @param bool $expectedResult
306335 * @return void
307336 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -310,6 +339,7 @@ public static function dataProviderForFixedBundleProduct(): array
310339 public function testValidateForBaseTotalInclTax (
311340 ?array $ attributeDetails ,
312341 array $ productDetails ,
342+ bool $ isMultiShipping ,
313343 bool $ expectedResult
314344 ):void {
315345 $ attributeResource = new DataObject ();
@@ -343,6 +373,9 @@ public function testValidateForBaseTotalInclTax(
343373 ->willReturn ($ attributeDetails ['attributeOperator ' ]);
344374 }
345375
376+ $ this ->quoteMock ->expects ($ this ->any ())
377+ ->method ('getIsMultiShipping ' )
378+ ->willReturn ($ isMultiShipping );
346379 /* @var AbstractItem|MockObject $quoteItemMock */
347380 $ this ->productMock ->expects ($ this ->any ())
348381 ->method ('getResource ' )
@@ -368,7 +401,8 @@ public function testValidateForBaseTotalInclTax(
368401 public static function dataProviderForBaseTotalInclTax (): array
369402 {
370403 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 ' =>
372406 [
373407 [
374408 'id ' => 'attribute_set_id ' ,
@@ -385,6 +419,7 @@ public static function dataProviderForBaseTotalInclTax(): array
385419 'baseRowTotalInclTax ' => 200 ,
386420 'valueParsed ' => 200
387421 ],
422+ false ,
388423 false
389424 ]
390425 ];
0 commit comments