Skip to content

Commit

Permalink
add getparent
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelroecker committed Aug 17, 2016
1 parent 6394d85 commit ebc8927
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/GlHtmlNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function add(
$this->node->appendChild($frag);
}

/**
* @return GlHtmlNode
*/
public function getParent() {
return new GlHtmlNode($this->node->parentNode);
}

/**
* @param string $html
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/GlHtmlNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ public function testReplaceMe() {
$this->assertEquals($htmlresult,$result);
}

public function testRemplaceMeParent() {
$html = "<!DOCTYPE html><html><head></head><body><div><span><div></div></span></div></body></html>";
$htmlresult = "<!DOCTYPE html><html><head></head><body><h1></h1></body></html>";

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

$node->getParent()->replaceMe("<h1></h1>");

$result = $dom->html();

$htmlresult = str_replace(["\n","\r"],'',$htmlresult);
$result = str_replace(["\n","\r"],'',$result);

$this->assertEquals($htmlresult,$result);
}

public function testsetAttributes() {
$html = "<!DOCTYPE html><html><head></head><body><div><span><div></div></span></div></body></html>";
$htmlresult = '<!DOCTYPE html><html><head></head><body><div><span id="test"><div></div></span></div></body></html>';
Expand Down

0 comments on commit ebc8927

Please sign in to comment.