function OptionsFieldUITest::testOptionsAllowedValuesBoolean

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

File

drupal/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php, line 212
Contains \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 field settings'));
  $this
    ->assertRaw(t('Updated field %label field settings.', array(
    '%label' => $this->field_name,
  )));

  // Clear field cache.
  field_info_cache_clear();

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