xref: /PHP-8.3/ext/dom/tests/domchardata.phpt (revision 2aebca89)
1--TEST--
2CharData: DOMCharacterData and related functionality
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7require_once("dom_test.inc");
8
9$dom = new DOMDocument;
10$dom->loadXML($xmlstr);
11if(!$dom) {
12  echo "Error while parsing the document\n";
13  exit;
14}
15
16$node = $dom->documentElement;
17
18$charnode = $dom->createElement('charnode');
19$node->appendChild($charnode);
20
21/* DOMComment */
22$comment = new DOMComment('Testing character data and extending nodes');
23$charnode->appendChild($comment);
24
25echo "Comment Length: ".$comment->length."\n";
26
27$comment->data = 'Updated comment';
28echo "New Comment Length: ".$comment->length."\n";
29echo "New Comment Data: ".$comment->data."\n";
30
31/* DOMCDataSection */
32$cdata = new DOMCDataSection('Chars: <>&"');
33$charnode->appendChild($cdata);
34
35echo "Substring: ".$cdata->substringData(7, 4)."\n";
36$cdata->replaceData(10, 1, "'");
37echo "New Substring: ".$cdata->substringData(7, 4)."\n";
38
39/* DOMCharacterData using DOMComment */
40$comment = new DOMComment('instructions');
41echo "Comment Value: ".$comment->data."\n";
42$comment->data = 'some more instructions';
43echo "New Comment Value: ".$comment->data."\n";
44
45$comment->insertData(10, 'pi ');
46$comment->replaceData(18, 5, 'i');
47$comment->insertData(20, 'g');
48$comment->deleteData(13, 2);
49$comment->deleteData(10, 3);
50$comment->insertData(10, 'comment ');
51echo "Updated Comment Value: ".$comment->data."\n";
52
53/* DOMText */
54$text = new DOMText('some text characters');
55
56echo "Whole Text: ".$text->wholeText."\n";
57$text2 = $text->splitText(9);
58echo "Is Whitespace?: ", $text2->isElementContentWhitespace()?'YES':'NO', "\n";
59
60echo "Split text: ".$text2->wholeText."\n";
61$text3 = $text2->splitText(1);
62
63echo "Is Whitespace?: ".($text2->isElementContentWhitespace()?'YES':'NO');
64?>
65--EXPECT--
66Comment Length: 42
67New Comment Length: 15
68New Comment Data: Updated comment
69Substring: <>&"
70New Substring: <>&'
71Comment Value: instructions
72New Comment Value: some more instructions
73Updated Comment Value: some more comment strings
74Whole Text: some text characters
75Is Whitespace?: NO
76Split text:  characters
77Is Whitespace?: YES
78