@@ -295,10 +295,11 @@ public function testGetDateRangeFirstPart($range, $customStart, $customEnd, $exp
295295 * @param string $customStart
296296 * @param string $customEnd
297297 * @param string $config
298+ * @param string $configVal
298299 * @dataProvider secondPartDateRangeDataProvider
299300 * @return void
300301 */
301- public function testGetDateRangeSecondPart ($ range , $ customStart , $ customEnd , $ config ): void
302+ public function testGetDateRangeSecondPart ($ range , $ customStart , $ customEnd , $ config, $ configVal ): void
302303 {
303304 $ this ->scopeConfigMock
304305 ->expects ($ this ->once ())
@@ -307,10 +308,39 @@ public function testGetDateRangeSecondPart($range, $customStart, $customEnd, $co
307308 $ config ,
308309 ScopeInterface::SCOPE_STORE
309310 )
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+ }
311339
312340 $ result = $ this ->collection ->getDateRange ($ range , $ customStart , $ customEnd );
313341 $ this ->assertCount (3 , $ result );
342+ $ resultStartDate = $ result ['from ' ];
343+ $ this ->assertEquals ($ dateStart ->format ('Y ' ), $ resultStartDate ->format ('Y ' ));
314344 }
315345
316346 /**
@@ -469,9 +499,9 @@ public function firstPartDateRangeDataProvider(): array
469499 public function secondPartDateRangeDataProvider (): array
470500 {
471501 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 ' ]
475505 ];
476506 }
477507
0 commit comments