You are here

public function PatternsFieldTestCase::testField in Patterns 7

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

File

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

Class

PatternsFieldTestCase
@file SimpleTests for the Field component of Patterns.

Code

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.'));
}