Skip to content

Commit eeb8b4f

Browse files
author
Oleksandr Iegorov
committed
ACP2E-673: Sporadic catalog price rule issue with Indexing
1 parent 55320ea commit eeb8b4f

File tree

1 file changed

+214
-65
lines changed

1 file changed

+214
-65
lines changed

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/ReindexRuleProductTest.php

Lines changed: 214 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ class ReindexRuleProductTest extends TestCase
5252
*/
5353
private $ruleMock;
5454

55+
/**
56+
* @var string
57+
*/
58+
private $adminTimeZone;
59+
60+
/**
61+
* @var string
62+
*/
63+
private $websiteTz;
64+
65+
5566
/**
5667
* @inheritDoc
5768
*/
@@ -71,6 +82,9 @@ protected function setUp(): void
7182
$this->localeDateMock,
7283
true
7384
);
85+
86+
$this->adminTimeZone = 'America/Chicago';
87+
$this->websiteTz = 'America/Los_Angeles';
7488
}
7589

7690
/**
@@ -106,8 +120,6 @@ public function testExecuteIfRuleWithoutWebsiteIds(): void
106120
public function testExecute(): void
107121
{
108122
$websiteId = 3;
109-
$adminTimeZone = 'America/Chicago';
110-
$websiteTz = 'America/Los_Angeles';
111123
$productIds = [
112124
4 => [$websiteId => 1],
113125
5 => [$websiteId => 1],
@@ -119,8 +131,8 @@ public function testExecute(): void
119131

120132
$this->localeDateMock->method('getConfigTimezone')
121133
->willReturnMap([
122-
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $adminTimeZone],
123-
[ScopeInterface::SCOPE_WEBSITE, $websiteId, $websiteTz]
134+
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $this->adminTimeZone],
135+
[ScopeInterface::SCOPE_WEBSITE, $websiteId, $this->websiteTz]
124136
]);
125137

126138
$batchRows = [
@@ -176,19 +188,14 @@ public function testExecute(): void
176188
}
177189

178190
/**
191+
* @param array $websitesIds
192+
* @param array $productIds
193+
* @param array $batchRows
179194
* @return void
195+
* @dataProvider executeDataProvider
180196
*/
181-
public function testExecuteWithExcludedWebsites(): void
197+
public function testExecuteWithExcludedWebsites(array $websitesIds, array $productIds, array $batchRows): void
182198
{
183-
$websitesIds = [1, 2, 3];
184-
$adminTimeZone = 'America/Chicago';
185-
$websiteTz = 'America/Los_Angeles';
186-
$productIds = [
187-
1 => [1 => 1],
188-
2 => [2 => 1],
189-
3 => [3 => 1]
190-
];
191-
192199
$this->prepareResourceMock();
193200
$this->prepareRuleMock($websitesIds, $productIds, [10, 20]);
194201

@@ -203,68 +210,210 @@ public function testExecuteWithExcludedWebsites(): void
203210

204211
$this->localeDateMock->method('getConfigTimezone')
205212
->willReturnMap([
206-
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $adminTimeZone],
207-
[ScopeInterface::SCOPE_WEBSITE, 1, $websiteTz],
208-
[ScopeInterface::SCOPE_WEBSITE, 2, $websiteTz],
209-
[ScopeInterface::SCOPE_WEBSITE, 3, $websiteTz]
213+
[ScopeInterface::SCOPE_WEBSITE, self::ADMIN_WEBSITE_ID, $this->adminTimeZone],
214+
[ScopeInterface::SCOPE_WEBSITE, 1, $this->websiteTz],
215+
[ScopeInterface::SCOPE_WEBSITE, 2, $this->websiteTz],
216+
[ScopeInterface::SCOPE_WEBSITE, 3, $this->websiteTz]
210217
]);
211218

