1--TEST--
2compareDocumentPosition: element order at a different tree depth
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$dom = new DOMDocument();
9$dom->loadXML(<<<XML
10<?xml version="1.0"?>
11<container>
12    <div>
13        <p>foo</p>
14    </div>
15    <div>
16        <div>
17            <p>bar</p>
18        </div>
19    </div>
20</container>
21XML);
22
23$xpath = new DOMXPath($dom);
24$query = $xpath->query("//p");
25$foo = $query->item(0);
26$bar = $query->item(1);
27
28for ($i = 0; $i < 2; $i++) {
29    echo "--- Check on depth $i ---\n";
30    var_dump($foo->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
31    var_dump($bar->compareDocumentPosition($foo) === DOMNode::DOCUMENT_POSITION_PRECEDING);
32    $foo = $foo->parentElement;
33    $bar = $bar->parentElement;
34}
35
36echo "--- One contains the other at depth 2 ---\n";
37var_dump(boolval($foo->compareDocumentPosition($bar) & DOMNode::DOCUMENT_POSITION_CONTAINED_BY));
38var_dump(boolval($bar->compareDocumentPosition($foo) & DOMNode::DOCUMENT_POSITION_CONTAINS));
39
40?>
41--EXPECT--
42--- Check on depth 0 ---
43bool(true)
44bool(true)
45--- Check on depth 1 ---
46bool(true)
47bool(true)
48--- One contains the other at depth 2 ---
49bool(true)
50bool(true)
51