In FormElementTestCase::testOptions() (file: modules/simpletest/tests/form.test), there's the following check:

     // Verify that custom #description properties are output.
    foreach (array('checkboxes', 'radios') as $type) {
      $elements = $this->xpath('//input[@name=:name]/following-sibling::div[@class=:class]', array(
        ':name' => $type . '[foo]',
        ':class' => 'description',
      ));
      $this->assertTrue(count($elements), t('Custom %type option description found.', array(
        '%type' => $type,
      )));
    } 

This should cause one test failure with the radios element: radios[foo] is not a valid name for radio elements. However, it seems my server is the only one that actually catches this failure. The HEAD tester doesn't, and checking with sun in IRC, his testing environment doesn't either.

CommentFileSizeAuthor
#2 977184-testoptions.patch973 bytesStevel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mark Trapp’s picture

Ah, it turns out this is the root cause: #933856: xpath() return values are inconsistent. The fix in there should only cause this test to fail for everyone instead of people with certain versions of libxml. For the record, it fails with the following environment:

PHP 5.3.3
Libxml 2.7.3

Stevel’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
973 bytes

No idea why it's not failing everywhere, but in my environment, the test fails as well.

PostgreSQL 9
PHP 5.3.3
libxml 2.7.7

Mark Trapp’s picture

Status: Active » Reviewed & tested by the community

Works as advertised: patch applies, tests pass. Hopefully #933856: xpath() return values are inconsistent will expose any other falsely-passing tests.

webchick’s picture

Status: Needs review » Fixed

Nice sleuthing!

Committed to HEAD. Thanks!

sun’s picture

Status: Fixed » Needs work

mmm, neither previous HEAD nor current HEAD are correct.

For #type radios, :name needs to be just $type (current), but
for #type checkboxes, :name needs to be $type . [foo] (previous)

Effectively, the wrapping foreach is wrong and both types need to be tested separately.

Stevel’s picture

Current HEAD does not search for the name attribute but uses the id attribute instead.

What is wrong with searching for the id edit-$type-foo? This is valid for both checkboxes and radios, and seems the only way to find the relevant radio element anyway.

Mark Trapp’s picture

Status: Needs work » Needs review

Current HEAD is correct: if the name attribute were just "radios", it'd match on both radio groups present on the page instead of the one with the custom description (see markup below). Using id instead of name allows the test to target just the radio element with the custom description, as it does with the checkboxes.

<!-- ... -->
<div class="form-item form-type-checkbox form-item-checkboxes-foo">
  <input type="checkbox" id="edit-checkboxes-foo" name="checkboxes[foo]" value="foo" class="form-checkbox"> <label class="option" for="edit-checkboxes-foo">Foo</label>
  <div class="description">
    Enable to foo.
  </div>
</div>
<div class="form-item form-type-checkbox form-item-checkboxes-bar">
  <input type="checkbox" id="edit-checkboxes-bar" name="checkboxes[bar]" value="bar" class="form-checkbox"> <label class="option" for="edit-checkboxes-bar">Bar</label>
</div>
<div class="form-item form-type-checkbox form-item-checkboxes-1">
  <input type="checkbox" id="edit-checkboxes-1" name="checkboxes[1]" value="1" class="form-checkbox"> <label class="option" for="edit-checkboxes-1">One</label>
</div>
<div class="form-item form-type-radios form-item-radios">
  <label for="edit-radios">Radios</label>
  <div id="edit-radios" class="form-radios">
    <div class="form-item form-type-radio form-item-radios">
      <input type="radio" id="edit-radios-0" name="radios" value="0" class="form-radio"> <label class="option" for="edit-radios-0">Zero</label>
    </div>
    <div class="form-item form-type-radio form-item-radios">
      <input type="radio" id="edit-radios-foo" name="radios" value="foo" class="form-radio"> <label class="option" for="edit-radios-foo">Foo</label>
      <div class="description">
        Enable to foo.
      </div>
    </div>
    <div class="form-item form-type-radio form-item-radios">
      <input type="radio" id="edit-radios-bar" name="radios" value="bar" class="form-radio"> <label class="option" for="edit-radios-bar">Bar</label>
    </div>
    <div class="form-item form-type-radio form-item-radios">
      <input type="radio" id="edit-radios-1" name="radios" value="1" class="form-radio"> <label class="option" for="edit-radios-1">One</label>
<!-- ... -->
sun’s picture

Status: Needs review » Fixed

ok, could have used an inline code comment, but I understand how it's able to work now, thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.