Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01409a5

Browse filesBrowse files
bug #47946 [FrameworkBundle] Fix checkboxes check assertions (MatTheCat)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Fix checkboxes check assertions | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47830 | License | MIT | Doc PR | N/A The CssSelector component knows better about the `checked` state! Commits ------- aace858 [FrameworkBundle] Fix checkboxes check assertions
2 parents 089ec9d + aace858 commit 01409a5
Copy full SHA for 01409a5

File tree

2 files changed

+6
-11
lines changed
Filter options

2 files changed

+6
-11
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Test/DomCrawlerAssertionsTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Test/DomCrawlerAssertionsTrait.php
+2-9Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPUnit\Framework\Constraint\LogicalNot;
1616
use Symfony\Component\DomCrawler\Crawler;
1717
use Symfony\Component\DomCrawler\Test\Constraint as DomCrawlerConstraint;
18-
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorAttributeValueSame;
1918
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorExists;
2019

2120
/**
@@ -87,18 +86,12 @@ public static function assertInputValueNotSame(string $fieldName, string $expect
8786

8887
public static function assertCheckboxChecked(string $fieldName, string $message = ''): void
8988
{
90-
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
91-
new CrawlerSelectorExists("input[name=\"$fieldName\"]"),
92-
new CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'checked', 'checked')
93-
), $message);
89+
self::assertThat(self::getCrawler(), new CrawlerSelectorExists("input[name=\"$fieldName\"]:checked"), $message);
9490
}
9591

9692
public static function assertCheckboxNotChecked(string $fieldName, string $message = ''): void
9793
{
98-
self::assertThat(self::getCrawler(), LogicalAnd::fromConstraints(
99-
new CrawlerSelectorExists("input[name=\"$fieldName\"]"),
100-
new LogicalNot(new CrawlerSelectorAttributeValueSame("input[name=\"$fieldName\"]", 'checked', 'checked'))
101-
), $message);
94+
self::assertThat(self::getCrawler(), new LogicalNot(new CrawlerSelectorExists("input[name=\"$fieldName\"]:checked")), $message);
10295
}
10396

10497
public static function assertFormValue(string $formSelector, string $fieldName, string $value, string $message = ''): void

‎src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,18 @@ public function testAssertInputValueNotSame()
238238
public function testAssertCheckboxChecked()
239239
{
240240
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
241+
$this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
241242
$this->expectException(AssertionFailedError::class);
242-
$this->expectExceptionMessage('matches selector "input[name="rememberMe"]" and has a node matching selector "input[name="rememberMe"]" with attribute "checked" of value "checked".');
243+
$this->expectExceptionMessage('matches selector "input[name="rememberMe"]:checked".');
243244
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxChecked('rememberMe');
244245
}
245246

246247
public function testAssertCheckboxNotChecked()
247248
{
248249
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
250+
$this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
249251
$this->expectException(AssertionFailedError::class);
250-
$this->expectExceptionMessage('matches selector "input[name="rememberMe"]" and does not have a node matching selector "input[name="rememberMe"]" with attribute "checked" of value "checked".');
252+
$this->expectExceptionMessage('does not match selector "input[name="rememberMe"]:checked".');
251253
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxNotChecked('rememberMe');
252254
}
253255

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.