1<?php 2 3namespace Sabre\DAVACL\Exception; 4 5use Sabre\DAV; 6 7class NeedPrivilegesTest extends \PHPUnit_Framework_TestCase { 8 9 function testSerialize() { 10 11 $uri = 'foo'; 12 $privileges = array( 13 '{DAV:}read', 14 '{DAV:}write', 15 ); 16 $ex = new NeedPrivileges($uri, $privileges); 17 18 $server = new DAV\Server(); 19 $dom = new \DOMDocument('1.0','utf-8'); 20 $root = $dom->createElementNS('DAV:','d:root'); 21 $dom->appendChild($root); 22 23 $ex->serialize($server, $root); 24 25 $xpaths = array( 26 '/d:root' => 1, 27 '/d:root/d:need-privileges' => 1, 28 '/d:root/d:need-privileges/d:resource' => 2, 29 '/d:root/d:need-privileges/d:resource/d:href' => 2, 30 '/d:root/d:need-privileges/d:resource/d:privilege' => 2, 31 '/d:root/d:need-privileges/d:resource/d:privilege/d:read' => 1, 32 '/d:root/d:need-privileges/d:resource/d:privilege/d:write' => 1, 33 ); 34 35 // Reloading because PHP DOM sucks 36 $dom2 = new \DOMDocument('1.0', 'utf-8'); 37 $dom2->loadXML($dom->saveXML()); 38 39 $dxpath = new \DOMXPath($dom2); 40 $dxpath->registerNamespace('d','DAV:'); 41 foreach($xpaths as $xpath=>$count) { 42 43 $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); 44 45 } 46 47 } 48 49} 50