From 7bf357f2c278df7dda1a90cedb969b225f78d459 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 13 Oct 2023 21:38:45 +0200 Subject: [PATCH] Added test --- tests/ElementTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/ElementTest.php b/tests/ElementTest.php index 149abaa..1d78d2c 100644 --- a/tests/ElementTest.php +++ b/tests/ElementTest.php @@ -8,6 +8,8 @@ use PHPUnit\Framework\Attributes\WithoutErrorHandler; use PHPUnit\Framework\TestCase; use s9e\SweetDOM\Document; +use s9e\SweetDOM\Element; +use s9e\SweetDOM\NodeCreator; #[CoversClass('s9e\SweetDOM\Element')] #[CoversClass('s9e\SweetDOM\NodeTraits\DeprecatedMethods')] @@ -47,6 +49,19 @@ public function testUnknownXslMethod() $dom->documentElement->appendXslUnknown(); } + public function testCustomNodeCreator() + { + $dom = new Document; + $dom->loadXML(''); + $dom->nodeCreator = new MyNodeCreator($dom); + $dom->documentElement->appendBr(); + + $this->assertXmlStringEqualsXmlString( + '
', + $dom->saveXML() + ); + } + #[DataProvider('getMagicMethodsTests')] public function testMagicMethods(string $expected, string $methodName, array $args = []) { @@ -540,4 +555,12 @@ public static function getInsertAdjacentXMLTests() ], ]; } +} + +class MyNodeCreator extends NodeCreator +{ + public function createBr(): Element + { + return $this->ownerDocument->createElement('br'); + } } \ No newline at end of file