1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\HTTP; 6*a1a3b679SAndreas Boehler 7*a1a3b679SAndreas Boehlerclass ServerMKCOLTest extends AbstractServer { 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehler function testMkcol() { 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehler $serverVars = array( 12*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 13*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 14*a1a3b679SAndreas Boehler ); 15*a1a3b679SAndreas Boehler 16*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 17*a1a3b679SAndreas Boehler $request->setBody(""); 18*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 19*a1a3b679SAndreas Boehler $this->server->exec(); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler $this->assertEquals(array( 22*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 23*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 24*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 25*a1a3b679SAndreas Boehler 26*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status); 27*a1a3b679SAndreas Boehler $this->assertEquals('', $this->response->body); 28*a1a3b679SAndreas Boehler $this->assertTrue(is_dir($this->tempDir . '/testcol')); 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler } 31*a1a3b679SAndreas Boehler 32*a1a3b679SAndreas Boehler /** 33*a1a3b679SAndreas Boehler * @depends testMkcol 34*a1a3b679SAndreas Boehler */ 35*a1a3b679SAndreas Boehler function testMKCOLUnknownBody() { 36*a1a3b679SAndreas Boehler 37*a1a3b679SAndreas Boehler $serverVars = array( 38*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 39*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 40*a1a3b679SAndreas Boehler ); 41*a1a3b679SAndreas Boehler 42*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 43*a1a3b679SAndreas Boehler $request->setBody("Hello"); 44*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 45*a1a3b679SAndreas Boehler $this->server->exec(); 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler $this->assertEquals(array( 48*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 49*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 50*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler $this->assertEquals(415, $this->response->status); 53*a1a3b679SAndreas Boehler 54*a1a3b679SAndreas Boehler } 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler /** 57*a1a3b679SAndreas Boehler * @depends testMkcol 58*a1a3b679SAndreas Boehler */ 59*a1a3b679SAndreas Boehler function testMKCOLBrokenXML() { 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler $serverVars = array( 62*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 63*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 64*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 65*a1a3b679SAndreas Boehler ); 66*a1a3b679SAndreas Boehler 67*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 68*a1a3b679SAndreas Boehler $request->setBody("Hello"); 69*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 70*a1a3b679SAndreas Boehler $this->server->exec(); 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler $this->assertEquals(array( 73*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 74*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 75*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 76*a1a3b679SAndreas Boehler 77*a1a3b679SAndreas Boehler $this->assertEquals(400, $this->response->getStatus(), $this->response->getBodyAsString() ); 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler } 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler /** 82*a1a3b679SAndreas Boehler * @depends testMkcol 83*a1a3b679SAndreas Boehler */ 84*a1a3b679SAndreas Boehler function testMKCOLUnknownXML() { 85*a1a3b679SAndreas Boehler 86*a1a3b679SAndreas Boehler $serverVars = array( 87*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 88*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 89*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 90*a1a3b679SAndreas Boehler ); 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 93*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?><html></html>'); 94*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 95*a1a3b679SAndreas Boehler $this->server->exec(); 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler $this->assertEquals(array( 98*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 99*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 100*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 101*a1a3b679SAndreas Boehler 102*a1a3b679SAndreas Boehler $this->assertEquals(400, $this->response->getStatus()); 103*a1a3b679SAndreas Boehler 104*a1a3b679SAndreas Boehler } 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler /** 107*a1a3b679SAndreas Boehler * @depends testMkcol 108*a1a3b679SAndreas Boehler */ 109*a1a3b679SAndreas Boehler function testMKCOLNoResourceType() { 110*a1a3b679SAndreas Boehler 111*a1a3b679SAndreas Boehler $serverVars = array( 112*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 113*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 114*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 115*a1a3b679SAndreas Boehler ); 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 118*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?> 119*a1a3b679SAndreas Boehler<mkcol xmlns="DAV:"> 120*a1a3b679SAndreas Boehler <set> 121*a1a3b679SAndreas Boehler <prop> 122*a1a3b679SAndreas Boehler <displayname>Evert</displayname> 123*a1a3b679SAndreas Boehler </prop> 124*a1a3b679SAndreas Boehler </set> 125*a1a3b679SAndreas Boehler</mkcol>'); 126*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 127*a1a3b679SAndreas Boehler $this->server->exec(); 128*a1a3b679SAndreas Boehler 129*a1a3b679SAndreas Boehler $this->assertEquals(array( 130*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 131*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 132*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 133*a1a3b679SAndreas Boehler 134*a1a3b679SAndreas Boehler $this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 135*a1a3b679SAndreas Boehler 136*a1a3b679SAndreas Boehler } 137*a1a3b679SAndreas Boehler 138*a1a3b679SAndreas Boehler /** 139*a1a3b679SAndreas Boehler * @depends testMkcol 140*a1a3b679SAndreas Boehler */ 141*a1a3b679SAndreas Boehler function testMKCOLIncorrectResourceType() { 142*a1a3b679SAndreas Boehler 143*a1a3b679SAndreas Boehler $serverVars = array( 144*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 145*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 146*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 147*a1a3b679SAndreas Boehler ); 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 150*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?> 151*a1a3b679SAndreas Boehler<mkcol xmlns="DAV:"> 152*a1a3b679SAndreas Boehler <set> 153*a1a3b679SAndreas Boehler <prop> 154*a1a3b679SAndreas Boehler <resourcetype><collection /><blabla /></resourcetype> 155*a1a3b679SAndreas Boehler </prop> 156*a1a3b679SAndreas Boehler </set> 157*a1a3b679SAndreas Boehler</mkcol>'); 158*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 159*a1a3b679SAndreas Boehler $this->server->exec(); 160*a1a3b679SAndreas Boehler 161*a1a3b679SAndreas Boehler $this->assertEquals(array( 162*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 163*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 164*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 165*a1a3b679SAndreas Boehler 166*a1a3b679SAndreas Boehler $this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 167*a1a3b679SAndreas Boehler 168*a1a3b679SAndreas Boehler } 169*a1a3b679SAndreas Boehler 170*a1a3b679SAndreas Boehler /** 171*a1a3b679SAndreas Boehler * @depends testMKCOLIncorrectResourceType 172*a1a3b679SAndreas Boehler */ 173*a1a3b679SAndreas Boehler function testMKCOLSuccess() { 174*a1a3b679SAndreas Boehler 175*a1a3b679SAndreas Boehler $serverVars = array( 176*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 177*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 178*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 179*a1a3b679SAndreas Boehler ); 180*a1a3b679SAndreas Boehler 181*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 182*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?> 183*a1a3b679SAndreas Boehler<mkcol xmlns="DAV:"> 184*a1a3b679SAndreas Boehler <set> 185*a1a3b679SAndreas Boehler <prop> 186*a1a3b679SAndreas Boehler <resourcetype><collection /></resourcetype> 187*a1a3b679SAndreas Boehler </prop> 188*a1a3b679SAndreas Boehler </set> 189*a1a3b679SAndreas Boehler</mkcol>'); 190*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 191*a1a3b679SAndreas Boehler $this->server->exec(); 192*a1a3b679SAndreas Boehler 193*a1a3b679SAndreas Boehler $this->assertEquals(array( 194*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 195*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 196*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 197*a1a3b679SAndreas Boehler 198*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 199*a1a3b679SAndreas Boehler 200*a1a3b679SAndreas Boehler } 201*a1a3b679SAndreas Boehler 202*a1a3b679SAndreas Boehler /** 203*a1a3b679SAndreas Boehler * @depends testMKCOLIncorrectResourceType 204*a1a3b679SAndreas Boehler */ 205*a1a3b679SAndreas Boehler function testMKCOLWhiteSpaceResourceType() { 206*a1a3b679SAndreas Boehler 207*a1a3b679SAndreas Boehler $serverVars = array( 208*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 209*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 210*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 211*a1a3b679SAndreas Boehler ); 212*a1a3b679SAndreas Boehler 213*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 214*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?> 215*a1a3b679SAndreas Boehler<mkcol xmlns="DAV:"> 216*a1a3b679SAndreas Boehler <set> 217*a1a3b679SAndreas Boehler <prop> 218*a1a3b679SAndreas Boehler <resourcetype> 219*a1a3b679SAndreas Boehler <collection /> 220*a1a3b679SAndreas Boehler </resourcetype> 221*a1a3b679SAndreas Boehler </prop> 222*a1a3b679SAndreas Boehler </set> 223*a1a3b679SAndreas Boehler</mkcol>'); 224*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 225*a1a3b679SAndreas Boehler $this->server->exec(); 226*a1a3b679SAndreas Boehler 227*a1a3b679SAndreas Boehler $this->assertEquals(array( 228*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 229*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 230*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 231*a1a3b679SAndreas Boehler 232*a1a3b679SAndreas Boehler $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 233*a1a3b679SAndreas Boehler 234*a1a3b679SAndreas Boehler } 235*a1a3b679SAndreas Boehler 236*a1a3b679SAndreas Boehler /** 237*a1a3b679SAndreas Boehler * @depends testMKCOLIncorrectResourceType 238*a1a3b679SAndreas Boehler */ 239*a1a3b679SAndreas Boehler function testMKCOLNoParent() { 240*a1a3b679SAndreas Boehler 241*a1a3b679SAndreas Boehler $serverVars = array( 242*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testnoparent/409me', 243*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 244*a1a3b679SAndreas Boehler ); 245*a1a3b679SAndreas Boehler 246*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 247*a1a3b679SAndreas Boehler $request->setBody(''); 248*a1a3b679SAndreas Boehler 249*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 250*a1a3b679SAndreas Boehler $this->server->exec(); 251*a1a3b679SAndreas Boehler 252*a1a3b679SAndreas Boehler $this->assertEquals(array( 253*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 254*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 255*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 256*a1a3b679SAndreas Boehler 257*a1a3b679SAndreas Boehler $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 258*a1a3b679SAndreas Boehler 259*a1a3b679SAndreas Boehler } 260*a1a3b679SAndreas Boehler 261*a1a3b679SAndreas Boehler /** 262*a1a3b679SAndreas Boehler * @depends testMKCOLIncorrectResourceType 263*a1a3b679SAndreas Boehler */ 264*a1a3b679SAndreas Boehler function testMKCOLParentIsNoCollection() { 265*a1a3b679SAndreas Boehler 266*a1a3b679SAndreas Boehler $serverVars = array( 267*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/test.txt/409me', 268*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 269*a1a3b679SAndreas Boehler ); 270*a1a3b679SAndreas Boehler 271*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 272*a1a3b679SAndreas Boehler $request->setBody(''); 273*a1a3b679SAndreas Boehler 274*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 275*a1a3b679SAndreas Boehler $this->server->exec(); 276*a1a3b679SAndreas Boehler 277*a1a3b679SAndreas Boehler $this->assertEquals(array( 278*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 279*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 280*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 281*a1a3b679SAndreas Boehler 282*a1a3b679SAndreas Boehler $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 283*a1a3b679SAndreas Boehler 284*a1a3b679SAndreas Boehler } 285*a1a3b679SAndreas Boehler 286*a1a3b679SAndreas Boehler /** 287*a1a3b679SAndreas Boehler * @depends testMKCOLIncorrectResourceType 288*a1a3b679SAndreas Boehler */ 289*a1a3b679SAndreas Boehler function testMKCOLAlreadyExists() { 290*a1a3b679SAndreas Boehler 291*a1a3b679SAndreas Boehler $serverVars = array( 292*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/test.txt', 293*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 294*a1a3b679SAndreas Boehler ); 295*a1a3b679SAndreas Boehler 296*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 297*a1a3b679SAndreas Boehler $request->setBody(''); 298*a1a3b679SAndreas Boehler 299*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 300*a1a3b679SAndreas Boehler $this->server->exec(); 301*a1a3b679SAndreas Boehler 302*a1a3b679SAndreas Boehler $this->assertEquals(array( 303*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 304*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 305*a1a3b679SAndreas Boehler 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], 306*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 307*a1a3b679SAndreas Boehler 308*a1a3b679SAndreas Boehler $this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 309*a1a3b679SAndreas Boehler 310*a1a3b679SAndreas Boehler } 311*a1a3b679SAndreas Boehler 312*a1a3b679SAndreas Boehler /** 313*a1a3b679SAndreas Boehler * @depends testMKCOLSuccess 314*a1a3b679SAndreas Boehler * @depends testMKCOLAlreadyExists 315*a1a3b679SAndreas Boehler */ 316*a1a3b679SAndreas Boehler function testMKCOLAndProps() { 317*a1a3b679SAndreas Boehler 318*a1a3b679SAndreas Boehler $serverVars = array( 319*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/testcol', 320*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'MKCOL', 321*a1a3b679SAndreas Boehler 'HTTP_CONTENT_TYPE' => 'application/xml', 322*a1a3b679SAndreas Boehler ); 323*a1a3b679SAndreas Boehler 324*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 325*a1a3b679SAndreas Boehler $request->setBody('<?xml version="1.0"?> 326*a1a3b679SAndreas Boehler<mkcol xmlns="DAV:"> 327*a1a3b679SAndreas Boehler <set> 328*a1a3b679SAndreas Boehler <prop> 329*a1a3b679SAndreas Boehler <resourcetype><collection /></resourcetype> 330*a1a3b679SAndreas Boehler <displayname>my new collection</displayname> 331*a1a3b679SAndreas Boehler </prop> 332*a1a3b679SAndreas Boehler </set> 333*a1a3b679SAndreas Boehler</mkcol>'); 334*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 335*a1a3b679SAndreas Boehler $this->server->exec(); 336*a1a3b679SAndreas Boehler 337*a1a3b679SAndreas Boehler $this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); 338*a1a3b679SAndreas Boehler 339*a1a3b679SAndreas Boehler $this->assertEquals(array( 340*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 341*a1a3b679SAndreas Boehler 'Content-Type' => ['application/xml; charset=utf-8'], 342*a1a3b679SAndreas Boehler ),$this->response->getHeaders()); 343*a1a3b679SAndreas Boehler 344*a1a3b679SAndreas Boehler } 345*a1a3b679SAndreas Boehler 346*a1a3b679SAndreas Boehler} 347