You are here

field.test in Patterns 7.2

Same filename and directory in other branches
  1. 7 tests/field/field.test

SimpleTests for the Field component of Patterns.

File

tests/field/field.test
View source
<?php

/**
 * @file
 * SimpleTests for the Field component of Patterns.
 *
 */
class PatternsFieldTestCase extends PatternsTestCase {
  var $field_tests_dir;
  static function getInfo() {
    return array(
      'name' => 'Field component with date',
      'description' => 'Create/Delete a Field, Define extra settings for Instances or field',
      'group' => 'Patterns',
    );
  }
  public function setUp($modules = array(), $first = FALSE) {
    $this->field_tests_dir = $this
      ->getPatternsTestDir() . 'field/';

    // Enable any modules required for the tests.
    $modules = array(
      'patterns_components',
      'patterns_yamlparser',
      'date',
    );
    parent::setUp($modules);
  }
  public function testField() {

    // Make sure that matches the name in the pattern file
    $entity_type = 'node';
    $name = 'field_first';
    $bundle_name = 'article';

    // create a new field
    parent::runFile('field_instance_create.yaml', 'Add custom fields to User and Node', $this->field_tests_dir);
    _field_info_collate_fields(true);
    $inst = field_info_instance($entity_type, $name, $bundle_name);

    //break;
    $this
      ->assertNotNull($inst, t('Instance created.'));

    /*   $weight = $inst['widget']['weight'];
        // Run the pattern.
        parent::runFile('field_weight_modify.yaml', 'Modify field weight', $this->field_tests_dir);
        _field_info_collate_fields(true);
        $inst = field_info_instance($entity_type, $name, $bundle_name);
        $this->assertNotNull($inst, t('Instance created.'));
        $this->assertNotEqual($inst['widget']['weight'], $weight, t('Modify Field pattern change instance weight correctly.'));*/
    $field = field_info_field($name);
    $length = $field['settings']['max_length'];

    //modify the field
    parent::runFile('field_field_modify.yaml', 'Modify field setting', $this->field_tests_dir);
    _field_info_collate_fields(true);
    $field = field_info_field($name);
    $this
      ->assertNotNull($field, t('Field found.'));
    $this
      ->assertNotEqual($field['settings']['max_length'], $length, t('Modify Field pattern change max_length correctly.'));
    $label = $inst['label'];
    $require = $inst['required'];
    $descr = $inst['description'];
    $cardi = $field['cardinality'];
    $textp = $inst['settings']['text_processing'];

    // modify the instance
    parent::runFile('field_instance_modify.yaml', 'Edit fields', $this->field_tests_dir);
    _field_info_collate_fields(true);
    $inst = field_info_instance($entity_type, $name, $bundle_name);
    $field = field_info_field($name);
    $this
      ->assertNotNull($inst, t('Instance found.'));
    $this
      ->assertNotEqual($inst['label'], $label, t('Modify Instance pattern change label correctly.'));
    $this
      ->assertNotEqual($inst['required'], $require, t('Modify Instance pattern changed required correctl.'));
    $this
      ->assertNotEqual($inst['description'], $descr, t('Modify Instance pattern changed description correctly.'));
    $this
      ->assertNotEqual($field['cardinality'], $cardi, t('Modify Instance pattern changed cardinality correctly.'));
    $this
      ->assertNotEqual($inst['settings']['text_processing'], $textp, t('Modify Instance pattern changed text_processing correctly.'));

    //delete the instance
    parent::runFile('field_instance_delete.yaml', 'Delete 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 instance successfully.'));
  }
  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.'));
  }

}

Classes

Namesort descending Description
PatternsFieldTestCase @file SimpleTests for the Field component of Patterns.