Browse Source

Test fails because of PHP bug

wrapper-classes
Dustin Wilson 3 years ago
parent
commit
aabd3a304d
  1. 8
      lib/Document.php
  2. 5
      tests/cases/TestElement.php
  3. 27
      tests/cases/TestTokenList.php
  4. 1
      tests/phpunit.dist.xml

8
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: # The createAttribute(localName) method steps are:
# 1. If localName does not match the Name production in XML, then throw an # 1. If localName does not match the Name production in XML, then throw an
# "InvalidCharacterError" DOMException. # "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 // 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. // some characters. We have to coerce them sometimes.
try { try {
return parent::createAttributeNS(null, $localName); return @parent::createAttributeNS(null, $localName);
} catch (\DOMException $e) { } catch (\DOMException $e) {
// The element name is invalid for XML // The element name is invalid for XML
// Replace any offending characters with "UHHHHHH" where H are the // Replace any offending characters with "UHHHHHH" where H are the
// uppercase hexadecimal digits of the character's code point // 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 // 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 // this library supports PHP 7.4 we cannot denote this in the method's
// signature. // signature.
return parent::createAttributeNS($namespace, $qualifiedName); return @parent::createAttributeNS($namespace, $qualifiedName);
} }
} }

5
tests/cases/TestElement.php

@ -10,10 +10,7 @@ namespace MensBeam\HTML\DOM\TestCase;
use MensBeam\HTML\DOM\{ use MensBeam\HTML\DOM\{
Document, Document,
DOMException, DOMException
Element,
ElementMap,
HTMLTemplateElement
}; };
use MensBeam\HTML\Parser; use MensBeam\HTML\Parser;

27
tests/cases/TestTokenList.php

@ -0,0 +1,27 @@
<?php
/**
* @license MIT
* Copyright 2017, Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details
*/
declare(strict_types=1);
namespace MensBeam\HTML\DOM\TestCase;
use MensBeam\HTML\DOM\{
Document,
DOMException
};
use MensBeam\HTML\Parser;
/** @covers \MensBeam\HTML\DOM\TokenList */
class TestTokenList extends \PHPUnit\Framework\TestCase {
/** @covers \MensBeam\HTML\DOM\TokenList::__get_length */
public function testPropertyGetLength(): void {
$d = new Document();
$e = $d->createElement('html');
$e->classList->add('ook', 'eek', 'ack', 'ookeek');
$this->assertSame(4, $e->classList->length);
}
}

1
tests/phpunit.dist.xml

@ -26,6 +26,7 @@
<file>cases/TestMoonwalk.php</file> <file>cases/TestMoonwalk.php</file>
<file>cases/TestNode.php</file> <file>cases/TestNode.php</file>
<file>cases/TestParentNode.php</file> <file>cases/TestParentNode.php</file>
<file>cases/TestTokenList.php</file>
<file>cases/TestWalk.php</file> <file>cases/TestWalk.php</file>
</testsuite> </testsuite>
<testsuite name="Serializer"> <testsuite name="Serializer">

Loading…
Cancel
Save