You are here

function CCKSelectOtherBasicTest::testFailValidationRequiredField in CCK Select Other 7

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

Fail validation of node edit form for required field.

File

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

Class

CCKSelectOtherBasicTest
@class CCK Select Other Basic Test Case

Code

function testFailValidationRequiredField() {

  // Make field instance required and update
  $this->test_instance['required'] = FALSE;
  field_update_instance($this->test_instance);
  $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]';
  $edit = array(
    $select_field => 'other',
    $text_field => '',
  );

  // First assert that we do not fail validation for a non-
  // required field.
  $this
    ->drupalLogin($this->web_user);
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this
    ->assertNoRaw(t('A non-empty value is required for this option.'), t('Did not fail validation for non-required field.'));
  $this
    ->drupalLogout();

  // Make field instance required and update
  $this->test_instance['required'] = TRUE;
  field_update_instance($this->test_instance);

  // Fairly straightforward, see above tests.
  $this
    ->drupalLogin($this->web_user);
  $field_str = str_replace('_', '-', $this->test_field['field_name']);
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this
    ->assertRaw(t('A non-empty value is required for this option.'), t('Failed validation for required field.'));
  $elements = $this
    ->xpath('//input[@name="' . $text_field . '" and contains(@class, "error")]');
  $this
    ->assertEqual(count($elements), 1, t('Found error class on %field element.', array(
    '%field' => $text_field,
  )));
  $this
    ->drupalLogout();
}