date_timezone.test 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * @file
  4. * Timezone tests.
  5. */
  6. class DateTimezoneTestCase extends DateFieldBasic {
  7. /**
  8. * @todo.
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Timezone & Granularity',
  13. 'description' => 'Test combinations of date field timezone handling and granularity.',
  14. 'group' => 'Date',
  15. );
  16. }
  17. /**
  18. * @todo.
  19. */
  20. public function testTimezone() {
  21. // Create a date fields with combinations of various timezone handling and
  22. // granularity.
  23. foreach (array('date', 'datestamp', 'datetime') as $field_type) {
  24. foreach (array('site', 'none', 'date', 'user', 'utc') as $tz_handling) {
  25. foreach (array('year', 'month', 'day', 'hour', 'minute', 'second') as $max_granularity) {
  26. // Skip invalid combinations.
  27. if (in_array($max_granularity, array('year', 'month', 'day')) && $tz_handling != 'none') {
  28. continue;
  29. }
  30. $field_name = "field_test";
  31. $label = 'Test';
  32. $granularity = date_granularity_array_from_precision($max_granularity);
  33. $options = array(
  34. 'label' => $label,
  35. 'widget_type' => 'date_text',
  36. 'field_name' => $field_name,
  37. 'field_type' => $field_type,
  38. 'input_format' => 'custom',
  39. 'input_format_custom' => 'm/d/Y - H:i:s',
  40. 'tz_handling' => $tz_handling,
  41. 'granularity' => $granularity,
  42. );
  43. $this->createDateField($options);
  44. $this->dateForm($field_name, $field_type, $max_granularity, $tz_handling);
  45. $this->deleteDateField($label);
  46. }
  47. }
  48. }
  49. }
  50. /**
  51. * Validates timezone handling with a multi-value date field.
  52. */
  53. public function testMultiUserTimezone() {
  54. // Create date fields with combinations of various types and granularity
  55. // using the "Date's Timezone" strategy.
  56. $field_type = 'datetime';
  57. $tz_handling = 'date';
  58. $max_granularity = 'minute';
  59. // Create date field
  60. $field_name = "field_test";
  61. $label = 'Test';
  62. $options = array(
  63. 'label' => $label,
  64. 'widget_type' => 'date_text',
  65. 'field_name' => $field_name,
  66. 'field_type' => $field_type,
  67. 'input_format' => 'custom',
  68. 'input_format_custom' => 'm/d/Y - H:i:s T',
  69. 'cardinality' => 3,
  70. 'tz_handling' => $tz_handling,
  71. );
  72. $this->createMultiDateField($options);
  73. // Submit a date field form with multiple values
  74. $this->dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling);
  75. $this->deleteDateField($label);
  76. }
  77. /**
  78. * Tests the submission of a date field's widget form when using unlimited
  79. * cardinality
  80. */
  81. public function dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling) {
  82. variable_set('date_format_long', 'D, m/d/Y - H:i:s T');
  83. $edit = array();
  84. $should_be = array();
  85. $edit['title'] = $this->randomName(8);
  86. $timezones = array('America/Chicago', 'America/Los_Angeles', 'America/New_York');
  87. switch ($max_granularity) {
  88. case 'hour':
  89. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
  90. $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
  91. $should_be[0] = 'Thu, 10/07/2010 - 10 CDT';
  92. $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
  93. $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
  94. $should_be[1] = 'Thu, 10/07/2010 - 10 PDT';
  95. $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
  96. $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
  97. $should_be[2] = 'Thu, 10/07/2010 - 10 EDT';
  98. break;
  99. case 'minute':
  100. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
  101. $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
  102. $should_be[0] = 'Thu, 10/07/2010 - 10:30 CDT';
  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:30 PDT';
  106. $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
  107. $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
  108. $should_be[2] = 'Thu, 10/07/2010 - 10:30 EDT';
  109. break;
  110. case 'second':
  111. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
  112. $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
  113. $should_be[0] = 'Thu, 10/07/2010 - 10:30:30 CDT';
  114. $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
  115. $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
  116. $should_be[1] = 'Thu, 10/07/2010 - 10:30:30 PDT';
  117. $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
  118. $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
  119. $should_be[2] = 'Thu, 10/07/2010 - 10:30:30 EDT';
  120. break;
  121. }
  122. $this->drupalPost('node/add/story', $edit, t('Save'));
  123. $this->assertText($edit['title'], "Node has been created");
  124. foreach ($should_be as $assertion) {
  125. $this->assertText($assertion, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
  126. }
  127. // Goto the edit page and save the node again.
  128. $node = $this->drupalGetNodeByTitle($edit['title']);
  129. $this->drupalGet('node/' . $node->nid . '/edit');
  130. // Re-assert the proper date timezones.
  131. foreach ($timezones as $key => $timezone) {
  132. $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.");
  133. }
  134. }
  135. /**
  136. * @todo.
  137. */
  138. public function dateForm($field_name, $field_type, $max_granularity, $tz_handling) {
  139. variable_set('date_format_long', 'D, m/d/Y - H:i:s');
  140. $edit = array();
  141. $edit['title'] = $this->randomName(8);
  142. $edit[$field_name . '[und][0][show_todate]'] = '1';
  143. switch ($max_granularity) {
  144. case 'year':
  145. $edit[$field_name . '[und][0][value][date]'] = '2010';
  146. $edit[$field_name . '[und][0][value2][date]'] = '2011';
  147. $should_be = '2010 to 2011';
  148. break;
  149. case 'month':
  150. $edit[$field_name . '[und][0][value][date]'] = '07/2010';
  151. $edit[$field_name . '[und][0][value2][date]'] = '08/2010';
  152. $should_be = '07/2010 to 08/2010';
  153. break;
  154. case 'day':
  155. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
  156. $edit[$field_name . '[und][0][value2][date]'] = '10/08/2010';
  157. $should_be = 'Thu, 10/07/2010 to Fri, 10/08/2010';
  158. break;
  159. case 'hour':
  160. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10';
  161. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11';
  162. $should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
  163. break;
  164. case 'minute':
  165. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
  166. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30';
  167. $should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
  168. break;
  169. case 'second':
  170. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30:30';
  171. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30:30';
  172. $should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
  173. break;
  174. }
  175. $this->drupalPost('node/add/story', $edit, t('Save'));
  176. $this->assertText($edit['title'], "Node has been created");
  177. $this->assertText($should_be, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
  178. }
  179. }