9 use \Magento\Setup\Fixtures\CartPriceRulesFixture;
19 private $fixtureModelMock;
29 private $ruleFactoryMock;
33 $this->fixtureModelMock = $this->createMock(\
Magento\Setup\Fixtures\FixtureModel::class);
34 $this->ruleFactoryMock = $this->createPartialMock(\
Magento\SalesRule\Model\RuleFactory::class, [
'create']);
40 $storeMock = $this->createMock(\
Magento\
Store\Model\Store::class);
41 $storeMock->expects($this->once())
42 ->method(
'getRootCategoryId')
43 ->will($this->returnValue(2));
45 $websiteMock = $this->createMock(\
Magento\
Store\Model\Website::class);
46 $websiteMock->expects($this->once())
48 ->will($this->returnValue([$storeMock]));
49 $websiteMock->expects($this->once())
51 ->will($this->returnValue(
'website_id'));
54 $abstractDbMock = $this->getMockForAbstractClass(
63 $abstractDbMock->expects($this->once())
64 ->method(
'getAllChildren')
65 ->will($this->returnValue([1]));
67 $storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManager::class);
68 $storeManagerMock->expects($this->once())
69 ->method(
'getWebsites')
70 ->will($this->returnValue([$websiteMock]));
72 $categoryMock = $this->createMock(\
Magento\Catalog\Model\Category::class);
73 $categoryMock->expects($this->once())
74 ->method(
'getResource')
75 ->will($this->returnValue($abstractDbMock));
76 $categoryMock->expects($this->once())
78 ->will($this->returnValue(
'path/to/file'));
79 $categoryMock->expects($this->once())
81 ->will($this->returnValue(
'category_id'));
84 [\Magento\Catalog\Model\Category::class, $categoryMock]
88 $objectManagerMock->expects($this->once())
90 ->will($this->returnValue($storeManagerMock));
91 $objectManagerMock->expects($this->once())
93 ->will($this->returnValueMap($objectValueMap));
96 [
'cart_price_rules', 0, 1],
97 [
'cart_price_rules_floor', 3, 3],
98 [
'cart_price_rules_advanced_type',
false,
false]
101 $this->fixtureModelMock
102 ->expects($this->exactly(3))
104 ->will($this->returnValueMap($valueMap));
105 $this->fixtureModelMock
106 ->expects($this->exactly(2))
107 ->method(
'getObjectManager')
108 ->will($this->returnValue($objectManagerMock));
110 $ruleMock = $this->createMock(\
Magento\SalesRule\Model\Rule::class);
111 $this->ruleFactoryMock->expects($this->once())
113 ->willReturn($ruleMock);
115 $this->model->execute();
120 $ruleMock = $this->createMock(\
Magento\SalesRule\Model\Rule::class);
121 $ruleMock->expects($this->never())->method(
'save');
124 $objectManagerMock->expects($this->never())
126 ->with($this->equalTo(\
Magento\SalesRule\Model\Rule::class))
127 ->willReturn($ruleMock);
129 $this->fixtureModelMock
130 ->expects($this->never())
131 ->method(
'getObjectManager')
132 ->willReturn($objectManagerMock);
133 $this->fixtureModelMock
134 ->expects($this->once())
138 $this->model->execute();
149 $reflection = new \ReflectionClass($this->model);
150 $reflectionProperty = $reflection->getProperty(
'cartPriceRulesCount');
151 $reflectionProperty->setAccessible(
true);
152 $reflectionProperty->setValue($this->model, $ruleCount);
154 $result = $this->model->generateAdvancedCondition(
$ruleId, $categoriesArray);
155 if (
$ruleId < ($ruleCount - 200)) {
157 'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
158 'attribute' =>
'category_ids',
164 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
165 'attribute' =>
'base_subtotal',
172 'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
173 'aggregator' =>
'all',
178 'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
179 'aggregator' =>
'all',
183 '1--1--1' => $firstCondition,
184 '1--2' => $secondCondition
188 'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Combine::class,
189 'aggregator' =>
'all',
197 $regions = [
'Alabama',
'Alaska',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
198 'Delaware',
'District of Columbia',
'Florida',
'Georgia',
'Hawaii',
'Idaho',
'Illinois',
199 'Indiana',
'Iowa',
'Kansas',
'Kentucky',
'Louisiana',
'Maine',
'Maryland',
'Massachusetts',
200 'Michigan',
'Minnesota',
'Mississippi',
'Missouri',
'Montana',
'Nebraska',
'Nevada',
201 'New Hampshire',
'New Jersey',
'New Mexico',
'New York',
'North Carolina',
'North Dakota',
202 'Ohio',
'Oklahoma',
'Oregon',
'Pennsylvania',
'Rhode Island',
'South Carolina',
'South Dakota',
203 'Tennessee',
'Texas',
'Utah',
'Vermont',
'Virginia',
'Washington',
'West Virginia',
204 'Wisconsin',
'Wyoming'];
206 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
207 'attribute' =>
'region',
209 'value' => $regions[(
$ruleId / 4) % 50],
213 'type' => \Magento\SalesRule\Model\Rule\Condition\Address::class,
214 'attribute' =>
'base_subtotal',
221 'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
222 'aggregator' =>
'all',
226 '1--1' => $firstCondition,
227 '1--2' => $secondCondition
231 'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Combine::class,
232 'aggregator' =>
'all',
239 $this->assertSame($expected,
$result);
255 $this->assertSame(
'Generating cart price rules', $this->model->getActionTitle());
261 'cart_price_rules' =>
'Cart Price Rules' 262 ], $this->model->introduceParamLabels());
dataProviderGenerateAdvancedCondition()
testIntroduceParamLabels()
testNoFixtureConfigValue()
testGenerateAdvancedCondition($ruleId, $categoriesArray, $ruleCount)