1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\FSExt; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV; 6*a1a3b679SAndreas Boehleruse Sabre\HTTP; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerrequire_once 'Sabre/DAV/AbstractServer.php'; 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehlerclass ServerTest extends DAV\AbstractServer{ 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler protected function getRootNode() { 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler return new Directory($this->tempDir); 15*a1a3b679SAndreas Boehler 16*a1a3b679SAndreas Boehler } 17*a1a3b679SAndreas Boehler 18*a1a3b679SAndreas Boehler function testGet() { 19*a1a3b679SAndreas Boehler 20*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/test.txt'); 21*a1a3b679SAndreas Boehler $filename = $this->tempDir . '/test.txt'; 22*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 23*a1a3b679SAndreas Boehler $this->server->exec(); 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.'); 26*a1a3b679SAndreas Boehler $this->assertEquals([ 27*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 28*a1a3b679SAndreas Boehler 'Content-Type' => ['application/octet-stream'], 29*a1a3b679SAndreas Boehler 'Content-Length' => [13], 30*a1a3b679SAndreas Boehler 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], 31*a1a3b679SAndreas Boehler 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], 32*a1a3b679SAndreas Boehler ], 33*a1a3b679SAndreas Boehler $this->response->getHeaders() 34*a1a3b679SAndreas Boehler ); 35*a1a3b679SAndreas Boehler 36*a1a3b679SAndreas Boehler 37*a1a3b679SAndreas Boehler $this->assertEquals('Test contents', stream_get_contents($this->response->body)); 38*a1a3b679SAndreas Boehler 39*a1a3b679SAndreas Boehler } 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler function testHEAD() { 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler $request = new HTTP\Request('HEAD', '/test.txt'); 44*a1a3b679SAndreas Boehler $filename = $this->tempDir . '/test.txt'; 45*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 46*a1a3b679SAndreas Boehler $this->server->exec(); 47*a1a3b679SAndreas Boehler 48*a1a3b679SAndreas Boehler $this->assertEquals([ 49*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 50*a1a3b679SAndreas Boehler 'Content-Type' => ['application/octet-stream'], 51*a1a3b679SAndreas Boehler 'Content-Length' => [13], 52*a1a3b679SAndreas Boehler 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))], 53*a1a3b679SAndreas Boehler 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], 54*a1a3b679SAndreas Boehler ], 55*a1a3b679SAndreas Boehler $this->response->getHeaders() 56*a1a3b679SAndreas Boehler ); 57*a1a3b679SAndreas Boehler 58*a1a3b679SAndreas Boehler $this->assertEquals(200,$this->response->status); 59*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler } 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler function testPut() { 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler $request = new HTTP\Request('PUT', '/testput.txt'); 66*a1a3b679SAndreas Boehler $filename = $this->tempDir . '/testput.txt'; 67*a1a3b679SAndreas Boehler $request->setBody('Testing new file'); 68*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 69*a1a3b679SAndreas Boehler $this->server->exec(); 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler $this->assertEquals([ 72*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 73*a1a3b679SAndreas Boehler 'Content-Length' => [0], 74*a1a3b679SAndreas Boehler 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], 75*a1a3b679SAndreas Boehler ], $this->response->getHeaders()); 76*a1a3b679SAndreas Boehler 77*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status); 78*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 79*a1a3b679SAndreas Boehler $this->assertEquals('Testing new file',file_get_contents($filename)); 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler } 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler function testPutAlreadyExists() { 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $request = new HTTP\Request('PUT', '/test.txt', ['If-None-Match' => '*']); 86*a1a3b679SAndreas Boehler $request->setBody('Testing new file'); 87*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 88*a1a3b679SAndreas Boehler $this->server->exec(); 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler $this->assertEquals([ 91*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 92*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 93*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 94*a1a3b679SAndreas Boehler 95*a1a3b679SAndreas Boehler $this->assertEquals(412, $this->response->status); 96*a1a3b679SAndreas Boehler $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler } 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler function testMkcol() { 101*a1a3b679SAndreas Boehler 102*a1a3b679SAndreas Boehler $request = new HTTP\Request('MKCOL', '/testcol'); 103*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 104*a1a3b679SAndreas Boehler $this->server->exec(); 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler $this->assertEquals([ 107*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 108*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 109*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 110*a1a3b679SAndreas Boehler 111*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status); 112*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 113*a1a3b679SAndreas Boehler $this->assertTrue(is_dir($this->tempDir . '/testcol')); 114*a1a3b679SAndreas Boehler 115*a1a3b679SAndreas Boehler } 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler function testPutUpdate() { 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler $request = new HTTP\Request('PUT', '/test.txt'); 120*a1a3b679SAndreas Boehler $request->setBody('Testing updated file'); 121*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 122*a1a3b679SAndreas Boehler $this->server->exec(); 123*a1a3b679SAndreas Boehler 124*a1a3b679SAndreas Boehler $this->assertEquals('0', $this->response->getHeader('Content-Length')); 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler $this->assertEquals(204, $this->response->status); 127*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 128*a1a3b679SAndreas Boehler $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); 129*a1a3b679SAndreas Boehler 130*a1a3b679SAndreas Boehler } 131*a1a3b679SAndreas Boehler 132*a1a3b679SAndreas Boehler function testDelete() { 133*a1a3b679SAndreas Boehler 134*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/test.txt'); 135*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 136*a1a3b679SAndreas Boehler $this->server->exec(); 137*a1a3b679SAndreas Boehler 138*a1a3b679SAndreas Boehler $this->assertEquals([ 139*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 140*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 141*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 142*a1a3b679SAndreas Boehler 143*a1a3b679SAndreas Boehler $this->assertEquals(204, $this->response->status); 144*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 145*a1a3b679SAndreas Boehler $this->assertFalse(file_exists($this->tempDir . '/test.txt')); 146*a1a3b679SAndreas Boehler 147*a1a3b679SAndreas Boehler } 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler function testDeleteDirectory() { 150*a1a3b679SAndreas Boehler 151*a1a3b679SAndreas Boehler mkdir($this->tempDir.'/testcol'); 152*a1a3b679SAndreas Boehler file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan'); 153*a1a3b679SAndreas Boehler 154*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/testcol'); 155*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 156*a1a3b679SAndreas Boehler $this->server->exec(); 157*a1a3b679SAndreas Boehler 158*a1a3b679SAndreas Boehler $this->assertEquals([ 159*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 160*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 161*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 162*a1a3b679SAndreas Boehler $this->assertEquals(204, $this->response->status); 163*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 164*a1a3b679SAndreas Boehler $this->assertFalse(file_exists($this->tempDir . '/col')); 165*a1a3b679SAndreas Boehler 166*a1a3b679SAndreas Boehler } 167*a1a3b679SAndreas Boehler 168*a1a3b679SAndreas Boehler function testOptions() { 169*a1a3b679SAndreas Boehler 170*a1a3b679SAndreas Boehler $request = new HTTP\Request('OPTIONS', '/'); 171*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 172*a1a3b679SAndreas Boehler $this->server->exec(); 173*a1a3b679SAndreas Boehler 174*a1a3b679SAndreas Boehler $this->assertEquals([ 175*a1a3b679SAndreas Boehler 'DAV' => ['1, 3, extended-mkcol'], 176*a1a3b679SAndreas Boehler 'MS-Author-Via' => ['DAV'], 177*a1a3b679SAndreas Boehler 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], 178*a1a3b679SAndreas Boehler 'Accept-Ranges' => ['bytes'], 179*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 180*a1a3b679SAndreas Boehler 'X-Sabre-Version'=> [DAV\Version::VERSION], 181*a1a3b679SAndreas Boehler ], $this->response->getHeaders()); 182*a1a3b679SAndreas Boehler 183*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->status); 184*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 185*a1a3b679SAndreas Boehler 186*a1a3b679SAndreas Boehler } 187*a1a3b679SAndreas Boehler 188*a1a3b679SAndreas Boehler function testMove() { 189*a1a3b679SAndreas Boehler 190*a1a3b679SAndreas Boehler mkdir($this->tempDir.'/testcol'); 191*a1a3b679SAndreas Boehler 192*a1a3b679SAndreas Boehler $request = new HTTP\Request('MOVE', '/test.txt', ['Destination' => '/testcol/test2.txt']); 193*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 194*a1a3b679SAndreas Boehler $this->server->exec(); 195*a1a3b679SAndreas Boehler 196*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status); 197*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 198*a1a3b679SAndreas Boehler 199*a1a3b679SAndreas Boehler $this->assertEquals([ 200*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 201*a1a3b679SAndreas Boehler 'X-Sabre-Version'=> [DAV\Version::VERSION], 202*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 203*a1a3b679SAndreas Boehler 204*a1a3b679SAndreas Boehler $this->assertTrue( 205*a1a3b679SAndreas Boehler is_file($this->tempDir . '/testcol/test2.txt') 206*a1a3b679SAndreas Boehler ); 207*a1a3b679SAndreas Boehler 208*a1a3b679SAndreas Boehler 209*a1a3b679SAndreas Boehler } 210*a1a3b679SAndreas Boehler 211*a1a3b679SAndreas Boehler /** 212*a1a3b679SAndreas Boehler * This test checks if it's possible to move a non-FSExt collection into a 213*a1a3b679SAndreas Boehler * FSExt collection. 214*a1a3b679SAndreas Boehler * 215*a1a3b679SAndreas Boehler * The moveInto function *should* ignore the object and let sabredav itself 216*a1a3b679SAndreas Boehler * execute the slow move. 217*a1a3b679SAndreas Boehler */ 218*a1a3b679SAndreas Boehler function testMoveOtherObject() { 219*a1a3b679SAndreas Boehler 220*a1a3b679SAndreas Boehler mkdir($this->tempDir.'/tree1'); 221*a1a3b679SAndreas Boehler mkdir($this->tempDir.'/tree2'); 222*a1a3b679SAndreas Boehler 223*a1a3b679SAndreas Boehler $tree = new DAV\Tree(new DAV\SimpleCollection('root', [ 224*a1a3b679SAndreas Boehler new DAV\FS\Directory($this->tempDir . '/tree1'), 225*a1a3b679SAndreas Boehler new DAV\FSExt\Directory($this->tempDir . '/tree2'), 226*a1a3b679SAndreas Boehler ])); 227*a1a3b679SAndreas Boehler $this->server->tree = $tree; 228*a1a3b679SAndreas Boehler 229*a1a3b679SAndreas Boehler $request = new HTTP\Request('MOVE', '/tree1', ['Destination' => '/tree2/tree1']); 230*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 231*a1a3b679SAndreas Boehler $this->server->exec(); 232*a1a3b679SAndreas Boehler 233*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status); 234*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 235*a1a3b679SAndreas Boehler 236*a1a3b679SAndreas Boehler $this->assertEquals([ 237*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 238*a1a3b679SAndreas Boehler 'X-Sabre-Version'=> [DAV\Version::VERSION], 239*a1a3b679SAndreas Boehler ],$this->response->getHeaders()); 240*a1a3b679SAndreas Boehler 241*a1a3b679SAndreas Boehler $this->assertTrue( 242*a1a3b679SAndreas Boehler is_dir($this->tempDir . '/tree2/tree1') 243*a1a3b679SAndreas Boehler ); 244*a1a3b679SAndreas Boehler 245*a1a3b679SAndreas Boehler } 246*a1a3b679SAndreas Boehler} 247