From ebc89276f65b55454e9a349e330a39d11c57937c Mon Sep 17 00:00:00 2001 From: Emmanuel ROECKER Date: Wed, 17 Aug 2016 22:23:27 +0200 Subject: [PATCH] add getparent --- src/GlHtmlNode.php | 7 +++++++ tests/GlHtmlNodeTest.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/GlHtmlNode.php b/src/GlHtmlNode.php index 008c3c9..e26115d 100644 --- a/src/GlHtmlNode.php +++ b/src/GlHtmlNode.php @@ -69,6 +69,13 @@ function add( $this->node->appendChild($frag); } + /** + * @return GlHtmlNode + */ + public function getParent() { + return new GlHtmlNode($this->node->parentNode); + } + /** * @param string $html */ diff --git a/tests/GlHtmlNodeTest.php b/tests/GlHtmlNodeTest.php index bd69096..97d6461 100644 --- a/tests/GlHtmlNodeTest.php +++ b/tests/GlHtmlNodeTest.php @@ -44,6 +44,23 @@ public function testReplaceMe() { $this->assertEquals($htmlresult,$result); } + public function testRemplaceMeParent() { + $html = "
"; + $htmlresult = "

"; + + $dom = new GlHtml($html); + $node = $dom->get("span")[0]; + + $node->getParent()->replaceMe("

"); + + $result = $dom->html(); + + $htmlresult = str_replace(["\n","\r"],'',$htmlresult); + $result = str_replace(["\n","\r"],'',$result); + + $this->assertEquals($htmlresult,$result); + } + public function testsetAttributes() { $html = "
"; $htmlresult = '
';