212-
$batchRows = [
219+
$this->connectionMock
220+
->method('insertMultiple')
221+
->with('catalogrule_product_replica', $batchRows);
222+
223+
self::assertTrue($this->model->execute($this->ruleMock, 100, true));
224+
}
225+
226+
/**
227+
* @return array
228+
*/
229+
public function executeDataProvider(): array
230+
{
231+
return [
213232
[
214-
'rule_id' => 100,
215-
'from_time' => 1498028400,
216-
'to_time' => 1498892399,
217-
'website_id' => 1,
218-
'customer_group_id' => 20,
219-
'product_id' => 1,
220-
'action_operator' => 'simple_action',
221-
'action_amount' => 43,
222-
'action_stop' => true,
223-
'sort_order' => 1
233+
[1, 2, 3],
234+
[
235+
1 => [1 => 1],
236+
2 => [2 => 1],
237+
3 => [3 => 1]
238+
],
239+
[
240+
[
241+
'rule_id' => 100,
242+
'from_time' => 1498028400,
243+
'to_time' => 1498892399,
244+
'website_id' => 1,
245+
'customer_group_id' => 20,
246+
'product_id' => 1,
247+
'action_operator' => 'simple_action',
248+
'action_amount' => 43,
249+
'action_stop' => true,
250+
'sort_order' => 1
251+
],
252+
[
253+
'rule_id' => 100,
254+
'from_time' => 1498028400,
255+
'to_time' => 1498892399,
256+
'website_id' => 2,
257+
'customer_group_id' => 20,
258+
'product_id' => 2,
259+
'action_operator' => 'simple_action',
260+
'action_amount' => 43,
261+
'action_stop' => true,
262+
'sort_order' => 1
263+
],
264+
[
265+
'rule_id' => 100,
266+
'from_time' => 1498028400,
267+
'to_time' => 1498892399,
268+
'website_id' => 3,
269+
'customer_group_id' => 10,
270+
'product_id' => 3,
271+
'action_operator' => 'simple_action',
272+
'action_amount' => 43,
273+
'action_stop' => true,
274+
'sort_order' => 1
275+
],
276+
[
277+
'rule_id' => 100,
278+
'from_time' => 1498028400,
279+
'to_time' => 1498892399,
280+
'website_id' => 3,
281+
'customer_group_id' => 20,
282+
'product_id' => 3,
283+
'action_operator' => 'simple_action',
284+
'action_amount' => 43,
285+
'action_stop' => true,
286+
'sort_order' => 1
287+
]
288+
]
224289
],
225290
[
226-
'rule_id' => 100,
227-
'from_time' => 1498028400,
228-
'to_time' => 1498892399,
229-
'website_id' => 2,
230-
'customer_group_id' => 20,
231-
'product_id' => 2,
232-
'action_operator' => 'simple_action',
233-
'action_amount' => 43,
234-
'action_stop' => true,
235-
'sort_order' => 1
291+
[1, 2, 3],
292+
[
293+
1 => [1 => true],
294+
2 => [2 => 'true'],
295+
3 => [3 => 0]
296+
],
297+
[
298+
[
299+
'rule_id' => 100,
300+
'from_time' => 1498028400,
301+
'to_time' => 1498892399,
302+
'website_id' => 1,
303+
'customer_group_id' => 20,
304+
'product_id' => 1,
305+
'action_operator' => 'simple_action',
306+
'action_amount' => 43,
307+
'action_stop' => true,
308+
'sort_order' => 1
309+
],
310+
[
311+
'rule_id' => 100,
312+
'from_time' => 1498028400,
313+
'to_time' => 1498892399,
314+
'website_id' => 2,
315+
'customer_group_id' => 20,
316+
'product_id' => 2,
317+
'action_operator' => 'simple_action',
318+
'action_amount' => 43,
319+
'action_stop' => true,
320+
'sort_order' => 1
321+
],
322+
[
323+
'rule_id' => 100,
324+
'from_time' => 1498028400,
325+
'to_time' => 1498892399,
326+
'website_id' => 3,
327+
'customer_group_id' => 10,
328+
'product_id' => 3,
329+
'action_operator' => 'simple_action',
330+
'action_amount' => 43,
331+
'action_stop' => true,
332+
'sort_order' => 1
333+
],
334+
[
335+
'rule_id' => 100,
336+
'from_time' => 1498028400,
337+
'to_time' => 1498892399,
338+
'website_id' => 3,
339+
'customer_group_id' => 20,
340+
'product_id' => 3,
341+
'action_operator' => 'simple_action',
342+
'action_amount' => 43,
343+
'action_stop' => true,
344+
'sort_order' => 1
345+
]
346+
]
236347
],
237348
[
238-
'rule_id' => 100,
239-
'from_time' => 1498028400,
240-
'to_time' => 1498892399,
241-
'website_id' => 3,
242-
'customer_group_id' => 10,
243-
'product_id' => 3,
244-
'action_operator' => 'simple_action',
245-
'action_amount' => 43,
246-
'action_stop' => true,
247-
'sort_order' => 1
349+
[1, 2, 3],
350+
[
351+
1 => [1 => true],
352+
2 => [2 => true],
353+
3 => [3 => null]
354+
],
355+
[
356+
[
357+
'rule_id' => 100,
358+
'from_time' => 1498028400,
359+
'to_time' => 1498892399,
360+
'website_id' => 1,
361+
'customer_group_id' => 20,
362+
'product_id' => 1,
363+
'action_operator' => 'simple_action',
364+
'action_amount' => 43,
365+
'action_stop' => true,
366+
'sort_order' => 1
367+
],
368+
[
369+
'rule_id' => 100,
370+
'from_time' => 1498028400,
371+
'to_time' => 1498892399,
372+
'website_id' => 2,
373+
'customer_group_id' => 20,
374+
'product_id' => 2,
375+
'action_operator' => 'simple_action',
376+
'action_amount' => 43,
377+
'action_stop' => true,
378+
'sort_order' => 1
379+
]
380+
]
248381
],
249382
[
250-
'rule_id' => 100,
251-
'from_time' => 1498028400,
252-
'to_time' => 1498892399,
253-
'website_id' => 3,
254-
'customer_group_id' => 20,
255-
'product_id' => 3,
256-
'action_operator' => 'simple_action',
257-
'action_amount' => 43,
258-
'action_stop' => true,
259-
'sort_order' => 1
383+
[1, 2, 3],
384+
[
385+
1 => [1 => true],
386+
2 => [2 => true],
387+
3 => []
388+
],
389+
[
390+
[
391+
'rule_id' => 100,
392+
'from_time' => 1498028400,
393+
'to_time' => 1498892399,
394+
'website_id' => 1,
395+
'customer_group_id' => 20,
396+
'product_id' => 1,
397+
'action_operator' => 'simple_action',
398+
'action_amount' => 43,
399+
'action_stop' => true,
400+
'sort_order' => 1
401+
],
402+
[
403+
'rule_id' => 100,
404+
'from_time' => 1498028400,
405+
'to_time' => 1498892399,
406+
'website_id' => 2,
407+
'customer_group_id' => 20,
408+
'product_id' => 2,
409+
'action_operator' => 'simple_action',
410+
'action_amount' => 43,
411+
'action_stop' => true,
412+
'sort_order' => 1
413+
]
414+
]
260415
]
261416
];
262-
263-
$this->connectionMock
264-
->method('insertMultiple')
265-
->with('catalogrule_product_replica', $batchRows);
266-
267-
self::assertTrue($this->model->execute($this->ruleMock, 100, true));
268417
}
269418

270419
/**

0 commit comments

Comments
 (0)