You are here

public function CCKSelectOtherNumericFieldTest::testSelectOtherList in CCK Select Other 7.2

Test numeric field CRUD.

File

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

Class

CCKSelectOtherNumericFieldTest
Assert that select other field widget can be used with non-text fields.

Code

public function testSelectOtherList() {
  $this
    ->drupalLogin($this->web_user);

  // Save a regular field value.
  $value = rand(1, 5);
  $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 => $value,
  );
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this->test_node = node_load($this->test_node->nid, NULL, TRUE);
  $this
    ->assertRaw($this->test_node->{$this->test_field['field_name']}['und'][0]['value'], t('Select other field data %field matches %match on node.', array(
    '%field' => $this->test_node->{$this->test_field['field_name']}['und'][0]['value'],
    '%match' => $value,
  )));

  // Save an other value as an integer.
  $value = rand(50, 1000);
  $edit[$select_field] = 'other';
  $edit[$text_field] = $value;
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this->test_node = node_load($this->test_node->nid, NULL, TRUE);
  $this
    ->assertRaw($this->test_node->{$this->test_field['field_name']}['und'][0]['value'], t('Select other field data %field matches %match on node.', array(
    '%field' => $this->test_node->{$this->test_field['field_name']}['und'][0]['value'],
    '%match' => $value,
  )));

  // Attempt to save an other value that is non-integer.
  $value = $this
    ->randomName(10);
  $edit[$text_field] = $value;
  $this
    ->drupalPost('node/' . $this->test_node->nid . '/edit', $edit, t('Save'));
  $this
    ->assertText('Only integers are allowed', t('Select other field did not save an illegal value.'));
}