You are here

public function DateRepeatFormTestCase::dateForm in Date 7.2

Same name and namespace in other branches
  1. 7.3 date_repeat/tests/date_repeat_form.test \DateRepeatFormTestCase::dateForm()

Tests date field functions.

1 call to DateRepeatFormTestCase::dateForm()
DateRepeatFormTestCase::testDateRepeatForm in date_repeat/tests/date_repeat_form.test
Test the Date Repeat form.

File

date_repeat/tests/date_repeat_form.test, line 216
Test Date Repeat form.

Class

DateRepeatFormTestCase
Test Date Repeat form.

Code

public function dateForm($options, $test_id = NULL, $is_count = FALSE, $exclude_include = NULL) {
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit['body[und][0][value]'] = $this
    ->randomName(16);
  $current_year = date('Y');
  switch ($options) {
    case 'select':
      $edit['field_test[und][0][value][year]'] = $current_year;
      $edit['field_test[und][0][value][month]'] = '10';
      $edit['field_test[und][0][value][day]'] = '7';
      $edit['field_test[und][0][value][hour]'] = '10';
      $edit['field_test[und][0][value][minute]'] = '30';
      break;
    case 'text':
      $edit['field_test[und][0][value][date]'] = format_string('!year-10-07 10:30', array(
        '!year' => $current_year,
      ));
      break;
    case 'popup':
      $edit['field_test[und][0][value][date]'] = format_string('!year-10-07', array(
        '!year' => $current_year,
      ));
      $edit['field_test[und][0][value][time]'] = '10:30';
      break;
  }

  // Tests that Date repeat settings function properly.
  if ($test_id !== NULL) {
    $edit['field_test[und][0][show_repeat_settings]'] = TRUE;
    $count = 5;
    switch ($test_id) {

      // Daily test cases.
      case 'daily_1':
        $edit['field_test[und][0][rrule][FREQ]'] = 'DAILY';
        $edit['field_test[und][0][rrule][daily][byday_radios]'] = 'INTERVAL';
        $edit['field_test[und][0][rrule][daily][INTERVAL_child]'] = 2;
        break;
      case 'daily_2':
        $edit['field_test[und][0][rrule][FREQ]'] = 'DAILY';
        $edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_weekday';
        break;
      case 'daily_3':
        $edit['field_test[und][0][rrule][FREQ]'] = 'DAILY';
        $edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_mo_we_fr';
        break;
      case 'daily_4':
        $edit['field_test[und][0][rrule][FREQ]'] = 'DAILY';
        $edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_tu_th';
        break;

      // Weekly test cases.
      case 'weekly_1':
        $edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY';
        $edit['field_test[und][0][rrule][weekly][BYDAY][MO]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][WE]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][TH]'] = TRUE;
        break;
      case 'weekly_2':
        $edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY';
        $edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 1;
        $edit['field_test[und][0][rrule][weekly][BYDAY][MO]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][FR]'] = TRUE;
        break;
      case 'weekly_3':
        $edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY';
        $edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 2;
        $edit['field_test[und][0][rrule][weekly][BYDAY][TU]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][TH]'] = TRUE;
        break;
      case 'weekly_4':
        $edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY';
        $edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 10;
        $edit['field_test[und][0][rrule][weekly][BYDAY][MO]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][TU]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][WE]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][TH]'] = TRUE;
        $edit['field_test[und][0][rrule][weekly][BYDAY][FR]'] = TRUE;
        break;

      // Monthly test cases.
      case 'monthly_1':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'FR';
        break;
      case 'monthly_2':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'SU';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][1]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][3]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][5]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][7]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][9]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][11]'] = TRUE;
        break;
      case 'monthly_3':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '-2';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'MO';
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][6]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][12]'] = TRUE;
        break;
      case 'monthly_4':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10';
        break;
      case 'monthly_5':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10';
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][1]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][3]'] = TRUE;
        break;
      case 'monthly_6':
        $edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY';
        $edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '-5';
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][4]'] = TRUE;
        $edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][6]'] = TRUE;
        break;

      // Yearly test cases.
      case 'yearly_1':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'FR';
        break;
      case 'yearly_2':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 2;
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'SU';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][1]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][3]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][5]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][7]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][9]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][11]'] = TRUE;
        break;
      case 'yearly_3':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 3;
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '-2';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'MO';
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][6]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][12]'] = TRUE;
        break;
      case 'yearly_4':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10';
        break;
      case 'yearly_5':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 2;
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10';
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][1]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][3]'] = TRUE;
        break;
      case 'yearly_6':
        $edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY';
        $edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 3;
        $edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYMONTHDAY_BYMONTH';
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '-5';
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][4]'] = TRUE;
        $edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][6]'] = TRUE;
        break;
    }

    // Test COUNT or UNTIL (default).
    if ($is_count) {
      $edit['field_test[und][0][rrule][range_of_repeat]'] = 'COUNT';
      $edit['field_test[und][0][rrule][count_child]'] = $count;
    }
    else {
      $edit['field_test[und][0][rrule][range_of_repeat]'] = 'UNTIL';
      $date = array(
        'year' => $current_year + 1,
        'month' => '10',
        'day' => '07',
      );
      $edit += $this
        ->formatDateForRRULEInputs('field_test[und][0][rrule][until_child]', $options, $date);
    }

    // Test date exceptions and/or additions.
    if ($exclude_include !== NULL) {
      $exclude_include_edit = array();
      switch ($exclude_include) {
        case 'exclude':
          $exclude_include_edit['field_test[und][0][rrule][show_exceptions]'] = TRUE;
          $date = array(
            'year' => $current_year,
            'month' => '10',
            'day' => '07',
          );
          $exclude_include_edit += $this
            ->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date);
          break;
        case 'include':
          $exclude_include_edit['field_test[und][0][rrule][show_additions]'] = TRUE;
          $date = array(
            'year' => $current_year + 3,
            'month' => '10',
            'day' => '07',
          );
          $exclude_include_edit += $this
            ->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date);
          break;
        case 'exclude_include':
          $exclude_include_edit['field_test[und][0][rrule][show_exceptions]'] = TRUE;
          $date = array(
            'year' => $current_year,
            'month' => '10',
            'day' => '07',
          );
          $exclude_include_edit += $this
            ->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date);
          $exclude_include_edit['field_test[und][0][rrule][show_additions]'] = TRUE;
          $date = array(
            'year' => $current_year + 3,
            'month' => '10',
            'day' => '07',
          );
          $exclude_include_edit += $this
            ->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date);
          break;
      }
      $edit += $exclude_include_edit;
    }
  }
  $this
    ->drupalPost('node/add/date', $edit, t('Save'));
  $this
    ->assertText($edit['body[und][0][value]'], 'Test node has been created');

  // Return the settings for later use in verification.
  return $edit;
}