node_textcontent.phpt 930 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Testing reading and writing to DOMNode::textContent
  3. --EXTENSIONS--
  4. dom
  5. --SKIPIF--
  6. <?php
  7. if (LIBXML_VERSION < 20707) die ('skip requires libxml2-2.7.7 or higher');
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. If this test is failing it is because the libxml2 library being used does
  13. not have this bug fix from 2009:
  14. https://github.com/GNOME/libxml2/commit/f3c06692e0d200ae0d35b5b3c31de8c56aa99ac6
  15. The workaround if you are being hit by this is to add a <!DOCTYPE html> tag
  16. */
  17. $html = <<<HTML
  18. <div id="test"><span>hi there</span></div>
  19. HTML;
  20. $text = '<p>hello world &trade;</p>';
  21. $dom = new DOMDocument('1.0', 'UTF-8');
  22. $dom->loadHTML($html);
  23. $node = $dom->getElementById('test');
  24. var_dump($node->textContent);
  25. $node->textContent = $text;
  26. var_dump($node->textContent == $text);
  27. var_dump($dom->saveHTML($node));
  28. ?>
  29. --EXPECT--
  30. string(8) "hi there"
  31. bool(true)
  32. string(63) "<div id="test">&lt;p&gt;hello world &amp;trade;&lt;/p&gt;</div>"