');
- }, DOMException::INVALID_CHARACTER ]
- ];
- }
-
-
- /**
- * @dataProvider provideElementCreationFailures
- * @covers \MensBeam\HTML\DOM\Document::__construct
- * @covers \MensBeam\HTML\DOM\DOMException::__construct
- */
- public function testElementCreationFailures(\Closure $closure, int $errorCode): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode($errorCode);
- $closure();
- }
-
-
- public function provideElementCreationNS(): iterable {
- return [
- // HTML element with a null namespace
- [ null, null, 'div', 'div', Element::class ],
- // Template element with a null namespace
- [ null, null, 'template', 'template', HTMLTemplateElement::class ],
- // Template element with a null namespace and uppercase name
- [ null, null, 'TEMPLATE', 'TEMPLATE', HTMLTemplateElement::class ],
- // Template element
- [ Parser::HTML_NAMESPACE, Parser::HTML_NAMESPACE, 'template', 'template', HTMLTemplateElement::class ],
- // SVG element with SVG namespace
- [ Parser::SVG_NAMESPACE, Parser::SVG_NAMESPACE, 'svg', 'svg', Element::class ],
- // SVG element with SVG namespace and uppercase local name
- [ Parser::SVG_NAMESPACE, Parser::SVG_NAMESPACE, 'SVG', 'SVG', Element::class ],
- // Name coercion
- [ 'steaming💩', 'steaming💩', 'poop💩', 'poopU01F4A9', Element::class ]
- ];
- }
-
- /**
- * @dataProvider provideElementCreationNS
- * @covers \MensBeam\HTML\DOM\Document::createElementNS
- * @covers \MensBeam\HTML\DOM\Document::validateAndExtract
- */
- public function testElementCreationNS(?string $nsIn, ?string $nsExpected, string $localNameIn, string $localNameExpected, string $classExpected): void {
- $d = new Document();
- $n = $d->createElementNS($nsIn, $localNameIn);
- $this->assertInstanceOf($classExpected, $n);
- $this->assertNotNull($n->ownerDocument);
- $this->assertSame($nsExpected, $n->namespaceURI);
- $this->assertSame($localNameExpected, $n->localName);
- }
-
-
- public function provideElementCreationNSFailures(): iterable {
- return [
- [ function() {
- $d = new Document();
- $d->createElementNS('ook', 'ook', 'FAIL');
- }, DOMException::NOT_SUPPORTED ],
- [ function() {
- $d = new Document();
- $d->createElementNS(null, '');
- }, DOMException::INVALID_CHARACTER ],
- [ function() {
- $d = new Document();
- $d->createElementNS(null, 'xmlns');
- }, DOMException::NAMESPACE_ERROR ]
- ];
- }
-
- /**
- * @dataProvider provideElementCreationNSFailures
- * @covers \MensBeam\HTML\DOM\Document::createElementNS
- * @covers \MensBeam\HTML\DOM\Document::validateAndExtract
- * @covers \MensBeam\HTML\DOM\DOMException::__construct
- */
- public function testElementCreationNSFailures(\Closure $closure, int $errorCode): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode($errorCode);
- $closure();
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::save
- * @covers \MensBeam\HTML\DOM\Document::saveHTMLFile
- */
- public function testFileSaving(): void {
- $vfs = vfsStream::setup('DOM', 0777);
- $path = $vfs->url() . '/test.html';
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->save($path);
- $this->assertSame('', file_get_contents($path));
- $d->saveHTMLFile($path);
- $this->assertSame('', file_get_contents($path));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::importNode */
- public function testImportNode() {
- $d = new Document();
- $t = $d->createElement('template');
-
- $d2 = new Document();
- $t2 = $d2->importNode($t, true);
- $this->assertFalse($t2->ownerDocument->isSameNode($t->ownerDocument));
- $this->assertSame($t2::class, $t::class);
-
- $d = new \DOMDocument();
- $t = $d->createElement('template');
- // Add a child template to cover recursive template conversions.
- $t->appendChild($d->createElement('template'));
- $this->assertSame(\DOMElement::class, $t::class);
-
- $d2 = new Document();
- $t2 = $d2->importNode($t, true);
- $this->assertSame(HTMLTemplateElement::class, $t2::class);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::importNode */
- public function testImportingNodesFailure() {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::NOT_SUPPORTED);
- $d = new \DOMDocument();
- $c = $d->createCDATASection('fail');
- $d2 = new Document();
- $d2->importNode($c);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::__get_body */
- public function testPropertyGetBody(): void {
- $d = new Document();
- $this->assertNull($d->body);
- $d->appendChild($d->createElement('html'));
- $this->assertNull($d->body);
- $d->documentElement->appendChild($d->createTextNode(' '));
- $this->assertNull($d->body);
- $f = $d->createElement('frameset');
- $d->documentElement->appendChild($f);
- $this->assertNotNull($d->body);
- $d->documentElement->removeChild($f);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::__set_body */
- public function testPropertySetBody(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $b = $d->createElement('body');
- $d->body = $b;
- $this->assertSame('body', $d->body->nodeName);
- $d->body = $b;
- $this->assertSame('body', $d->body->nodeName);
-
- $b = $d->createElement('body');
- $b->appendChild($d->createTextNode('Ook'));
- $d->body = $b;
- $this->assertSame('Ook', $d->body->firstChild->data);
- }
-
- public function providePropertySetBodyFailures(): iterable {
- $result = [];
- $d = new Document();
- $result[] = [ $d, $d->createElement('body') ];
- $d = new Document();
- $result[] = [ $d, $d->createElement('div') ];
- $d = new Document();
- $result[] = [ $d, $d->createTextNode('FAIL') ];
- return $result;
- }
-
- /**
- * @dataProvider providePropertySetBodyFailures
- * @covers \MensBeam\HTML\DOM\Document::__set_body
- * @covers \MensBeam\HTML\DOM\DOMException::__construct
- */
- public function testPropertySetBodyFailures(Document $document, \DOMNode $node): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::HIERARCHY_REQUEST_ERROR);
- $document->body = $node;
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::__get_charset
- * @covers \MensBeam\HTML\DOM\Document::__get_characterSet
- * @covers \MensBeam\HTML\DOM\Document::__get_inputEncoding
- */
- public function testPropertyGetCharset(): void {
- $d = new Document(null, 'UTF-8');
- $this->assertSame('UTF-8', $d->charset);
- $this->assertSame('UTF-8', $d->characterSet);
- $this->assertSame('UTF-8', $d->inputEncoding);
-
- $d = new Document('');
- $this->assertSame('gb18030', $d->charset);
- $this->assertSame('gb18030', $d->characterSet);
- $this->assertSame('gb18030', $d->inputEncoding);
- }
-
-
- public function providePropertyGetCompatMode(): iterable {
- return [
- // Empty document
- [ null, 'CSS1Compat' ],
- // Document without doctype
- [ '', 'BackCompat' ],
- // Document with doctype
- [ '', 'CSS1Compat' ]
- ];
- }
-
- /**
- * @dataProvider providePropertyGetCompatMode
- * @covers \MensBeam\HTML\DOM\Document::__get_compatMode
- */
- public function testPropertyGetCompatMode(?string $html, string $compatMode): void {
- $d = new Document($html);
- $this->assertSame($compatMode, $d->compatMode);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::__get_contentType */
- public function testPropertyGetContentType(): void {
- $d = new Document();
- $this->assertSame('text/html', $d->contentType);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\Document::__get_xpath */
- public function testPropertyGetXPath(): void {
- $d = new Document();
- $this->assertSame('DOMXPath', get_class($d->xpath));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::__destruct
- * @covers \MensBeam\HTML\DOM\ElementMap::add
- * @covers \MensBeam\HTML\DOM\ElementMap::delete
- * @covers \MensBeam\HTML\DOM\ElementMap::destroy
- * @covers \MensBeam\HTML\DOM\ElementMap::has
- * @covers \MensBeam\HTML\DOM\ElementMap::index
- */
- public function testTemplateElementReferences(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $t = $d->createElement('template');
- $this->assertFalse(ElementMap::has($t));
- $d->documentElement->appendChild($t);
- $this->assertTrue(ElementMap::has($t));
- $d->__destruct();
- $this->assertFalse(ElementMap::has($t));
-
- $d = new Document();
- $d->appendChild($d->createElement('html'));
-
- $t = $d->importNode($t);
- $this->assertFalse(ElementMap::has($t));
- $d->documentElement->appendChild($t);
- $this->assertTrue(ElementMap::has($t));
- $d->documentElement->removeChild($t);
- $this->assertFalse(ElementMap::has($t));
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestDocumentFragment.php b/tests/cases/TestDocumentFragment.php
deleted file mode 100644
index 990d6fe..0000000
--- a/tests/cases/TestDocumentFragment.php
+++ /dev/null
@@ -1,68 +0,0 @@
-createDocumentFragment();
- $o = $df->appendChild($d->createElement('span'));
- $o->setAttribute('id', 'eek');
- $this->assertSame(Element::class, $df->getElementById('eek')::class);
- $this->assertNull($df->getElementById('ook'));
- }
-
- /** @covers \MensBeam\HTML\DOM\DocumentFragment::__get_host */
- public function testGetHost(): void {
- $d = new Document();
- // From a template
- $t = $d->createElement('template');
- $this->assertSame(HTMLTemplateElement::class, get_class($t->content->host));
- // From a created document fragment
- $df = $d->createDocumentFragment();
- $this->assertNull($df->host);
- }
-
- public function provideSetHostFailures(): iterable {
- return [
- [ function() {
- $d = new Document();
- $t = $d->createElement('template');
- $t->content->host = $d->createElement('template');
- } ],
- [ function() {
- $d = new Document();
- $df = $d->createDocumentFragment();
- $df->host = $d->createElement('template');
- } ]
- ];
- }
-
- /**
- * @dataProvider provideSetHostFailures
- * @covers \MensBeam\HTML\DOM\DocumentFragment::__set_host
- * @covers \MensBeam\HTML\DOM\Exception::__construct
- */
- public function testSetHostFailures(\Closure $closure): void {
- $this->expectException(Exception::class);
- $this->expectExceptionCode(Exception::READONLY_PROPERTY);
- $closure();
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestDocumentOrElement.php b/tests/cases/TestDocumentOrElement.php
deleted file mode 100644
index 9905856..0000000
--- a/tests/cases/TestDocumentOrElement.php
+++ /dev/null
@@ -1,25 +0,0 @@
-assertSame(0, $d->getElementsByClassName('fail')->length);
- $this->assertSame(0, $d->getElementsByClassName('')->length);
- $d->appendChild($d->createElement('html'));
- $d->documentElement->setAttribute('class', 'ook');
- $this->assertSame($d->documentElement->nodeName, $d->getElementsByClassName('ook')->item(0)->nodeName);
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestElement.php b/tests/cases/TestElement.php
deleted file mode 100644
index de0c845..0000000
--- a/tests/cases/TestElement.php
+++ /dev/null
@@ -1,303 +0,0 @@
-createElement('html');
- $d->appendChild($e);
-
- $this->assertSame([], $e->getAttributeNames());
-
- $e->setAttribute('ook:eek', 'ook');
- $e->setAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns:xlink', Parser::XLINK_NAMESPACE);
- $e->setAttribute('ook', 'eek');
-
- $this->assertSame([
- 'ook:eek',
- 'xmlns:xlink',
- 'ook'
- ], $e->getAttributeNames());
- }
-
-
- public function provideGetHasSetAttribute(): iterable {
- return [
- [ 'ook', 'eek', 'ook', 'eek' ],
- [ 'ook:eek', 'ook', 'ook:eek', 'ook' ],
- [ 'poop💩', 'soccer', 'poop💩', 'soccer' ]
- ];
- }
-
- /**
- * @dataProvider provideGetHasSetAttribute
- * @covers \MensBeam\HTML\DOM\Element::getAttribute
- * @covers \MensBeam\HTML\DOM\Element::hasAttribute
- * @covers \MensBeam\HTML\DOM\Element::setAttribute
- */
- public function testGetHasSetAttribute(string $nameIn, string $valueIn, string $nameExpected, string $valueExpected): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $e = $d->documentElement;
- $e->setAttribute($nameIn, $valueIn);
- $this->assertTrue($e->hasAttribute($nameExpected));
- $this->assertSame($valueExpected, $e->getAttribute($nameExpected));
- }
-
-
- public function provideGetHasSetAttributeNS(): iterable {
- return [
- [ 'fake_ns', 'ook', 'eek', 'ookeek', 'ook', 'eek', 'ookeek' ],
- [ 'another_fake_ns', 'steaming💩', 'poop💩', 'soccer', 'steaming💩', 'poop💩', 'soccer' ],
- [ Parser::XMLNS_NAMESPACE, 'xmlns', 'xlink', Parser::XLINK_NAMESPACE, 'xmlns', 'xlink', Parser::XLINK_NAMESPACE ]
- ];
- }
-
- /**
- * @dataProvider provideGetHasSetAttributeNS
- * @covers \MensBeam\HTML\DOM\Element::getAttributeNS
- * @covers \MensBeam\HTML\DOM\Element::hasAttributeNS
- * @covers \MensBeam\HTML\DOM\Element::setAttributeNS
- */
- public function testGetHasSetAttributeNS(?string $namespaceIn, ?string $prefixIn, string $localNameIn, string $valueIn, ?string $prefixExpected, string $localNameExpected, string $valueExpected): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $e = $d->documentElement;
- $qualifiedNameIn = ($prefixIn === null || $prefixIn === '') ? $localNameIn : "{$prefixIn}:{$localNameIn}";
- $e->setAttributeNS($namespaceIn, $qualifiedNameIn, $valueIn);
- $this->assertTrue($e->hasAttributeNS($namespaceIn, $localNameExpected));
- $this->assertSame($valueExpected, $e->getAttributeNS($namespaceIn, $localNameExpected));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::__get_classList
- * @covers \MensBeam\HTML\DOM\TokenList::__construct
- */
- public function testPropertyGetClassList(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->setAttribute('class', 'ook eek ack ookeek');
- $this->assertSame(4, $d->documentElement->classList->length);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::__get_innerHTML
- * @covers \MensBeam\HTML\DOM\Element::__set_innerHTML
- * @covers \MensBeam\HTML\DOM\Document::importNode
- */
- public function testPropertyGetSetInnerHTML(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $s = $d->body->appendChild($d->createElement('span'));
- $s->appendChild($d->createTextNode('ook'));
- $this->assertSame('ook', $d->body->innerHTML);
-
- $d->body->innerHTML = 'eek
';
- $this->assertSame('eek
', $d->body->innerHTML);
-
- $t = $d->body->appendChild($d->createElement('template'));
- $t->innerHTML = 'ook';
- $this->assertSame('ook', $t->innerHTML);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::__get_outerHTML
- * @covers \MensBeam\HTML\DOM\Element::__set_outerHTML
- */
- public function testPropertyGetSetOuterHTML(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $d->body->setAttribute('class', 'ook');
- $s = $d->body->appendChild($d->createElement('span'));
- $s->appendChild($d->createTextNode('ook'));
- $this->assertSame('ook', $d->body->outerHTML);
-
- $d->body->outerHTML = 'eek';
- $this->assertSame('eek', $d->body->outerHTML);
-
- $f = $d->createDocumentFragment();
- $div = $f->appendChild($d->createElement('div'));
- $div->outerHTML = 'ook';
- $this->assertSame('ook', (string)$f);
-
- $div = $d->createElement('div');
- $div->appendChild($d->createTextNode('ook'));
- $div->outerHTML = 'eek
';
- $this->assertSame('ook
', (string)$div);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::__set_outerHTML
- */
- public function testPropertySetOuterHTMLFailure(): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::NO_MODIFICATION_ALLOWED);
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->outerHTML = 'FAIL';
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::getAttribute
- */
- public function testGetAttribute(): void {
- // Just need to test nonexistent attributes
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $this->assertNull($d->documentElement->getAttribute('ook'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::getAttributeNodeNS
- */
- public function testGetAttributeNodeNS(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->setAttribute('ook', 'eek');
- // Empty string namespace
- $ook = $d->documentElement->getAttributeNodeNS('', 'ook');
- $this->assertSame('eek', $ook->value);
- // Bogus attribute
- $this->assertNull($d->documentElement->getAttributeNodeNS(null, 'what'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::getAttributeNS
- */
- public function testGetAttributeNS(): void {
- // Just need to test nonexistent attributes
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $this->assertNull($d->documentElement->getAttributeNS(Parser::HTML_NAMESPACE, 'ook'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::hasAttributeNS
- */
- public function testHasAttributeNS(): void {
- // Just need to test empty string namespace
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->setAttribute('ook', 'eek');
- $this->assertTrue($d->documentElement->hasAttributeNS('', 'ook'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::removeAttribute
- */
- public function testRemoveAttribute(): void {
- // Just need to test classList updates
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->classList->add('ook', 'eek');
- $d->documentElement->removeAttribute('class');
- $this->assertNull($d->documentElement->getAttribute('class'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::removeAttributeNS
- */
- public function testRemoveAttributeNS(): void {
- // Just need to test classList updates
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->classList->add('ook', 'eek');
- $d->documentElement->removeAttributeNS(null, 'class');
- $this->assertNull($d->documentElement->getAttribute('class'));
-
- $d->documentElement->setAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns', Parser::HTML_NAMESPACE);
- $d->documentElement->removeAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns');
- $this->assertNull($d->documentElement->getAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::setAttribute
- * @covers \MensBeam\HTML\DOM\TokenList::add
- */
- public function testSetAttribute(): void {
- // Need to test classList updates
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->classList->add('ook', 'eek');
- $d->documentElement->setAttribute('class', 'ack');
- $this->assertSame('ack', $d->documentElement->classList[0]);
- // Test setting class to empty string
- $d->documentElement->setAttribute('class', '');
- $this->assertSame('', $d->documentElement->getAttribute('class'));
- // Test setting id attribute
- $d->documentElement->setAttribute('id', 'ook');
- $this->assertSame('ook', $d->documentElement->getAttribute('id'));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::setAttribute
- * @covers \MensBeam\HTML\DOM\TokenList::add
- */
- public function testSetAttributeFailure(): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::INVALID_CHARACTER);
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->setAttribute('ook eek', 'fail');
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Element::setAttributeNS
- * @covers \MensBeam\HTML\DOM\TokenList::add
- */
- public function testSetAttributeNS(): void {
- $d = new Document();
- // Don't append html element and set attribute
- $de = $d->createElement('html');
- $de->setAttributeNS(null, 'id', 'ook');
- $this->assertSame('ook', $de->getAttribute('id'));
- $de->setAttributeNS(null, 'class', 'ook');
- $this->assertSame('ook', $de->getAttribute('class'));
-
- $de->setAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns', Parser::HTML_NAMESPACE);
- $this->assertSame(Parser::HTML_NAMESPACE, $de->getAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns'));
-
- $b = $d->createElement('body');
- $b->setAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns', Parser::HTML_NAMESPACE);
- $this->assertSame(Parser::HTML_NAMESPACE, $b->getAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns'));
-
- $t = $d->createElement('template');
- $t->setAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns', Parser::HTML_NAMESPACE);
- $this->assertSame(Parser::HTML_NAMESPACE, $t->getAttributeNS(Parser::XMLNS_NAMESPACE, 'xmlns'));
-
- // Test name coercion when namespace is null
- $de->setAttributeNS(null, 'poop💩', 'ook');
- $this->assertSame('ook', $de->getAttribute('poop💩'));
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestElementMap.php b/tests/cases/TestElementMap.php
deleted file mode 100644
index 3fb4143..0000000
--- a/tests/cases/TestElementMap.php
+++ /dev/null
@@ -1,38 +0,0 @@
-createElement('template');
- $this->assertTrue(ElementMap::add($t));
- $this->assertFalse(ElementMap::add($t));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\ElementMap::delete */
- public function testDelete(): void {
- $d = new Document();
- $t = $d->createElement('template');
- $this->assertTrue(ElementMap::add($t));
- $this->assertTrue(ElementMap::delete($t));
- $this->assertFalse(ElementMap::delete($t));
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestLeafNode.php b/tests/cases/TestLeafNode.php
deleted file mode 100644
index bc0798b..0000000
--- a/tests/cases/TestLeafNode.php
+++ /dev/null
@@ -1,49 +0,0 @@
-appendChild($d->createElement('fail'));
- } ],
- [ function($d, $n) {
- $n->insertBefore($d->createElement('fail'));
- } ],
- [ function($d, $n) {
- $n->removeChild($d->createElement('fail'));
- } ],
- [ function($d, $n) {
- $n->replaceChild($d->createElement('fail2'), $d->createElement('fail'));
- } ],
- ];
- }
-
- /**
- * @dataProvider provideDisabledMethods
- * @covers \MensBeam\HTML\DOM\LeafNode::appendChild
- * @covers \MensBeam\HTML\DOM\LeafNode::insertBefore
- * @covers \MensBeam\HTML\DOM\LeafNode::removeChild
- * @covers \MensBeam\HTML\DOM\LeafNode::replaceChild
- */
- public function testDisabledMethods(\Closure $closure): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::HIERARCHY_REQUEST_ERROR);
- $d = new Document();
- $closure($d, $d->createTextNode('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..1dff3a5
--- /dev/null
+++ b/tests/cases/TestNode.php
@@ -0,0 +1,40 @@
+appendChild($d->createElement('html'));
+ $d->documentElement->appendChild($d->createElement('body'));
+ $b = $d->body;
+ $b->appendChild($d->createElement('span'));
+ $b->appendChild($d->createTextNode('ook'));
+
+ // Node::childNodes on Element
+ $childNodes = $d->body->childNodes;
+ $this->assertEquals(2, $childNodes->length);
+ $this->assertSame('SPAN', $childNodes[0]->nodeName);
+
+ // Node::childNodes on Text
+ $childNodes = $d->body->lastChild->childNodes;
+ $this->assertEquals(0, $childNodes->length);
+ // Try it again to test caching
+ $childNodes = $d->body->lastChild->childNodes;
+ }
+}
\ No newline at end of file
diff --git a/tests/cases/TestNodeList.php b/tests/cases/TestNodeList.php
deleted file mode 100644
index 5433c5d..0000000
--- a/tests/cases/TestNodeList.php
+++ /dev/null
@@ -1,103 +0,0 @@
-expectException(Exception::class);
- $this->expectExceptionCode(Exception::ARGUMENT_TYPE_ERROR);
- $closure();
- }
-
-
- /** @covers \MensBeam\HTML\DOM\NodeList::count */
- public function testCount(): void {
- $d = new Document();
- $list = new NodeList([
- $d->createElement('ook'),
- $d->createTextNode('eek'),
- $d->createComment('ack')
- ]);
- $this->assertEquals(3, count($list));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\NodeList::item */
- public function testItem(): void {
- $d = new Document();
- $list = new NodeList([
- $d->createElement('ook'),
- $d->createTextNode('eek'),
- $d->createComment('ack')
- ]);
- $this->assertNull($list->item(42));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\NodeList::current
- * @covers \MensBeam\HTML\DOM\NodeList::item
- * @covers \MensBeam\HTML\DOM\NodeList::key
- * @covers \MensBeam\HTML\DOM\NodeList::next
- * @covers \MensBeam\HTML\DOM\NodeList::rewind
- * @covers \MensBeam\HTML\DOM\NodeList::offsetExists
- * @covers \MensBeam\HTML\DOM\NodeList::offsetGet
- * @covers \MensBeam\HTML\DOM\NodeList::valid
- */
- public function testIteration(): void {
- $d = new Document();
- $list = new NodeList([
- $d->createElement('ook'),
- $d->createTextNode('eek'),
- $d->createComment('ack')
- ]);
-
- foreach ($list as $key => $node) {
- $this->assertSame($node, $list[$key]);
- // test offsetExists
- $this->assertTrue(isset($list[$key]));
- }
- }
-
-
- /** @covers \MensBeam\HTML\DOM\NodeList::__get_length */
- public function testPropertyGetLength(): void {
- $d = new Document();
- $list = new NodeList([
- $d->createElement('ook'),
- $d->createTextNode('eek'),
- $d->createComment('ack')
- ]);
- $this->assertEquals(3, $list->length);
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestNodeTrait.php b/tests/cases/TestNodeTrait.php
deleted file mode 100644
index 8f19bc9..0000000
--- a/tests/cases/TestNodeTrait.php
+++ /dev/null
@@ -1,167 +0,0 @@
-appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $d->body->innerHTML = 'Eek
Ook eek, ook?
';
- $m = $d->getElementsByTagName('main')->item(0);
- $f = $d->getElementsByTagName('footer')->item(0);
- $e = $d->getElementById('eek');
- $h2Id = $e->getAttributeNode('id');
- $h2Class = $e->getAttributeNode('class');
- $aHref = $d->getElementsByTagName('a')->item(0)->getAttributeNode('href');
-
- $compareMainToBody = $m->compareDocumentPosition($d->body);
- $this->assertEquals(10, $compareMainToBody);
- $compareBodyToMain = $d->body->compareDocumentPosition($m);
- $this->assertEquals(20, $compareBodyToMain);
- $compareFooterToMain = $f->compareDocumentPosition($m);
- $this->assertEquals(2, $compareFooterToMain);
- $compareMainToFooter = $m->compareDocumentPosition($f);
- $this->assertEquals(4, $compareMainToFooter);
- $compareH2IdToAHref = $h2Id->compareDocumentPosition($aHref);
- $this->assertEquals(4, $compareH2IdToAHref);
- $compareH2IdToH2Class = $h2Id->compareDocumentPosition($h2Class);
- $this->assertEquals(36, $compareH2IdToH2Class);
- $compareH2ClassToH2Id = $h2Class->compareDocumentPosition($h2Id);
- $this->assertEquals(34, $compareH2ClassToH2Id);
- $this->assertEquals(0, $m->compareDocumentPosition($m));
-
- $this->assertGreaterThan(0, $compareMainToBody & Document::DOCUMENT_POSITION_CONTAINS);
- $this->assertGreaterThan(0, $compareMainToBody & Document::DOCUMENT_POSITION_PRECEDING);
- $this->assertEquals(0, $compareMainToBody & Document::DOCUMENT_POSITION_FOLLOWING);
-
- $this->assertGreaterThan(0, $compareBodyToMain & Document::DOCUMENT_POSITION_CONTAINED_BY);
- $this->assertGreaterThan(0, $compareBodyToMain & Document::DOCUMENT_POSITION_FOLLOWING);
- $this->assertEquals(0, $compareBodyToMain & Document::DOCUMENT_POSITION_PRECEDING);
-
- $this->assertGreaterThan(0, $compareFooterToMain & Document::DOCUMENT_POSITION_PRECEDING);
- $this->assertGreaterThan(0, $compareMainToFooter & Document::DOCUMENT_POSITION_FOLLOWING);
-
- $this->assertGreaterThan(0, $compareH2IdToAHref & Document::DOCUMENT_POSITION_FOLLOWING);
- $this->assertGreaterThan(0, $compareH2IdToH2Class & Document::DOCUMENT_POSITION_FOLLOWING);
- $this->assertGreaterThan(0, $compareH2ClassToH2Id & Document::DOCUMENT_POSITION_PRECEDING);
-
- $m->parentNode->removeChild($m);
- $compareDetachedMainToFooter = $m->compareDocumentPosition($f);
- $this->assertEquals($compareDetachedMainToFooter, $m->compareDocumentPosition($f));
- $this->assertGreaterThanOrEqual(35, $compareDetachedMainToFooter);
- $this->assertLessThanOrEqual(37, $compareDetachedMainToFooter);
- $this->assertNotEquals(36, $compareDetachedMainToFooter);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\NodeTrait::contains */
- public function testContains(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $o = $d->body->appendChild($d->createTextNode('Ook!'));
- $d2 = new Document();
- $d2->appendChild($d2->createElement('html'));
-
- $this->assertTrue($d->documentElement->contains($d->body));
- $this->assertTrue($d->contains($o));
- $this->assertFalse($o->contains($d));
- $this->assertFalse($d->contains($d2->documentElement));
- }
-
-
- public function provideDisabledMethods(): iterable {
- return [
- [ 'C14N' ],
- [ 'C14NFile', 'ook' ],
- [ 'getLineNo' ]
- ];
- }
-
- /**
- * @dataProvider provideDisabledMethods
- * @covers \MensBeam\HTML\DOM\NodeTrait::C14N
- * @covers \MensBeam\HTML\DOM\NodeTrait::C14NFile
- * @covers \MensBeam\HTML\DOM\NodeTrait::getLineNo
- */
- public function testDisabledMethods(string $methodName, ...$arguments): void {
- $this->expectException(Exception::class);
- $this->expectExceptionCode(Exception::DISABLED_METHOD);
- $d = new Document();
- $d->$methodName(...$arguments);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\NodeTrait::getRootNode */
- public function testGetRootNode(): void {
- $d = new Document();
- $t = $d->createElement('template');
- $div = $t->content->appendChild($d->createElement('div'));
- $this->assertTrue($t->content->isSameNode($div->getRootNode()));
- }
-
- /** @covers \MensBeam\HTML\DOM\NodeTrait::isEqualNode */
- public function testIsEqualNode(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $d->body->innerHTML = 'Ook
Eek
';
-
- $d2 = new Document();
- $d2->appendChild($d2->createElement('html'));
- $d2->documentElement->appendChild($d2->createElement('body'));
- $d2->body->innerHTML = 'Ook
Eek
';
-
- $this->assertTrue($d->isEqualNode($d2));
-
- $d = new Document();
- $de = $d->createElement('html');
- $this->assertFalse($d->isEqualNode($de));
-
- $d = new Document();
- $d->appendChild($d->implementation->createDocumentType('html', '', ''));
-
- $d2 = new Document();
- $d2->appendChild($d2->implementation->createDocumentType('ook', 'eek', 'ack'));
- $this->assertFalse($d->isEqualNode($d2));
-
- $d = new Document('Ook!Eek
');
- $d2 = new Document('Eek!Eek
');
- $this->assertFalse($d->isEqualNode($d2));
-
- $d = new Document();
- $f = $d->createDocumentFragment();
- $f->appendChild($d->createElement('span'));
- $f->appendChild($d->createTextNode('Ook'));
-
- $f2 = $d->createDocumentFragment();
- $f2->appendChild($d->createElement('span'));
- $this->assertFalse($f->isEqualNode($f2));
-
- $s = $d->createElement('span');
- $s->setAttribute('id', 'ook');
- $s2 = $d->createElement('span');
- $s2->setAttribute('class', 'ook');
- $this->assertFalse($s->isEqualNode($s2));
-
- $s = $d->createElement('span');
- $br = $d->createElement('br');
- $this->assertFalse($s->isEqualNode($br));
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestParentNode.php b/tests/cases/TestParentNode.php
deleted file mode 100644
index 9ad50a5..0000000
--- a/tests/cases/TestParentNode.php
+++ /dev/null
@@ -1,289 +0,0 @@
-appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $div = $d->body->appendChild($d->createElement('div'));
- $ook = $d->body->insertBefore($d->createTextNode('ook'), $div);
-
- $this->assertSame('ook', (string)$d->body);
-
- $t = $d->body->insertBefore($d->createElement('template'), $ook);
-
- $this->assertSame('ook', (string)$d->body);
- $this->assertTrue(ElementMap::has($t));
- }
-
-
- public function providePreInsertionValidationFailures(): iterable {
- return [
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $b = $d->documentElement->appendChild($d->createElement('body'));
- $b->appendChild($d->documentElement);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $b = $d->documentElement->appendChild($d->createElement('body'));
- $t = $b->appendChild($d->createElement('template'));
- $t->content->appendChild($b);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $b = $d->documentElement->appendChild($d->createElement('body'));
- $d->insertBefore($d->createElement('fail'), $b);
- }, DOMException::NOT_FOUND ],
- [ function() {
- $d = new Document();
- $df = $d->createDocumentFragment();
- $df->appendChild($d->createElement('html'));
- $df->appendChild($d->createTextNode(' '));
- $d->appendChild($df);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->implementation->createDocumentType('html'));
- $d->appendChild($d->implementation->createDocumentType('html'));
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->appendChild($d->implementation->createDocumentType('html'));
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $c = $d->appendChild($d->createComment('ook'));
- $d->insertBefore($d->implementation->createDocumentType('html'), $c);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->insertBefore($d->implementation->createDocumentType('html'));
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->insertBefore($d->implementation->createDocumentType('html'));
- } ],
- [ function() {
- $d = new Document();
- $dt = $d->appendChild($d->implementation->createDocumentType('html'));
- $df = $d->createDocumentFragment();
- $df->appendChild($d->createElement('html'));
- $d->insertBefore($df, $dt);
- } ],
- [ function() {
- $d = new Document();
- $c = $d->appendChild($d->createComment('OOK'));
- $d->appendChild($d->implementation->createDocumentType('html'));
- $df = $d->createDocumentFragment();
- $df->appendChild($d->createElement('html'));
- $d->insertBefore($df, $c);
- } ],
- [ function() {
- $d = new Document();
- $dt = $d->appendChild($d->implementation->createDocumentType('html'));
- $d->insertBefore($d->createElement('html'), $dt);
- } ],
- [ function() {
- $d = new Document();
- $c = $d->appendChild($d->createComment('OOK'));
- $d->appendChild($d->implementation->createDocumentType('html'));
- $d->insertBefore($d->createElement('html'), $c);
- } ],
- [ function() {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->appendChild($d->createElement('body'));
- } ]
- ];
- }
-
- /**
- * @dataProvider providePreInsertionValidationFailures
- * @covers \MensBeam\HTML\DOM\DOMException::__construct
- * @covers \MensBeam\HTML\DOM\NodeTrait::getRootNode
- * @covers \MensBeam\HTML\DOM\ParentNode::preInsertionValidity
- */
- public function testPreInsertionValidationFailures(\Closure $closure, int $errorCode = DOMException::HIERARCHY_REQUEST_ERROR): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode($errorCode);
- $closure();
- }
-
-
- /** @covers \MensBeam\HTML\DOM\ParentNode::__get_children */
- public function testPropertyGetChildren(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
-
- $this->assertSame(1, $d->documentElement->children->length);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\ParentNode::querySelector
- * @covers \MensBeam\HTML\DOM\ParentNode::querySelectorAll
- * @covers \MensBeam\HTML\DOM\ParentNode::scopeMatchSelector
- * @covers \MensBeam\HTML\DOM\NodeList::__construct
- * @covers \MensBeam\HTML\DOM\NodeList::item
- */
- public function testQuerySelector(): void {
- $d = new Document('ook
eek
');
- $div = $d->body->querySelector('div');
- $this->assertSame('div', $div->nodeName);
- $this->assertNull($d->querySelector('body::before'));
-
- $divs = $d->body->querySelectorAll('div');
- $this->assertEquals(2, $divs->length);
- $this->assertSame('eek', $divs->item(1)->getAttribute('id'));
- $this->assertNull($d->querySelector('.ook'));
- $this->assertEquals(0, $d->querySelectorAll('body::before')->length);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\ParentNode::querySelector
- * @covers \MensBeam\HTML\DOM\ParentNode::querySelectorAll
- * @covers \MensBeam\HTML\DOM\ParentNode::scopeMatchSelector
- */
- public function testQuerySelectorFailure(): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode(DOMException::SYNTAX_ERROR);
- $d = new Document();
- $d->querySelector('ook?');
- }
-
-
- /** @covers \MensBeam\HTML\DOM\ParentNode::replaceChild */
- public function testReplaceChild(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $div = $d->body->appendChild($d->createElement('div'));
- $ook = $d->body->replaceChild($d->createTextNode('ook'), $div);
-
- $this->assertSame('ook', (string)$d->body);
-
- $t = $d->body->replaceChild($d->createElement('template'), $ook);
-
- $this->assertSame('', (string)$d->body);
- $this->assertTrue(ElementMap::has($t));
-
- $d->body->replaceChild($d->createElement('br'), $t);
-
- $this->assertSame('
', (string)$d->body);
- $this->assertFalse(ElementMap::has($t));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\ParentNode::replaceChildren */
- public function testReplaceChildren(): void {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $div = $d->body->appendChild($d->createElement('div'));
- $ook = $d->body->appendChild($d->createTextNode('ook'), $d->body->appendChild($d->createElement('div')));
-
- $d->body->replaceChildren($d->createElement('br'), 'ook', $d->createElement('span'), 'eek');
- $this->assertSame('
ookeek', (string)$d->body);
-
- $d->body->replaceChildren('ook');
- $this->assertSame('ook', (string)$d->body);
- }
-
-
- /** @covers \MensBeam\HTML\DOM\ParentNode::walk */
- public function testWalk(): void {
- // Test removal of elements when walking
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $d->body->innerHTML = 'OOOK';
- $spans = $d->body->walk(function($n) {
- return ($n instanceof Element && $n->nodeName === 'span');
- });
-
- foreach ($spans as $s) {
- if ($s->getAttribute('class') === 'three') {
- $s->parentNode->removeChild($s);
- }
- }
-
- $this->assertSame('OOK', (string)$d->body);
-
- // Test walking through templates' content
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $t = $d->body->appendChild($d->createElement('template'));
- $t->content->appendChild($d->createElement('ook'));
-
- $this->assertSame('ook', $d->body->walk(function($n) {
- return ($n instanceof Element && $n->nodeName === 'ook');
- })->current()->nodeName);
- }
-
-
- public function provideWalkFailures(): iterable {
- $d = new Document();
- $d->appendChild($d->createElement('html'));
- $d->documentElement->appendChild($d->createElement('body'));
- $d->body->innerHTML = 'Eek
Ook eek, ook?
';
-
- return [
- [ function() use ($d) {
- $d->body->walk(function($n) {
- return 'ook';
- })->current();
- } ],
- [ function() use ($d) {
- $d->body->walk(function($n) {
- return new \DateTime();
- })->current();
- } ]
- ];
- }
-
- /**
- * @dataProvider provideWalkFailures
- * @covers \MensBeam\HTML\DOM\DOMException::__construct
- * @covers \MensBeam\HTML\DOM\ParentNode::walk
- */
- public function testWalkFailures(\Closure $closure): void {
- $this->expectException(Exception::class);
- $this->expectExceptionCode(Exception::CLOSURE_RETURN_TYPE_ERROR);
- $closure();
- }
-}
\ No newline at end of file
diff --git a/tests/cases/TestTokenList.php b/tests/cases/TestTokenList.php
deleted file mode 100644
index 58b4247..0000000
--- a/tests/cases/TestTokenList.php
+++ /dev/null
@@ -1,230 +0,0 @@
-createElement('html');
- $e->classList->add('');
- }, DOMException::SYNTAX_ERROR ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->remove('');
- }, DOMException::SYNTAX_ERROR ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->replace('ack', '');
- }, DOMException::SYNTAX_ERROR ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->toggle('');
- }, DOMException::SYNTAX_ERROR ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->add('fail fail');
- }, DOMException::INVALID_CHARACTER ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->remove('fail fail');
- }, DOMException::INVALID_CHARACTER ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->replace('ack', 'fail fail');
- }, DOMException::INVALID_CHARACTER ],
- [ function() {
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->toggle('fail fail');
- }, DOMException::INVALID_CHARACTER ]
- ];
- }
-
- /**
- * @dataProvider provideAddRemoveReplaceToggleFailures
- * @covers \MensBeam\HTML\DOM\TokenList::add
- * @covers \MensBeam\HTML\DOM\TokenList::remove
- * @covers \MensBeam\HTML\DOM\TokenList::replace
- * @covers \MensBeam\HTML\DOM\TokenList::toggle
- */
- public function testAddRemoveReplaceFailures(\Closure $closure, int $errorCode): void {
- $this->expectException(DOMException::class);
- $this->expectExceptionCode($errorCode);
- $closure();
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::contains */
- public function testContains(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertTrue($e->classList->contains('ack'));
- $this->assertFalse($e->classList->contains('fail'));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::count */
- public function testCount(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertSame(4, count($e->classList));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::item */
- public function testItem(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertNull($e->classList->item(42));
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\TokenList::current
- * @covers \MensBeam\HTML\DOM\TokenList::item
- * @covers \MensBeam\HTML\DOM\TokenList::key
- * @covers \MensBeam\HTML\DOM\TokenList::next
- * @covers \MensBeam\HTML\DOM\TokenList::rewind
- * @covers \MensBeam\HTML\DOM\TokenList::offsetExists
- * @covers \MensBeam\HTML\DOM\TokenList::offsetGet
- * @covers \MensBeam\HTML\DOM\TokenList::valid
- */
- public function testIteration(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
-
- foreach ($e->classList as $key => $className) {
- $this->assertSame($className, $e->classList[$key]);
- // test offsetExists
- $this->assertTrue(isset($e->classList[$key]));
- }
- }
-
- /** @covers \MensBeam\HTML\DOM\TokenList::__get_length */
- public function testPropertyGetLength(): void {
- // Test it with and without an attached document element
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertSame(4, $e->classList->length);
-
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertSame(4, $e->classList->length);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\TokenList::__get_value
- * @covers \MensBeam\HTML\DOM\TokenList::__set_value
- */
- public function testPropertyGetSetValue(): void {
- // Test it with and without an attached document element
- $d = new Document();
- $e = $d->createElement('html');
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertSame('ook eek ack ookeek', $e->classList->value);
- $this->assertSame('ook eek ack ookeek', $e->getAttribute('class'));
- $e->classList->value = 'omg wtf bbq lol zor bor xxx';
- $this->assertSame('lol', $e->classList[3]);
- $this->assertSame('omg wtf bbq lol zor bor xxx', $e->classList->value);
- $this->assertSame('omg wtf bbq lol zor bor xxx', $e->getAttribute('class'));
- $e->classList->value = '';
- $this->assertSame('', $e->classList->value);
- $this->assertSame('', $e->getAttribute('class'));
-
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertSame('ook eek ack ookeek', $e->classList->value);
- $this->assertSame('ook eek ack ookeek', $e->getAttribute('class'));
- $e->classList->value = 'omg wtf bbq lol zor bor xxx';
- $this->assertSame('lol', $e->classList[3]);
- $this->assertSame('omg wtf bbq lol zor bor xxx', $e->classList->value);
- $this->assertSame('omg wtf bbq lol zor bor xxx', $e->getAttribute('class'));
- $e->classList->value = '';
- $this->assertSame('', $e->classList->value);
- $this->assertSame('', $e->getAttribute('class'));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::replace */
- public function testReplace(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->setAttribute('class', 'ook eek ack ookeek');
- $this->assertTrue($e->classList->replace('ack', 'what'));
- $this->assertSame('ook eek what ookeek', $e->classList->value);
- $this->assertSame('ook eek what ookeek', $e->getAttribute('class'));
- $this->assertFalse($e->classList->replace('fail', 'eekook'));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::remove */
- public function testRemove(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->setAttribute('class', 'ook eek ack ookeek');
- $e->classList->remove('ack');
- $this->assertSame('ook eek ookeek', $e->classList->value);
- $this->assertSame('ook eek ookeek', $e->getAttribute('class'));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::supports */
- public function testSupports(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->classList->add('ook', 'eek', 'ack', 'ookeek');
- $this->assertTrue($e->classList->supports('ack'));
- }
-
-
- /** @covers \MensBeam\HTML\DOM\TokenList::toggle */
- public function testToggle(): void {
- $d = new Document();
- $e = $d->appendChild($d->createElement('html'));
- $e->setAttribute('class', 'ook eek ack ookeek');
- $this->assertFalse($e->classList->toggle('ack'));
- $this->assertSame('ook eek ookeek', $e->classList->value);
- $this->assertSame('ook eek ookeek', $e->getAttribute('class'));
- $this->assertTrue($e->classList->toggle('ack'));
- $this->assertSame('ook eek ookeek ack', $e->classList->value);
- $this->assertSame('ook eek ookeek ack', $e->getAttribute('class'));
- $this->assertTrue($e->classList->toggle('ack', true));
- $this->assertSame('ook eek ookeek ack', $e->classList->value);
- $this->assertSame('ook eek ookeek ack', $e->getAttribute('class'));
- $this->assertFalse($e->classList->toggle('eekook', false));
- $this->assertSame('ook eek ookeek ack', $e->classList->value);
- $this->assertSame('ook eek ookeek ack', $e->getAttribute('class'));
- $this->assertTrue($e->classList->toggle('eekook', true));
- $this->assertSame('ook eek ookeek ack eekook', $e->classList->value);
- $this->assertSame('ook eek ookeek ack eekook', $e->getAttribute('class'));
- }
-}
\ No newline at end of file
diff --git a/tests/cases/serializer/TestSerializer.php b/tests/cases/serializer/TestSerializer.php
deleted file mode 100644
index 974b1cc..0000000
--- a/tests/cases/serializer/TestSerializer.php
+++ /dev/null
@@ -1,279 +0,0 @@
-append(new \GlobIterator(\MensBeam\HTML\DOM\BASE."tests/cases/Serializer/standard/*.dat", \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME));
- foreach ($files as $file) {
- if (!in_array(basename($file), $blacklist)) {
- yield from $this->parseTreeTestFile($file);
- }
- }
- }
-
- /**
- * @dataProvider provideStandardTreeTests
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::blockElementFilterFactory
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- * @covers \MensBeam\HTML\DOM\Document::__toString
- * @covers \MensBeam\HTML\DOM\ToString::__toString
- */
- public function testStandardTreeTests(array $data, bool $fragment, string $exp): void {
- $node = $this->buildTree($data, $fragment);
- $this->assertSame($exp, (string)$node);
- }
-
-
- public function provideFormattedTreeTests(): iterable {
- $files = new \AppendIterator();
- $files->append(new \GlobIterator(\MensBeam\HTML\DOM\BASE."tests/cases/Serializer/formatted/*.dat", \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME));
- foreach ($files as $file) {
- yield from $this->parseTreeTestFile($file);
- }
- }
-
- /**
- * @dataProvider provideFormattedTreeTests
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::blockElementFilterFactory
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- * @covers \MensBeam\HTML\DOM\Document::__toString
- * @covers \MensBeam\HTML\DOM\ToString::__toString
- */
- public function testFormattedTreeTests(array $data, bool $fragment, string $exp): void {
- $node = $this->buildTree($data, $fragment, true);
- $this->assertSame($exp, (string)$node);
- }
-
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- */
- public function testSerializingDocumentType(): void {
- $d = new Document();
- $dt = $d->implementation->createDocumentType('ook', 'eek', 'ack');
- $d->appendChild($dt);
- $this->assertSame('', $d->saveHTML($dt));
- }
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- */
- public function testSerializingDocumentFragments(): void {
- $d = new Document();
- $d->formatOutput = true;
- $df = $d->createDocumentFragment();
- $df->appendChild($d->createTextNode('ook'));
- $this->assertSame('ook', (string)$df);
- $this->assertSame('ook', $d->saveHTML($df));
- }
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- * @covers \MensBeam\HTML\DOM\ToString::__toString
- */
- public function testSerializingElements(): void {
- $d = new Document();
- $i = $d->createElement('input');
- $i->appendChild($d->createTextNode('You should not see this text'));
- $this->assertSame('', (string)$i);
- $this->assertSame('', $d->saveHTML($i));
-
- $t = $d->createElement('template');
- $t->setAttribute('ook', 'eek');
- $t->content->appendChild($d->createTextNode('Ook!'));
- $this->assertSame('Ook!', (string)$t);
- $this->assertSame('Ook!', $d->saveHTML($t));
- }
-
- /**
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- * @covers \MensBeam\HTML\DOM\Document::serializeNode
- * @covers \MensBeam\HTML\DOM\ToString::__toString
- */
- public function testSerializingTextNodes(): void {
- $d = new Document();
- $d->formatOutput = true;
- $i = $d->createTextNode('test');
- $this->assertSame('test', (string)$i);
- $this->assertSame('test', $d->saveHTML($i));
- }
-
-
- public function provideSerializerFailures(): iterable {
- return [
- [ function() {
- $d = new Document();
- $h = $d->createElement('html');
- $d2 = new Document();
- $d2->saveHTML($h);
- }, DOMException::class, DOMException::WRONG_DOCUMENT ],
- [ function() {
- $d = new Document();
- $d->saveHTML($d->createAttribute('fail'));
- }, Exception::class, Exception::ARGUMENT_TYPE_ERROR ],
- [ function() {
- $d = new Document();
- $d->saveHTML(new \DOMDocument());
- }, Exception::class, Exception::ARGUMENT_TYPE_ERROR ],
- [ function() {
- $d = new Document();
- $d2 = new \DOMDocument();
- $d->saveHTML($d2->createComment('fail'));
- }, Exception::class, Exception::ARGUMENT_TYPE_ERROR ]
- ];
- }
-
- /**
- * @dataProvider provideSerializerFailures
- * @covers \MensBeam\HTML\DOM\Document::saveHTML
- */
- public function testSerializerFailures(\Closure $closure, string $exceptionClassName, int $errorCode): void {
- $this->expectException($exceptionClassName);
- $this->expectExceptionCode($errorCode);
- $closure();
- }
-
-
-
-
- protected function buildTree(array $data, bool $fragment, bool $formatOutput = false): \DOMNode {
- $document = new Document;
- $document->formatOutput = $formatOutput;
- if ($fragment) {
- $document->appendChild($document->createElement("html"));
- $out = $document->createDocumentFragment();
- } else {
- $out = $document;
- }
- $cur = $out;
- $pad = 2;
- // process each line in turn
- for ($l = 0; $l < sizeof($data); $l++) {
- preg_match('/^(\|\s+)(.+)/', $data[$l], $m);
- // pop any parents as long as the padding of the line is less than the expected padding
- $p = strlen((string) $m[1]);
- assert($p >= 2 && $p <= $pad && !($p % 2), new \Exception("Input data is invalid on line ".($l + 1)));
- while ($p < $pad) {
- $pad -= 2;
- $cur = $cur->parentNode;
- }
- // act based upon what the rest of the line looks like
- $d = $m[2];
- if (preg_match('/^$/', $d, $m)) {
- // comment
- $cur->appendChild($document->createComment($m[1]));
- } elseif (preg_match('/^]*)(?: "([^"]*)" "([^"]*)")?)?>$/', $d, $m)) {
- // doctype
- $name = strlen((string) ($m[1] ?? "")) ? $m[1] : " ";
- $public = strlen((string) ($m[2] ?? "")) ? $m[2] : "";
- $system = strlen((string) ($m[3] ?? "")) ? $m[3] : "";
- $cur->appendChild($document->implementation->createDocumentType($name, $public, $system));
- } elseif (preg_match('/^<\?([^ ]+) ([^>]*)>$/', $d, $m)) {
- $cur->appendChild($document->createProcessingInstruction($m[1], $m[2]));
- } elseif (preg_match('/^<(?:([^ ]+) )?([^>]+)>$/', $d, $m)) {
- // element
- $ns = strlen((string) $m[1]) ? (array_flip(Parser::NAMESPACE_MAP)[$m[1]] ?? $m[1]) : null;
- $cur = $cur->appendChild($document->createElementNS($ns, $m[2]));
- $pad += 2;
- } elseif (preg_match('/^(?:([^" ]+) )?([^"=]+)="((?:[^"]|"(?!$))*)"$/', $d, $m)) {
- // attribute
- $ns = strlen((string) $m[1]) ? (array_flip(Parser::NAMESPACE_MAP)[$m[1]] ?? $m[1]) : "";
-
- if ($ns === '') {
- $cur->setAttribute($m[2], $m[3]);
- } else {
- $cur->setAttributeNS($ns, $m[2], $m[3]);
- }
- } elseif (preg_match('/^"((?:[^"]|"(?!$))*)("?)$/', $d, $m)) {
- // text
- $t = $m[1];
- while (!strlen((string) $m[2])) {
- preg_match('/^((?:[^"]|"(?!$))*)("?)$/', $data[++$l], $m);
- $t .= "\n".$m[1];
- }
- $cur->appendChild($document->createTextNode($t));
- } else {
- throw new \Exception("Input data is invalid on line ".($l + 1));
- }
- }
- return $out;
- }
-
- protected function parseTreeTestFile(string $file): \Generator {
- $index = 0;
- $l = 0;
- $lines = array_map(function($v) {
- return rtrim($v, "\n");
- }, file($file));
- while ($l < sizeof($lines)) {
- $pos = $l + 1;
- assert(in_array($lines[$l], ["#document", "#fragment"]), new \Exception("Test $file #$index does not start with #document or #fragment tag at line ".($l + 1)));
- $fragment = $lines[$l] === "#fragment";
- // collect the test input
- $data = [];
- for (++$l; $l < sizeof($lines); $l++) {
- if (preg_match('/^#(script-(on|off)|output)$/', $lines[$l])) {
- break;
- }
- $data[] = $lines[$l];
- }
- // set the script mode, if present
- assert(preg_match('/^#(script-(on|off)|output)$/', $lines[$l]) === 1, new \Exception("Test $file #$index follows data with something other than script flag or output at line ".($l + 1)));
- $script = null;
- if ($lines[$l] === "#script-off") {
- $script = false;
- $l++;
- } elseif ($lines[$l] === "#script-on") {
- $script = true;
- $l++;
- }
- // collect the output string
- $exp = [];
- assert($lines[$l] === "#output", new \Exception("Test $file #$index follows input with something other than output at line ".($l + 1)));
- for (++$l; $l < sizeof($lines); $l++) {
- if ($lines[$l] === "" && in_array(($lines[$l + 1] ?? ""), ["#document", "#fragment"])) {
- break;
- }
- assert(preg_match('/^([^#]|$)/', $lines[$l]) === 1, new \Exception("Test $file #$index contains unrecognized data after output at line ".($l + 1)));
- $exp[] = $lines[$l];
- }
- $exp = implode("\n", $exp);
- if (!$script) {
- yield basename($file)." #$index (line $pos)" => [$data, $fragment, $exp];
- }
- $l++;
- $index++;
- }
- }
-}
diff --git a/tests/cases/serializer/formatted/mensbeam01.dat b/tests/cases/serializer/formatted/mensbeam01.dat
deleted file mode 100644
index 6751566..0000000
--- a/tests/cases/serializer/formatted/mensbeam01.dat
+++ /dev/null
@@ -1,153 +0,0 @@
-#fragment
-|
-#output
-
-
-#document
-|
-|
-|
-#output
-
-
-
-
-#document
-|
-|
-|
-|
-#output
-
-
-
-
-
-
-
-#document
-|
-|
-|
-|
-#output
-
-
-
-
-
-
-#document
-|
-|
-|