Skip to content

Commit 8b2ee2e

Browse files
Merge branch '7.2' into 7.3
* 7.2: Fix-type-error-when-revealing-broken-secret fix compatibility with Relay 0.11 [Security] Handle non-callable implementations of `FirewallListenerInterface` [DomCrawler] Allow selecting `button`s by their `value` flip excluded properties with keys with Doctrine-style constraint config
2 parents 0fabbc3 + a747376 commit 8b2ee2e

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Crawler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,12 @@ public function selectImage(string $value): static
747747
}
748748

749749
/**
750-
* Selects a button by name or alt value for images.
750+
* Selects a button by its text content, id, value, name or alt attribute.
751751
*/
752752
public function selectButton(string $value): static
753753
{
754754
return $this->filterRelativeXPath(
755-
\sprintf('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
755+
\sprintf('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
756756
);
757757
}
758758

Tests/AbstractCrawlerTestCase.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ public function testFilterXpathComplexQueries()
452452
$this->assertCount(0, $crawler->filterXPath('/body'));
453453
$this->assertCount(1, $crawler->filterXPath('./body'));
454454
$this->assertCount(1, $crawler->filterXPath('.//body'));
455-
$this->assertCount(5, $crawler->filterXPath('.//input'));
455+
$this->assertCount(6, $crawler->filterXPath('.//input'));
456456
$this->assertCount(4, $crawler->filterXPath('//form')->filterXPath('//button | //input'));
457457
$this->assertCount(1, $crawler->filterXPath('body'));
458-
$this->assertCount(6, $crawler->filterXPath('//button | //input'));
458+
$this->assertCount(8, $crawler->filterXPath('//button | //input'));
459459
$this->assertCount(1, $crawler->filterXPath('//body'));
460460
$this->assertCount(1, $crawler->filterXPath('descendant-or-self::body'));
461461
$this->assertCount(1, $crawler->filterXPath('//div[@id="parent"]')->filterXPath('./div'), 'A child selection finds only the current div');
@@ -723,16 +723,23 @@ public function testSelectButton()
723723
$this->assertNotSame($crawler, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
724724
$this->assertInstanceOf(Crawler::class, $crawler->selectButton('FooValue'), '->selectButton() returns a new instance of a crawler');
725725

726-
$this->assertEquals(1, $crawler->selectButton('FooValue')->count(), '->selectButton() selects buttons');
727-
$this->assertEquals(1, $crawler->selectButton('FooName')->count(), '->selectButton() selects buttons');
728-
$this->assertEquals(1, $crawler->selectButton('FooId')->count(), '->selectButton() selects buttons');
726+
$this->assertCount(1, $crawler->selectButton('FooValue'), '->selectButton() selects type-submit inputs by value');
727+
$this->assertCount(1, $crawler->selectButton('FooName'), '->selectButton() selects type-submit inputs by name');
728+
$this->assertCount(1, $crawler->selectButton('FooId'), '->selectButton() selects type-submit inputs by id');
729729

730-
$this->assertEquals(1, $crawler->selectButton('BarValue')->count(), '->selectButton() selects buttons');
731-
$this->assertEquals(1, $crawler->selectButton('BarName')->count(), '->selectButton() selects buttons');
732-
$this->assertEquals(1, $crawler->selectButton('BarId')->count(), '->selectButton() selects buttons');
730+
$this->assertCount(1, $crawler->selectButton('BarValue'), '->selectButton() selects type-button inputs by value');
731+
$this->assertCount(1, $crawler->selectButton('BarName'), '->selectButton() selects type-button inputs by name');
732+
$this->assertCount(1, $crawler->selectButton('BarId'), '->selectButton() selects type-button inputs by id');
733733

734-
$this->assertEquals(1, $crawler->selectButton('FooBarValue')->count(), '->selectButton() selects buttons with form attribute too');
735-
$this->assertEquals(1, $crawler->selectButton('FooBarName')->count(), '->selectButton() selects buttons with form attribute too');
734+
$this->assertCount(1, $crawler->selectButton('ImageAlt'), '->selectButton() selects type-image inputs by alt');
735+
736+
$this->assertCount(1, $crawler->selectButton('ButtonValue'), '->selectButton() selects buttons by value');
737+
$this->assertCount(1, $crawler->selectButton('ButtonName'), '->selectButton() selects buttons by name');
738+
$this->assertCount(1, $crawler->selectButton('ButtonId'), '->selectButton() selects buttons by id');
739+
$this->assertCount(1, $crawler->selectButton('ButtonText'), '->selectButton() selects buttons by text content');
740+
741+
$this->assertCount(1, $crawler->selectButton('FooBarValue'), '->selectButton() selects buttons with form attribute too');
742+
$this->assertCount(1, $crawler->selectButton('FooBarName'), '->selectButton() selects buttons with form attribute too');
736743
}
737744

738745
public function testSelectButtonWithSingleQuotesInNameAttribute()
@@ -1322,6 +1329,9 @@ public function createTestCrawler($uri = null)
13221329
<input type="submit" value="FooBarValue" name="FooBarName" form="FooFormId" />
13231330
<input type="text" value="FooTextValue" name="FooTextName" form="FooFormId" />
13241331
1332+
<input type="image" alt="ImageAlt" form="FooFormId">
1333+
<button form="FooFormId">ButtonText</button>
1334+
13251335
<ul class="first">
13261336
<li class="first">One</li>
13271337
<li>Two</li>

0 commit comments

Comments
 (0)