1--TEST--
2compareDocumentPosition: disconnected
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8function check($element1, $element2) {
9    echo "Disconnect and implementation flag (1->2): ";
10    var_dump(($element1->compareDocumentPosition($element2) & (DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOMNode::DOCUMENT_POSITION_DISCONNECTED)) === (DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOMNode::DOCUMENT_POSITION_DISCONNECTED));
11    echo "Disconnect and implementation flag (2->1): ";
12    var_dump(($element2->compareDocumentPosition($element1) & (DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOMNode::DOCUMENT_POSITION_DISCONNECTED)) === (DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOMNode::DOCUMENT_POSITION_DISCONNECTED));
13
14    // Must be the opposite result
15    echo "Opposite result: ";
16    if ($element1->compareDocumentPosition($element2) & DOMNode::DOCUMENT_POSITION_FOLLOWING) {
17        var_dump(($element2->compareDocumentPosition($element1) & DOMNode::DOCUMENT_POSITION_PRECEDING) === DOMNode::DOCUMENT_POSITION_PRECEDING);
18    } else {
19        var_dump(($element2->compareDocumentPosition($element1) & DOMNode::DOCUMENT_POSITION_FOLLOWING) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
20    }
21}
22
23$dom1 = new DOMDocument();
24$dom1->loadXML('<?xml version="1.0"?><container/>');
25$dom2 = new DOMDocument();
26$dom2->loadXML('<?xml version="1.0"?><container/>');
27
28echo "--- Two documents ---\n";
29check($dom1, $dom2);
30echo "--- Two document roots ---\n";
31check($dom1->documentElement, $dom2->documentElement);
32echo "--- Fragment ---\n";
33$fragment = $dom1->createDocumentFragment();
34$foo = $fragment->appendChild(new DOMText("foo"));
35check($foo, $dom1);
36echo "--- Unattached element ---\n";
37check(new DOMElement("foo"), new DOMElement("bar"));
38echo "--- Unattached attribute ---\n";
39check(new DOMAttr("foo"), new DOMAttr("bar"));
40echo "--- Unattached attribute & element ---\n";
41check(new DOMAttr("foo"), new DOMElement("bar"));
42
43?>
44--EXPECT--
45--- Two documents ---
46Disconnect and implementation flag (1->2): bool(true)
47Disconnect and implementation flag (2->1): bool(true)
48Opposite result: bool(true)
49--- Two document roots ---
50Disconnect and implementation flag (1->2): bool(true)
51Disconnect and implementation flag (2->1): bool(true)
52Opposite result: bool(true)
53--- Fragment ---
54Disconnect and implementation flag (1->2): bool(true)
55Disconnect and implementation flag (2->1): bool(true)
56Opposite result: bool(true)
57--- Unattached element ---
58Disconnect and implementation flag (1->2): bool(true)
59Disconnect and implementation flag (2->1): bool(true)
60Opposite result: bool(true)
61--- Unattached attribute ---
62Disconnect and implementation flag (1->2): bool(true)
63Disconnect and implementation flag (2->1): bool(true)
64Opposite result: bool(true)
65--- Unattached attribute & element ---
66Disconnect and implementation flag (1->2): bool(true)
67Disconnect and implementation flag (2->1): bool(true)
68Opposite result: bool(true)
69