1 date_validation.test public DateValidationTestCase::dateRangeTests($field_name, $field_type, $widget_type)

Tests for date ranges.

These tests are run using a required field.

File

core/modules/date/tests/date_validation.test, line 164
Date validation tests.

Class

DateValidationTestCase

Code

public function dateRangeTests($field_name, $field_type, $widget_type) {
  // Create a node with wrong end date.
  $edit = array();
  $edit['title'] = $this->randomName(8);
  $edit['body[und][0][value]'] = $this->randomName(16);

  if ($widget_type == 'date_select') {
    $edit[$field_name . '[und][0][show_todate]'] = '1';
    $edit[$field_name . '[und][0][value][year]'] = '2011';
    $edit[$field_name . '[und][0][value][month]'] = '12';
    $edit[$field_name . '[und][0][value][day]'] = '10';
    $edit[$field_name . '[und][0][value][hour]'] = '10';
    $edit[$field_name . '[und][0][value][minute]'] = '00';

    $edit[$field_name . '[und][0][value2][year]'] = '2011';
    $edit[$field_name . '[und][0][value2][month]'] = '12';
    $edit[$field_name . '[und][0][value2][day]'] = '10';
    $edit[$field_name . '[und][0][value2][hour]'] = '9';
    $edit[$field_name . '[und][0][value2][minute]'] = '00';
  }
  elseif ($widget_type == 'date_text') {
    $edit[$field_name . '[und][0][show_todate]'] = '1';
    $edit[$field_name . '[und][0][value][date]'] = '12/10/2011 - 10:00';
    $edit[$field_name . '[und][0][value2][date]'] = '12/10/2011 - 9:00';
  }
  elseif ($widget_type == 'date_popup') {
    $edit[$field_name . '[und][0][show_todate]'] = '1';
    $edit[$field_name . '[und][0][value][date]'] = '12/10/2011';
    $edit[$field_name . '[und][0][value][time]'] = '10:00';

    $edit[$field_name . '[und][0][value2][date]'] = '12/10/2011';
    $edit[$field_name . '[und][0][value2][time]'] = '9:00';
  }
  elseif ($widget_type == 'date_html5') {
    $edit[$field_name . '[und][0][value][date]'] = '2011-12-10';
    $edit[$field_name . '[und][0][value][time]'] = '11:00';

    $edit[$field_name . '[und][0][value2][date]'] = '2011-12-10';
    $edit[$field_name . '[und][0][value2][time]'] = '10:00';
  }
  $this->backdropPost('node/add/story', $edit, t('Save'));
  $should_not_be = $edit['title'] . ' has been created';
  $args = array(
    '@field_type' => $field_type,
    '@widget_type' => $widget_type,
  );
  $this->assertNoText($should_not_be, format_string('Correctly blocked creation of node with end date after start date for a @field_type field using the @widget_type widget.', $args));
  $this->assertText('must be greater', format_string('Marked form with wrong end date as invalid for a @field_type field using the @widget_type widget.', $args));

  // Create a node with missing start date.
  // date_select doesn't allow empty dates when required.
  if ($widget_type != 'date_select') {
    $edit =[];
    $edit['title'] = $this->randomName(8);
    $edit['body[und][0][value]'] = $this->randomName(16);

    if ($widget_type == 'date_select') {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value][year]'] = '';
      $edit[$field_name . '[und][0][value][month]'] = '';
      $edit[$field_name . '[und][0][value[day]'] = '';
      $edit[$field_name . '[und][0][value][hour]'] = '';
      $edit[$field_name . '[und][0][value][minute]'] = '';

      $edit[$field_name . '[und][0][value2][year]'] = '2011';
      $edit[$field_name . '[und][0][value2][month]'] = '12';
      $edit[$field_name . '[und][0][value2][day]'] = '10';
      $edit[$field_name . '[und][0][value2][hour]'] = '9';
      $edit[$field_name . '[und][0][value2][minute]'] = '00';
    }
    elseif ($widget_type == 'date_text') {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value][date]'] = '';
      $edit[$field_name . '[und][0][value2][date]'] = '12/10/2011 9:00';
    }
    elseif ($widget_type == 'date_popup') {
      $edit[$field_name . '[und][0][show_todate]'] = '1';
      $edit[$field_name . '[und][0][value][date]'] = '';
      $edit[$field_name . '[und][0][value][time]'] = '';
      $edit[$field_name . '[und][0][value2][date]'] = '12/10/2011';
      $edit[$field_name . '[und][0][value2][time]'] = '9:00';
    }
    elseif ($widget_type == 'date_html5') {
      $edit[$field_name . '[und][0][value][date]'] = '';
      $edit[$field_name . '[und][0][value][time]'] = '';
      $edit[$field_name . '[und][0][value2][date]'] = '2011-12-10';
      $edit[$field_name . '[und][0][value2][time]'] = '10:00';
    }
    $this->backdropPost('node/add/story', $edit, t('Save'));
    $should_not_be = $edit['title'] . ' has been created';
    $args = array(
      '@field_type' => $field_type,
      '@widget_type' => $widget_type,
    );
    $this->assertNoText($should_not_be, format_string('Correctly blocked creation of node with missing start date for a @field_type field using the @widget_type widget.', $args));
    $this->assertText('A start date is required', format_string('Marked form with start date as invalid for a @field_type field using the @widget_type widget.', $args));
  }
}