1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAVServerTest; 6*a1a3b679SAndreas Boehleruse Sabre\HTTP; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehler/** 9*a1a3b679SAndreas Boehler * Tests related to the PUT request. 10*a1a3b679SAndreas Boehler * 11*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 12*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 13*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 14*a1a3b679SAndreas Boehler */ 15*a1a3b679SAndreas Boehlerclass HttpDeleteTest extends DAVServerTest { 16*a1a3b679SAndreas Boehler 17*a1a3b679SAndreas Boehler /** 18*a1a3b679SAndreas Boehler * Sets up the DAV tree. 19*a1a3b679SAndreas Boehler * 20*a1a3b679SAndreas Boehler * @return void 21*a1a3b679SAndreas Boehler */ 22*a1a3b679SAndreas Boehler public function setUpTree() { 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler $this->tree = new Mock\Collection('root', [ 25*a1a3b679SAndreas Boehler 'file1' => 'foo', 26*a1a3b679SAndreas Boehler 'dir' => [ 27*a1a3b679SAndreas Boehler 'subfile' => 'bar', 28*a1a3b679SAndreas Boehler 'subfile2' => 'baz', 29*a1a3b679SAndreas Boehler ], 30*a1a3b679SAndreas Boehler ]); 31*a1a3b679SAndreas Boehler 32*a1a3b679SAndreas Boehler } 33*a1a3b679SAndreas Boehler 34*a1a3b679SAndreas Boehler /** 35*a1a3b679SAndreas Boehler * A successful DELETE 36*a1a3b679SAndreas Boehler */ 37*a1a3b679SAndreas Boehler public function testDelete() { 38*a1a3b679SAndreas Boehler 39*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/file1'); 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler $response = $this->request($request); 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler $this->assertEquals( 44*a1a3b679SAndreas Boehler 204, 45*a1a3b679SAndreas Boehler $response->getStatus(), 46*a1a3b679SAndreas Boehler "Incorrect status code. Response body: " . $response->getBodyAsString() 47*a1a3b679SAndreas Boehler ); 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler $this->assertEquals( 50*a1a3b679SAndreas Boehler [ 51*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 52*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 53*a1a3b679SAndreas Boehler ], 54*a1a3b679SAndreas Boehler $response->getHeaders() 55*a1a3b679SAndreas Boehler ); 56*a1a3b679SAndreas Boehler 57*a1a3b679SAndreas Boehler } 58*a1a3b679SAndreas Boehler 59*a1a3b679SAndreas Boehler /** 60*a1a3b679SAndreas Boehler * Deleting a Directory 61*a1a3b679SAndreas Boehler */ 62*a1a3b679SAndreas Boehler public function testDeleteDirectory() { 63*a1a3b679SAndreas Boehler 64*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/dir'); 65*a1a3b679SAndreas Boehler 66*a1a3b679SAndreas Boehler $response = $this->request($request); 67*a1a3b679SAndreas Boehler 68*a1a3b679SAndreas Boehler $this->assertEquals( 69*a1a3b679SAndreas Boehler 204, 70*a1a3b679SAndreas Boehler $response->getStatus(), 71*a1a3b679SAndreas Boehler "Incorrect status code. Response body: " . $response->getBodyAsString() 72*a1a3b679SAndreas Boehler ); 73*a1a3b679SAndreas Boehler 74*a1a3b679SAndreas Boehler $this->assertEquals( 75*a1a3b679SAndreas Boehler [ 76*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [Version::VERSION], 77*a1a3b679SAndreas Boehler 'Content-Length' => ['0'], 78*a1a3b679SAndreas Boehler ], 79*a1a3b679SAndreas Boehler $response->getHeaders() 80*a1a3b679SAndreas Boehler ); 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler } 83*a1a3b679SAndreas Boehler 84*a1a3b679SAndreas Boehler /** 85*a1a3b679SAndreas Boehler * DELETE on a node that does not exist 86*a1a3b679SAndreas Boehler */ 87*a1a3b679SAndreas Boehler public function testDeleteNotFound() { 88*a1a3b679SAndreas Boehler 89*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/file2'); 90*a1a3b679SAndreas Boehler $response = $this->request($request); 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler $this->assertEquals( 93*a1a3b679SAndreas Boehler 404, 94*a1a3b679SAndreas Boehler $response->getStatus(), 95*a1a3b679SAndreas Boehler "Incorrect status code. Response body: " . $response->getBodyAsString() 96*a1a3b679SAndreas Boehler ); 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler } 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler /** 101*a1a3b679SAndreas Boehler * DELETE with preconditions 102*a1a3b679SAndreas Boehler */ 103*a1a3b679SAndreas Boehler public function testDeletePreconditions() { 104*a1a3b679SAndreas Boehler 105*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/file1', [ 106*a1a3b679SAndreas Boehler 'If-Match' => '"' . md5('foo') . '"', 107*a1a3b679SAndreas Boehler ]); 108*a1a3b679SAndreas Boehler 109*a1a3b679SAndreas Boehler $response = $this->request($request); 110*a1a3b679SAndreas Boehler 111*a1a3b679SAndreas Boehler $this->assertEquals( 112*a1a3b679SAndreas Boehler 204, 113*a1a3b679SAndreas Boehler $response->getStatus(), 114*a1a3b679SAndreas Boehler "Incorrect status code. Response body: " . $response->getBodyAsString() 115*a1a3b679SAndreas Boehler ); 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler } 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler /** 120*a1a3b679SAndreas Boehler * DELETE with incorrect preconditions 121*a1a3b679SAndreas Boehler */ 122*a1a3b679SAndreas Boehler public function testDeletePreconditionsFailed() { 123*a1a3b679SAndreas Boehler 124*a1a3b679SAndreas Boehler $request = new HTTP\Request('DELETE', '/file1', [ 125*a1a3b679SAndreas Boehler 'If-Match' => '"' . md5('bar') . '"', 126*a1a3b679SAndreas Boehler ]); 127*a1a3b679SAndreas Boehler 128*a1a3b679SAndreas Boehler $response = $this->request($request); 129*a1a3b679SAndreas Boehler 130*a1a3b679SAndreas Boehler $this->assertEquals( 131*a1a3b679SAndreas Boehler 412, 132*a1a3b679SAndreas Boehler $response->getStatus(), 133*a1a3b679SAndreas Boehler "Incorrect status code. Response body: " . $response->getBodyAsString() 134*a1a3b679SAndreas Boehler ); 135*a1a3b679SAndreas Boehler 136*a1a3b679SAndreas Boehler } 137*a1a3b679SAndreas Boehler} 138