You are here

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

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

File

tests/select_or_other_text.test, line 149

Class

SelectOrOtherTextTestCase
Tests the select or other text field based functionality

Code

function testOtherSelectedWithPreExistingKey() {
  $edit = array();
  $langcode = LANGUAGE_NONE;

  // A node requires a title
  $edit["title"] = $this
    ->randomName(8);

  // Test single select other.
  $edit["{$this->single_field_name}[{$langcode}][select]"] = 'select_or_other';
  $edit["{$this->single_field_name}[{$langcode}][other]"] = 'keyed';

  // Test multi select other.
  $edit["{$this->multi_field_name}[{$langcode}][select][]"] = array(
    'multi_keyed',
    'select_or_other',
  );
  $edit["{$this->multi_field_name}[{$langcode}][other]"] = 'multi_unkeyed';

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

  // Check if the values have been created.
  $this
    ->assertRaw('keyed');
  $this
    ->assertRaw('multi_keyed');
  $this
    ->assertRaw('multi_unkeyed');

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

  // Edit the node.
  $this
    ->drupalGet('node/1/edit');

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

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