1--TEST--
2compareDocumentPosition: element order at the same 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        <div>
14            <strong/>
15            <p>foo</p>
16        </div>
17    </div>
18    <div>
19        <div>
20            <p>bar</p>
21            <strong/>
22        </div>
23    </div>
24</container>
25XML);
26
27$xpath = new DOMXPath($dom);
28$query = $xpath->query("//p");
29$foo = $query->item(0);
30$bar = $query->item(1);
31
32echo "--- strong & foo ---\n";
33var_dump($foo->previousElementSibling->compareDocumentPosition($foo) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
34var_dump($foo->compareDocumentPosition($foo->previousElementSibling) === DOMNode::DOCUMENT_POSITION_PRECEDING);
35
36echo "--- strong & bar ---\n";
37var_dump($bar->nextElementSibling->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_PRECEDING);
38var_dump($bar->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
39
40echo "--- strong & strong ---\n";
41var_dump($foo->previousElementSibling->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
42var_dump($bar->nextElementSibling->compareDocumentPosition($foo->previousElementSibling) === DOMNode::DOCUMENT_POSITION_PRECEDING);
43
44for ($i = 0; $i < 3; $i++) {
45    echo "--- Check on depth $i ---\n";
46    var_dump($foo->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
47    var_dump($bar->compareDocumentPosition($foo) === DOMNode::DOCUMENT_POSITION_PRECEDING);
48    $foo = $foo->parentElement;
49    $bar = $bar->parentElement;
50}
51
52?>
53--EXPECT--
54--- strong & foo ---
55bool(true)
56bool(true)
57--- strong & bar ---
58bool(true)
59bool(true)
60--- strong & strong ---
61bool(true)
62bool(true)
63--- Check on depth 0 ---
64bool(true)
65bool(true)
66--- Check on depth 1 ---
67bool(true)
68bool(true)
69--- Check on depth 2 ---
70bool(true)
71bool(true)
72