From aabd3a304dfd546cd890e448a1f7a250a6abf480 Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Tue, 12 Oct 2021 16:54:39 -0500 Subject: [PATCH] Test fails because of PHP bug --- lib/Document.php | 8 ++++---- tests/cases/TestElement.php | 5 +---- tests/cases/TestTokenList.php | 27 +++++++++++++++++++++++++++ tests/phpunit.dist.xml | 1 + 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 tests/cases/TestTokenList.php diff --git a/lib/Document.php b/lib/Document.php index 4de248b..bcc3dc2 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -156,7 +156,7 @@ class Document extends \DOMDocument { } - public function createAttribute($localName): \DOMAttr { + public function createAttribute($localName) { # The createAttribute(localName) method steps are: # 1. If localName does not match the Name production in XML, then throw an # "InvalidCharacterError" DOMException. @@ -174,12 +174,12 @@ class Document extends \DOMDocument { // We need to do a couple more things here. PHP's XML-based DOM doesn't allow // some characters. We have to coerce them sometimes. try { - return parent::createAttributeNS(null, $localName); + return @parent::createAttributeNS(null, $localName); } catch (\DOMException $e) { // The element name is invalid for XML // Replace any offending characters with "UHHHHHH" where H are the // uppercase hexadecimal digits of the character's code point - return parent::createAttributeNS(null, $this->coerceName($localName)); + return @parent::createAttributeNS(null, $this->coerceName($localName)); } } @@ -210,7 +210,7 @@ class Document extends \DOMDocument { // way to avoid this other than allowing this method to return Attr|false. Since // this library supports PHP 7.4 we cannot denote this in the method's // signature. - return parent::createAttributeNS($namespace, $qualifiedName); + return @parent::createAttributeNS($namespace, $qualifiedName); } } diff --git a/tests/cases/TestElement.php b/tests/cases/TestElement.php index d4c09de..8d3aaff 100644 --- a/tests/cases/TestElement.php +++ b/tests/cases/TestElement.php @@ -10,10 +10,7 @@ namespace MensBeam\HTML\DOM\TestCase; use MensBeam\HTML\DOM\{ Document, - DOMException, - Element, - ElementMap, - HTMLTemplateElement + DOMException }; use MensBeam\HTML\Parser; diff --git a/tests/cases/TestTokenList.php b/tests/cases/TestTokenList.php new file mode 100644 index 0000000..e7bad27 --- /dev/null +++ b/tests/cases/TestTokenList.php @@ -0,0 +1,27 @@ +createElement('html'); + $e->classList->add('ook', 'eek', 'ack', 'ookeek'); + $this->assertSame(4, $e->classList->length); + } +} \ No newline at end of file diff --git a/tests/phpunit.dist.xml b/tests/phpunit.dist.xml index f3c89ba..5713573 100644 --- a/tests/phpunit.dist.xml +++ b/tests/phpunit.dist.xml @@ -26,6 +26,7 @@ cases/TestMoonwalk.php cases/TestNode.php cases/TestParentNode.php + cases/TestTokenList.php cases/TestWalk.php