1 date_field.test public DateFieldTestCase::dateForm($field_name, $field_type, $widget_type, $todate = TRUE)

Tests that date field functions properly on the node form.

File

core/modules/date/tests/date_field.test, line 289
Basic functions for Date tests.

Class

DateFieldTestCase

Code

public function dateForm($field_name, $field_type, $widget_type, $todate = TRUE) {
  $edit = array();
  $edit['title'] = $this->randomName(8);
  if ($widget_type == 'date_select') {
    $edit[$field_name . '[und][0][value][year]'] = '2010';
    $edit[$field_name . '[und][0][value][month]'] = '10';
    $edit[$field_name . '[und][0][value][day]'] = '7';
    $edit[$field_name . '[und][0][value][hour]'] = '10';
    $edit[$field_name . '[und][0][value][minute]'] = '30';
    $edit[$field_name . '[und][0][value][ampm]'] = 'am';
    if ($todate) {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value2][year]'] = '2010';
      $edit[$field_name . '[und][0][value2][month]'] = '10';
      $edit[$field_name . '[und][0][value2][day]'] = '7';
      $edit[$field_name . '[und][0][value2][hour]'] = '11';
      $edit[$field_name . '[und][0][value2][minute]'] = '30';
      $edit[$field_name . '[und][0][value2][ampm]'] = 'am';
    }
  }
  elseif ($widget_type == 'date_text') {
    $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30am';
    if ($todate) {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30am';
    }
  }
  elseif ($widget_type == 'date_popup') {
    $edit[$field_name . '[und][0][value][date]'] = '10/07/2010';
    $edit[$field_name . '[und][0][value][time]'] = '10:30am';
    if ($todate) {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value2][date]'] = '10/07/2010';
      $edit[$field_name . '[und][0][value2][time]'] = '11:30am';
    }
  }
  // Test that the date is displayed correctly using both the 'short' and
  // 'long' date types.
  //
  // For the short type, save an explicit format and assert that is the one
  // which is displayed.
  $format = system_date_format_load('short');
  $format['pattern'] = 'l, m/d/Y - H:i:s';
  system_date_format_save($format);
  $instance = field_info_instance('node', $field_name, 'story');
  $instance['display']['default']['settings']['format_type'] = 'short';
  field_update_instance($instance);
  $this->backdropPost('node/add/story', $edit, t('Save'));
  $this->assertText($edit['title'], "Node has been created");
  $should_be = $todate ? 'Thursday, 10/07/2010 - 10:30 to 11:30' : 'Thursday, 10/07/2010 - 10:30';
  $this->assertText($should_be, "Found the correct date for a $field_type field using the $widget_type widget displayed using the short date format.");
  // For the long format, do not save anything, and assert that the displayed
  // date uses the expected default value of this format provided by Backdrop
  // core ('l, F j, Y - H:i').
  $instance = field_info_instance('node', $field_name, 'story');
  $instance['display']['default']['settings']['format_type'] = 'long';
  field_update_instance($instance);
  $this->backdropPost('node/add/story', $edit, t('Save'));
  $this->assertText($edit['title'], "Node has been created");
  $should_be = $todate ? 'Thursday, October 7, 2010 - 10:30am to 11:30am' : 'Thursday, October 7, 2010 - 10:30am';
  $this->assertText($should_be, "Found the correct date for a $field_type field using the $widget_type widget displayed using the long date format.");
}