1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test Date Now unit tests.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test Date Now unit tests.
|
10
|
*/
|
11
|
class DateNowUnitTestCase extends DrupalUnitTestCase {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => t('Date Now'),
|
19
|
'description' => t('Test Date Now function.') ,
|
20
|
'group' => t('Date'),
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* {@inheritdoc}
|
26
|
*/
|
27
|
public function setUp() {
|
28
|
drupal_load('module', 'date_api');
|
29
|
parent::setUp();
|
30
|
}
|
31
|
|
32
|
public function testDateNowNoTimezone() {
|
33
|
// Test without passing a timezone.
|
34
|
$now = date_now();
|
35
|
|
36
|
$this->assertTrue(($now instanceof DateObject), 'Test date_now() returns a DateObject');
|
37
|
}
|
38
|
|
39
|
public function testDateNowStringTimezones() {
|
40
|
// Test with a string timezone.
|
41
|
$la_time = date_now('America/Los_Angeles');
|
42
|
$ny_time = date_now('America/New_York');
|
43
|
|
44
|
$this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
|
45
|
$this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
|
46
|
|
47
|
$this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
|
48
|
}
|
49
|
|
50
|
public function testDateNowObjectTimezones() {
|
51
|
// Test with object timezones.
|
52
|
$la_tz = new DateTimeZone('America/Los_Angeles');
|
53
|
$ny_tz = new DateTimeZone('America/New_York');
|
54
|
|
55
|
$la_time = date_now($la_tz);
|
56
|
$ny_time = date_now($ny_tz);
|
57
|
|
58
|
$this->assertTrue(($la_time instanceof DateObject), 'Test America/Los_Angeles returns a DateObject');
|
59
|
$this->assertTrue(($ny_time instanceof DateObject), 'Test America/New_York returns a DateObject');
|
60
|
|
61
|
$this->assertEqual($la_time->getTimestamp(), $ny_time->getTimestamp(), 'Test different timezones have same Unix timestamp');
|
62
|
}
|
63
|
|
64
|
}
|