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 |
b720ea3e
|
Assos Assos
|
/**
|
54 |
|
|
* Validates timezone handling with a multi-value date field.
|
55 |
|
|
*/
|
56 |
|
|
public function testMultiUserTimezone() {
|
57 |
|
|
// Create date fields with combinations of various types and granularity
|
58 |
|
|
// using the "Date's Timezone" strategy.
|
59 |
|
|
$field_type = 'datetime';
|
60 |
|
|
$tz_handling = 'date';
|
61 |
|
|
$max_granularity = 'minute';
|
62 |
|
|
|
63 |
|
|
// Create date field
|
64 |
|
|
$field_name = "field_test";
|
65 |
|
|
$label = 'Test';
|
66 |
|
|
$options = array(
|
67 |
|
|
'label' => $label,
|
68 |
|
|
'widget_type' => 'date_text',
|
69 |
|
|
'field_name' => $field_name,
|
70 |
|
|
'field_type' => $field_type,
|
71 |
|
|
'input_format' => 'custom',
|
72 |
|
|
'input_format_custom' => 'm/d/Y - H:i:s T',
|
73 |
|
|
'cardinality' => 3,
|
74 |
|
|
'tz_handling' => $tz_handling,
|
75 |
|
|
);
|
76 |
|
|
$this->createMultiDateField($options);
|
77 |
|
|
|
78 |
|
|
// Submit a date field form with multiple values
|
79 |
|
|
$this->dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling);
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
$this->deleteDateField($label);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/**
|
86 |
|
|
* Tests the submission of a date field's widget form when using unlimited
|
87 |
|
|
* cardinality
|
88 |
|
|
*/
|
89 |
|
|
public function dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling) {
|
90 |
|
|
variable_set('date_format_long', 'D, m/d/Y - H:i:s T');
|
91 |
|
|
|
92 |
|
|
$edit = array();
|
93 |
|
|
$should_be = array();
|
94 |
|
|
$edit['title'] = $this->randomName(8);
|
95 |
|
|
$timezones = array('America/Chicago', 'America/Los_Angeles', 'America/New_York');
|
96 |
|
|
|
97 |
|
|
switch ($max_granularity) {
|
98 |
|
|
case 'hour':
|
99 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
|
100 |
|
|
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
|
101 |
|
|
$should_be[0] = 'Thu, 10/07/2010 - 10 CDT';
|
102 |
|
|
|
103 |
|
|
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
|
104 |
|
|
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
|
105 |
|
|
$should_be[1] = 'Thu, 10/07/2010 - 10 PDT';
|
106 |
|
|
|
107 |
|
|
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
|
108 |
|
|
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
|
109 |
|
|
$should_be[2] = 'Thu, 10/07/2010 - 10 EDT';
|
110 |
|
|
|
111 |
|
|
break;
|
112 |
|
|
case 'minute':
|
113 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
|
114 |
|
|
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
|
115 |
|
|
$should_be[0] = 'Thu, 10/07/2010 - 10:30 CDT';
|
116 |
|
|
|
117 |
|
|
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
|
118 |
|
|
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
|
119 |
|
|
$should_be[1] = 'Thu, 10/07/2010 - 10:30 PDT';
|
120 |
|
|
|
121 |
|
|
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
|
122 |
|
|
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
|
123 |
|
|
$should_be[2] = 'Thu, 10/07/2010 - 10:30 EDT';
|
124 |
|
|
|
125 |
|
|
break;
|
126 |
|
|
case 'second':
|
127 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
|
128 |
|
|
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
|
129 |
|
|
$should_be[0] = 'Thu, 10/07/2010 - 10:30:30 CDT';
|
130 |
|
|
|
131 |
|
|
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
|
132 |
|
|
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
|
133 |
|
|
$should_be[1] = 'Thu, 10/07/2010 - 10:30:30 PDT';
|
134 |
|
|
|
135 |
|
|
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
|
136 |
|
|
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
|
137 |
|
|
$should_be[2] = 'Thu, 10/07/2010 - 10:30:30 EDT';
|
138 |
|
|
break;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
$this->drupalPost('node/add/story', $edit, t('Save'));
|
142 |
|
|
$this->assertText($edit['title'], "Node has been created");
|
143 |
|
|
|
144 |
|
|
foreach ($should_be as $assertion) {
|
145 |
|
|
$this->assertText($assertion, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
// Goto the edit page and save the node again.
|
149 |
|
|
$node = $this->drupalGetNodeByTitle($edit['title']);
|
150 |
|
|
$this->drupalGet('node/' . $node->nid . '/edit');
|
151 |
|
|
|
152 |
|
|
// Re-assert the proper date timezones.
|
153 |
|
|
foreach ($timezones as $key => $timezone) {
|
154 |
|
|
$this->assertOptionSelected('edit-field-test-und-' . $key . '-timezone-timezone', $timezone, "Found the correct timezone $timezone for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
|
158 |
85ad3d82
|
Assos Assos
|
/**
|
159 |
|
|
* @todo.
|
160 |
|
|
*/
|
161 |
|
|
public function dateForm($field_name, $field_type, $max_granularity, $tz_handling) {
|
162 |
|
|
variable_set('date_format_long', 'D, m/d/Y - H:i:s');
|
163 |
|
|
$edit = array();
|
164 |
|
|
$edit['title'] = $this->randomName(8);
|
165 |
|
|
$edit[$field_name . '[und][0][show_todate]'] = '1';
|
166 |
|
|
switch ($max_granularity) {
|
167 |
|
|
case 'year':
|
168 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '2010';
|
169 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '2011';
|
170 |
|
|
$should_be = '2010 to 2011';
|
171 |
|
|
break;
|
172 |
|
|
case 'month':
|
173 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '07/2010';
|
174 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '08/2010';
|
175 |
|
|
$should_be = '07/2010 to 08/2010';
|
176 |
|
|
break;
|
177 |
|
|
case 'day':
|
178 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
|
179 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/08/2010';
|
180 |
|
|
$should_be = 'Thu, 10/07/2010 to Fri, 10/08/2010';
|
181 |
|
|
break;
|
182 |
|
|
case 'hour':
|
183 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10';
|
184 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11';
|
185 |
|
|
$should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
|
186 |
|
|
break;
|
187 |
|
|
case 'minute':
|
188 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
|
189 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30';
|
190 |
|
|
$should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
|
191 |
|
|
break;
|
192 |
|
|
case 'second':
|
193 |
|
|
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30:30';
|
194 |
|
|
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30:30';
|
195 |
|
|
$should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
|
196 |
|
|
break;
|
197 |
|
|
}
|
198 |
|
|
$this->drupalPost('node/add/story', $edit, t('Save'));
|
199 |
|
|
$this->assertText($edit['title'], "Node has been created");
|
200 |
|
|
$this->assertText($should_be, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
|
201 |
|
|
}
|
202 |
|
|
} |