You are here

function SelectOrOtherNumberTestCase::testOtherSelectedWithPreExistingKey in Select (or other) 7.3

Same name and namespace in other branches
  1. 7.2 tests/select_or_other_number.test \SelectOrOtherNumberTestCase::testOtherSelectedWithPreExistingKey()

File

tests/select_or_other_number.test, line 87

Class

SelectOrOtherNumberTestCase
Tests the select or other text field based functionality

Code

function testOtherSelectedWithPreExistingKey() {
  foreach ($this->fields as $field_name => $field) {
    $options = $this
      ->getAvailableOptions($field['instance_settings']);
    $keys = array_keys($options);
    $this
      ->setFieldValue($field_name, 'select_or_other', $keys[0]);

    // Add the </div> because assertRaw fails for integer values.
    $this
      ->assertRaw("{$keys[0]}</div>");
    $this
      ->assertNoRaw('select_or_other');

    // Edit the node.
    $this
      ->clickLink(t('Edit'));

    // Make sure the pre-existing option was selected.
    if ($field['widget'] === 'select_or_other') {

      // Select widgets have options which get selected.
      $this
        ->assertOptionSelected("edit-{$field_name}-und-select", $keys[0]);
    }
    else {

      // Checkboxes and radios have options that get checked. They are checked
      // by #id, which is why we need to remove the '.' from the key.
      $key = str_replace('.', '', $keys[0]);
      $this
        ->assertFieldChecked("edit-{$field_name}-und-select-{$key}");
    }
  }
}