date_timezone.test 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * @todo.
  52. */
  53. public function dateForm($field_name, $field_type, $max_granularity, $tz_handling) {
  54. variable_set('date_format_long', 'D, m/d/Y - H:i:s');
  55. $edit = array();
  56. $edit['title'] = $this->randomName(8);
  57. $edit[$field_name . '[und][0][show_todate]'] = '1';
  58. switch ($max_granularity) {
  59. case 'year':
  60. $edit[$field_name . '[und][0][value][date]'] = '2010';
  61. $edit[$field_name . '[und][0][value2][date]'] = '2011';
  62. $should_be = '2010 to 2011';
  63. break;
  64. case 'month':
  65. $edit[$field_name . '[und][0][value][date]'] = '07/2010';
  66. $edit[$field_name . '[und][0][value2][date]'] = '08/2010';
  67. $should_be = '07/2010 to 08/2010';
  68. break;
  69. case 'day':
  70. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
  71. $edit[$field_name . '[und][0][value2][date]'] = '10/08/2010';
  72. $should_be = 'Thu, 10/07/2010 to Fri, 10/08/2010';
  73. break;
  74. case 'hour':
  75. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10';
  76. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11';
  77. $should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
  78. break;
  79. case 'minute':
  80. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
  81. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30';
  82. $should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
  83. break;
  84. case 'second':
  85. $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30:30';
  86. $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30:30';
  87. $should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
  88. break;
  89. }
  90. $this->drupalPost('node/add/story', $edit, t('Save'));
  91. $this->assertText($edit['title'], "Node has been created");
  92. $this->assertText($should_be, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
  93. }
  94. }