Skip to content

Commit 023e4cc

Browse files
committed
ACP2E-866: Incorrect Dashboard YTD values
1 parent 09da6c2 commit 023e4cc

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Order/CollectionTest.php

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,18 @@ public function testGetDateRangeFirstPart($range, $customStart, $customEnd, $exp
296296
* @param string $customEnd
297297
* @param string $config
298298
* @param string $configVal
299+
* @param DateTime $expectedYear
299300
* @dataProvider secondPartDateRangeDataProvider
300301
* @return void
301302
*/
302-
public function testGetDateRangeSecondPart($range, $customStart, $customEnd, $config, $configVal): void
303-
{
303+
public function testGetDateRangeSecondPart(
304+
$range,
305+
$customStart,
306+
$customEnd,
307+
$config,
308+
$configVal,
309+
$expectedYear
310+
): void {
304311
$this->scopeConfigMock
305312
->expects($this->once())
306313
->method('getValue')
@@ -310,37 +317,10 @@ public function testGetDateRangeSecondPart($range, $customStart, $customEnd, $co
310317
)
311318
->willReturn($configVal);
312319

313-
$dateStart = new \DateTime();
314-
$dateStart->setTime(0, 0, 0);
315-
316-
switch ($range) {
317-
case '1m':
318-
$dateStart->setDate(
319-
(int)$dateStart->format('Y'),
320-
(int)$dateStart->format('m'),
321-
(int)$configVal
322-
);
323-
break;
324-
325-
case '1y':
326-
case '2y':
327-
$startMonthDay = explode(
328-
',',
329-
$configVal
330-
);
331-
$startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1;
332-
$startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1;
333-
$dateStart->setDate((int)$dateStart->format('Y'), $startMonth, $startDay);
334-
if ($range == '2y') {
335-
$dateStart->modify('-1 year');
336-
}
337-
break;
338-
}
339-
340320
$result = $this->collection->getDateRange($range, $customStart, $customEnd);
341321
$this->assertCount(3, $result);
342322
$resultStartDate = $result['from'];
343-
$this->assertEquals($dateStart->format('Y'), $resultStartDate->format('Y'));
323+
$this->assertEquals($expectedYear, $resultStartDate->format('Y'));
344324
}
345325

346326
/**
@@ -498,10 +478,14 @@ public function firstPartDateRangeDataProvider(): array
498478
*/
499479
public function secondPartDateRangeDataProvider(): array
500480
{
481+
$dateStart = new \DateTime();
482+
$expectedYear = $dateStart->format('Y');
483+
$expected2YTDYear = $expectedYear - 1;
484+
501485
return [
502-
['1m', 1, 10, 'reports/dashboard/mtd_start', '1'],
503-
['1y', 1, 10, 'reports/dashboard/ytd_start', '1,1'],
504-
['2y', 1, 10, 'reports/dashboard/ytd_start', '1,1']
486+
['1m', 1, 10, 'reports/dashboard/mtd_start', '1', $expectedYear],
487+
['1y', 1, 10, 'reports/dashboard/ytd_start', '1,1', $expectedYear],
488+
['2y', 1, 10, 'reports/dashboard/ytd_start', '1,1', $expected2YTDYear]
505489
];
506490
}
507491

0 commit comments

Comments
 (0)