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

Confirms that fields missing the time granularity are accepted.

File

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

Class

DateValidationTestCase

Code

public function checkGranularity($field_name, $field_type, $widget_type) {
  // Create a node with incorrect granularity -- missing time.
  $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][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]'] = '';
    $edit[$field_name . '[und][0][value][minute]'] = '';
  }
  elseif ($widget_type == 'date_text') {
    $edit[$field_name . '[und][0][value][date]'] = '12/10/2011';
  }
  elseif ($widget_type == 'date_popup') {
    $edit[$field_name . '[und][0][value][date]'] = '12/10/2011';
    $edit[$field_name . '[und][0][value][time]'] = '';
  }
  elseif ($widget_type == 'date_html5') {
    $edit[$field_name . '[und][0][value][date]'] = '2011-12-10';
    $edit[$field_name . '[und][0][value][time]'] = '';
  }
  $this->backdropPost('node/add/story', $edit, t('Save'));
  $message = format_string('Story %title has been created.', array('%title' => $edit['title']));

  if ($widget_type === 'date_select') {
    $this->assertNoRaw($message, "Correctly blocked creation of node with missing time for a $field_type field using the $widget_type widget.");
    $this->assertText('invalid', "Marked form with missing time as invalid for a $field_type field using the $widget_type widget.");
  }
  else {
    $this->assertRaw($message, "Correctly allowed creation of node with missing time for a $field_type field using the $widget_type widget.");
  }
}