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