1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Timezone tests.
|
5 |
|
|
*/
|
6 |
|
|
class DateTimezoneTestCase extends DateFieldBasic {
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* @todo.
|
10 |
|
|
*/
|
11 |
|
|
public static function getInfo() {
|
12 |
|
|
return array(
|
13 |
|
|
'name' => 'Timezone & Granularity',
|
14 |
|
|
'description' => 'Test combinations of date field timezone handling and granularity.',
|
15 |
|
|
'group' => 'Date',
|
16 |
|
|
);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* @todo.
|
21 |
|
|
*/
|
22 |
|
|
public function testTimezone() {
|
23 |
|
|
// Create a date fields with combinations of various timezone handling and
|
24 |
|
|
// granularity.
|
25 |
|
|
foreach (array('date', 'datestamp', 'datetime') as $field_type) {
|
26 |
|
|
foreach (array('site', 'none', 'date', 'user', 'utc') as $tz_handling) {
|
27 |
|
|
foreach (array('year', 'month', 'day', 'hour', 'minute', 'second') as $max_granularity) {
|
28 |
|
|
// Skip invalid combinations.
|
29 |
|
|
if (in_array($max_granularity, array('year', 'month', 'day')) && $tz_handling != 'none') {
|
30 |
|
|
continue;
|
31 |
|
|
}
|
32 |
|
|
$field_name = "field_test";
|
33 |
|
|
$label = 'Test';
|
34 |
|
|
$granularity = date_granularity_array_from_precision($max_granularity);
|
35 |
|
|
$options = array(
|
36 |
|
|
'label' => $label,
|
37 |
|
|
'widget_type' => 'date_text',
|
38 |
|
|
'field_name' => $field_name,
|
39 |
|
|
'field_type' => $field_type,
|
40 |
|
|
'input_format' => 'custom',
|
41 |
|
|
'input_format_custom' => 'm/d/Y - H:i:s',
|
42 |
|
|
'tz_handling' => $tz_handling,
|
43 |
|
|
'granularity' => $granularity,
|
44 |
|
|
);
|
45 |
|
|
$this->createDateField($options);
|
46 |
|
|
$this->dateForm($field_name, $field_type, $max_granularity, $tz_handling);
|
47 |
|
|
$this->deleteDateField($label);
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* @todo.
|
55 |
|
|
*/
|
56 |
|
|
public function dateForm($field_name, $field_type, $max_granularity, $tz_handling) {
|
57 |
|
|
variable_set('date_format_long', 'D, m/d/Y - H:i:s');
|
58 |
|
|
$edit = array();
|
59 |
|
|
$edit['title'] = $this->randomName(8);
|
60 |
|
|
$edit[$field_name . '[und][0][show_todate]'] = '1';
|
61 |
|
|
switch ($max_granularity) {
|
62 |
|
|
case 'year':
|
63 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '2010';
|
64 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '2011';
|
65 |
|
|
$should_be = '2010 to 2011';
|
66 |
|
|
break;
|
67 |
|
|
case 'month':
|
68 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '07/2010';
|
69 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '08/2010';
|
70 |
|
|
$should_be = '07/2010 to 08/2010';
|
71 |
|
|
break;
|
72 |
|
|
case 'day':
|
73 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
|
74 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/08/2010';
|
75 |
|
|
$should_be = 'Thu, 10/07/2010 to Fri, 10/08/2010';
|
76 |
|
|
break;
|
77 |
|
|
case 'hour':
|
78 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10';
|
79 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11';
|
80 |
|
|
$should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
|
81 |
|
|
break;
|
82 |
|
|
case 'minute':
|
83 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
|
84 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30';
|
85 |
|
|
$should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
|
86 |
|
|
break;
|
87 |
|
|
case 'second':
|
88 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30:30';
|
89 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30:30';
|
90 |
|
|
$should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
|
91 |
|
|
break;
|
92 |
|
|
}
|
93 |
|
|
$this->drupalPost('node/add/story', $edit, t('Save'));
|
94 |
|
|
$this->assertText($edit['title'], "Node has been created");
|
95 |
|
|
$this->assertText($should_be, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
|
96 |
|
|
}
|
97 |
|
|
} |