node_textcontent.phpt 939 B

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