Skip to content

Commit

Permalink
Prepending self node fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ttk authored and Christoph Singer committed Feb 19, 2019
1 parent dbefacd commit 563bc7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Tests/HtmlPageCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ public function testPrepend()
$c = new HtmlPageCrawler('<div id="content"></div>');
$c->filter('#content')->prepend(new HtmlPageCrawler('<p>Text before h1</p><p>and more text before</p>'));
$this->assertEquals('<div id="content"><p>Text before h1</p><p>and more text before</p></div>', $c->saveHTML());

$c = new HtmlPageCrawler('<div id="content"><span>Prepend Self</span></div>');
$c->filter('#content')->prepend($c->filter('span'));
$this->assertEquals('<div id="content"><span>Prepend Self</span></div>', $c->saveHTML());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlPageCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function prepend($content)
$newnode = static::importNewnode($newnode, $node, $i);
if ($refnode === null) {
$node->appendChild($newnode);
} else {
} else if ($refnode !== $newnode) {
$node->insertBefore($newnode, $refnode);
}
$newnodes[] = $newnode;
Expand Down

0 comments on commit 563bc7a

Please sign in to comment.