Skip to content

Commit bbf29b7

Browse files
committed
Add tests with wrong output
1 parent ca5d482 commit bbf29b7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
replaceWith() without a parent
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadXML(<<<XML
9+
<?xml version="1.0"?>
10+
<container>
11+
<child/>
12+
</container>
13+
XML);
14+
15+
$container = $doc->documentElement;
16+
$child = $container->firstElementChild;
17+
18+
$test = $doc->createElement('foo');
19+
$test->replaceWith($child);
20+
echo $doc->saveXML();
21+
echo $doc->saveXML($test);
22+
?>
23+
--EXPECTF--
24+
Fatal error: Uncaught DOMException: Not Found Error in %s:%d
25+
Stack trace:
26+
#0 %s(%d): DOMElement->replaceWith(Object(DOMElement))
27+
#1 {main}
28+
thrown in %s on line %d
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
replaceWith() with a non-variable next sibling
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadXML(<<<XML
9+
<?xml version="1.0"?>
10+
<container>
11+
<child>
12+
<alone/>
13+
</child>
14+
</container>
15+
XML);
16+
17+
$container = $doc->documentElement;
18+
$child = $container->firstElementChild;
19+
$alone = $child->firstElementChild;
20+
21+
$child->after($alone);
22+
echo $doc->saveXML();
23+
$child->replaceWith($alone);
24+
echo $doc->saveXML();
25+
?>
26+
--EXPECT--
27+
<?xml version="1.0"?>
28+
<container>
29+
<child>
30+
31+
</child><alone/>
32+
</container>
33+
<?xml version="1.0"?>
34+
<container>
35+
36+
</container>
37+
38+
=================================================================
39+
==1151863==ERROR: LeakSanitizer: detected memory leaks
40+
41+
Direct leak of 120 byte(s) in 1 object(s) allocated from:
42+
#0 0x7fc122ee1369 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
43+
#1 0x7fc122d02bd0 in xmlNewNodeEatName /home/niels/libxml2/tree.c:2317
44+
45+
SUMMARY: AddressSanitizer: 120 byte(s) leaked in 1 allocation(s).

0 commit comments

Comments
 (0)