You are here

function CCKSelectOtherMultipleValueListTest::testFieldEditSave in CCK Select Other 7.2

Same name and namespace in other branches
  1. 7 tests/cck_select_other.test \CCKSelectOtherMultipleValueListTest::testFieldEditSave()

File

tests/cck_select_other.test, line 481
CCK Select Other Functional Tests

Class

CCKSelectOtherMultipleValueListTest
Assert multiple value list fields where $delta > 1 or -1 (unlimited).

Code

function testFieldEditSave() {
  $this
    ->drupalLogin($this->web_user);

  // Load node edit form and check element default values.
  // edit-field-wqs9w-und-0-select-other-list
  $name = substr($this->test_field['field_name'], 6);
  $this
    ->drupalGet('node/' . $this->test_node->nid . '/edit');
  $this
    ->assertOptionSelected('edit-field-' . $name . '-und-0-select-other-list', $this->test_instance['default_value'][0]['value']);
  $this
    ->assertOptionSelected('edit-field-' . $name . '-und-1-select-other-list', $this->test_instance['default_value'][0]['value']);

  // Try to post and make sure it saved both values correctly. In unlimited
  // situation, there are two elements by default. Test add more function
  // later.
  $options_arr = cck_select_other_options($this->test_instance);
  do {
    $firstoption = array_rand(cck_select_other_options($this->test_instance));
  } while (in_array($firstoption, array(
    'other',
    '_none',
    '',
  )));
  $otheroption = $this
    ->randomName(16);
  $edit = array(
    $this->test_instance['field_name'] . '[und][0][select_other_list]' => 'other',
    $this->test_instance['field_name'] . '[und][0][select_other_text_input]' => $otheroption,
    $this->test_instance['field_name'] . '[und][1][select_other_list]' => $firstoption,
  );
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this
    ->assertRaw($otheroption, t('Found first select other list option on node.'));
  $this
    ->assertRaw($firstoption, t('Found second select other list option on node.'));
  $this
    ->drupalLogout();
}