You are here

function HierarchicalTermFormatterTestCase::testFieldInfo in Hierarchical Term Formatter 7

Test that custom info settings are set and retained.

File

./hierarchical_term_formatter.test, line 200
Tests for Field Multiple Limit, based on examples from field.test

Class

HierarchicalTermFormatterTestCase
Test the field formatter settings work.

Code

function testFieldInfo() {
  $settings = hierarchical_term_formatter_field_formatter_info();
  $this->formatter_settings = $settings['hierarchical_term_formatter']['settings'];

  // Load the field instance and check that the defaults are correct.
  $instance = field_read_instance($this->entity_type, $this->field_name, $this->bundle);
  $field_htf_display = $instance['display']['default']['settings']['display'];
  $this
    ->assertEqual($field_htf_display, $this->formatter_settings['display'], 'Default display is set to all.');
  $field_htf_link = $instance['display']['default']['settings']['link'];
  $this
    ->assertEqual($field_htf_link, $this->formatter_settings['link'], 'Default link terms is off.');
  $field_htf_wrap = $instance['display']['default']['settings']['wrap'];
  $this
    ->assertEqual($field_htf_wrap, $this->formatter_settings['wrap'], 'Default html wrap is none.');
  $field_htf_separator = $instance['display']['default']['settings']['separator'];
  $this
    ->assertEqual($field_htf_separator, $this->formatter_settings['separator'], 'Default separator is " » ".');

  // Load the field instance, change all the settings and save.
  $instance = field_read_instance($this->entity_type, $this->instance['field_name'], $this->instance['bundle']);
  $instance['display']['default']['settings']['display'] = 'parents';
  $instance['display']['default']['settings']['link'] = 1;
  $instance['display']['default']['settings']['wrap'] = 'span';
  $instance['display']['default']['settings']['separator'] = ' | ';
  field_update_instance($instance);

  // Reload it, and check that the values were saved.
  $instance = field_read_instance($this->entity_type, $this->field_name, $this->bundle);
  $field_htf_display = $instance['display']['default']['settings']['display'];
  $this
    ->assertEqual($field_htf_display, 'parents', 'Display is changed to parents.');
  $field_htf_link = $instance['display']['default']['settings']['link'];
  $this
    ->assertEqual($field_htf_link, '1', 'Link terms changed to on.');
  $field_htf_wrap = $instance['display']['default']['settings']['wrap'];
  $this
    ->assertEqual($field_htf_wrap, 'span', 'HTML wrap changed to <span>.');
  $field_htf_separator = $instance['display']['default']['settings']['separator'];
  $this
    ->assertEqual($field_htf_separator, ' | ', 'Separator changed to " | ".');
}