Skip to content

Commit 251cd69

Browse files
committed
Fix tests
1 parent 78e1d0f commit 251cd69

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/Support/Helper/WPWidget.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,21 @@ public function addBlockWidget($I, $blockName, $blockProgrammaticName, $blockCon
143143
$I->selectOption($fieldID, $attributes[1]);
144144
break;
145145
case 'toggle':
146-
$I->click($field);
146+
// The block editor doesn't use the field ID, so we need to find the field by the label.
147+
$field = "//label[normalize-space(text())='" . $field . "']/preceding-sibling::span/input";
148+
149+
// Determine if the toggle has checked the checkbox.
150+
$isChecked = $I->grabAttributeFrom($field, 'checked');
151+
152+
// If the attribute is true, and the checkbox is not checked, click the toggle to check it.
153+
if ( $attributes[1] && ! $isChecked ) {
154+
$I->click($field);
155+
}
156+
157+
// If the attribute is false, and the checkbox is checked, click the toggle to uncheck it.
158+
if ( ! $attributes[1] && $isChecked ) {
159+
$I->click($field);
160+
}
147161
break;
148162
default:
149163
$I->fillField($fieldID, $attributes[1]);

0 commit comments

Comments
 (0)