Browse Source

More testing, forever testing

master
Dustin Wilson 3 years ago
parent
commit
1cd73a1479
  1. 4
      composer.lock
  2. 2
      lib/DOMImplementation.php
  3. 1
      lib/Document.php
  4. 48
      tests/cases/TestAttr.php
  5. 45
      tests/cases/TestInnerDocument.php
  6. 2
      tests/phpunit.dist.xml
  7. 24
      vendor-bin/phpunit/composer.lock

4
composer.lock

@ -63,7 +63,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "mensbeam-gitea:MensBeam/HTML-Parser.git", "url": "mensbeam-gitea:MensBeam/HTML-Parser.git",
"reference": "f33cc4344bf0138bed059af80cf896adcf4ee06d" "reference": "a8435f7c358faaf39f9a0daa7f7a331a3e7cffca"
}, },
"require": { "require": {
"ext-dom": "*", "ext-dom": "*",
@ -130,7 +130,7 @@
"parsing", "parsing",
"whatwg" "whatwg"
], ],
"time": "2021-11-29T18:54:16+00:00" "time": "2021-12-05T15:00:39+00:00"
}, },
{ {
"name": "mensbeam/intl", "name": "mensbeam/intl",

2
lib/DOMImplementation.php

@ -35,7 +35,7 @@ class DOMImplementation {
} }
public function createDocument(?string $namespace = null, string $qualifiedName, ?DocumentType $doctype = null): XMLDocument { public function createDocument(?string $namespace, string $qualifiedName, ?DocumentType $doctype = null): XMLDocument {
# The createDocument(namespace, qualifiedName, doctype) method steps are: # The createDocument(namespace, qualifiedName, doctype) method steps are:
# #
# 1. Let document be a new XMLDocument. # 1. Let document be a new XMLDocument.

1
lib/Document.php

@ -110,7 +110,6 @@ class Document extends Node implements \ArrayAccess {
foreach ($children as $child) { foreach ($children as $child) {
if ($child instanceof \DOMElement && $child->namespaceURI === null && $child->tagName === 'head') { if ($child instanceof \DOMElement && $child->namespaceURI === null && $child->tagName === 'head') {
return $this->innerNode->getWrapperNode($child); return $this->innerNode->getWrapperNode($child);
break;
} }
} }
} }

48
tests/cases/TestAttr.php

@ -0,0 +1,48 @@
<?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,
Node
};
/** @covers \MensBeam\HTML\DOM\Attr */
class TestAttr extends \PHPUnit\Framework\TestCase {
public function testProperty_name(): void {
$d = new Document('<!DOCTYPE html><html><body ook="ook" poop💩="poop💩"><svg id="eek"></svg></body></html>', 'utf-8');
$body = $d->body;
$svg = $d->getElementById('eek');
$svg->setAttributeNS(Node::XMLNS_NAMESPACE, 'xmlns:xlink', Node::XLINK_NAMESPACE);
// HTML name
$this->assertSame('ook', $body->getAttributeNode('ook')->name);
// Coerced name
$this->assertSame('poop💩', $body->getAttributeNode('poop💩')->name);
// Foreign attribute name
$this->assertSame('xlink', $svg->getAttributeNodeNS(Node::XMLNS_NAMESPACE, 'xlink')->name);
}
public function testProperty_prefix(): void {
$d = new Document('<!DOCTYPE html><html><body><svg id="eek"></svg></body></html>', 'utf-8');
$svg = $d->getElementById('eek');
$svg->setAttributeNS(Node::XMLNS_NAMESPACE, 'xmlns:xlink', Node::XLINK_NAMESPACE);
$svg->setAttributeNS('https://poop.poop', 'poop💩:poop💩', 'poop💩');
// Foreign attribute name
$this->assertSame('xmlns', $svg->getAttributeNodeNS(Node::XMLNS_NAMESPACE, 'xlink')->prefix);
$this->assertSame('poop💩', $svg->getAttributeNodeNS('https://poop.poop', 'poop💩')->prefix);
}
public function testProperty_specified(): void {
$d = new Document('<!DOCTYPE html><html><body ook="ook"></body></html>', 'utf-8');
$this->assertTrue($d->body->getAttributeNode('ook')->specified);
}
}

45
tests/cases/TestInnerDocument.php

@ -0,0 +1,45 @@
<?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,
HTMLElement,
HTMLPreElement,
HTMLUnknownElement
};
/** @covers \MensBeam\HTML\DOM\Inner\Document */
class TestInnerDocument extends \PHPUnit\Framework\TestCase {
/**
* @covers \MensBeam\HTML\DOM\Inner\Document::getWrapperNode
*
* @covers \MensBeam\HTML\DOM\Document::__construct
* @covers \MensBeam\HTML\DOM\Document::createElement
* @covers \MensBeam\HTML\DOM\DOMImplementation::__construct
* @covers \MensBeam\HTML\DOM\Element::__construct
* @covers \MensBeam\HTML\DOM\Node::__construct
* @covers \MensBeam\HTML\DOM\Inner\Document::__construct
* @covers \MensBeam\HTML\DOM\Inner\NodeCache::get
* @covers \MensBeam\HTML\DOM\Inner\NodeCache::has
* @covers \MensBeam\HTML\DOM\Inner\NodeCache::key
* @covers \MensBeam\HTML\DOM\Inner\NodeCache::set
* @covers \MensBeam\HTML\DOM\Inner\Reflection::createFromProtectedConstructor
*/
public function testMethod_getWrapperNode(): void {
// Everything tests this method thoroughly except some element interfaces.
$d = new Document();
$this->assertSame(HTMLUnknownElement::class, $d->createElement('applet')::class);
$this->assertSame(HTMLElement::class, $d->createElement('noembed')::class);
$this->assertSame(HTMLPreElement::class, $d->createElement('xmp')::class);
$this->assertSame(HTMLPreElement::class, $d->createElement('pre')::class);
$this->assertSame(HTMLElement::class, $d->createElement('p-icon')::class);
}
}

