You are here

protected function DateFieldTestBase::createDateField in Date 7.3

Same name and namespace in other branches
  1. 7.2 tests/DateFieldTestBase.test \DateFieldTestBase::createDateField()

Creates a date field from an array of settings values.

All values have defaults, only need to specify values that need to be different.

9 calls to DateFieldTestBase::createDateField()
DateFieldTestBase::checkDateField in tests/DateFieldTestBase.test
Run some tests against a specific field type/widget combination.
DateFieldTestCase::testRelativeDefault in tests/DateFieldTestCase.test
Test relative default values.
DatePopupWithViewsTestCase::setUp in date_popup/tests/DateViewsPopupTestCase.test
Sets up a Drupal site for running functional and integration tests.
DatePopupWithViewsTestCase::setUp in date_popup/tests/DatePopupWithViewsTestCase.test
Test setup actions.
DateTimezoneTestCase::testFieldWidgetSettings in tests/DateTimezoneTestCase.test
Test timezone handling validation on the field settings form.

... See full list

1 method overrides DateFieldTestBase::createDateField()
DateViewsFilterTestCase::createDateField in date_views/tests/date_views_filter.test
Adds a date field to a node bundle.

File

tests/DateFieldTestBase.test, line 60
Shared test functionality.

Class

DateFieldTestBase
Shared test functionality.

Code

protected function createDateField($values = array()) {
  $this
    ->verbose($values);
  extract($values);
  $field_name = !empty($field_name) ? $field_name : 'field_test';
  $entity_type = !empty($entity_type) ? $entity_type : 'node';
  $bundle = !empty($bundle) ? $bundle : 'story';
  $label = !empty($label) ? $label : 'Test';
  $field_type = !empty($field_type) ? $field_type : 'datetime';
  $repeat = !empty($repeat) ? $repeat : 0;
  $todate = !empty($todate) ? $todate : 'optional';
  $widget_type = !empty($widget_type) ? $widget_type : 'date_select';
  $tz_handling = !empty($tz_handling) ? $tz_handling : 'site';
  $granularity = !empty($granularity) ? $granularity : array(
    'year',
    'month',
    'day',
    'hour',
    'minute',
  );
  $year_range = !empty($year_range) ? $year_range : '2010:+1';
  $input_format = !empty($input_format) ? $input_format : date_default_format($widget_type);
  $input_format_custom = !empty($input_format_custom) ? $input_format_custom : '';
  $text_parts = !empty($text_parts) ? $text_parts : array();
  $increment = !empty($increment) ? $increment : 15;
  $default_value = !empty($default_value) ? $default_value : 'now';
  $default_value_code = !empty($default_value_code) ? $default_value_code : NULL;
  $default_value2 = !empty($default_value2) ? $default_value2 : 'blank';
  $default_format = !empty($default_format) ? $default_format : 'long';
  $cache_enabled = !empty($cache_enabled);
  $cache_count = !empty($cache_count) ? $cache_count : 4;
  $field = array(
    'field_name' => $field_name,
    'type' => $field_type,
    'cardinality' => !empty($repeat) ? FIELD_CARDINALITY_UNLIMITED : 1,
    'settings' => array(
      'granularity' => $granularity,
      'tz_handling' => $tz_handling,
      'timezone_db' => date_get_timezone_db($tz_handling),
      'repeat' => $repeat,
      'todate' => $todate,
      'cache_enabled' => $cache_enabled,
      'cache_count' => $cache_count,
    ),
  );
  $instance = array(
    'entity_type' => $entity_type,
    'field_name' => $field_name,
    'label' => $label,
    'bundle' => $bundle,
    // Move the date to the top.
    'weight' => -100,
    'widget' => array(
      'type' => $widget_type,
      // Increment for minutes and seconds, can be 1, 5, 10, 15, or 30.
      'settings' => array(
        'increment' => $increment,
        // The number of years to go back and forward in drop-down year
        // selectors.
        'year_range' => $year_range,
        'input_format' => $input_format,
        'input_format_custom' => $input_format_custom,
        'text_parts' => $text_parts,
        'label_position' => 'above',
        'repeat_collapsed' => 0,
      ),
      'weight' => -100,
    ),
    'settings' => array(
      'default_value' => $default_value,
      'default_value_code' => $default_value_code,
      'default_value2' => $default_value2,
    ),
  );
  $instance['display'] = array(
    'default' => array(
      'label' => 'above',
      'type' => 'date_default',
      'settings' => array(
        'format_type' => $default_format,
        'show_repeat_rule' => 'show',
        'multiple_number' => '',
        'multiple_from' => '',
        'multiple_to' => '',
        'fromto' => 'both',
      ),
      'module' => 'date',
      'weight' => 0,
    ),
    'teaser' => array(
      'label' => 'above',
      'type' => 'date_default',
      'weight' => 0,
      'settings' => array(
        'format_type' => $default_format,
        'show_repeat_rule' => 'show',
        'multiple_number' => '',
        'multiple_from' => '',
        'multiple_to' => '',
        'fromto' => 'both',
      ),
      'module' => 'date',
    ),
  );
  $this
    ->verbose($field);
  $field = field_create_field($field);
  $this
    ->verbose($instance);
  $instance = field_create_instance($instance);
  field_info_cache_clear();
  field_cache_clear();

  // Look at how the field got configured.
  $this
    ->drupalGet("admin/structure/types/manage/{$bundle}/fields/{$field_name}");
  $this
    ->drupalGet("admin/structure/types/manage/{$bundle}/display");
}