Skip to content

Commit ad5cb06

Browse files
committed
More test coverage for new types
1 parent 86d437c commit ad5cb06

8 files changed

+220
-29
lines changed

ext/dom/tests/dom_import_simplexml.phpt

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ if(!$s) {
1212
}
1313
$dom = dom_import_simplexml($s);
1414
print $dom->ownerDocument->saveXML();
15+
16+
// This should fail because it has been imported already above in legacy DOM
17+
try {
18+
DOM\import_simplexml($s);
19+
} catch (TypeError $e) {
20+
echo $e->getMessage(), "\n";
21+
}
1522
?>
1623
--EXPECT--
1724
<?xml version="1.0"?>
@@ -25,3 +32,4 @@ print $dom->ownerDocument->saveXML();
2532
<author>John Steinbeck</author>
2633
</book>
2734
</books>
35+
DOM\import_simplexml(): Argument #1 ($node) must not be already imported as a DOMNode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
DOMNode::getRootNode()
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
// Same as DOMNode_getRootNode.phpt but for modern DOM
9+
10+
$dom = DOM\XMLDocument::createFromString('<?xml version="1.0"?><html><body/></html>');
11+
12+
var_dump($dom->documentElement->firstElementChild->getRootNode() === $dom);
13+
$p = $dom->createElement('p');
14+
var_dump($p->getRootNode() === $p);
15+
$dom->documentElement->appendChild($p);
16+
var_dump($p->getRootNode() === $dom);
17+
$dom->documentElement->remove();
18+
var_dump($p->getRootNode() === $p);
19+
20+
$fragment = $dom->createDocumentFragment();
21+
var_dump($fragment->getRootNode() === $fragment);
22+
$div = $fragment->appendChild($dom->createElement('div'));
23+
$div->appendChild($p);
24+
var_dump($p->getRootNode() === $fragment);
25+
26+
?>
27+
--EXPECT--
28+
bool(true)
29+
bool(true)
30+
bool(true)
31+
bool(true)
32+
bool(true)
33+
bool(true)

ext/dom/tests/modern/spec/DOMNode_textContent_edge_case.phpt

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test processing instruction character data manipulation
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = DOM\XMLDocument::createFromString('<root><?pi value?></root>');
9+
10+
$pi = $dom->documentElement->firstChild;
11+
12+
echo $pi->substringData(0, 3), "\n";
13+
$pi->appendData('foobar');
14+
echo $pi->textContent, "\n";
15+
$pi->insertData(6, 'oooooo');
16+
echo $pi->textContent, "\n";
17+
$pi->deleteData(0, strlen('value'));
18+
echo $pi->textContent, "\n";
19+
$pi->replaceData(1, 8, 'oo');
20+
echo $pi->textContent, "\n";
21+
22+
?>
23+
--EXPECT--
24+
val
25+
valuefoobar
26+
valuefoooooooobar
27+
foooooooobar
28+
foobar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
XMLDocument::$version
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = DOM\XMLDocument::createFromString('<root><child/></root>');
9+
var_dump($dom->xmlVersion);
10+
11+
foreach (['0.1', '1.0', '1.1', '', 'foo'] as $version) {
12+
try {
13+
$dom->xmlVersion = $version;
14+
} catch (ValueError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
var_dump($dom->xmlVersion);
18+
}
19+
20+
?>
21+
--EXPECT--
22+
string(3) "1.0"
23+
Invalid XML version
24+
string(3) "1.0"
25+
string(3) "1.0"
26+
string(3) "1.1"
27+
Invalid XML version
28+
string(3) "1.1"
29+
Invalid XML version
30+
string(3) "1.1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Document URI/URL
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = DOM\XMLDocument::createFromString('<root><child/></root>');
9+
var_dump($dom->documentURI);
10+
var_dump($dom->URL);
11+
12+
try {
13+
$dom->URL = NULL;
14+
var_dump($dom->documentURI);
15+
var_dump($dom->URL);
16+
} catch (TypeError $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
$dom->URL = "";
21+
var_dump($dom->documentURI);
22+
var_dump($dom->URL);
23+
24+
$dom->URL = "http://example.com/";
25+
var_dump($dom->documentURI);
26+
var_dump($dom->URL);
27+
28+
?>
29+
--EXPECT--
30+
string(20) "/home/niels/php-src/"
31+
string(20) "/home/niels/php-src/"
32+
Cannot assign null to property DOM\Document::$URL of type string
33+
string(0) ""
34+
string(0) ""
35+
string(19) "http://example.com/"
36+
string(19) "http://example.com/"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
textContent edge cases
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = DOM\XMLDocument::createFromString('<container>text<?pi value?></container>');
9+
10+
echo "document text content: ";
11+
var_dump($dom->textContent);
12+
try {
13+
$dom->textContent = "foo";
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
$container = $dom->documentElement;
19+
20+
$text = $container->firstChild;
21+
$pi = $text->nextSibling;
22+
23+
echo "text node text content: ";
24+
var_dump($text->textContent);
25+
echo "pi node text content: ";
26+
var_dump($pi->textContent);
27+
28+
$text->textContent = NULL;
29+
$pi->textContent = NULL;
30+
31+
echo "text node text content: ";
32+
var_dump($text->textContent);
33+
echo "pi node text content: ";
34+
var_dump($pi->textContent);
35+
36+
$container->textContent = NULL;
37+
echo $dom->saveXML(), "\n";
38+
39+
?>
40+
--EXPECT--
41+
document text content: NULL
42+
Cannot modify readonly property DOM\XMLDocument::$textContent
43+
text node text content: string(4) "text"
44+
pi node text content: string(5) "value"
45+
text node text content: string(0) ""
46+
pi node text content: string(0) ""
47+
<?xml version="1.0" encoding="UTF-8"?>
48+
<container></container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Interoperability with SimpleXML
3+
--EXTENSIONS--
4+
dom
5+
simplexml
6+
--FILE--
7+
<?php
8+
9+
$sxe = simplexml_load_string('<container xmlns="urn:a">foo</container>');
10+
11+
$element = DOM\import_simplexml($sxe);
12+
var_dump($element->attributes);
13+
echo $element->ownerDocument->saveXML($element), "\n";
14+
15+
$element->appendChild($element->ownerDocument->createElementNS('urn:a', 'child'));
16+
echo $element->ownerDocument->saveXML($element), "\n";
17+
18+
$sxe->addChild('name', 'value');
19+
echo $element->ownerDocument->saveXML($element), "\n";
20+
21+
// This should fail because it has been imported already above in modern DOM
22+
try {
23+
dom_import_simplexml($sxe);
24+
} catch (TypeError $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
28+
?>
29+
--EXPECT--
30+
object(DOM\NamedNodeMap)#3 (1) {
31+
["length"]=>
32+
int(1)
33+
}
34+
<container xmlns="urn:a">foo</container>
35+
<container xmlns="urn:a">foo<child/></container>
36+
<container xmlns="urn:a">foo<child/><name>value</name></container>
37+
dom_import_simplexml(): Argument #1 ($node) must not be already imported as a DOM\Node

0 commit comments

Comments
 (0)