xref: /PHP-7.0/ext/dom/tests/node_textcontent.phpt (revision 6576d809)
1--TEST--
2Testing reading and writing to DOMNode::textContent
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6if (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
14   https://github.com/GNOME/libxml2/commit/f3c06692e0d200ae0d35b5b3c31de8c56aa99ac6
15
16 The workaround if you are being hit by this is to add a <!DOCTYPE html> tag
17*/
18$html = <<<HTML
19<div id="test"><span>hi there</span></div>
20HTML;
21
22$text = '<p>hello world &trade;</p>';
23
24$dom = new DOMDocument('1.0', 'UTF-8');
25$dom->loadHTML($html);
26
27$node = $dom->getElementById('test');
28var_dump($node->textContent);
29$node->textContent = $text;
30var_dump($node->textContent == $text);
31
32var_dump($dom->saveHTML($node));
33
34?>
35--EXPECT--
36string(8) "hi there"
37bool(true)
38string(63) "<div id="test">&lt;p&gt;hello world &amp;trade;&lt;/p&gt;</div>"
39
40