@@ -136,19 +136,162 @@ public function testValidateQtySalesRuleWithConfigurable()
136
136
*
137
137
* @magentoDataFixture Magento/ConfigurableProduct/_files/quote_with_configurable_product.php
138
138
* @magentoDataFixture Magento/SalesRule/_files/rules_parent_category.php
139
+ * @dataProvider conditionsDataProvider
139
140
*/
140
- public function testValidateParentCategoryWithConfigurable ()
141
+ public function testValidateParentCategoryWithConfigurable (array $ conditions , bool $ expected ): void
141
142
{
142
143
$ quote = $ this ->getQuote ('test_cart_with_configurable ' );
143
144
$ registry = $ this ->objectManager ->get (Registry::class);
144
145
/** @var Rule $rule */
145
146
$ rule = $ this ->objectManager ->create (Rule::class);
146
147
$ ruleId = $ registry ->registry ('50% Off on Configurable parent category ' );
147
148
$ rule ->load ($ ruleId );
149
+ $ rule ->getConditions ()->setConditions ([])->loadArray (
150
+ [
151
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Combine::class,
152
+ 'attribute ' => null ,
153
+ 'operator ' => null ,
154
+ 'value ' => '1 ' ,
155
+ 'is_value_processed ' => null ,
156
+ 'aggregator ' => 'all ' ,
157
+ 'conditions ' => $ conditions
158
+ ]
159
+ );
160
+ $ rule ->save ();
148
161
149
- $ this ->assertFalse (
150
- $ rule ->validate ($ quote ->getBillingAddress ()),
162
+ $ this ->assertEquals (
163
+ $ expected ,
164
+ $ rule ->validate ($ quote ->getShippingAddress ()),
151
165
'Cart price rule validation failed. '
152
166
);
153
167
}
168
+
169
+ /**
170
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
171
+ * @return array
172
+ */
173
+ public function conditionsDataProvider (): array
174
+ {
175
+ return [
176
+ 'If total quantity is 1 for a subselection of items in cart matching ALL of these conditions: ' .
177
+ 'Category (Parent Only) is not "Default Category" ' => [
178
+ 'conditions ' => [
179
+ [
180
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product \Subselect::class,
181
+ 'attribute ' => 'qty ' ,
182
+ 'operator ' => '== ' ,
183
+ 'value ' => '1 ' ,
184
+ 'is_value_processed ' => null ,
185
+ 'aggregator ' => 'all ' ,
186
+ 'conditions ' =>
187
+ [
188
+ [
189
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product::class,
190
+ 'attribute ' => 'category_ids ' ,
191
+ 'attribute_scope ' => 'parent ' ,
192
+ 'operator ' => '!= ' ,
193
+ 'value ' => '2 ' ,
194
+ 'is_value_processed ' => false ,
195
+ ],
196
+ ],
197
+ ],
198
+ ],
199
+ 'expected ' => false
200
+ ],
201
+ 'If total quantity is 1 for a subselection of items in cart matching ALL of these conditions: ' .
202
+ 'Category (Parent Only) is "Default Category" ' => [
203
+ 'conditions ' => [
204
+ [
205
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product \Subselect::class,
206
+ 'attribute ' => 'qty ' ,
207
+ 'operator ' => '== ' ,
208
+ 'value ' => '1 ' ,
209
+ 'is_value_processed ' => null ,
210
+ 'aggregator ' => 'all ' ,
211
+ 'conditions ' =>
212
+ [
213
+ [
214
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product::class,
215
+ 'attribute ' => 'category_ids ' ,
216
+ 'attribute_scope ' => 'parent ' ,
217
+ 'operator ' => '== ' ,
218
+ 'value ' => '2 ' ,
219
+ 'is_value_processed ' => false ,
220
+ ],
221
+ ],
222
+ ],
223
+ ],
224
+ 'expected ' => true
225
+ ],
226
+ 'If an item is found in the cart with all these conditions true: ' .
227
+ 'Category (Parent Only) is not "Default Category" ' => [
228
+ 'conditions ' => [
229
+ [
230
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product \Found::class,
231
+ 'value ' => '1 ' ,
232
+ 'is_value_processed ' => null ,
233
+ 'aggregator ' => 'all ' ,
234
+ 'conditions ' =>
235
+ [
236
+ [
237
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product::class,
238
+ 'attribute ' => 'category_ids ' ,
239
+ 'attribute_scope ' => 'parent ' ,
240
+ 'operator ' => '!= ' ,
241
+ 'value ' => '2 ' ,
242
+ 'is_value_processed ' => false ,
243
+ ],
244
+ ],
245
+ ],
246
+ ],
247
+ 'expected ' => false
248
+ ],
249
+ 'If an item is found in the cart with all these conditions true: ' .
250
+ 'Category (Parent Only) is "Default Category" ' => [
251
+ 'conditions ' => [
252
+ [
253
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product \Found::class,
254
+ 'value ' => '1 ' ,
255
+ 'is_value_processed ' => null ,
256
+ 'aggregator ' => 'all ' ,
257
+ 'conditions ' =>
258
+ [
259
+ [
260
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product::class,
261
+ 'attribute ' => 'category_ids ' ,
262
+ 'attribute_scope ' => 'parent ' ,
263
+ 'operator ' => '== ' ,
264
+ 'value ' => '2 ' ,
265
+ 'is_value_processed ' => false ,
266
+ ],
267
+ ],
268
+ ],
269
+ ],
270
+ 'expected ' => true
271
+ ],
272
+ 'If an item is not found in the cart with all these conditions true: ' .
273
+ 'Category (Parent Only) is "Default Category" ' => [
274
+ 'conditions ' => [
275
+ [
276
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product \Found::class,
277
+ 'value ' => '0 ' ,
278
+ 'is_value_processed ' => null ,
279
+ 'aggregator ' => 'all ' ,
280
+ 'conditions ' =>
281
+ [
282
+ [
283
+ 'type ' => \Magento \SalesRule \Model \Rule \Condition \Product::class,
284
+ 'attribute ' => 'category_ids ' ,
285
+ 'attribute_scope ' => 'parent ' ,
286
+ 'operator ' => '== ' ,
287
+ 'value ' => '2 ' ,
288
+ 'is_value_processed ' => false ,
289
+ ],
290
+ ],
291
+ ],
292
+ ],
293
+ 'expected ' => false
294
+ ],
295
+ ];
296
+ }
154
297
}
0 commit comments