Skip to content

Commit c878cb8

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Serializer] Save missing arguments in MissingConstructorArgumentsException remove support for deprecated "threadKey" parameter Remove useless comment in test [DomCrawler] Added Crawler::innerText() method [Form] Add the EnumType Fix iterrator in ServiceConfigurator [Console] Add support of RGB functional notation for output colors Add Slovak lang translation #41081 [Validator] Add error's uid to `Count` and `Length` constraints with "exactly" option enabled [Validator] Add missing thai translation [Yaml] Add 0 to float repr [Translation] Add Burmese translation [Notifier] Update FirebaseTransport.php fix: #43086 remove shortcut e for option exclude of Yaml/LintCommand - solve conflict with --env -e Map `multipart/form-data` as `form` Content-Type [Serializer] Throw NotNormalizableValueException when type is not known or not in body in discriminator map [Yaml] Use more concise float representation in dump [FrameworkBundle] Remove translation data_collector BEFORE adding it to profiler
2 parents df890f9 + 6496a56 commit c878cb8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ CHANGELOG
66

77
* Remove `Crawler::parents()` method, use `ancestors()` instead
88

9+
5.4
10+
---
11+
12+
* Add `Crawler::innerText` method.
13+
914
5.3
1015
---
1116

Crawler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ public function text(string $default = null, bool $normalizeWhitespace = true):
566566
return $text;
567567
}
568568

569+
/**
570+
* Returns only the inner text that is the direct descendent of the current node, excluding any child nodes.
571+
*/
572+
public function innerText(): string
573+
{
574+
return $this->filterXPath('.//text()')->text();
575+
}
576+
569577
/**
570578
* Returns the first node of the list as HTML.
571579
*

Tests/AbstractCrawlerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ public function testText()
344344
$this->assertSame('my value', $this->createTestCrawler(null)->filterXPath('//ol')->text('my value'));
345345
}
346346

347+
public function testInnerText()
348+
{
349+
self::assertCount(1, $crawler = $this->createTestCrawler()->filterXPath('//*[@id="complex-element"]'));
350+
351+
self::assertSame('Parent text Child text', $crawler->text());
352+
self::assertSame('Parent text', $crawler->innerText());
353+
}
354+
347355
public function testHtml()
348356
{
349357
$this->assertEquals('<img alt="Bar">', $this->createTestCrawler()->filterXPath('//a[5]')->html());
@@ -1248,6 +1256,10 @@ public function createTestCrawler($uri = null)
12481256
<div id="child2" xmlns:foo="http://example.com"></div>
12491257
</div>
12501258
<div id="sibling"><img /></div>
1259+
<div id="complex-element">
1260+
Parent text
1261+
<span>Child text</span>
1262+
</div>
12511263
</body>
12521264
</html>
12531265
');

0 commit comments

Comments
 (0)