1 list.test ListFieldDisplayTestCase::testListDisplayFormatterBoolean()

List (boolen) : test 'On/Off' values input.

File

core/modules/field/modules/list/tests/list.test, line 485
Tests for list.module.

Class

ListFieldDisplayTestCase
Tests that formatters are working properly.

Code

function testListDisplayFormatterBoolean() {
  $this->field_name = 'field_list_boolean';
  $this->createListField('list_boolean');

  $on = $this->randomName();
  $off = $this->randomName();
  $allowed_values = array(1 => $on, 0 => $off);
  $edit = array(
    'on' => $on,
    'off' => $off,
  );
  $this->backdropPost($this->admin_path, $edit, t('Save settings'));
  $this->assertText("Saved field_list_boolean configuration.", "The 'On' and 'Off' form fields work for boolean fields.");

  $settings = array(
    'type' => $this->type,
    $this->field_name => array(LANGUAGE_NONE => array(array('value' => 1))),
  );
  $node = $this->backdropCreateNode($settings);

  // Test display on/off values set by user
  $edit = array(
    "fields[{$this->field_name}][type]" => 'list_default',
  );
  $this->backdropPost("admin/structure/types/manage/{$this->type}/display/default", $edit, t('Save'));

  $this->backdropGet('node/' . $node->nid);
  $this->assertText($on, format_string('On value is present.'));

  // Test Yes/No output format.
  $instance_info = field_info_instance('node', $this->field_name, $this->type);
  $instance_info['display']['default']['type'] = 'boolean_yes_no';
  field_update_instance($instance_info);

  $this->backdropGet('node/' . $node->nid);
  $this->assertText(t('Yes'), format_string('On value is present.'));

  // Enable the default setting to use custom on/off text.
  $instance_info = field_info_instance('node', $this->field_name, $this->type);
  $instance_info['display']['default']['type'] = 'boolean_yes_no';
  $instance_info['display']['default']['settings']['format'] = 'custom';
  $on = $this->randomName();
  $off = $this->randomName();
  $instance_info['display']['default']['settings']['custom_on'] = $on;
  $instance_info['display']['default']['settings']['custom_off'] = $off;
  field_update_instance($instance_info);

  $this->backdropGet('node/' . $node->nid);
  $this->assertText($on, format_string('Custom on value is present.'));

  // Enable the default setting to use custom reverse on/off text.
  $instance_info = field_info_instance('node', $this->field_name, $this->type);
  $instance_info['display']['default']['settings']['reverse'] = TRUE;
  field_update_instance($instance_info);

  $this->backdropGet('node/' . $node->nid);
  $this->assertText($off, format_string('Custom reversed on value is present.'));
}