diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index 71e008b..7d80e37 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -655,13 +655,13 @@ public function grabFromCurrentUrl(string $uri = null): mixed public function seeCheckboxIsChecked($checkbox): void { $checkboxes = $this->getFieldsByLabelOrCss($checkbox); - $this->assertDomContains($checkboxes->filter('input[checked=checked]'), 'checkbox'); + $this->assertGreaterThan(0, $checkboxes->filter('input[checked]')->count()); } public function dontSeeCheckboxIsChecked($checkbox): void { $checkboxes = $this->getFieldsByLabelOrCss($checkbox); - $this->assertSame(0, $checkboxes->filter('input[checked=checked]')->count()); + $this->assertSame(0, $checkboxes->filter('input[checked]')->count()); } public function seeInField($field, $value): void diff --git a/tests/data/app/view/form/checkbox_checked.php b/tests/data/app/view/form/checkbox_checked.php new file mode 100755 index 0000000..082a567 --- /dev/null +++ b/tests/data/app/view/form/checkbox_checked.php @@ -0,0 +1,6 @@ + +
+ + + + diff --git a/tests/unit/Codeception/Module/TestsForWeb.php b/tests/unit/Codeception/Module/TestsForWeb.php index 0bab4ad..10a3868 100644 --- a/tests/unit/Codeception/Module/TestsForWeb.php +++ b/tests/unit/Codeception/Module/TestsForWeb.php @@ -7,6 +7,7 @@ use Codeception\Lib\Framework; use Codeception\Test\Unit; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\ExpectationFailedException; /** * Author: davert @@ -480,22 +481,36 @@ public function testFileFieldByLabel() $this->assertNotEmpty(data::get('files')); } - public function testSeeCheckboxIsNotChecked() - { - $this->module->amOnPage('/form/checkbox'); - $this->module->dontSeeCheckboxIsChecked('#checkin'); - $this->module->dontSeeCheckboxIsChecked(['css' => '#checkin']); - $this->module->dontSeeCheckboxIsChecked('I Agree'); + public function checkBoxes(): iterable { + yield ['/form/checkbox_checked', ['css' => "#checkedbox1"], true]; + yield ['/form/checkbox_checked', ['css' => "#checkedbox2"], true]; + yield ['/form/checkbox', '#checkin', false]; + yield ['/form/checkbox', ['css' => '#checkin'], false]; + yield ['/form/checkbox', 'I Agree', false]; + yield ['/info', 'input[type=checkbox]', true]; + yield ['/info', ['css' => 'input[type=checkbox]'], true]; + yield ['/info', 'Checked', true]; } - public function testSeeCheckboxChecked() + #[\Codeception\Attribute\DataProvider('checkBoxes')] + public function testSeeCheckboxIsNotChecked(string $page, string|array $selector, bool $checked): void { - $this->module->amOnPage('/info'); - $this->module->seeCheckboxIsChecked('input[type=checkbox]'); - $this->module->seeCheckboxIsChecked(['css' => 'input[type=checkbox]']); - $this->module->seeCheckboxIsChecked('Checked'); + $this->module->amOnPage($page); + if ($checked) { + $this->expectException(ExpectationFailedException::class); + } + $this->module->dontSeeCheckboxIsChecked($selector); } + #[\Codeception\Attribute\DataProvider('checkBoxes')] + public function testSeeCheckboxIsChecked(string $page, string|array $selector, bool $checked): void + { + $this->module->amOnPage($page); + if (!$checked) { + $this->expectException(ExpectationFailedException::class); + } + $this->module->seeCheckboxIsChecked($selector); + } public function testSeeWithNonLatin() { $this->module->amOnPage('/info');