diff --git a/composer.json b/composer.json
index 41e9976..cb1f0ca 100644
--- a/composer.json
+++ b/composer.json
@@ -46,5 +46,11 @@
"bamarni/composer-bin-plugin": "^1.3",
"daux/daux.io": "^0.16.0",
"mikey179/vfsstream": "^1.6"
- }
+ },
+ "repositories": [
+ {
+ "type": "git",
+ "url": "mensbeam-gitea:MensBeam/HTML-Parser.git"
+ }
+ ]
}
diff --git a/composer.lock b/composer.lock
index af9ea42..79e761c 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,15 +4,15 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "c5d8046a2bc8743cc92add9484f3380f",
+ "content-hash": "3371a9b669d02688e062be96d83f1eff",
"packages": [
{
"name": "mensbeam/html-parser",
"version": "dev-master",
"source": {
"type": "git",
- "url": "https://code.mensbeam.com/MensBeam/HTML-Parser",
- "reference": "49764a456743ac69074b4f64619cf87af254c071"
+ "url": "mensbeam-gitea:MensBeam/HTML-Parser.git",
+ "reference": "29127c51ee3b127fb607df4f5518920046df9704"
},
"require": {
"ext-dom": "*",
@@ -42,7 +42,20 @@
"lib/Parser/ctype.php"
]
},
- "notification-url": "https://packagist.org/downloads/",
+ "autoload-dev": {
+ "psr-4": {
+ "MensBeam\\HTML\\Test\\": "tests/lib/",
+ "MensBeam\\HTML\\TestCase\\": "tests/cases/"
+ }
+ },
+ "scripts": {
+ "post-install-cmd": [
+ "@composer bin all install"
+ ],
+ "post-update-cmd": [
+ "@composer bin all update"
+ ]
+ },
"license": [
"MIT"
],
@@ -59,7 +72,7 @@
}
],
"description": "Parses modern HTML text into a PHP DOMDocument",
- "time": "2021-09-28T20:15:07+00:00"
+ "time": "2021-10-09T03:23:33+00:00"
},
{
"name": "mensbeam/intl",
diff --git a/lib/Document.php b/lib/Document.php
index 3cd7649..d343a0e 100644
--- a/lib/Document.php
+++ b/lib/Document.php
@@ -67,7 +67,7 @@ class Document extends \DOMDocument {
return null;
}
- protected function __set_body(?\DOMNode $value) {
+ protected function __set_body(\DOMNode $value) {
# On setting, the following algorithm must be run:
#
# 1. If the new value is not a body or frameset element, then throw a
diff --git a/lib/traits/Node.php b/lib/traits/Node.php
index 7548579..2498106 100644
--- a/lib/traits/Node.php
+++ b/lib/traits/Node.php
@@ -14,12 +14,12 @@ namespace MensBeam\HTML\DOM;
trait Node {
// Disable C14N
public function C14N($exclusive = null, $with_comments = null, ?array $xpath = null, ?array $ns_prefixes = null): bool {
- return false;
+ throw new DOMException(DOMException::NOT_SUPPORTED, __CLASS__ . ' is meant for XML and buggy; use Document::saveHTML or cast to a string');
}
// Disable C14NFile
public function C14NFile($uri, $exclusive = null, $with_comments = null, ?array $xpath = null, ?array $ns_prefixes = null): bool {
- return false;
+ throw new DOMException(DOMException::NOT_SUPPORTED, __CLASS__ . ' is meant for XML and buggy; use Document::saveHTMLFile');
}
public function getRootNode(): ?\DOMNode {
diff --git a/tests/cases/TestChildNode.php b/tests/cases/TestChildNode.php
index 994ee87..68ca69a 100644
--- a/tests/cases/TestChildNode.php
+++ b/tests/cases/TestChildNode.php
@@ -13,7 +13,10 @@ use MensBeam\HTML\DOM\Document;
/** @covers \MensBeam\HTML\DOM\ChildNode */
class TestChildNode extends \PHPUnit\Framework\TestCase {
- /** @covers \MensBeam\HTML\DOM\ChildNode::after */
+ /**
+ * @covers \MensBeam\HTML\DOM\ChildNode::after
+ * @covers \MensBeam\HTML\DOM\Node::convertNodesToNode
+ */
public function testAfter(): void {
$d = new Document();
$d->appendChild($d->createElement('html'));
@@ -23,8 +26,8 @@ class TestChildNode extends \PHPUnit\Framework\TestCase {
$div2 = $d->body->appendChild($d->createElement('div'));
// On node with parent
- $div->after($d->createElement('span'), $o, $d->createElement('br'));
- $this->assertSame('
ook
', (string)$d->body);
+ $div->after($d->createElement('span'), $o, 'eek');
+ $this->assertSame('ookeek', (string)$d->body);
$div->after($o);
// On node with no parent
diff --git a/tests/cases/TestDocument.php b/tests/cases/TestDocument.php
index 2a76c73..6ca04cd 100644
--- a/tests/cases/TestDocument.php
+++ b/tests/cases/TestDocument.php
@@ -121,6 +121,7 @@ class TestDocument extends \PHPUnit\Framework\TestCase {
* @covers \MensBeam\HTML\DOM\Document::preInsertionValidity
* @covers \MensBeam\HTML\DOM\Document::replaceTemplates
* @covers \MensBeam\HTML\DOM\Document::__get_quirksMode
+ * @covers \MensBeam\HTML\DOM\Node::getRootNode
*/
public function testDocumentCreation(): void {
// Test null source
diff --git a/tests/cases/TestMagicProperties.php b/tests/cases/TestMagicProperties.php
new file mode 100644
index 0000000..4748b15
--- /dev/null
+++ b/tests/cases/TestMagicProperties.php
@@ -0,0 +1,79 @@
+omgWTFBBQ;
+ }, Exception::NONEXISTENT_PROPERTY ],
+ [ function() {
+ $d = new Document();
+ $d->omgWTFBBQ = 'ook';
+ }, Exception::NONEXISTENT_PROPERTY ],
+ [ function() {
+ $d = new Document();
+ $d->xpath = 'ook';
+ }, Exception::READONLY_PROPERTY ],
+ [ function() {
+ $d = new Document();
+ unset($d->xpath);
+ }, Exception::READONLY_PROPERTY ]
+ ];
+ }
+
+ /**
+ * @dataProvider provideFailures
+ * @covers \MensBeam\HTML\DOM\MagicProperties::__get
+ * @covers \MensBeam\HTML\DOM\MagicProperties::__set
+ * @covers \MensBeam\HTML\DOM\MagicProperties::__unset
+ */
+ public function testFailures(\Closure $closure, int $errorCode): void {
+ $this->expectException(Exception::class);
+ $this->expectExceptionCode($errorCode);
+ $closure();
+ }
+
+ /** @covers \MensBeam\HTML\DOM\MagicProperties::__isset */
+ public function testIsset(): void {
+ $d = new Document();
+ $this->assertTrue(isset($d->body));
+ }
+
+ /** @covers \MensBeam\HTML\DOM\MagicProperties::__unset */
+ public function testUnset(): void {
+ // Nothing allows setting values to null yet, so make one
+ $d = new class {
+ use MagicProperties;
+ protected ?string $_ook = 'ook';
+
+
+ protected function __get_ook(): ?string {
+ return $this->_ook;
+ }
+
+ protected function __set_ook(?string $value): void {
+ $this->_ook = $value;
+ }
+ };
+
+ unset($d->ook);
+ $this->assertNull($d->ook);
+ }
+}
\ No newline at end of file
diff --git a/tests/cases/TestNode.php b/tests/cases/TestNode.php
new file mode 100644
index 0000000..e6ab997
--- /dev/null
+++ b/tests/cases/TestNode.php
@@ -0,0 +1,43 @@
+C14N();
+ } ],
+ [ function() {
+ $d = new Document();
+ $d->C14NFile('fail');
+ } ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideDisabledMethods
+ * @covers \MensBeam\HTML\DOM\Node::C14N
+ * @covers \MensBeam\HTML\DOM\Node::C14NFile
+ */
+ public function testDisabledMethods(\Closure $closure): void {
+ $this->expectException(DOMException::class);
+ $this->expectExceptionCode(DOMException::NOT_SUPPORTED);
+ $closure();
+ }
+}
\ No newline at end of file
diff --git a/tests/cases/TestParentNode.php b/tests/cases/TestParentNode.php
index dd795d6..096ba54 100644
--- a/tests/cases/TestParentNode.php
+++ b/tests/cases/TestParentNode.php
@@ -113,6 +113,7 @@ class TestParentNode extends \PHPUnit\Framework\TestCase {
* @covers \MensBeam\HTML\DOM\ParentNode::__get_children
* @covers \MensBeam\HTML\DOM\ParentNode::preInsertionValidity
* @covers \MensBeam\HTML\DOM\DOMException::__construct
+ * @covers \MensBeam\HTML\DOM\Node::getRootNode
*/
public function testPreInsertionValidationFailures(\Closure $closure, int $errorCode = DOMException::HIERARCHY_REQUEST_ERROR): void {
$this->expectException(DOMException::class);
diff --git a/tests/phpunit.dist.xml b/tests/phpunit.dist.xml
index 4d4ce53..cf03ae7 100644
--- a/tests/phpunit.dist.xml
+++ b/tests/phpunit.dist.xml
@@ -23,6 +23,8 @@
cases/TestElementMap.php
cases/TestException.php
cases/TestLeafNode.php
+ cases/TestMagicProperties.php
+ cases/TestNode.php
cases/TestParentNode.php