1--TEST--
2compareDocumentPosition: attribute vs child order
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$dom = new DOMDocument();
9$dom->loadXML(<<<XML
10<?xml version="1.0"?>
11<container>
12<before/>
13<outer align="center">
14    <p>foo</p>
15    <div>
16        <div>
17            <p>bar</p>
18        </div>
19    </div>
20</outer>
21</container>
22XML);
23
24$before = $dom->documentElement->firstElementChild;
25$outer = $before->nextElementSibling;
26$foo = $outer->firstElementChild;
27$bar = $foo->nextElementSibling->firstElementChild->firstElementChild;
28
29// See note about attributes vs children positions: attributes precede children
30
31echo "--- outer attribute vs before ---\n";
32var_dump($outer->attributes[0]->compareDocumentPosition($before) === DOMNode::DOCUMENT_POSITION_PRECEDING);
33var_dump($before->compareDocumentPosition($outer->attributes[0]) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
34
35echo "--- outer attribute vs foo ---\n";
36var_dump($outer->attributes[0]->compareDocumentPosition($foo) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
37var_dump($foo->compareDocumentPosition($outer->attributes[0]) === DOMNode::DOCUMENT_POSITION_PRECEDING);
38
39echo "--- outer attribute vs bar ---\n";
40var_dump($outer->attributes[0]->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_FOLLOWING);
41var_dump($bar->compareDocumentPosition($outer->attributes[0]) === DOMNode::DOCUMENT_POSITION_PRECEDING);
42
43?>
44--EXPECT--
45--- outer attribute vs before ---
46bool(true)
47bool(true)
48--- outer attribute vs foo ---
49bool(true)
50bool(true)
51--- outer attribute vs bar ---
52bool(true)
53bool(true)
54