You are here

function DateRepeatFormTest::dateForm in Date 8

1 call to DateRepeatFormTest::dateForm()
DateRepeatFormTest::testDateRepeatForm in date_repeat/lib/Drupal/date_repeat/Tests/DateRepeatFormTest.php

File

date_repeat/lib/Drupal/date_repeat/Tests/DateRepeatFormTest.php, line 202
Test Date Repeat form.

Class

DateRepeatFormTest

Namespace

Drupal\date_repeat\Tests

Code

function dateForm($options, $test_id = NULL, $is_count = FALSE, $exclude_include = NULL) {

  // Tests that date field functions properly.
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit['body[und][0][value]'] = $this
    ->randomName(16);
  switch ($options) {
    case 'select':
      $edit['field_test[und][0][value][year]'] = '2010';
      $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]'] = '2010-10-07 10:30';
      break;
    case 'popup':
      $edit['field_test[und][0][value][date]'] = '2010-10-07';
      $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' => '2011',
        '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' => '2010',
            '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' => '2013',
            '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' => '2010',
            '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' => '2013',
            '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;
}