date.test 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * @file
  4. * Test date UI.
  5. */
  6. class DateUITestCase extends DrupalWebTestCase {
  7. protected $privileged_user;
  8. /**
  9. * @todo.
  10. */
  11. public static function getInfo() {
  12. return array(
  13. 'name' => 'Field UI',
  14. 'description' => 'Test creation of various date fields and widgets using Field UI.',
  15. 'group' => 'Date',
  16. );
  17. }
  18. /**
  19. * @todo.
  20. */
  21. public function setUp() {
  22. // Load the date_api module.
  23. parent::setUp('field', 'field_ui', 'date_api', 'date', 'date_popup', 'date_tools');
  24. // Create and log in our privileged user.
  25. $this->privileged_user = $this->drupalCreateUser(
  26. array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools')
  27. );
  28. $this->drupalLogin($this->privileged_user);
  29. variable_set('date_format_long', 'D, m/d/Y - H:i');
  30. }
  31. /**
  32. * @todo.
  33. */
  34. public function testFieldUI() {
  35. $edit = array();
  36. $edit['name'] = 'Story';
  37. $edit['type'] = 'story';
  38. $this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
  39. $this->assertText('The content type Story has been added.', 'Content type added.');
  40. // Creates select list field stored as a date with default settings.
  41. $this->createDateField($type = 'date', $widget = 'date_select');
  42. $edit = array();
  43. $this->drupalPost(NULL, $edit, t('Save field settings'));
  44. $this->dateForm($options = 'select');
  45. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
  46. $this->deleteDateField();
  47. // Creates text field stored as a date with default settings.
  48. $this->createDateField($type = 'date', $widget = 'date_text');
  49. $edit = array();
  50. $this->drupalPost(NULL, $edit, t('Save field settings'));
  51. $this->dateForm($options = 'text');
  52. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
  53. $this->deleteDateField();
  54. // Creates popup field stored as a date with default settings.
  55. $this->createDateField($type = 'date', $widget = 'date_popup');
  56. $edit = array();
  57. $this->drupalPost(NULL, $edit, t('Save field settings'));
  58. $this->dateForm($options = 'popup');
  59. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
  60. $this->deleteDateField();
  61. // Creates select list field stored as a datestamp with default settings.
  62. $this->createDateField($type = 'datestamp', $widget = 'date_select');
  63. $edit = array();
  64. $this->drupalPost(NULL, $edit, t('Save field settings'));
  65. $this->dateForm($options = 'select');
  66. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
  67. $this->deleteDateField();
  68. // Creates text field stored as a datestamp with default settings.
  69. $this->createDateField($type = 'datestamp', $widget = 'date_text');
  70. $edit = array();
  71. $this->drupalPost(NULL, $edit, t('Save field settings'));
  72. $this->dateForm($options = 'text');
  73. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
  74. $this->deleteDateField();
  75. // Creates popup field stored as a datestamp with default settings.
  76. $this->createDateField($type = 'datestamp', $widget = 'date_popup');
  77. $edit = array();
  78. $this->drupalPost(NULL, $edit, t('Save field settings'));
  79. $this->dateForm($options = 'popup');
  80. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
  81. $this->deleteDateField();
  82. // Creates select list field stored as a datetime with default settings.
  83. $this->createDateField($type = 'datetime', $widget = 'date_select');
  84. $edit = array();
  85. $this->drupalPost(NULL, $edit, t('Save field settings'));
  86. $this->dateForm($options = 'select');
  87. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
  88. $this->deleteDateField();
  89. // Creates text field stored as a datetime with default settings.
  90. $this->createDateField($type = 'datetime', $widget = 'date_text');
  91. $edit = array();
  92. $this->drupalPost(NULL, $edit, t('Save field settings'));
  93. $this->dateForm($options = 'text');
  94. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
  95. $this->deleteDateField();
  96. // Creates popup field stored as a datetime with default settings.
  97. $this->createDateField($type = 'datetime', $widget = 'date_popup');
  98. $edit = array();
  99. $this->drupalPost(NULL, $edit, t('Save field settings'));
  100. $this->dateForm($options = 'popup');
  101. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
  102. $this->deleteDateField();
  103. // Test timezone handling validation on the field settings form.
  104. $this->createDateField($type = 'date', $widget = 'date_select');
  105. $edit = array('field[settings][granularity][hour]' => FALSE);
  106. $this->drupalPost(NULL, $edit, t('Save field settings'));
  107. $this->assertText("Dates without hours granularity must not use any timezone handling.", "Dates without hours granularity required to use timezone handling of 'none.'");
  108. $this->deleteDateField();
  109. }
  110. /**
  111. * @todo.
  112. */
  113. function dateForm($options) {
  114. // Tests that date field functions properly.
  115. $edit = array();
  116. $edit['title'] = $this->randomName(8);
  117. $edit['body[und][0][value]'] = $this->randomName(16);
  118. if ($options == 'select') {
  119. $edit['field_test[und][0][value][year]'] = '2010';
  120. $edit['field_test[und][0][value][month]'] = '10';
  121. $edit['field_test[und][0][value][day]'] = '7';
  122. $edit['field_test[und][0][value][hour]'] = '10';
  123. $edit['field_test[und][0][value][minute]'] = '30';
  124. }
  125. elseif ($options == 'text') {
  126. $edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
  127. }
  128. elseif ($options == 'popup') {
  129. $edit['field_test[und][0][value][date]'] = '10/07/2010';
  130. $edit['field_test[und][0][value][time]'] = '10:30';
  131. }
  132. $this->drupalPost('node/add/story', $edit, t('Save'));
  133. $this->assertText($edit['body[und][0][value]'], 'Test node has been created');
  134. }
  135. /**
  136. * @todo.
  137. */
  138. function createDateField($type, $widget) {
  139. $edit = array();
  140. $edit['fields[_add_new_field][label]'] = 'Test';
  141. $edit['fields[_add_new_field][field_name]'] = 'test';
  142. $edit['fields[_add_new_field][weight]'] = '-4';
  143. $edit['fields[_add_new_field][type]'] = $type;
  144. $edit['fields[_add_new_field][widget_type]'] = $widget;
  145. $this->drupalPost('admin/structure/types/manage/story/fields', $edit, t('Save'));
  146. }
  147. /**
  148. * @todo.
  149. */
  150. function deleteDateField() {
  151. $this->drupalGet('admin/structure/types/manage/story/fields');
  152. $this->clickLink('delete');
  153. $this->drupalPost(NULL, NULL, t('Delete'));
  154. $this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
  155. }
  156. }