[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

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    }
  26  
  27    function testDate() {  
  28      // Creates select list date field stored as a date with default settings.
  29      $this->createDateField($type = 'date', $widget = 'date_select');
  30      $edit = array();
  31      $this->drupalPost(NULL, $edit, t('Save field settings'));
  32      $this->dateForm($options = 'select');
  33      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
  34      $this->deleteDateField();
  35      // Creates text date field stored as a date with default settings.
  36      $this->createDateField($type = 'date', $widget = 'date_text');
  37      $edit = array();
  38      $this->drupalPost(NULL, $edit, t('Save field settings'));
  39      $this->dateForm($options = 'text');
  40      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
  41      $this->deleteDateField();
  42      // Creates popup date field stored as a date with default settings.
  43      $this->createDateField($type = 'date', $widget = 'date_popup');
  44      $edit = array();
  45      $this->drupalPost(NULL, $edit, t('Save field settings'));
  46      $this->dateForm($options = 'popup');
  47      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
  48      $this->deleteDateField();
  49      // Creates select list date field stored as a datestamp with default settings.
  50      $this->createDateField($type = 'datestamp', $widget = 'date_select');
  51      $edit = array();
  52      $this->drupalPost(NULL, $edit, t('Save field settings'));
  53      $this->dateForm($options = 'select');
  54      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
  55      $this->deleteDateField();
  56      // Creates text date field stored as a datestamp with default settings.
  57      $this->createDateField($type = 'datestamp', $widget = 'date_text');
  58      $edit = array();
  59      $this->drupalPost(NULL, $edit, t('Save field settings'));
  60      $this->dateForm($options = 'text');
  61      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
  62      $this->deleteDateField();
  63      // Creates popup date field stored as a datestamp with default settings.
  64      $this->createDateField($type = 'datestamp', $widget = 'date_popup');
  65      $edit = array();
  66      $this->drupalPost(NULL, $edit, t('Save field settings'));
  67      $this->dateForm($options = 'popup');
  68      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
  69      $this->deleteDateField();
  70      // Creates select list date field stored as a datetime with default settings.
  71      $this->createDateField($type = 'datetime', $widget = 'date_select');
  72      $edit = array();
  73      $this->drupalPost(NULL, $edit, t('Save field settings'));
  74      $this->dateForm($options = 'select');
  75      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
  76      $this->deleteDateField();
  77      // Creates text date field stored as a datetime with default settings.
  78      $this->createDateField($type = 'datetime', $widget = 'date_text');
  79      $edit = array();
  80      $this->drupalPost(NULL, $edit, t('Save field settings'));
  81      $this->dateForm($options = 'text');
  82      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
  83      $this->deleteDateField();
  84      // Creates popup date field stored as a datetime with default settings.
  85      $this->createDateField($type = 'datetime', $widget = 'date_popup');
  86      $edit = array();
  87      $this->drupalPost(NULL, $edit, t('Save field settings'));
  88      $this->dateForm($options = 'popup');
  89      $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
  90      $this->deleteDateField();
  91    }
  92  
  93    function createDateField($type, $widget) {
  94      $edit = array();
  95      $edit['_add_new_field[label]'] = 'Test';
  96      $edit['_add_new_field[field_name]'] = 'test';
  97      $edit['_add_new_field[weight]'] = '-4';
  98      $edit['_add_new_field[type]'] = $type;
  99      $edit['_add_new_field[widget_type]'] = $widget;
 100      $this->drupalPost('admin/content/node-type/story/fields', $edit, t('Save'));
 101      
 102    }
 103  
 104    function dateForm($options) {
 105      // Tests that date field functions properly.
 106      $edit = array();
 107      $edit['title'] = $this->randomName(8);
 108      $edit['body'] = $this->randomName(16);
 109      if ($options == 'select') {
 110        $edit['field_test[0][value][year]'] = '2010';
 111        $edit['field_test[0][value][month]'] = '10';
 112        $edit['field_test[0][value][day]'] = '7';
 113        $edit['field_test[0][value][hour]'] = '10';
 114        $edit['field_test[0][value][minute]'] = '30';
 115      }
 116      elseif ($options == 'text') {
 117        $edit['field_test[0][value][date]'] = '10/07/2010 - 10:30';
 118      }
 119      elseif ($options == 'popup') {
 120        // The default format for a popup is an odd one.
 121        $edit['field_test[0][value][date]'] = '10/07/2010';
 122        $edit['field_test[0][value][time]'] = '10:30';
 123      }
 124      $this->drupalPost('node/add/story', $edit, t('Save'));
 125      $this->assertText($edit['title'], 'Test node has been created');
 126    }
 127  
 128    function deleteDateField() {
 129      $this->drupalGet('admin/content/node-type/story/fields');
 130      $this->clickLink('Remove');
 131      $this->drupalPost(NULL, NULL, t('Remove'));
 132      $this->assertText('Removed field Test from Story.', 'Removed date field.');
 133    }
 134  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7