function SimpleNewsSchedulerDaylightSavingSwitchTest::testDSTMonthly in Simplenews Scheduler 6.2
Same name and namespace in other branches
- 7 tests/simplenews_scheduler.test \SimpleNewsSchedulerDaylightSavingSwitchTest::testDSTMonthly()
Test edition time after DST changes for a monthly newsletter.
@todo: generalize this for other intervals.
File
- tests/
simplenews_scheduler.test, line 530 - Tests for Simplenews Scheduler.
Class
- SimpleNewsSchedulerDaylightSavingSwitchTest
- Test edition time around DST changes.
Code
function testDSTMonthly() {
$timezone_object = date_default_timezone();
// Create a last run time before DST begins, and a now time after.
// Use date_create() rather than strtotime so that we create a date at the
// given time *in the current timezone* rather than UTC.
$last_run_date = new DateTime("01-Mar-12 12:00:00", $timezone_object);
$now_date = new DateTime("05-Apr-12 12:00:00", $timezone_object);
//debug('last run date TZ: ' . $last_run_date->getTimezone()->getName());
//debug('now date TZ: ' . $now_date->getTimezone()->getName());
// Fake up newsletter data.
$newsletter_parent_data = (object) array(
'last_run' => $last_run_date
->getTimestamp(),
'send_interval' => 'month',
'interval_frequency' => 1,
);
// Get the edition time.
$edition_time = simplenews_scheduler_calculate_edition_time($newsletter_parent_data, $now_date
->getTimestamp());
$edition_date = date_create('@' . $edition_time);
// Because we create from a timestamp we have to set the timezone separately.
$edition_date
->setTimezone($timezone_object);
//debug($edition_date->format(DATE_ATOM));
// Format the edition time.
$edition_time_formatted = $this
->format_date_helper($edition_date, 'custom', DATE_ATOM);
$edition_hour_formatted = $this
->format_date_helper($edition_date, 'custom', 'H:i');
$this
->assertEqual($edition_hour_formatted, '12:00', t('Edition time is at 12:00 in the local timezone; full edition time is %time.', array(
'%time' => $edition_time_formatted,
)));
}