|
@ -9,16 +9,11 @@ namespace MensBeam\HTML\TestCase; |
|
|
use MensBeam\HTML\Document; |
|
|
use MensBeam\HTML\Document; |
|
|
use MensBeam\HTML\TemplateElement; |
|
|
use MensBeam\HTML\TemplateElement; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @covers \MensBeam\HTML\Document |
|
|
|
|
|
* @covers \MensBeam\HTML\DocumentFragment |
|
|
|
|
|
* @covers \MensBeam\HTML\Element |
|
|
|
|
|
* @covers \MensBeam\HTML\TemplateElement |
|
|
|
|
|
* @covers \MensBeam\HTML\Comment |
|
|
|
|
|
* @covers \MensBeam\HTML\Text |
|
|
|
|
|
*/ |
|
|
|
|
|
class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
/** @dataProvider provideNamespacedElements */ |
|
|
/** |
|
|
|
|
|
* @dataProvider provideNamespacedElements |
|
|
|
|
|
* @covers \MensBeam\HTML\Document::createElementNS |
|
|
|
|
|
*/ |
|
|
public function testCreateNamespacedElements(?string $nsIn, string $nameIn, ?string $nsOut, string $local, string $prefix): void { |
|
|
public function testCreateNamespacedElements(?string $nsIn, string $nameIn, ?string $nsOut, string $local, string $prefix): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$e = $d->createElementNS($nsIn, $nameIn); |
|
|
$e = $d->createElementNS($nsIn, $nameIn); |
|
@ -45,7 +40,10 @@ class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
["http://www.w3.org/1998/Math/MathML", "TEST", "http://www.w3.org/1998/Math/MathML", "TEST", ""], |
|
|
["http://www.w3.org/1998/Math/MathML", "TEST", "http://www.w3.org/1998/Math/MathML", "TEST", ""], |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
/** @dataProvider provideBareElements */ |
|
|
/** |
|
|
|
|
|
* @dataProvider provideBareElements |
|
|
|
|
|
* @covers \MensBeam\HTML\Document::createElement |
|
|
|
|
|
*/ |
|
|
public function testCreateBareElements(string $nameIn, $nameOut): void { |
|
|
public function testCreateBareElements(string $nameIn, $nameOut): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$e = $d->createElement($nameIn); |
|
|
$e = $d->createElement($nameIn); |
|
@ -63,6 +61,7 @@ class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** @covers \MensBeam\HTML\Document::createElementNS */ |
|
|
public function testCreateTemplateElements(): void { |
|
|
public function testCreateTemplateElements(): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$t = $d->createElement("template"); |
|
|
$t = $d->createElement("template"); |
|
@ -85,7 +84,10 @@ class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
$this->assertNotNull($t->ownerDocument); |
|
|
$this->assertNotNull($t->ownerDocument); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** @dataProvider provideNamespacedAttributeCreations */ |
|
|
/** |
|
|
|
|
|
* @dataProvider provideNamespacedAttributeCreations |
|
|
|
|
|
* @covers \MensBeam\HTML\Document::createAttributeNS |
|
|
|
|
|
*/ |
|
|
public function testCreateNamespacedAttributes(?string $nsIn, string $nameIn, string $local, string $prefix): void { |
|
|
public function testCreateNamespacedAttributes(?string $nsIn, string $nameIn, string $local, string $prefix): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$d->appendChild($d->createElement("html")); |
|
|
$d->appendChild($d->createElement("html")); |
|
@ -97,15 +99,22 @@ class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
|
|
|
|
|
|
public function provideNamespacedAttributeCreations(): iterable { |
|
|
public function provideNamespacedAttributeCreations(): iterable { |
|
|
return [ |
|
|
return [ |
|
|
[null, "test", "test", ""], |
|
|
[null, "test", "test", ""], |
|
|
[null, "test:test", "testU00003Atest", ""], |
|
|
[null, "test:test", "testU00003Atest", ""], |
|
|
[null, "test", "test", ""], |
|
|
[null, "test", "test", ""], |
|
|
[null, "TEST:TEST", "TESTU00003ATEST", ""], |
|
|
[null, "TEST:TEST", "TESTU00003ATEST", ""], |
|
|
["fake_ns", "test", "test", ""], |
|
|
["fake_ns", "test", "test", ""], |
|
|
|
|
|
["fake_ns", "test:test", "test", "test"], |
|
|
|
|
|
["fake_ns", "TEST:TEST", "TEST", "TEST"], |
|
|
|
|
|
["fake_ns", "test:test:test", "testU00003Atest", "test"], |
|
|
|
|
|
["fake_ns", "TEST:TEST:TEST", "TESTU00003ATEST", "TEST"], |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** @dataProvider provideBareAttributeCreations */ |
|
|
/** |
|
|
|
|
|
* @dataProvider provideBareAttributeCreations |
|
|
|
|
|
* @covers \MensBeam\HTML\Document::createAttribute |
|
|
|
|
|
*/ |
|
|
public function testCreateBareAttributes(string $nameIn, string $nameOut): void { |
|
|
public function testCreateBareAttributes(string $nameIn, string $nameOut): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$d->appendChild($d->createElement("html")); |
|
|
$d->appendChild($d->createElement("html")); |
|
@ -123,31 +132,128 @@ class TestDOM extends \PHPUnit\Framework\TestCase { |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** @dataProvider provideNamespacedAttributeSettings */ |
|
|
/** |
|
|
|
|
|
* @dataProvider provideNamespacedAttributeSettings |
|
|
|
|
|
* @covers \MensBeam\HTML\Element::setAttributeNS |
|
|
|
|
|
*/ |
|
|
public function testSetNamespoacedAttributes(?string $elementNS, ?string $attrNS, string $nameIn, string $nameOut): void { |
|
|
public function testSetNamespoacedAttributes(?string $elementNS, ?string $attrNS, string $nameIn, string $nameOut): void { |
|
|
$d = new Document; |
|
|
$d = new Document; |
|
|
$e = $d->createElementNS($elementNS, "test"); |
|
|
$e = $d->createElementNS($elementNS, "test"); |
|
|
|
|
|
$this->assertSame(0, $e->attributes->length); |
|
|
$e->setAttributeNS($attrNS, $nameIn, "test"); |
|
|
$e->setAttributeNS($attrNS, $nameIn, "test"); |
|
|
$this->assertSame(1, $e->attributes->length); |
|
|
$this->assertSame(1, $e->attributes->length); |
|
|
$this->assertTrue($e->hasAttribute($nameOut)); |
|
|
$a = $e->attributes[0]; |
|
|
$this->assertSame($attrNS, $e->attributes[0]->namespaceURI); |
|
|
$this->assertSame($nameOut, $a->nodeName); |
|
|
|
|
|
$this->assertSame($attrNS, $a->namespaceURI); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function provideNamespacedAttributeSettings(): iterable { |
|
|
public function provideNamespacedAttributeSettings(): iterable { |
|
|
return [ |
|
|
return [ |
|
|
[null, null, "test", "test"], |
|
|
[null, null, "test", "test"], |
|
|
[null, null, "TEST", "test"], |
|
|
[null, null, "TEST", "test"], |
|
|
["http://www.w3.org/1999/xhtml", null, "test", "test"], |
|
|
["http://www.w3.org/1999/xhtml", null, "test", "test"], |
|
|
["http://www.w3.org/1999/xhtml", null, "TEST", "test"], |
|
|
["http://www.w3.org/1999/xhtml", null, "TEST", "test"], |
|
|
[null, null, "test:test", "testU00003Atest"], |
|
|
[null, null, "test:test", "testU00003Atest"], |
|
|
[null, null, "TEST:TEST", "testU00003Atest"], |
|
|
[null, null, "TEST:TEST", "testU00003Atest"], |
|
|
["http://www.w3.org/1999/xhtml", null, "test:test", "testU00003Atest"], |
|
|
["http://www.w3.org/1999/xhtml", null, "test:test", "testU00003Atest"], |
|
|
["http://www.w3.org/1999/xhtml", null, "TEST:TEST", "testU00003Atest"], |
|
|
["http://www.w3.org/1999/xhtml", null, "TEST:TEST", "testU00003Atest"], |
|
|
[null, "http://www.w3.org/1999/xhtml", "test:test", "test:test"], |
|
|
[null, "http://www.w3.org/1999/xhtml", "test:test", "test:test"], |
|
|
[null, "http://www.w3.org/1999/xhtml", "TEST:TEST", "TEST:TEST"], |
|
|
[null, "http://www.w3.org/1999/xhtml", "TEST:TEST", "TEST:TEST"], |
|
|
["http://www.w3.org/1998/Math/MathML", null, "test", "test"], |
|
|
["http://www.w3.org/1998/Math/MathML", null, "test", "test"], |
|
|
["http://www.w3.org/1998/Math/MathML", null, "TEST", "TEST"], |
|
|
["http://www.w3.org/1998/Math/MathML", null, "TEST", "TEST"], |
|
|
[null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink", "xmlns:xlink"], |
|
|
[null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink", "xmlns:xlink"], |
|
|
|
|
|
[null, "http://www.w3.org/2000/xmlns/", "xmlns:XLINK", "xmlns:XLINK"], |
|
|
|
|
|
[null, "fake_ns", "test:test:test", "test:testU00003Atest"], |
|
|
|
|
|
[null, "fake_ns", "TEST:TEST:TEST", "TEST:TESTU00003ATEST"], |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @dataProvider provideBareAttributeSettings |
|
|
|
|
|
* @covers \MensBeam\HTML\Element::setAttribute |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testSetBareAttributes(?string $elementNS, string $nameIn, string $nameOut): void { |
|
|
|
|
|
$d = new Document; |
|
|
|
|
|
$e = $d->createElementNS($elementNS, "test"); |
|
|
|
|
|
$this->assertSame(0, $e->attributes->length); |
|
|
|
|
|
$e->setAttribute($nameIn, "test"); |
|
|
|
|
|
$this->assertSame(1, $e->attributes->length); |
|
|
|
|
|
$a = $e->attributes[0]; |
|
|
|
|
|
$this->assertSame($nameOut, $a->nodeName); |
|
|
|
|
|
$this->assertNull($a->namespaceURI); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function provideBareAttributeSettings(): iterable { |
|
|
|
|
|
return [ |
|
|
|
|
|
[null, "test", "test"], |
|
|
|
|
|
[null, "TEST", "test"], |
|
|
|
|
|
["http://www.w3.org/1999/xhtml", "test", "test"], |
|
|
|
|
|
["http://www.w3.org/1999/xhtml", "TEST", "test"], |
|
|
|
|
|
[null, "test:test", "testU00003Atest"], |
|
|
|
|
|
[null, "TEST:TEST", "testU00003Atest"], |
|
|
|
|
|
["http://www.w3.org/1999/xhtml", "test:test", "testU00003Atest"], |
|
|
|
|
|
["http://www.w3.org/1999/xhtml", "TEST:TEST", "testU00003Atest"], |
|
|
|
|
|
["http://www.w3.org/1998/Math/MathML", "test", "test"], |
|
|
|
|
|
["http://www.w3.org/1998/Math/MathML", "TEST", "TEST"], |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @dataProvider provideAttributeNodeSettings |
|
|
|
|
|
* @covers \MensBeam\HTML\Element::setAttributeNode |
|
|
|
|
|
* @covers \MensBeam\HTML\Element::setAttributeNodeNS |
|
|
|
|
|
*/ |
|
|
|
|
|
public function testSetAttributeNodes(bool $ns, ?string $elementNS, ?string $attrNS, string $name): void { |
|
|
|
|
|
$d = new Document; |
|
|
|
|
|
$e = $d->createElementNS($elementNS, "test"); |
|
|
|
|
|
$d->appendChild($e); |
|
|
|
|
|
$this->assertSame(0, $e->attributes->length); |
|
|
|
|
|
$a = $d->createAttributeNS($attrNS, $name); |
|
|
|
|
|
if ($ns) { |
|
|
|
|
|
$e->setAttributeNodeNS($a); |
|
|
|
|
|
} else { |
|
|
|
|
|
$e->setAttributeNode($a); |
|
|
|
|
|
} |
|
|
|
|
|
$this->assertSame(1, $e->attributes->length); |
|
|
|
|
|
$a = $e->attributes[0]; |
|
|
|
|
|
$this->assertSame($name, $a->nodeName); |
|
|
|
|
|
$this->assertSame($attrNS, $a->namespaceURI); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function provideAttributeNodeSettings(): iterable { |
|
|
|
|
|
return [ |
|
|
|
|
|
[true, null, null, "test"], |
|
|
|
|
|
[true, null, null, "TEST"], |
|
|
|
|
|
[true, "http://www.w3.org/1999/xhtml", null, "test"], |
|
|
|
|
|
[true, "http://www.w3.org/1999/xhtml", null, "TEST"], |
|
|
|
|
|
[true, null, null, "testU00003Atest"], |
|
|
|
|
|
[true, null, null, "TESTU00003ATEST"], |
|
|
|
|
|
[true, "http://www.w3.org/1999/xhtml", null, "testU00003Atest"], |
|
|
|
|
|
[true, "http://www.w3.org/1999/xhtml", null, "TESTU00003ATEST"], |
|
|
|
|
|
[true, null, "http://www.w3.org/1999/xhtml", "test:test"], |
|
|
|
|
|
[true, null, "http://www.w3.org/1999/xhtml", "TEST:TEST"], |
|
|
|
|
|
[true, "http://www.w3.org/1998/Math/MathML", null, "test"], |
|
|
|
|
|
[true, "http://www.w3.org/1998/Math/MathML", null, "TEST"], |
|
|
|
|
|
[true, null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink"], |
|
|
|
|
|
[true, null, "http://www.w3.org/2000/xmlns/", "xmlns:XLINK"], |
|
|
|
|
|
[true, null, "fake_ns", "test:testU00003Atest"], |
|
|
|
|
|
[true, null, "fake_ns", "TEST:TESTU00003ATEST"], |
|
|
|
|
|
[false, null, null, "test"], |
|
|
|
|
|
[false, null, null, "TEST"], |
|
|
|
|
|
[false, "http://www.w3.org/1999/xhtml", null, "test"], |
|
|
|
|
|
[false, "http://www.w3.org/1999/xhtml", null, "TEST"], |
|
|
|
|
|
[false, null, null, "testU00003Atest"], |
|
|
|
|
|
[false, null, null, "TESTU00003ATEST"], |
|
|
|
|
|
[false, "http://www.w3.org/1999/xhtml", null, "testU00003Atest"], |
|
|
|
|
|
[false, "http://www.w3.org/1999/xhtml", null, "TESTU00003ATEST"], |
|
|
|
|
|
[false, null, "http://www.w3.org/1999/xhtml", "test:test"], |
|
|
|
|
|
[false, null, "http://www.w3.org/1999/xhtml", "TEST:TEST"], |
|
|
|
|
|
[false, "http://www.w3.org/1998/Math/MathML", null, "test"], |
|
|
|
|
|
[false, "http://www.w3.org/1998/Math/MathML", null, "TEST"], |
|
|
|
|
|
[false, null, "http://www.w3.org/2000/xmlns/", "xmlns:xlink"], |
|
|
|
|
|
[false, null, "http://www.w3.org/2000/xmlns/", "xmlns:XLINK"], |
|
|
|
|
|
[false, null, "fake_ns", "test:testU00003Atest"], |
|
|
|
|
|
[false, null, "fake_ns", "TEST:TESTU00003ATEST"], |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|