[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/date/tests/ -> date.test (source)

   1  <?php
   2  class DateTestCase extends DrupalWebTestCase {
   3    protected $privileged_user;
   4  
   5    function getInfo() {
   6      return array(
   7        'name' => 'CCK UI',
   8        'description' => 'Test creation of various date fields and widgets using CCK UI.',
   9        'group' => 'Date',
  10      );
  11    }
  12  
  13    function setUp() {
  14      // Load the date_api module.
  15      parent::setUp('content', 'date_api', 'date_timezone', 'date', 'date_popup', 'jquery_ui');
  16  
  17      // Create and log in our privileged user.
  18      $this->privileged_user = $this->drupalCreateUser(array(
  19        'administer content types', 'administer nodes'
  20      ));
  21      $this->drupalLogin($this->privileged_user);
  22  
  23      variable_set('date_format_long', 'D, m/d/Y - H:i');
  24      variable_set('date_format_short', 'm/d/Y - H:i');
  25      variable_set('date_popup_timepicker', 'none');
  26    }
  27  
  28    function testDate() {  
  29      // Creates select list date field stored as a date with default settings.
  30      $this->createDateField($type = 'date', $widget = 'date_select');
  31      $edit = array();
  32      $this->drupalPost(NULL, $edit, t('Save field settings'));
  33      $this->dateForm($options = 'select');
  34      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
  35      $this->deleteDateField();
  36      // Creates text date field stored as a date with default settings.
  37      $this->createDateField($type = 'date', $widget = 'date_text');
  38      $edit = array();
  39      $this->drupalPost(NULL, $edit, t('Save field settings'));
  40      $this->dateForm($options = 'text');
  41      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
  42      $this->deleteDateField();
  43      // Creates popup date field stored as a date with default settings.
  44      $this->createDateField($type = 'date', $widget = 'date_popup');
  45      $edit = array();
  46      $this->drupalPost(NULL, $edit, t('Save field settings'));
  47      $this->dateForm($options = 'popup');
  48      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
  49      $this->deleteDateField();
  50      // Creates select list date field stored as a datestamp with default settings.
  51      $this->createDateField($type = 'datestamp', $widget = 'date_select');
  52      $edit = array();
  53      $this->drupalPost(NULL, $edit, t('Save field settings'));
  54      $this->dateForm($options = 'select');
  55      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
  56      $this->deleteDateField();
  57      // Creates text date field stored as a datestamp with default settings.
  58      $this->createDateField($type = 'datestamp', $widget = 'date_text');
  59      $edit = array();
  60      $this->drupalPost(NULL, $edit, t('Save field settings'));
  61      $this->dateForm($options = 'text');
  62      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
  63      $this->deleteDateField();
  64      // Creates popup date field stored as a datestamp with default settings.
  65      $this->createDateField($type = 'datestamp', $widget = 'date_popup');
  66      $edit = array();
  67      $this->drupalPost(NULL, $edit, t('Save field settings'));
  68      $this->dateForm($options = 'popup');
  69      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
  70      $this->deleteDateField();
  71      // Creates select list date field stored as a datetime with default settings.
  72      $this->createDateField($type = 'datetime', $widget = 'date_select');
  73      $edit = array();
  74      $this->drupalPost(NULL, $edit, t('Save field settings'));
  75      $this->dateForm($options = 'select');
  76      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
  77      $this->deleteDateField();
  78      // Creates text date field stored as a datetime with default settings.
  79      $this->createDateField($type = 'datetime', $widget = 'date_text');
  80      $edit = array();
  81      $this->drupalPost(NULL, $edit, t('Save field settings'));
  82      $this->dateForm($options = 'text');
  83      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
  84      $this->deleteDateField();
  85      // Creates popup date field stored as a datetime with default settings.
  86      $this->createDateField($type = 'datetime', $widget = 'date_popup');
  87      $edit = array();
  88      $this->drupalPost(NULL, $edit, t('Save field settings'));
  89      $this->dateForm($options = 'popup');
  90      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
  91      $this->deleteDateField();
  92    }
  93  
  94    function createDateField($type, $widget) {
  95      $edit = array();
  96      $edit['_add_new_field[label]'] = 'Test';
  97      $edit['_add_new_field[field_name]'] = 'test';
  98      $edit['_add_new_field[weight]'] = '-4';
  99      $edit['_add_new_field[type]'] = $type;
 100      $edit['_add_new_field[widget_type]'] = $widget;
 101      $this->drupalPost('admin/content/node-type/story/fields', $edit, t('Save'));
 102  
 103    }
 104  
 105    function dateForm($options) {
 106      // Tests that date field functions properly.
 107      $edit = array();
 108      $edit['title'] = $this->randomName(8);
 109      $edit['body'] = $this->randomName(16);
 110      if ($options == 'select') {
 111        $edit['field_test[0][value][year]'] = '2010';
 112        $edit['field_test[0][value][month]'] = '10';
 113        $edit['field_test[0][value][day]'] = '7';
 114        $edit['field_test[0][value][hour]'] = '10';
 115        $edit['field_test[0][value][minute]'] = '30';
 116      }
 117      elseif ($options == 'text') {
 118        $edit['field_test[0][value][date]'] = '10/07/2010 - 10:30';
 119      }
 120      elseif ($options == 'popup') {
 121        // The default format for a popup is an odd one.
 122        $edit['field_test[0][value][date]'] = '10/07/2010';
 123        $edit['field_test[0][value][time]'] = '10:30';
 124      }
 125      $this->drupalPost('node/add/story', $edit, t('Save'));
 126      $this->assertText($edit['title'], 'Test node has been created');
 127    }
 128  
 129    function deleteDateField() {
 130      $this->drupalGet('admin/content/node-type/story/fields');
 131      $this->clickLink('Remove');
 132      $this->drupalPost(NULL, NULL, t('Remove'));
 133      $this->assertText('Removed field Test from Story.', 'Removed date field.');
 134    }
 135  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7