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