Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've been trying to test if checkbox is checked using assertFieldByXPath and looks like it is impossible to use the assertFieldBy... methods for this. When I'm trying to use 0 value for assertion - assertFieldByXPath just skips the whole checking for value b/c of "if ($value)".
I'm using this code in my test:
$this->assertFieldById('checkbox-id', 0, 'Checkbox is not selected');
I wonder if I'm doing something wrong?
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#7 | assert-field-checked.patch | 3.91 KB | boombatower |
#6 | assert-field-checked.patch | 3.91 KB | boombatower |
#5 | assert-field-checked.patch | 4.27 KB | dropcube |
Comments
Comment #1
boombatower CreditAttribution: boombatower commentedSounds like assertFieldBy... needs to do something better like != NULL.
That should be fixed in D7 core and backported.
Comment #3
dropcube CreditAttribution: dropcube commentedassertFieldBy* checks for the value attribute, but there is no way to check if a checkbox is checked.
Comment #4
boombatower CreditAttribution: boombatower commentedI'll take a look at this.
Comment #5
dropcube CreditAttribution: dropcube commentedAttached a patch that adds
assertFieldChecked()
andassertNoFieldChecked()
to DrupalWebTestCase. The new methods are used in locale.test, where the same xpath approach is being used.Comment #6
boombatower CreditAttribution: boombatower commentedLooks good, re-rolled without Eclipse stuff.
Comment #7
boombatower CreditAttribution: boombatower commentedExtra space after one of the parameters.
Comment #8
webchickWell that's much nicer!
Committed to HEAD.