1.20.x form.test FormElementTestCase::testOptions()

Tests expansion of #options for #type checkboxes and radios.

File

modules/simpletest/tests/form.test, line 618
Unit tests for the Backdrop Form API.

Class

FormElementTestCase
Tests building and processing of core form elements.

Code

function testOptions() {
  $this->backdropGet('form-test/checkboxes-radios');

  // Verify that all options appear in their defined order.
  foreach (array('checkbox', 'radio') as $type) {
    $elements = $this->xpath('//input[@type=:type]', array(':type' => $type));
    $expected_values = array('0', 'foo', '1', 'bar', '>');
    foreach ($elements as $element) {
      $expected = array_shift($expected_values);
      $this->assertIdentical((string) $element['value'], $expected);
    }
  }

  // Enable customized option sub-elements.
  $this->backdropGet('form-test/checkboxes-radios/customize');

  // Verify that all options appear in their defined order, taking a custom
  // #weight into account.
  foreach (array('checkbox', 'radio') as $type) {
    $elements = $this->xpath('//input[@type=:type]', array(':type' => $type));
    $expected_values = array('0', 'foo', 'bar', '>', '1');
    foreach ($elements as $element) {
      $expected = array_shift($expected_values);
      $this->assertIdentical((string) $element['value'], $expected);
    }
  }
  // Verify that custom #description properties are output.
  foreach (array('checkboxes', 'radios') as $type) {
    $elements = $this->xpath('//input[@id=:id]/following-sibling::div[@class=:class]', array(
      ':id' => 'edit-' . $type . '-foo',
      ':class' => 'description',
    ));
    $this->assertTrue(count($elements), format_string('Custom %type option description found.', array(
      '%type' => $type,
    )));
  }
}