Skip to content

Commit 2c03342

Browse files
MAGETWO-62405: Ignoring product visibility for SalesRules
1 parent 50f500e commit 2c03342

File tree

1 file changed

+22
-32
lines changed
  • dev/tests/integration/testsuite/Magento/SalesRule/Model/Rule/Condition

1 file changed

+22
-32
lines changed

dev/tests/integration/testsuite/Magento/SalesRule/Model/Rule/Condition/ProductTest.php

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,40 @@ protected function setUp()
1919
}
2020

2121
/**
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
2327
*
2428
* @magentoAppIsolation enabled
2529
* @param int $categoryId
26-
* @param int $visibility
2730
* @param bool $expectedResult
28-
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product.php
31+
* @magentoDataFixture Magento/ConfigurableProduct/_files/quote_with_configurable_product.php
2932
* @magentoDataFixture Magento/SalesRule/_files/rules_category.php
3033
* @dataProvider validateProductConditionDataProvider
3134
*/
32-
public function testValidateCategorySalesRuleIgnoresVisibility($categoryId, $visibility, $expectedResult)
35+
public function testValidateCategorySalesRuleIncludesChildren($categoryId, $expectedResult)
3336
{
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');
4541

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
4743
/** @var $rule \Magento\SalesRule\Model\Rule */
4844
$rule = $this->objectManager->get(\Magento\Framework\Registry::class)
4945
->registry('_fixture/Magento_SalesRule_Category');
5046

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));
5256
}
5357

5458
/**
@@ -58,29 +62,15 @@ public function validateProductConditionDataProvider()
5862
{
5963
$validCategoryId = 66;
6064
$invalidCategoryId = 2;
61-
$visible = \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH;
62-
$invisible = \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE;
6365
return [
6466
[
6567
'categoryId' => $validCategoryId,
66-
'visibility' => $visible,
67-
'expectedResult' => true
68-
],
69-
[
70-
'categoryId' => $validCategoryId,
71-
'visibility' => $invisible,
7268
'expectedResult' => true
7369
],
7470
[
7571
'categoryId' => $invalidCategoryId,
76-
'visibility' => $visible,
7772
'expectedResult' => false
78-
],
79-
[
80-
'categoryId' => $invalidCategoryId,
81-
'visibility' => $invisible,
82-
'expectedResult' => false
83-
],
73+
]
8474
];
8575
}
8676
}

0 commit comments

Comments
 (0)