2
tests/phpunit.dist.xml

@ -16,11 +16,13 @@
</coverage> </coverage>
<testsuites> <testsuites>
<testsuite name="DOM"> <testsuite name="DOM">
<file>cases/TestAttr.php</file>
<file>cases/TestDocument.php</file> <file>cases/TestDocument.php</file>
<file>cases/TestDocumentOrElement.php</file> <file>cases/TestDocumentOrElement.php</file>
<file>cases/TestDOMImplementation.php</file> <file>cases/TestDOMImplementation.php</file>
<file>cases/TestDOMTokenList.php</file> <file>cases/TestDOMTokenList.php</file>
<file>cases/TestElement.php</file> <file>cases/TestElement.php</file>
<file>cases/TestInnerDocument.php</file>
<file>cases/TestNode.php</file> <file>cases/TestNode.php</file>
<file>cases/TestParentNode.php</file> <file>cases/TestParentNode.php</file>
</testsuite> </testsuite>

24
vendor-bin/phpunit/composer.lock

@ -529,16 +529,16 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "9.2.9", "version": "9.2.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b" "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f301eb1453c9e7a1bc912ee8b0ea9db22c60223b", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687",
"reference": "f301eb1453c9e7a1bc912ee8b0ea9db22c60223b", "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -594,7 +594,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.9" "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10"
}, },
"funding": [ "funding": [
{ {
@ -602,20 +602,20 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-11-19T15:21:02+00:00" "time": "2021-12-05T09:12:13+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
"version": "3.0.5", "version": "3.0.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
"reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -654,7 +654,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6"
}, },
"funding": [ "funding": [
{ {
@ -662,7 +662,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2020-09-28T05:57:25+00:00" "time": "2021-12-02T12:48:52+00:00"
}, },
{ {
"name": "phpunit/php-invoker", "name": "phpunit/php-invoker",

Loading…
Cancel
Save