xref: /PHP-7.4/ext/dom/tests/domchardata.phpt (revision d679f022)
1--TEST--
2CharData: DOMCharacterData and related functionality
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
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);
58
59echo "Split text: ".$text2->wholeText."\n";
60$text3 = $text2->splitText(1);
61
62echo "Is Whitespace?: ".($text2->isElementContentWhitespace()?'YES':'NO');
63?>
64--EXPECT--
65Comment Length: 42
66New Comment Length: 15
67New Comment Data: Updated comment
68Substring: <>&"
69New Substring: <>&'
70Comment Value: instructions
71New Comment Value: some more instructions
72Updated Comment Value: some more comment strings
73Whole Text: some text characters
74Split text:  characters
75Is Whitespace?: YES
76