Skip to content

Commit 1ff95d9

Browse files
add tests for Dashboard::get_next_period - needs failing tests for #302
1 parent 5e19982 commit 1ff95d9

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/class-dashboard.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function show(): void
7979
require __DIR__ . '/views/dashboard-page.php';
8080
}
8181

82-
private function get_next_period(\DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, int $dir = 1): array
82+
public function get_next_period(\DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, int $dir = 1): array
8383
{
8484
$now = new \DateTimeImmutable('now', wp_timezone());
8585
$modifier = $dir > 0 ? "+" : "-";
@@ -104,6 +104,7 @@ private function get_next_period(\DateTimeImmutable $dateStart, \DateTimeImmutab
104104
$compareEnd = $periodEnd;
105105
}
106106

107+
107108
return [ $periodStart, $periodEnd, $compareEnd ];
108109
}
109110

tests/DashboardTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ public function testGetDatesForRangeLastWeekWithWeekStartOnMonday(): void
7676
self::assertEquals([new DateTimeImmutable('2024-12-23'), new DateTimeImmutable('2024-12-29 23:59:59')], $i->get_dates_for_range(new DateTimeImmutable('2025-01-05'), 'last_week', 1));
7777
self::assertEquals([new DateTimeImmutable('2024-12-30'), new DateTimeImmutable('2025-01-05 23:59:59')], $i->get_dates_for_range(new DateTimeImmutable('2025-01-06'), 'last_week', 1));
7878
}
79+
80+
public function testGetNextPeriod(): void
81+
{
82+
$i = new Dashboard();
83+
84+
self::assertEquals($i->get_next_period(new DateTimeImmutable('2025-01-01'), new DateTimeImmutable('2025-01-02'), 1), [new DateTimeImmutable('2025-01-03'), new DateTimeImmutable('2025-01-04'), new DateTimeImmutable('2025-01-04')]);
85+
self::assertEquals($i->get_next_period(new DateTimeImmutable('2025-01-01'), new DateTimeImmutable('2025-01-02'), -1), [new DateTimeImmutable('2024-12-30'), new DateTimeImmutable('2024-12-31'), new DateTimeImmutable('2024-12-31')]);
86+
}
7987
}

tests/mocks.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ function _deprecated_function($function, $version, $replacement)
151151
{
152152
}
153153

154+
function wp_timezone(): DateTimeZone
155+
{
156+
return new DateTimeZone('UTC');
157+
}
158+
154159
class wpdb_mock
155160
{
156161
public $prefix = '';

0 commit comments

Comments
 (0)