You are here

function DateRestrictionsBase::postNode in Date Restrictions 7

Post a node with a date field populated.

10 calls to DateRestrictionsBase::postNode()
DateRestrictionsHostEntityMinMaxTestCase::_testDateGreaterThanMax in modules/minmax/tests/date_restrictions_minmax_host_entity.test
DateRestrictionsHostEntityMinMaxTestCase::_testDateLowerThanMin in modules/minmax/tests/date_restrictions_minmax_host_entity.test
DateRestrictionsHostEntityMinMaxTestCase::_testIntervalGreaterThanMax in modules/minmax/tests/date_restrictions_minmax_host_entity.test
DateRestrictionsHostEntityMinMaxTestCase::_testIntervalLowerThanMin in modules/minmax/tests/date_restrictions_minmax_host_entity.test
DateRestrictionsStaticMinMaxTestCase::_testDateGreaterThanMax in modules/minmax/tests/date_restrictions_minmax.test

... See full list

File

tests/date_restrictions_base.test, line 83
Tests for date_restrictions.module.

Class

DateRestrictionsBase
Base class for Date Restrictions tests.

Code

function postNode($field_name, $field_type, $widget_type, $start, $end = NULL, $edit = array()) {

  // Complete date arrays with missing parts.
  $defaults = array(
    'hour' => $this->date_default_hour,
    'minute' => $this->date_default_minute,
  );
  $start += $defaults;
  if (!is_null($end)) {
    $end += $defaults;
  }

  // Build POST data array.
  $edit['title'] = $this
    ->randomName(8);
  $parents = "{$field_name}[und][0]";
  if (!is_null($end)) {
    $edit["{$parents}['show_todate']"] = TRUE;
  }

  // Add date values based on widget type.
  if ($widget_type == 'date_select') {
    foreach ($start as $key => $value) {
      $edit[$parents . '[value][' . $key . ']'] = $value;
    }
    if (!is_null($end)) {
      foreach ($end as $key => $value) {
        $edit[$parents . '[value2][' . $key . ']'] = $value;
      }
    }
  }
  else {

    // Both date_text and date_popup have a similar format.
    $date = $start['day'] . '/' . $start['month'] . '/' . $start['year'];
    $time = $start['hour'] . ':' . $start['minute'];
    if (!is_null($end)) {
      $date2 = $end['day'] . '/' . $end['month'] . '/' . $end['year'];
      $time2 = $end['hour'] . ':' . $end['minute'];
    }
    if ($widget_type == 'date_text') {
      $edit[$parents . '[value][date]'] = $date . ' - ' . $time;
      if (!is_null($end)) {
        $edit[$parents . '[value2][date]'] = $date2 . ' - ' . $time2;
      }
    }
    elseif ($widget_type == 'date_popup') {
      $edit[$parents . '[value][date]'] = $date;
      $edit[$parents . '[value][time]'] = $time;
      if (!is_null($end)) {
        $edit[$parents . '[value2][date]'] = $date2;
        $edit[$parents . '[value2][time]'] = $time2;
      }
    }
  }
  $this
    ->drupalPost('node/add/story', $edit, t('Save'));
  return $edit;
}