function OptionsFieldUITest::testOptionsAllowedValuesBoolean

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

File

drupal/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php, line 204
Definition of Drupal\options\Tests\OptionsFieldUITest.

Class

OptionsFieldUITest
Options module UI tests.

Namespace

Drupal\options\Tests

Code

function testOptionsAllowedValuesBoolean() {
  $this->field_name = 'field_options_boolean';
  $this
    ->createOptionsField('list_boolean');

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

  // Test the allowed_values on the field settings form.
  $this
    ->drupalGet($this->admin_path);
  $this
    ->assertFieldByName('on', $on, t("The 'On' value is stored correctly."));
  $this
    ->assertFieldByName('off', $off, t("The 'Off' value is stored correctly."));
  $field = field_info_field($this->field_name);
  $this
    ->assertEqual($field['settings']['allowed_values'], $allowed_values, 'The allowed value is correct');
  $this
    ->assertFalse(isset($field['settings']['on']), 'The on value is not saved into settings');
  $this
    ->assertFalse(isset($field['settings']['off']), 'The off value is not saved into settings');
}