Skip to content

[DomCrawler] Improve html5Parser tests #49669

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

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ public function testHtml5ParserNotSameAsNativeParserForSpecificHtml()
$this->assertNotEquals($nativeCrawler->filterXPath('//h1')->text(), $html5Crawler->filterXPath('//h1')->text(), 'Native parser and Html5 parser must be different');
}
Comment on lines 60 to 61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this prior test (testHtml5ParserNotSameAsNativeParserForSpecificHtml) be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's not a perfect test but it still validating a certain behaviour of the domCrawler component and can be interesting to keep ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test case is useful to me, it tests the behavior and that's what we need also.
If the behavior of the xml parser changes, we'll know also, and this is good.


/**
* @testWith [true]
* [false]
*/
public function testHasHtml5Parser(bool $useHtml5Parser)
{
$crawler = $this->createCrawler(null, null, null, $useHtml5Parser);

$r = new \ReflectionProperty($crawler::class, 'html5Parser');
$html5Parser = $r->getValue($crawler);

if ($useHtml5Parser) {
$this->assertInstanceOf(\Masterminds\HTML5::class, $html5Parser, 'Html5Parser must be a Masterminds\HTML5 instance');
} else {
$this->assertNull($html5Parser, 'Html5Parser must be null');
}
}

public static function validHtml5Provider(): iterable
{
$html = self::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
Expand Down