Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2, 8.3]
php: [8.0, 8.1, 8.2, 8.3, 8.4, 8.5]
dependency-version: [prefer-lowest, prefer-stable]

steps:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Requirements and Compatibility

Version 3.x:
- PHP 8.x
- [Symfony\Components\DomCrawler](https://github.com/symfony/DomCrawler) 6.x | 7.x
- [Symfony\Components\CssSelector](https://github.com/symfony/CssSelector) 6.x | 7.x
- [Symfony\Components\DomCrawler](https://github.com/symfony/DomCrawler) 6.x | 7.x | 8.x
- [Symfony\Components\CssSelector](https://github.com/symfony/CssSelector) 6.x | 7.x | 8.x

Version 2.x:
- PHP ^7.4 | 8.x
Expand Down
30 changes: 21 additions & 9 deletions Tests/HtmlPageCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,23 @@ public function testClasses()
public function testAddContent()
{
$c = new HtmlPageCrawler();
$c->addContent('<html><body><div id="content"><h1>Title</h1></div></body>');
$c->addContent('<html><head></head><body><div id="content"><h1>Title</h1></div></body>');

// The behaviour of Symfony's \Symfony\Component\DomCrawler\Crawler varies based on Symfony version and PHP Version.
// So for this test, we normalize the output.

$html = $c->saveHTML();

// Old parser (PHP < 8.4) or old Symfony: remove added HTML 4.0 DOCTYPE at the beginning of the html
$html = preg_replace('#^\s*<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">\s*#', '', $html);

// Remove XML encoding declaration added by Symfony's UTF-8 handling (varies by Symfony version)
$html = preg_replace('#^\s*<\?xml encoding="UTF-8">\s*#', '', $html);
$html = $this->_ignoreNewlines($html);

$this->assertEquals(
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">'
. "" . '<html><body><div id="content"><h1>Title</h1></div></body></html>' . "",
$this->_ignoreNewlines($c->saveHTML())
'<html><head></head><body><div id="content"><h1>Title</h1></div></body></html>',
$html
);

$c = new HtmlPageCrawler();
Expand Down Expand Up @@ -442,12 +454,12 @@ public function testUnwrap()
$p->unwrap();
$this->assertEquals('<div id="content"><div>Before</div><p>Absatz 1</p><div>After</div></div>', $c->saveHTML());
}
public function testUnwrapInnerOnDOMElementExeption()

public function testUnwrapInnerOnDOMElementException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectErrorMessage('DOMElement does not have a parent DOMElement node.');
$this->expectExceptionMessage('DOMElement does not have a parent DOMElement node.');

$c = HtmlPageCrawler::create('<div id="content"></div>');
$p = $c->filter('div#content');
$p->unwrapInner();
Expand Down Expand Up @@ -565,7 +577,7 @@ public function testAttr()
$this->assertNull($c->attr('data-foo'));

}

public function testAttrOnInvalidNodeList()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"ext-dom":"*",
"ext-libxml":"*",
"symfony/polyfill-mbstring": "~1.0",
"symfony/dom-crawler":"^6.0 || ^7.0",
"symfony/css-selector":"^6.0 || ^7.0"
"symfony/dom-crawler":"^6.0 || ^7.0 || ^8.0",
"symfony/css-selector":"^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9",
Expand Down