xref: /PHP-8.1/ext/dom/tests/gh10234.phpt (revision c473787a)
1--TEST--
2GH-10234 (Setting DOMAttr::textContent results in an empty attribute value.)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$document = new DOMDocument();
8$document->loadXML('<element attribute="value"/>');
9$attribute = $document->documentElement->getAttributeNode('attribute');
10
11echo "-- Attribute tests --\n";
12
13var_dump($document->saveHTML());
14var_dump($attribute->textContent);
15
16$attribute->textContent = 'new value';
17var_dump($attribute->textContent);
18var_dump($document->saveHTML());
19
20$attribute->textContent = 'hello & world';
21var_dump($attribute->textContent);
22var_dump($document->saveHTML());
23
24$attribute->textContent = '<b>hi</b>';
25var_dump($attribute->textContent);
26var_dump($document->saveHTML());
27
28$attribute->textContent = 'quote "test"';
29var_dump($attribute->textContent);
30var_dump($document->saveHTML());
31
32$attribute->textContent = "quote 'test'";
33var_dump($attribute->textContent);
34var_dump($document->saveHTML());
35
36$attribute->textContent = "quote '\"test\"'";
37var_dump($attribute->textContent);
38var_dump($document->saveHTML());
39
40echo "-- Document element tests --\n";
41
42$document->documentElement->textContent = 'hello & world';
43var_dump($document->documentElement->textContent);
44var_dump($document->saveHTML());
45
46$document->documentElement->textContent = '<b>hi</b>';
47var_dump($document->documentElement->textContent);
48var_dump($document->saveHTML());
49
50$document->documentElement->textContent = 'quote "test"';
51var_dump($document->documentElement->textContent);
52var_dump($document->saveHTML());
53
54$document->documentElement->textContent = "quote 'test'";
55var_dump($document->documentElement->textContent);
56var_dump($document->saveHTML());
57?>
58--EXPECT--
59-- Attribute tests --
60string(38) "<element attribute="value"></element>
61"
62string(5) "value"
63string(9) "new value"
64string(42) "<element attribute="new value"></element>
65"
66string(13) "hello & world"
67string(50) "<element attribute="hello &amp; world"></element>
68"
69string(9) "<b>hi</b>"
70string(54) "<element attribute="&lt;b&gt;hi&lt;/b&gt;"></element>
71"
72string(12) "quote "test""
73string(45) "<element attribute='quote "test"'></element>
74"
75string(12) "quote 'test'"
76string(45) "<element attribute="quote 'test'"></element>
77"
78string(14) "quote '"test"'"
79string(57) "<element attribute="quote '&quot;test&quot;'"></element>
80"
81-- Document element tests --
82string(13) "hello & world"
83string(74) "<element attribute="quote '&quot;test&quot;'">hello &amp; world</element>
84"
85string(9) "<b>hi</b>"
86string(78) "<element attribute="quote '&quot;test&quot;'">&lt;b&gt;hi&lt;/b&gt;</element>
87"
88string(12) "quote "test""
89string(69) "<element attribute="quote '&quot;test&quot;'">quote "test"</element>
90"
91string(12) "quote 'test'"
92string(69) "<element attribute="quote '&quot;test&quot;'">quote 'test'</element>
93"
94