You are here

function DateValidationTestCase::malFormedDate in Date 7

Same name and namespace in other branches
  1. 7.3 tests/DateValidationTestCase.test \DateValidationTestCase::malFormedDate()
  2. 7.2 tests/DateValidationTestCase.test \DateValidationTestCase::malFormedDate()
1 call to DateValidationTestCase::malFormedDate()
DateValidationTestCase::testValidation in tests/date_validation.test

File

tests/date_validation.test, line 41

Class

DateValidationTestCase

Code

function malFormedDate($options, $date_format = 'mm/dd/yyyy') {

  // Tests that date field filters improper dates.
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit['body[und][0][value]'] = $this
    ->randomName(16);
  if ($options == 'select') {
    $edit['field_test[und][0][value][year]'] = '2011';
    $edit['field_test[und][0][value][month]'] = '15';
    $edit['field_test[und][0][value][day]'] = '49';
    $edit['field_test[und][0][value][hour]'] = '10';
    $edit['field_test[und][0][value][minute]'] = '30';
  }
  elseif ($options == 'text') {
    $edit['field_test[und][0][value][date]'] = '15/49/2011 - 10:30';
  }
  elseif ($options == 'popup') {
    $edit['field_test[und][0][value][date]'] = '15/49/2011';
    $edit['field_test[und][0][value][time]'] = '10:30';
  }
  $this
    ->drupalPost('node/add/story', $edit, t('Save'));
  $this
    ->assertNoText('Test node has been created');
  $this
    ->assertText('The month is invalid.');
  $this
    ->assertText('The day is invalid.');

  // Test two-digit entry for year where 4-digit is expected
  if ($options == 'select') {
    $edit['field_test[und][0][value][year]'] = '11';
    $edit['field_test[und][0][value][month]'] = '12';
    $edit['field_test[und][0][value][day]'] = '10';
    $edit['field_test[und][0][value][hour]'] = '10';
    $edit['field_test[und][0][value][minute]'] = '30';
  }
  elseif ($options == 'text') {
    $edit['field_test[und][0][value][date]'] = '12/10/11 - 10:30';
  }
  elseif ($options == 'popup') {
    $edit['field_test[und][0][value][date]'] = '12/10/11';
    $edit['field_test[und][0][value][time]'] = '10:30';
  }
  $this
    ->drupalPost('node/add/story', $edit, t('Save'));
  $this
    ->assertNoText('Test node has been created');
  $this
    ->assertText('The year is invalid. Please check that entry includes four digits.');

  // Test invalid hour/minute entry for time
  if ($options == 'select') {
    $edit['field_test[und][0][value][year]'] = '2011';
    $edit['field_test[und][0][value][month]'] = '12';
    $edit['field_test[und][0][value][day]'] = '10';
    $edit['field_test[und][0][value][hour]'] = '29';
    $edit['field_test[und][0][value][minute]'] = '95';
  }
  elseif ($options == 'text') {
    $edit['field_test[und][0][value][date]'] = '12/10/2011 - 29:95';
  }
  elseif ($options == 'popup') {
    $edit['field_test[und][0][value][date]'] = '12/10/2011';
    $edit['field_test[und][0][value][time]'] = '29:95';
  }
  $this
    ->drupalPost('node/add/story', $edit, t('Save'));
  $this
    ->assertNoText('Test node has been created');
  $this
    ->assertText('The hour is invalid.');
  $this
    ->assertText('The minute is invalid.');
}