You are here

public function PatternsFieldTestCase::testDate in Patterns 7

Same name and namespace in other branches
  1. 7.2 tests/field/field.test \PatternsFieldTestCase::testDate()

File

tests/field/field.test, line 89
SimpleTests for the Field component of Patterns.

Class

PatternsFieldTestCase
@file SimpleTests for the Field component of Patterns.

Code

public function testDate() {

  // make sure the date module has been downloaded.
  // Make sure that matches the name in the pattern file
  if (!patterns_utils_is_module_enabled('date')) {
    $this
      ->fail('Date module not found. Skipping all related tests');
    return;
  }
  $entity_type = 'node';
  $name = 'field_date';
  $bundle_name = 'article';
  module_enable(array(
    'date',
  ));

  // create a new date field
  parent::runFile('date_field_create.yaml', 'Add date fields to NODE', $this->field_tests_dir);
  module_load_include('inc', 'date', 'date.field');
  _field_info_collate_fields(true);
  _field_info_collate_types(true);
  $inst = field_info_instance($entity_type, $name, $bundle_name);
  $this
    ->assertNotNull($inst, t('Date instance created.'));

  // modify the instance
  parent::runFile('date_field_modify.yaml', 'Modify date fields', $this->field_tests_dir);

  //  break;
  _field_info_collate_fields(true);
  _field_info_collate_types(true);
  $inst = field_info_instance($entity_type, $name, $bundle_name);
  $field = field_info_field($name);
  $this
    ->assertNotNull($inst, t('Instance found.'));
  $this
    ->assertEqual($field['cardinality'], '2', t('Modify Instance pattern changed cardinality correctly'));
  $this
    ->assertEqual($inst['settings']['default_value'], 'strtotime', t('Modify Instance pattern changed default_value correctly.'));
  $this
    ->assertEqual($inst['settings']['default_value_code'], '-10', t('Modify Instance pattern changed default_value_code correctly.'));
  $this
    ->assertEqual($inst['widget']['settings']['increment'], '10', t('Modify Instance pattern changed increment correctly.'));
  $this
    ->assertEqual($inst['widget']['settings']['input_format'], 'Y/m/d - H:i:s', t('Modify Instance pattern changed input format correctly.'));
  $this
    ->assertEqual($inst['widget']['settings']['year_range'], '-2:+2', t('Modify Instance pattern changed years_forward correctly.'));
  $this
    ->assertEqual($inst['widget']['settings']['label_position'], 'within', t('Modify Instance pattern changed label_postion correctly.'));
  $this
    ->assertTrue(in_array('year', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts year correctly.'));
  $this
    ->assertTrue(in_array('month', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts month correctly.'));
  $this
    ->assertTrue(in_array('day', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts day correctly.'));
  $this
    ->assertTrue(in_array('hour', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts hour correctly.'));
  $this
    ->assertTrue(in_array('minute', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts minute correctly.'));
  $this
    ->assertTrue(in_array('second', $inst['widget']['settings']['text_parts']), t('Modify Instance pattern changed test parts second correctly.'));
  $this
    ->assertEqual('second', $field['settings']['granularity']['second'], t('Modify Instance pattern changed granularity second correctly.'));
  $this
    ->assertEqual('date', $field['settings']['tz_handling'], t('Modify Instance pattern changed time zone handling correctly.'));
  $this
    ->assertEqual('optional', $field['settings']['todate'], t('Modify Instance pattern changed enddate_get correctly.'));

  // Delete the instance
  parent::runFile('date_field_delete.yaml', 'Delete date fields', $this->field_tests_dir);
  _field_info_collate_fields(true);
  $inst = field_info_instance($entity_type, $entity_type, $bundle_name);
  $this
    ->assertNull($inst, t('Delete date instance successfully.'));
}