1KA_F2F/frontend/drupal/sites/all/modules/date/tests/DateNowUnitTestCase.test

70 lines
1.8 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Test Date Now unit tests.
*/
/**
* Test Date Now unit tests.
*/
class DateNowUnitTestCase extends DrupalUnitTestCase {
/**
2022-02-06 16:58:04 +01:00
* Test Date Now function.
*/
public static function getInfo() {
return array(
'name' => t('Date Now'),
2022-02-06 16:58:04 +01:00
'description' => t('Test Date Now function.'),
'group' => t('Date'),
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
drupal_load('module', 'date_api');
parent::setUp();
}
2022-02-06 16:58:04 +01:00
/**
* Test without passing a timezone.
*/
public function testDateNowNoTimezone() {
$now = date_now();
$this->assertTrue(($now instanceof DateObject), 'Test date_now() returns a DateObject');
}
2022-02-06 16:58:04 +01:00
/**
* Test with a string timezone.
*/
public function testDateNowStringTimezones() {
$la_time = date_now('America/Los_Angeles');
$ny_time = date_now('America/New_York');
$this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
$this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
$this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
}
2022-02-06 16:58:04 +01:00
/**
* Test with object timezones.
*/
public function testDateNowObjectTimezones() {
$la_tz = new DateTimeZone('America/Los_Angeles');
$ny_tz = new DateTimeZone('America/New_York');
$la_time = date_now($la_tz);
$ny_time = date_now($ny_tz);
$this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
$this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
$this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
}
}