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:
# 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);
}
}

5
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;

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/TestNode.php</file>
<file>cases/TestParentNode.php</file>
<file>cases/TestTokenList.php</file>
<file>cases/TestWalk.php</file>
</testsuite>
<testsuite name="Serializer">

Loading…
Cancel
Save