date_tools.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Date Tools.
  5. */
  6. class DateToolsTestCase extends DrupalWebTestCase {
  7. protected $privileged_user;
  8. /**
  9. * @todo.
  10. */
  11. public static function getInfo() {
  12. return array(
  13. 'name' => 'Date Tools',
  14. 'description' => 'Test Date Wizard and other Date Tools.',
  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', 'administer fields')
  27. );
  28. $this->drupalLogin($this->privileged_user);
  29. variable_set('date_format_long', 'D, m/d/Y - H:i');
  30. }
  31. /**
  32. * Creates a date field using the Date Wizard.
  33. */
  34. public function testTools() {
  35. $form_values = array('label' => 'Test', 'field_type' => 'datetime', 'widget_type' => 'date_select', 'todate' => '');
  36. $this->createDateWizard($form_values);
  37. $this->dateForm($options = 'select');
  38. $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for the Date Wizard datetime field using the date_select widget.');
  39. $this->deleteDateField();
  40. }
  41. /**
  42. * Tests that date field functions properly.
  43. */
  44. function dateForm($options) {
  45. $edit = array();
  46. $edit['title'] = $this->randomName(8);
  47. $edit['body[und][0][value]'] = $this->randomName(16);
  48. if ($options == 'select') {
  49. $edit['field_test[und][0][value][year]'] = '2010';
  50. $edit['field_test[und][0][value][month]'] = '10';
  51. $edit['field_test[und][0][value][day]'] = '7';
  52. $edit['field_test[und][0][value][hour]'] = '10';
  53. $edit['field_test[und][0][value][minute]'] = '30';
  54. }
  55. elseif ($options == 'text') {
  56. $edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
  57. }
  58. elseif ($options == 'popup') {
  59. $edit['field_test[und][0][value][date]'] = '10/07/2010';
  60. $edit['field_test[und][0][value][time]'] = '10:30';
  61. }
  62. $this->drupalPost('node/add/story', $edit, t('Save'));
  63. $this->assertText($edit['body[und][0][value]'], 'Test node has been created');
  64. }
  65. /**
  66. * @todo.
  67. */
  68. function deleteDateField() {
  69. $this->drupalGet('admin/structure/types/manage/story/fields');
  70. $this->clickLink('delete');
  71. $this->drupalPost(NULL, NULL, t('Delete'));
  72. $this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
  73. }
  74. /**
  75. * Creates a date field using the Date Wizard.
  76. */
  77. function createDateWizard($edit) {
  78. $edit += array(
  79. 'bundle' => 'story',
  80. 'name' => 'Story',
  81. 'type_description' => 'A test content type.',
  82. 'field_name' => 'test',
  83. 'label' => 'Test',
  84. 'widget_type' => 'date_select',
  85. 'todate' => 'optional',
  86. 'field_type' => 'date',
  87. 'granularity[]' => array('year', 'month', 'day', 'hour', 'minute'),
  88. 'tz_handling' => 'site',
  89. 'year_range' => '2010:+2',
  90. );
  91. $this->drupalPost('admin/config/date/tools/date_wizard', $edit, t('Save'));
  92. $this->assertText('Your date field Test has been created.', 'Create a date field using the Date Wizard.');
  93. }
  94. }