You are here

function CCKSelectOtherMultipleValueListTest::testFieldEditSave in CCK Select Other 7

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

File

tests/cck_select_other.test, line 486
test file for cck_select_other Testing file

Class

CCKSelectOtherMultipleValueListTest
@class CCK Select Other Multiple Value List Field Case Tests 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'], t('%b', array(
    '%b' => json_encode($this->test_instance['default_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.
  // We'll try add more 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();
}