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

[DomCrawler] Change ->text() , ->html() and ->attr() methods to retur… #28614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[DomCrawler] Change ->text() , ->html() and ->attr() methods to retur…
…n null if node list is empty
  • Loading branch information
rajaamerkhan committed Sep 26, 2018
commit b0e20bcc2b7b63b6c654d0253f6f7004280c973e
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function testReduce()
public function testAttr()
{
$this->assertEquals('first', $this->createTestCrawler()->filterXPath('//li')->attr('class'), '->attr() returns the attribute of the first element of the node list');
$this->assertEquals(null, $this->createTestCrawler()->filterXPath('//ol')->attr('class'), '->attr() returns null if the node list is empty');
$this->assertNull($this->createTestCrawler()->filterXPath('//ol')->attr('class'), '->attr() returns null if the node list is empty');
}

public function testMissingAttrValueIsNull()
Expand Down Expand Up @@ -379,14 +379,14 @@ public function testNodeName()
public function testText()
{
$this->assertEquals('One', $this->createTestCrawler()->filterXPath('//li')->text(), '->text() returns the node value of the first element of the node list');
$this->assertEquals(null, $this->createTestCrawler()->filterXPath('//ol')->text(), '->text() returns null if the node list is empty');
$this->assertNull($this->createTestCrawler()->filterXPath('//ol')->text(), '->text() returns null if the node list is empty');
}

public function testHtml()
{
$this->assertEquals('<img alt="Bar">', $this->createTestCrawler()->filterXPath('//a[5]')->html());
$this->assertEquals('<input type="text" value="TextValue" name="TextName"><input type="submit" value="FooValue" name="FooName" id="FooId"><input type="button" value="BarValue" name="BarName" id="BarId"><button value="ButtonValue" name="ButtonName" id="ButtonId"></button>', trim(preg_replace('~>\s+<~', '><', $this->createTestCrawler()->filterXPath('//form[@id="FooFormId"]')->html())));
$this->assertEquals(null, $this->createTestCrawler()->filterXPath('//ol')->html(), '->html() returns null if the node list is empty');
$this->assertNull($this->createTestCrawler()->filterXPath('//ol')->html(), '->html() returns null if the node list is empty');
}

public function testExtract()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.