date.test 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @file
  4. * Test date UI.
  5. */
  6. class DateUITestCase extends DateFieldBasic {
  7. /**
  8. * @todo.
  9. */
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Field UI',
  13. 'description' => 'Test creation of various date fields and widgets using Field UI.',
  14. 'group' => 'Date',
  15. );
  16. }
  17. /**
  18. * @todo.
  19. */
  20. public function setUp() {
  21. parent::setUp();
  22. variable_set('date_format_long', 'D, m/d/Y - H:i');
  23. }
  24. /**
  25. * @todo.
  26. */
  27. public function testFieldUI() {
  28. $label = 'Test';
  29. $current_year = date('Y');
  30. $field_types = array('date', 'datestamp', 'datetime');
  31. $widget_types = array('date_select', 'date_text', 'date_popup');
  32. // Test widgets with default settings using every widget and field type.
  33. foreach ($field_types as $field_type) {
  34. foreach ($widget_types as $widget_type) {
  35. $this->createDateField(
  36. array(
  37. 'label' => $label,
  38. 'field_type' => $field_type,
  39. 'widget_type' => $widget_type,
  40. )
  41. );
  42. $this->dateForm($widget_type);
  43. $this->assertText(format_string('10/07/!year - 10:30', array('!year' => $current_year)), 'Found the correct date for a date field using the ' . $widget_type . ' widget.');
  44. $this->deleteDateField($label);
  45. }
  46. }
  47. // Test timezone handling validation on the field settings form.
  48. $this->createDateField(array('label' => $label, 'field_type' => 'date', 'widget_type' => 'date_select', 'granularity' => array('year', 'month', 'day')));
  49. $edit = array('field[settings][granularity][hour]' => FALSE);
  50. $this->drupalPost('admin/structure/types/manage/story/fields/field_' . strtolower($label), $edit, t('Save settings'));
  51. $this->assertText("Dates without hours granularity must not use any timezone handling.", "Dates without hours granularity required to use timezone handling of 'none.'");
  52. $this->deleteDateField($label);
  53. }
  54. /**
  55. * @todo.
  56. */
  57. function dateForm($options) {
  58. // Tests that date field functions properly.
  59. $edit = array();
  60. $edit['title'] = $this->randomName(8);
  61. $edit['body[und][0][value]'] = $this->randomName(16);
  62. $current_year = date('Y');
  63. if ($options == 'date_select') {
  64. $edit['field_test[und][0][value][year]'] = $current_year;
  65. $edit['field_test[und][0][value][month]'] = '10';
  66. $edit['field_test[und][0][value][day]'] = '7';
  67. $edit['field_test[und][0][value][hour]'] = '10';
  68. $edit['field_test[und][0][value][minute]'] = '30';
  69. }
  70. elseif ($options == 'date_text') {
  71. $edit['field_test[und][0][value][date]'] = format_string('10/07/!year - 10:30', array('!year' => $current_year));
  72. }
  73. elseif ($options == 'date_popup') {
  74. $edit['field_test[und][0][value][date]'] = format_string('10/07/!year', array('!year' => $current_year));
  75. $edit['field_test[und][0][value][time]'] = '10:30';
  76. }
  77. $this->drupalPost('node/add/story', $edit, t('Save'));
  78. $this->assertText($edit['body[und][0][value]'], 'Test node has been created');
  79. }
  80. }