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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

boombatower’s picture

Project: SimpleTest » Drupal core
Version: 6.x-2.5 » 7.x-dev
Component: Code » simpletest.module
Category: support » bug
Priority: Minor » Normal

Sounds like assertFieldBy... needs to do something better like != NULL.

That should be fixed in D7 core and backported.

dropcube’s picture

Title: How to use assertFieldByXPath » How to assert if a checkbox is checked ?

assertFieldBy* checks for the value attribute, but there is no way to check if a checkbox is checked.

boombatower’s picture

Assigned: Unassigned » boombatower

I'll take a look at this.

dropcube’s picture

Title: How to assert if a checkbox is checked ? » Assert if a checkbox is checked
Category: bug » feature
Status: Active » Needs review
FileSize
4.27 KB

Attached a patch that adds assertFieldChecked() and assertNoFieldChecked() to DrupalWebTestCase. The new methods are used in locale.test, where the same xpath approach is being used.

boombatower’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
3.91 KB

Looks good, re-rolled without Eclipse stuff.

boombatower’s picture

FileSize
3.91 KB

Extra space after one of the parameters.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Well that's much nicer!

Committed to HEAD.

Status: Fixed » Closed (fixed)

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