@@ -19,36 +19,40 @@ protected function setUp()
19
19
}
20
20
21
21
/**
22
- * Ensure that SalesRules filtering on category ignore product visibility
22
+ * Ensure that SalesRules filtering on category validates children products of configurables
23
+ *
24
+ * 1. Load a quote with a configured product and a sales rule set to filter based on category
25
+ * 2. Set product's associated category according to test case
26
+ * 3. Attempt to validate the sales rule against the quote and assert the output is as expected
23
27
*
24
28
* @magentoAppIsolation enabled
25
29
* @param int $categoryId
26
- * @param int $visibility
27
30
* @param bool $expectedResult
28
- * @magentoDataFixture Magento/Checkout /_files/quote_with_simple_product .php
31
+ * @magentoDataFixture Magento/ConfigurableProduct /_files/quote_with_configurable_product .php
29
32
* @magentoDataFixture Magento/SalesRule/_files/rules_category.php
30
33
* @dataProvider validateProductConditionDataProvider
31
34
*/
32
- public function testValidateCategorySalesRuleIgnoresVisibility ($ categoryId, $ visibility , $ expectedResult )
35
+ public function testValidateCategorySalesRuleIncludesChildren ($ categoryId , $ expectedResult )
33
36
{
34
- /** @var $session \Magento\Checkout\Model\Session */
35
- $ session = $ this ->objectManager ->create (\Magento \Checkout \Model \Session::class);
36
-
37
- // Prepare product with given visibility and category settings
38
- /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
39
- $ productRepository = $ this ->objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class);
40
- /** @var $product \Magento\Catalog\Model\Product */
41
- $ product = $ productRepository ->get ('simple ' );
42
- $ product ->setVisibility ($ visibility );
43
- $ product ->setCategoryIds ([$ categoryId ]);
44
- $ product ->save ();
37
+ // Load the quote that contains a child of a configurable product
38
+ /** @var \Magento\Quote\Model\Quote $quote */
39
+ $ quote = $ this ->objectManager ->create (\Magento \Quote \Model \Quote::class)
40
+ ->load ('test_cart_with_configurable ' , 'reserved_order_id ' );
45
41
46
- // Load the SalesRule looking for products in a category and assert that the validation is as expected
42
+ // Load the SalesRule looking for products in a specific category
47
43
/** @var $rule \Magento\SalesRule\Model\Rule */
48
44
$ rule = $ this ->objectManager ->get (\Magento \Framework \Registry::class)
49
45
->registry ('_fixture/Magento_SalesRule_Category ' );
50
46
51
- $ this ->assertEquals ($ expectedResult , $ rule ->validate ($ session ->getQuote ()));
47
+ // Prepare the parent product with the given category setting
48
+ /** @var $product \Magento\Catalog\Model\Product */
49
+ $ product = $ this ->objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class)
50
+ ->get ('configurable ' );
51
+ $ product ->setCategoryIds ([$ categoryId ]);
52
+ $ product ->save ();
53
+
54
+ // Assert the validation result matches the expected result given the child product and category rule
55
+ $ this ->assertEquals ($ expectedResult , $ rule ->validate ($ quote ));
52
56
}
53
57
54
58
/**
@@ -58,29 +62,15 @@ public function validateProductConditionDataProvider()
58
62
{
59
63
$ validCategoryId = 66 ;
60
64
$ invalidCategoryId = 2 ;
61
- $ visible = \Magento \Catalog \Model \Product \Visibility::VISIBILITY_BOTH ;
62
- $ invisible = \Magento \Catalog \Model \Product \Visibility::VISIBILITY_NOT_VISIBLE ;
63
65
return [
64
66
[
65
67
'categoryId ' => $ validCategoryId ,
66
- 'visibility ' => $ visible ,
67
- 'expectedResult ' => true
68
- ],
69
- [
70
- 'categoryId ' => $ validCategoryId ,
71
- 'visibility ' => $ invisible ,
72
68
'expectedResult ' => true
73
69
],
74
70
[
75
71
'categoryId ' => $ invalidCategoryId ,
76
- 'visibility ' => $ visible ,
77
72
'expectedResult ' => false
78
- ],
79
- [
80
- 'categoryId ' => $ invalidCategoryId ,
81
- 'visibility ' => $ invisible ,
82
- 'expectedResult ' => false
83
- ],
73
+ ]
84
74
];
85
75
}
86
76
}
0 commit comments