You are here

function CCKSelectOtherAllowedValuesTest::testAllowedValues in CCK Select Other 7.2

Same name and namespace in other branches
  1. 6 tests/cck_select_other.test \CCKSelectOtherAllowedValuesTest::testAllowedValues()
  2. 7 tests/cck_select_other.test \CCKSelectOtherAllowedValuesTest::testAllowedValues()

Fail validation or test allowed values for other option

File

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

Class

CCKSelectOtherAllowedValuesTest
Assert that allowed values restrict select other list options in the rare case that someone decides to use them.

Code

function testAllowedValues() {
  $this
    ->drupalLogin($this->admin_user);

  //Setup some allowed values to equal our select list options + another known value
  $options = cck_select_other_options($this->test_instance);
  $options['AllowedValue'] = 'AllowedValue';
  $this->test_field['settings']['allowed_values'] = $options;
  field_update_field($this->test_field);
  $this->test_field = field_info_field($this->test_field['field_name']);
  $this
    ->assertEqual($this->test_field['id'], $this->test_instance['field_id'], t('Field name @first is equal to @second. Field updated successfully.', array(
    '@first' => $this->test_field['id'],
    '@second' => $this->test_instance['field_id'],
  )));
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->web_user);
  $select_field = $this->test_field['field_name'] . '[und][0][select_other_list]';
  $text_field = $this->test_field['field_name'] . '[und][0][select_other_text_input]';
  $goodEdit = array(
    $select_field => 'other',
    $text_field => 'AllowedValue',
  );
  $badEdit = array(
    $select_field => 'other',
    $text_field => 'DisallowedValue',
  );

  // try to save a disallowed value
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $badEdit, t('Save'));
  $this
    ->assertText(t('@name: illegal value.', array(
    '@name' => $this->test_instance['label'],
  )), t('Successfully blocked submission of DisallowedValue.'));

  // try to save an allowed value
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $goodEdit, t('Save'));
  $this
    ->assertNoText(t('@name: illegal value.', array(
    '@name' => $this->test_instance['label'],
  )), t('Successfully saved form with allowed value, AllowedValue.'));
  $this
    ->assertRaw('AllowedValue', t('Found %allowed allowed value on node view.', array(
    '%allowed' => 'AllowedValue',
  )));
  $this
    ->drupalLogout();
}