xref: /PHP-8.1/ext/dom/tests/DOMEntity_fields.phpt (revision d439ee18)
1--TEST--
2DOMEntity fields
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$xmlString = <<<XML
8<?xml version="1.0"?>
9<!DOCTYPE test [
10    <!ENTITY sampleInternalEntity "This is a sample entity value.">
11    <!ENTITY sampleExternalSystemWithNotationName SYSTEM "external.stuff" NDATA stuff>
12    <!ENTITY sampleExternalSystemWithoutNotationName SYSTEM "external.stuff" NDATA >
13    <!ENTITY sampleExternalPublicWithNotationName1 PUBLIC "public id" "external.stuff" NDATA stuff>
14    <!ENTITY sampleExternalPublicWithNotationName2 PUBLIC "" "external.stuff" NDATA stuff>
15    <!ENTITY sampleExternalPublicWithoutNotationName1 PUBLIC "public id" "external.stuff" NDATA >
16    <!ENTITY sampleExternalPublicWithoutNotationName2 PUBLIC "" "external.stuff" NDATA >
17]>
18<root/>
19XML;
20
21$dom = new DOMDocument();
22$dom->loadXML($xmlString);
23
24// Sort them, the iteration order isn't defined
25$entities = iterator_to_array($dom->doctype->entities);
26ksort($entities);
27
28foreach ($entities as $entity) {
29    echo "Entity name: {$entity->nodeName}\n";
30    echo "publicId: ";
31    var_dump($entity->publicId);
32    echo "systemId: ";
33    var_dump($entity->systemId);
34    echo "notationName: ";
35    var_dump($entity->notationName);
36    echo "actualEncoding: ";
37    var_dump($entity->actualEncoding);
38    echo "encoding: ";
39    var_dump($entity->encoding);
40    echo "version: ";
41    var_dump($entity->version);
42    echo "\n";
43}
44?>
45--EXPECT--
46Entity name: sampleExternalPublicWithNotationName1
47publicId: string(9) "public id"
48systemId: string(14) "external.stuff"
49notationName: string(5) "stuff"
50actualEncoding: NULL
51encoding: NULL
52version: NULL
53
54Entity name: sampleExternalPublicWithNotationName2
55publicId: string(0) ""
56systemId: string(14) "external.stuff"
57notationName: string(5) "stuff"
58actualEncoding: NULL
59encoding: NULL
60version: NULL
61
62Entity name: sampleExternalPublicWithoutNotationName1
63publicId: string(9) "public id"
64systemId: string(14) "external.stuff"
65notationName: string(0) ""
66actualEncoding: NULL
67encoding: NULL
68version: NULL
69
70Entity name: sampleExternalPublicWithoutNotationName2
71publicId: string(0) ""
72systemId: string(14) "external.stuff"
73notationName: string(0) ""
74actualEncoding: NULL
75encoding: NULL
76version: NULL
77
78Entity name: sampleExternalSystemWithNotationName
79publicId: NULL
80systemId: string(14) "external.stuff"
81notationName: string(5) "stuff"
82actualEncoding: NULL
83encoding: NULL
84version: NULL
85
86Entity name: sampleExternalSystemWithoutNotationName
87publicId: NULL
88systemId: string(14) "external.stuff"
89notationName: string(0) ""
90actualEncoding: NULL
91encoding: NULL
92version: NULL
93
94Entity name: sampleInternalEntity
95publicId: NULL
96systemId: NULL
97notationName: NULL
98actualEncoding: NULL
99encoding: NULL
100version: NULL
101