@@ -295,10 +295,11 @@ public function testGetDateRangeFirstPart($range, $customStart, $customEnd, $exp
295
295
* @param string $customStart
296
296
* @param string $customEnd
297
297
* @param string $config
298
+ * @param string $configVal
298
299
* @dataProvider secondPartDateRangeDataProvider
299
300
* @return void
300
301
*/
301
- public function testGetDateRangeSecondPart ($ range , $ customStart , $ customEnd , $ config ): void
302
+ public function testGetDateRangeSecondPart ($ range , $ customStart , $ customEnd , $ config, $ configVal ): void
302
303
{
303
304
$ this ->scopeConfigMock
304
305
->expects ($ this ->once ())
@@ -307,10 +308,39 @@ public function testGetDateRangeSecondPart($range, $customStart, $customEnd, $co
307
308
$ config ,
308
309
ScopeInterface::SCOPE_STORE
309
310
)
310
- ->willReturn (1 );
311
+ ->willReturn ($ configVal );
312
+
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
+ }
311
339
312
340
$ result = $ this ->collection ->getDateRange ($ range , $ customStart , $ customEnd );
313
341
$ this ->assertCount (3 , $ result );
342
+ $ resultStartDate = $ result ['from ' ];
343
+ $ this ->assertEquals ($ dateStart ->format ('Y ' ), $ resultStartDate ->format ('Y ' ));
314
344
}
315
345
316
346
/**
@@ -469,9 +499,9 @@ public function firstPartDateRangeDataProvider(): array
469
499
public function secondPartDateRangeDataProvider (): array
470
500
{
471
501
return [
472
- ['1m ' , 1 , 10 , 'reports/dashboard/mtd_start ' ],
473
- ['1y ' , 1 , 10 , 'reports/dashboard/ytd_start ' ],
474
- ['2y ' , 1 , 10 , 'reports/dashboard/ytd_start ' ]
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 ' ]
475
505
];
476
506
}
477
507
0 commit comments