You are here

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

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

File

tests/select_or_other_number.test, line 180

Class

SelectOrOtherNumberTestCase
Tests the select or other text field based functionality

Code

function testOtherSelectedWithPreExistingKey() {
  $langcode = LANGUAGE_NONE;
  foreach ($this->field_options as $cardinality => $field_types) {
    foreach ($field_types as $type => $field_names) {
      foreach ($field_names as $field_name => $options) {
        $edit = array();

        // A node requires a title
        $edit["title"] = $this
          ->randomName(8);
        $keys = array_keys($options);
        $key = $keys[0];
        if ($cardinality === 'single') {

          // Test single select.
          $edit["{$field_name}[{$langcode}][select]"] = 'select_or_other';
        }
        else {

          // Test multiple select.
          $edit["{$field_name}[{$langcode}][select][]"] = array(
            'select_or_other',
          );
        }
        $edit["{$field_name}[{$langcode}][other]"] = $key;

        // Create the node.
        $this
          ->drupalPost('node/add/page', $edit, t('Save'));

        // Check if the values have been created.
        // Add the </div> because assertRaw fails for integer values.
        $this
          ->assertRaw("{$key}</div>");

        // Check if the 'select_or_other' option is not displayed.
        $this
          ->assertNoRaw('select_or_other');

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

        // Check if the other field is empty and if the select field has the correct
        // selected value.
        $this
          ->assertFieldByName("{$field_name}[{$langcode}][other]", '');
        $this
          ->assertOptionSelected("edit-{$field_name}-und-select", $key);
      }
    }
  }
}