Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix replaceChild() method #120

Closed
wants to merge 1 commit into from
Closed

Fix replaceChild() method #120

wants to merge 1 commit into from

Conversation

ma-si
Copy link

@ma-si ma-si commented Jul 29, 2017

Issue:
replaceChild() removes old child but did not add new child

Test code:

        $html = file_get_contents($source);
        $dom = new Dom();
        $dom->load($html);
        $nodes = $dom->find($node);
        foreach ($nodes as $element) {
            $text = new Dom\TextNode($replacement);
            $element->getParent()->replaceChild($element->id(), $text);
        }
        $resultHTML = $dom;

Debug:
Original result $this->children:

  1 => PHPHtmlParser\Dom\HtmlNode {#3347}
  2 => PHPHtmlParser\Dom\TextNode {#910}
  3 => PHPHtmlParser\Dom\HtmlNode {#4375}
  4 => PHPHtmlParser\Dom\TextNode {#6482}
  5 => PHPHtmlParser\Dom\HtmlNode {#889}
  6 => PHPHtmlParser\Dom\TextNode {#846}

馃 $element->getParent()->replaceChild($element->id(), $text);

  1 => PHPHtmlParser\Dom\HtmlNode {#3347}
  2 => PHPHtmlParser\Dom\TextNode {#910}
  3 => PHPHtmlParser\Dom\HtmlNode {#4375}
  4 => PHPHtmlParser\Dom\TextNode {#6482}

Other results are OK:
$element->getParent()->removeChild($element->id());

  1 => PHPHtmlParser\Dom\HtmlNode {#3347}
  2 => PHPHtmlParser\Dom\TextNode {#910}
  3 => PHPHtmlParser\Dom\HtmlNode {#4375}
  4 => PHPHtmlParser\Dom\TextNode {#6482}
  5 => PHPHtmlParser\Dom\TextNode {#846}

$element->getParent()->addChild($text);

  1 => PHPHtmlParser\Dom\HtmlNode {#3347}
  2 => PHPHtmlParser\Dom\TextNode {#910}
  3 => PHPHtmlParser\Dom\HtmlNode {#4375}
  4 => PHPHtmlParser\Dom\TextNode {#6482}
  5 => PHPHtmlParser\Dom\HtmlNode {#889}
  6 => PHPHtmlParser\Dom\TextNode {#846}
  7 => PHPHtmlParser\Dom\TextNode {#2288}

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 94.104% when pulling bec9ec9 on ma-si:master into 9663472 on paquettg:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 94.104% when pulling bec9ec9 on ma-si:master into 9663472 on paquettg:master.

@paquettg paquettg closed this Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants