You are here

function ContentOptionWidgetTest::testOnOffCheckbox in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 tests/content.crud.test \ContentOptionWidgetTest::testOnOffCheckbox()

On/Off Checkbox, not required:

  • Create a node with the value checked.
  • FAILS: Edit the node and uncheck the value.

On/Off Checkbox, required:

  • TODO: what behavior do we want ?

File

tests/content.crud.test, line 914

Class

ContentOptionWidgetTest

Code

function testOnOffCheckbox() {
  $type = $this->content_types[0];
  $type_url = str_replace('_', '-', $type->type);

  // Create the field.
  $on_text = $this
    ->randomName(5);
  $on_value = $this
    ->randomName(5);
  $off_text = $on_text . '_off';
  $off_value = $on_value . '_off';
  $settings = array(
    'type' => 'text',
    'widget_type' => 'optionwidgets_onoff',
    'allowed_values' => "{$off_value}|{$off_text}\r\n{$on_value}|{$on_text}",
  );
  $field = $this
    ->createField($settings, 0);
  $field_name = $field['field_name'];

  // Create a node with the checkbox on.
  $edit = array(
    'title' => $this
      ->randomName(20),
    'body' => $this
      ->randomName(20),
    $field_name . '[value]' => $on_value,
  );
  $this
    ->drupalPost('node/add/' . $type_url, $edit, 'Save');
  $node = node_load(array(
    'title' => $edit['title'],
  ));
  $this
    ->assertEqual($node->{$field_name}[0]['value'], $on_value, 'Checkbox: checked (saved)');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($on_text, 'Checkbox: checked (displayed)');

  // Edit the node and uncheck the box.
  $edit = array(
    $field_name . '[value]' => FALSE,
  );
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
  $node = node_load($node->nid, NULL, TRUE);
  $this
    ->assertEqual($node->{$field_name}[0]['value'], $off_value, 'Checkbox: unchecked (saved)');
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText($off_text, 'Checkbox: unchecked (displayed)');
}