Skip to content

Commit a889481

Browse files
committed
Update tests to verify correct date ranges.
1 parent eb7eca5 commit a889481

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/phpunit/integration/Core/Email_Reporting/Initiator_TaskTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,46 @@ public function test_handle_callback_action_without_subscribers_still_schedules_
197197

198198
$this->assertEmpty( $posts, 'No email logs should be created when there are no subscribers.' );
199199
}
200+
201+
/**
202+
* @dataProvider data_build_reference_dates_uses_expected_inclusive_period_length
203+
*/
204+
public function test_build_reference_dates_uses_expected_inclusive_period_length( $frequency, $expected_days ) {
205+
$original_timezone_string = get_option( 'timezone_string' );
206+
$original_gmt_offset = get_option( 'gmt_offset' );
207+
208+
update_option( 'timezone_string', 'UTC' );
209+
update_option( 'gmt_offset', 0 );
210+
211+
try {
212+
$timestamp = strtotime( '2026-03-16 00:00:00 UTC' );
213+
214+
$reference_dates = Initiator_Task::build_reference_dates(
215+
$frequency,
216+
$timestamp
217+
);
218+
219+
$current_start = new \DateTimeImmutable( $reference_dates['startDate'] );
220+
$current_end = new \DateTimeImmutable( $reference_dates['sendDate'] );
221+
$current_days = (int) $current_start->diff( $current_end )->days + 1;
222+
223+
$compare_start = new \DateTimeImmutable( $reference_dates['compareStartDate'] );
224+
$compare_end = new \DateTimeImmutable( $reference_dates['compareEndDate'] );
225+
$compare_days = (int) $compare_start->diff( $compare_end )->days + 1;
226+
227+
$this->assertSame( $expected_days, $current_days, 'Expected current reference range to use inclusive period length.' );
228+
$this->assertSame( $expected_days, $compare_days, 'Expected compare reference range to use inclusive period length.' );
229+
} finally {
230+
update_option( 'timezone_string', $original_timezone_string );
231+
update_option( 'gmt_offset', $original_gmt_offset );
232+
}
233+
}
234+
235+
public function data_build_reference_dates_uses_expected_inclusive_period_length() {
236+
return array(
237+
'weekly' => array( Email_Reporting_Settings::FREQUENCY_WEEKLY, 7 ),
238+
'monthly' => array( Email_Reporting_Settings::FREQUENCY_MONTHLY, 30 ),
239+
'quarterly' => array( Email_Reporting_Settings::FREQUENCY_QUARTERLY, 90 ),
240+
);
241+
}
200242
}

0 commit comments

Comments
 (0)