1<?php 2 3namespace Sabre\DAV; 4use Sabre\HTTP; 5 6require_once 'Sabre/DAV/AbstractServer.php'; 7 8class ServerPropsInfiniteDepthTest extends AbstractServer { 9 10 protected function getRootNode() { 11 12 return new FSExt\Directory(SABRE_TEMPDIR); 13 14 } 15 16 function setUp() { 17 18 if (file_exists(SABRE_TEMPDIR.'../.sabredav')) unlink(SABRE_TEMPDIR.'../.sabredav'); 19 parent::setUp(); 20 file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2'); 21 mkdir(SABRE_TEMPDIR . '/col'); 22 mkdir(SABRE_TEMPDIR . '/col/col'); 23 file_put_contents(SABRE_TEMPDIR . 'col/col/test.txt', 'Test contents'); 24 $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR . '/.locksdb'))); 25 $this->server->enablePropfindDepthInfinity = true; 26 27 } 28 29 function tearDown() { 30 31 parent::tearDown(); 32 if (file_exists(SABRE_TEMPDIR.'../.locksdb')) unlink(SABRE_TEMPDIR.'../.locksdb'); 33 34 } 35 36 private function sendRequest($body) { 37 38 $request = new HTTP\Request('PROPFIND', '/', ['Depth' => 'infinity']); 39 $request->setBody($body); 40 41 $this->server->httpRequest = $request; 42 $this->server->exec(); 43 44 } 45 46 public function testPropFindEmptyBody() { 47 48 $hasFired = false; 49 50 $self = $this; 51 52 $this->sendRequest(""); 53 54 $this->assertEquals(207, $this->response->status, 'Incorrect status received. Full response body: ' . $this->response->getBodyAsString()); 55 56 $this->assertEquals(array( 57 'X-Sabre-Version' => [Version::VERSION], 58 'Content-Type' => ['application/xml; charset=utf-8'], 59 'DAV' => ['1, 3, extended-mkcol, 2'], 60 'Vary' => ['Brief,Prefer'], 61 ), 62 $this->response->getHeaders() 63 ); 64 65 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); 66 $xml = simplexml_load_string($body); 67 $xml->registerXPathNamespace('d','urn:DAV'); 68 69 list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); 70 $this->assertEquals('/',(string)$data,'href element should have been /'); 71 72 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); 73 // 8 resources are to be returned: /, col, col/col, col/col/test.txt, dir, dir/child.txt, test.txt and test2.txt 74 $this->assertEquals(8,count($data)); 75 76 } 77 78 function testSupportedLocks() { 79 80 $xml = '<?xml version="1.0"?> 81<d:propfind xmlns:d="DAV:"> 82 <d:prop> 83 <d:supportedlock /> 84 </d:prop> 85</d:propfind>'; 86 87 $this->sendRequest($xml); 88 89 $body = $this->response->getBodyAsString(); 90 $this->assertEquals(207, $this->response->getStatus(), $body); 91 92 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$body); 93 $xml = simplexml_load_string($body); 94 $xml->registerXPathNamespace('d','urn:DAV'); 95 96 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry'); 97 $this->assertEquals(16,count($data),'We expected sixteen \'d:lockentry\' tags'); 98 99 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope'); 100 $this->assertEquals(16,count($data),'We expected sixteen \'d:lockscope\' tags'); 101 102 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype'); 103 $this->assertEquals(16,count($data),'We expected sixteen \'d:locktype\' tags'); 104 105 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared'); 106 $this->assertEquals(8,count($data),'We expected eight \'d:shared\' tags'); 107 108 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive'); 109 $this->assertEquals(8,count($data),'We expected eight \'d:exclusive\' tags'); 110 111 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write'); 112 $this->assertEquals(16,count($data),'We expected sixteen \'d:write\' tags'); 113 } 114 115 function testLockDiscovery() { 116 117 $xml = '<?xml version="1.0"?> 118<d:propfind xmlns:d="DAV:"> 119 <d:prop> 120 <d:lockdiscovery /> 121 </d:prop> 122</d:propfind>'; 123 124 $this->sendRequest($xml); 125 126 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); 127 $xml = simplexml_load_string($body); 128 $xml->registerXPathNamespace('d','urn:DAV'); 129 130 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery'); 131 $this->assertEquals(8,count($data),'We expected eight \'d:lockdiscovery\' tags'); 132 133 } 134 135 function testUnknownProperty() { 136 137 $xml = '<?xml version="1.0"?> 138<d:propfind xmlns:d="DAV:"> 139 <d:prop> 140 <d:macaroni /> 141 </d:prop> 142</d:propfind>'; 143 144 $this->sendRequest($xml); 145 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); 146 $xml = simplexml_load_string($body); 147 $xml->registerXPathNamespace('d','urn:DAV'); 148 $pathTests = array( 149 '/d:multistatus', 150 '/d:multistatus/d:response', 151 '/d:multistatus/d:response/d:propstat', 152 '/d:multistatus/d:response/d:propstat/d:status', 153 '/d:multistatus/d:response/d:propstat/d:prop', 154 '/d:multistatus/d:response/d:propstat/d:prop/d:macaroni', 155 ); 156 foreach($pathTests as $test) { 157 $this->assertTrue(count($xml->xpath($test))==true,'We expected the ' . $test . ' element to appear in the response, we got: ' . $body); 158 } 159 160 $val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); 161 $this->assertEquals(8,count($val),$body); 162 $this->assertEquals('HTTP/1.1 404 Not Found',(string)$val[0]); 163 164 } 165 166} 167