1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Sync; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse 6*a1a3b679SAndreas Boehler Sabre\DAV, 7*a1a3b679SAndreas Boehler Sabre\HTTP; 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehlerrequire_once __DIR__ . '/MockSyncCollection.php'; 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehlerclass PluginTest extends \Sabre\DAVServerTest { 12*a1a3b679SAndreas Boehler 13*a1a3b679SAndreas Boehler protected $collection; 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler function setUp() { 16*a1a3b679SAndreas Boehler 17*a1a3b679SAndreas Boehler parent::setUp(); 18*a1a3b679SAndreas Boehler $this->server->addPlugin(new Plugin()); 19*a1a3b679SAndreas Boehler 20*a1a3b679SAndreas Boehler } 21*a1a3b679SAndreas Boehler 22*a1a3b679SAndreas Boehler function testGetInfo() { 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler $this->assertArrayHasKey( 25*a1a3b679SAndreas Boehler 'name', 26*a1a3b679SAndreas Boehler (new Plugin())->getPluginInfo() 27*a1a3b679SAndreas Boehler ); 28*a1a3b679SAndreas Boehler 29*a1a3b679SAndreas Boehler } 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler function setUpTree() { 32*a1a3b679SAndreas Boehler 33*a1a3b679SAndreas Boehler $this->collection = 34*a1a3b679SAndreas Boehler new MockSyncCollection('coll', [ 35*a1a3b679SAndreas Boehler new DAV\SimpleFile('file1.txt','foo'), 36*a1a3b679SAndreas Boehler new DAV\SimpleFile('file2.txt','bar'), 37*a1a3b679SAndreas Boehler ]); 38*a1a3b679SAndreas Boehler $this->tree = [ 39*a1a3b679SAndreas Boehler $this->collection, 40*a1a3b679SAndreas Boehler new DAV\SimpleCollection('normalcoll', []) 41*a1a3b679SAndreas Boehler ]; 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler } 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler function testSupportedReportSet() { 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler $result = $this->server->getProperties('/coll', ['{DAV:}supported-report-set']); 48*a1a3b679SAndreas Boehler $this->assertFalse($result['{DAV:}supported-report-set']->has('{DAV:}sync-collection')); 49*a1a3b679SAndreas Boehler 50*a1a3b679SAndreas Boehler // Making a change 51*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler $result = $this->server->getProperties('/coll', ['{DAV:}supported-report-set']); 54*a1a3b679SAndreas Boehler $this->assertTrue($result['{DAV:}supported-report-set']->has('{DAV:}sync-collection')); 55*a1a3b679SAndreas Boehler 56*a1a3b679SAndreas Boehler } 57*a1a3b679SAndreas Boehler 58*a1a3b679SAndreas Boehler function testGetSyncToken() { 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler $result = $this->server->getProperties('/coll', ['{DAV:}sync-token']); 61*a1a3b679SAndreas Boehler $this->assertFalse(isset($result['{DAV:}sync-token'])); 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler // Making a change 64*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 65*a1a3b679SAndreas Boehler 66*a1a3b679SAndreas Boehler $result = $this->server->getProperties('/coll', ['{DAV:}sync-token']); 67*a1a3b679SAndreas Boehler $this->assertTrue(isset($result['{DAV:}sync-token'])); 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler // non-sync-enabled collection 70*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler $result = $this->server->getProperties('/normalcoll', ['{DAV:}sync-token']); 73*a1a3b679SAndreas Boehler $this->assertFalse(isset($result['{DAV:}sync-token'])); 74*a1a3b679SAndreas Boehler } 75*a1a3b679SAndreas Boehler 76*a1a3b679SAndreas Boehler function testSyncInitialSyncCollection() { 77*a1a3b679SAndreas Boehler 78*a1a3b679SAndreas Boehler // Making a change 79*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler $request = new HTTP\Request('REPORT', '/coll/', ['Content-Type' => 'application/xml']); 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler $body = <<<BLA 84*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 85*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 86*a1a3b679SAndreas Boehler <D:sync-token/> 87*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 88*a1a3b679SAndreas Boehler <D:prop> 89*a1a3b679SAndreas Boehler <D:getcontentlength/> 90*a1a3b679SAndreas Boehler </D:prop> 91*a1a3b679SAndreas Boehler</D:sync-collection> 92*a1a3b679SAndreas BoehlerBLA; 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $request->setBody($body); 95*a1a3b679SAndreas Boehler 96*a1a3b679SAndreas Boehler $response = $this->request($request); 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Full response body:' . $response->body); 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler $multiStatus = $this->server->xml->parse($response->getBodyAsString()); 101*a1a3b679SAndreas Boehler 102*a1a3b679SAndreas Boehler // Checking the sync-token 103*a1a3b679SAndreas Boehler $this->assertEquals( 104*a1a3b679SAndreas Boehler 'http://sabre.io/ns/sync/1', 105*a1a3b679SAndreas Boehler $multiStatus->getSyncToken() 106*a1a3b679SAndreas Boehler ); 107*a1a3b679SAndreas Boehler 108*a1a3b679SAndreas Boehler $responses = $multiStatus->getResponses(); 109*a1a3b679SAndreas Boehler $this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response'); 110*a1a3b679SAndreas Boehler 111*a1a3b679SAndreas Boehler $response = $responses[0]; 112*a1a3b679SAndreas Boehler 113*a1a3b679SAndreas Boehler $this->assertNull($response->getHttpStatus()); 114*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file1.txt', $response->getHref()); 115*a1a3b679SAndreas Boehler $this->assertEquals([ 116*a1a3b679SAndreas Boehler 200 => [ 117*a1a3b679SAndreas Boehler '{DAV:}getcontentlength' => 3, 118*a1a3b679SAndreas Boehler ] 119*a1a3b679SAndreas Boehler ], $response->getResponseProperties()); 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler $response = $responses[1]; 122*a1a3b679SAndreas Boehler 123*a1a3b679SAndreas Boehler $this->assertNull($response->getHttpStatus()); 124*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file2.txt', $response->getHref()); 125*a1a3b679SAndreas Boehler $this->assertEquals([ 126*a1a3b679SAndreas Boehler 200 => [ 127*a1a3b679SAndreas Boehler '{DAV:}getcontentlength' => 3, 128*a1a3b679SAndreas Boehler ] 129*a1a3b679SAndreas Boehler ], $response->getResponseProperties()); 130*a1a3b679SAndreas Boehler 131*a1a3b679SAndreas Boehler } 132*a1a3b679SAndreas Boehler 133*a1a3b679SAndreas Boehler function testSubsequentSyncSyncCollection() { 134*a1a3b679SAndreas Boehler 135*a1a3b679SAndreas Boehler // Making a change 136*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 137*a1a3b679SAndreas Boehler // Making another change 138*a1a3b679SAndreas Boehler $this->collection->addChange([], ['file2.txt'], ['file3.txt']); 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 141*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 142*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 143*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 144*a1a3b679SAndreas Boehler ]); 145*a1a3b679SAndreas Boehler 146*a1a3b679SAndreas Boehler $body = <<<BLA 147*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 148*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 149*a1a3b679SAndreas Boehler <D:sync-token>http://sabre.io/ns/sync/1</D:sync-token> 150*a1a3b679SAndreas Boehler <D:sync-level>infinite</D:sync-level> 151*a1a3b679SAndreas Boehler <D:prop> 152*a1a3b679SAndreas Boehler <D:getcontentlength/> 153*a1a3b679SAndreas Boehler </D:prop> 154*a1a3b679SAndreas Boehler</D:sync-collection> 155*a1a3b679SAndreas BoehlerBLA; 156*a1a3b679SAndreas Boehler 157*a1a3b679SAndreas Boehler $request->setBody($body); 158*a1a3b679SAndreas Boehler 159*a1a3b679SAndreas Boehler $response = $this->request($request); 160*a1a3b679SAndreas Boehler 161*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Full response body:' . $response->body); 162*a1a3b679SAndreas Boehler 163*a1a3b679SAndreas Boehler $multiStatus = $this->server->xml->parse($response->getBodyAsString()); 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler // Checking the sync-token 166*a1a3b679SAndreas Boehler $this->assertEquals( 167*a1a3b679SAndreas Boehler 'http://sabre.io/ns/sync/2', 168*a1a3b679SAndreas Boehler $multiStatus->getSyncToken() 169*a1a3b679SAndreas Boehler ); 170*a1a3b679SAndreas Boehler 171*a1a3b679SAndreas Boehler $responses = $multiStatus->getResponses(); 172*a1a3b679SAndreas Boehler $this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response'); 173*a1a3b679SAndreas Boehler 174*a1a3b679SAndreas Boehler $response = $responses[0]; 175*a1a3b679SAndreas Boehler 176*a1a3b679SAndreas Boehler $this->assertNull($response->getHttpStatus()); 177*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file2.txt', $response->getHref()); 178*a1a3b679SAndreas Boehler $this->assertEquals([ 179*a1a3b679SAndreas Boehler 200 => [ 180*a1a3b679SAndreas Boehler '{DAV:}getcontentlength' => 3, 181*a1a3b679SAndreas Boehler ] 182*a1a3b679SAndreas Boehler ], $response->getResponseProperties()); 183*a1a3b679SAndreas Boehler 184*a1a3b679SAndreas Boehler $response = $responses[1]; 185*a1a3b679SAndreas Boehler 186*a1a3b679SAndreas Boehler $this->assertEquals('404', $response->getHttpStatus()); 187*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file3.txt', $response->getHref()); 188*a1a3b679SAndreas Boehler $this->assertEquals([], $response->getResponseProperties()); 189*a1a3b679SAndreas Boehler 190*a1a3b679SAndreas Boehler } 191*a1a3b679SAndreas Boehler 192*a1a3b679SAndreas Boehler function testSubsequentSyncSyncCollectionLimit() { 193*a1a3b679SAndreas Boehler 194*a1a3b679SAndreas Boehler // Making a change 195*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 196*a1a3b679SAndreas Boehler // Making another change 197*a1a3b679SAndreas Boehler $this->collection->addChange([], ['file2.txt'], ['file3.txt']); 198*a1a3b679SAndreas Boehler 199*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 200*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 201*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 202*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 203*a1a3b679SAndreas Boehler ]); 204*a1a3b679SAndreas Boehler 205*a1a3b679SAndreas Boehler $body = <<<BLA 206*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 207*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 208*a1a3b679SAndreas Boehler <D:sync-token>http://sabre.io/ns/sync/1</D:sync-token> 209*a1a3b679SAndreas Boehler <D:sync-level>infinite</D:sync-level> 210*a1a3b679SAndreas Boehler <D:prop> 211*a1a3b679SAndreas Boehler <D:getcontentlength/> 212*a1a3b679SAndreas Boehler </D:prop> 213*a1a3b679SAndreas Boehler <D:limit><D:nresults>1</D:nresults></D:limit> 214*a1a3b679SAndreas Boehler</D:sync-collection> 215*a1a3b679SAndreas BoehlerBLA; 216*a1a3b679SAndreas Boehler 217*a1a3b679SAndreas Boehler $request->setBody($body); 218*a1a3b679SAndreas Boehler 219*a1a3b679SAndreas Boehler $response = $this->request($request); 220*a1a3b679SAndreas Boehler 221*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Full response body:' . $response->body); 222*a1a3b679SAndreas Boehler 223*a1a3b679SAndreas Boehler $multiStatus = $this->server->xml->parse( 224*a1a3b679SAndreas Boehler $response->getBodyAsString() 225*a1a3b679SAndreas Boehler ); 226*a1a3b679SAndreas Boehler 227*a1a3b679SAndreas Boehler // Checking the sync-token 228*a1a3b679SAndreas Boehler $this->assertEquals( 229*a1a3b679SAndreas Boehler 'http://sabre.io/ns/sync/2', 230*a1a3b679SAndreas Boehler $multiStatus->getSyncToken() 231*a1a3b679SAndreas Boehler ); 232*a1a3b679SAndreas Boehler 233*a1a3b679SAndreas Boehler $responses = $multiStatus->getResponses(); 234*a1a3b679SAndreas Boehler $this->assertEquals(1, count($responses), 'We expected exactly 1 {DAV:}response'); 235*a1a3b679SAndreas Boehler 236*a1a3b679SAndreas Boehler $response = $responses[0]; 237*a1a3b679SAndreas Boehler 238*a1a3b679SAndreas Boehler $this->assertEquals('404', $response->getHttpStatus()); 239*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file3.txt', $response->getHref()); 240*a1a3b679SAndreas Boehler $this->assertEquals([], $response->getResponseProperties()); 241*a1a3b679SAndreas Boehler 242*a1a3b679SAndreas Boehler } 243*a1a3b679SAndreas Boehler 244*a1a3b679SAndreas Boehler function testSubsequentSyncSyncCollectionDepthFallBack() { 245*a1a3b679SAndreas Boehler 246*a1a3b679SAndreas Boehler // Making a change 247*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 248*a1a3b679SAndreas Boehler // Making another change 249*a1a3b679SAndreas Boehler $this->collection->addChange([], ['file2.txt'], ['file3.txt']); 250*a1a3b679SAndreas Boehler 251*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 252*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 253*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 254*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 255*a1a3b679SAndreas Boehler 'HTTP_DEPTH' => "1", 256*a1a3b679SAndreas Boehler ]); 257*a1a3b679SAndreas Boehler 258*a1a3b679SAndreas Boehler $body = <<<BLA 259*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 260*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 261*a1a3b679SAndreas Boehler <D:sync-token>http://sabre.io/ns/sync/1</D:sync-token> 262*a1a3b679SAndreas Boehler <D:prop> 263*a1a3b679SAndreas Boehler <D:getcontentlength/> 264*a1a3b679SAndreas Boehler </D:prop> 265*a1a3b679SAndreas Boehler</D:sync-collection> 266*a1a3b679SAndreas BoehlerBLA; 267*a1a3b679SAndreas Boehler 268*a1a3b679SAndreas Boehler $request->setBody($body); 269*a1a3b679SAndreas Boehler 270*a1a3b679SAndreas Boehler $response = $this->request($request); 271*a1a3b679SAndreas Boehler 272*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Full response body:' . $response->body); 273*a1a3b679SAndreas Boehler 274*a1a3b679SAndreas Boehler $multiStatus = $this->server->xml->parse( 275*a1a3b679SAndreas Boehler $response->getBodyAsString() 276*a1a3b679SAndreas Boehler ); 277*a1a3b679SAndreas Boehler 278*a1a3b679SAndreas Boehler // Checking the sync-token 279*a1a3b679SAndreas Boehler $this->assertEquals( 280*a1a3b679SAndreas Boehler 'http://sabre.io/ns/sync/2', 281*a1a3b679SAndreas Boehler $multiStatus->getSyncToken() 282*a1a3b679SAndreas Boehler ); 283*a1a3b679SAndreas Boehler 284*a1a3b679SAndreas Boehler $responses = $multiStatus->getResponses(); 285*a1a3b679SAndreas Boehler $this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response'); 286*a1a3b679SAndreas Boehler 287*a1a3b679SAndreas Boehler $response = $responses[0]; 288*a1a3b679SAndreas Boehler 289*a1a3b679SAndreas Boehler $this->assertNull($response->getHttpStatus()); 290*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file2.txt', $response->getHref()); 291*a1a3b679SAndreas Boehler $this->assertEquals([ 292*a1a3b679SAndreas Boehler 200 => [ 293*a1a3b679SAndreas Boehler '{DAV:}getcontentlength' => 3, 294*a1a3b679SAndreas Boehler ] 295*a1a3b679SAndreas Boehler ], $response->getResponseProperties()); 296*a1a3b679SAndreas Boehler 297*a1a3b679SAndreas Boehler $response = $responses[1]; 298*a1a3b679SAndreas Boehler 299*a1a3b679SAndreas Boehler $this->assertEquals('404', $response->getHttpStatus()); 300*a1a3b679SAndreas Boehler $this->assertEquals('/coll/file3.txt', $response->getHref()); 301*a1a3b679SAndreas Boehler $this->assertEquals([], $response->getResponseProperties()); 302*a1a3b679SAndreas Boehler 303*a1a3b679SAndreas Boehler } 304*a1a3b679SAndreas Boehler 305*a1a3b679SAndreas Boehler function testSyncNoSyncInfo() { 306*a1a3b679SAndreas Boehler 307*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 308*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 309*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 310*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 311*a1a3b679SAndreas Boehler ]); 312*a1a3b679SAndreas Boehler 313*a1a3b679SAndreas Boehler $body = <<<BLA 314*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 315*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 316*a1a3b679SAndreas Boehler <D:sync-token/> 317*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 318*a1a3b679SAndreas Boehler <D:prop> 319*a1a3b679SAndreas Boehler <D:getcontentlength/> 320*a1a3b679SAndreas Boehler </D:prop> 321*a1a3b679SAndreas Boehler</D:sync-collection> 322*a1a3b679SAndreas BoehlerBLA; 323*a1a3b679SAndreas Boehler 324*a1a3b679SAndreas Boehler $request->setBody($body); 325*a1a3b679SAndreas Boehler 326*a1a3b679SAndreas Boehler $response = $this->request($request); 327*a1a3b679SAndreas Boehler 328*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 329*a1a3b679SAndreas Boehler // be supported. 330*a1a3b679SAndreas Boehler $this->assertEquals(415, $response->status, 'Full response body:' . $response->body); 331*a1a3b679SAndreas Boehler 332*a1a3b679SAndreas Boehler } 333*a1a3b679SAndreas Boehler 334*a1a3b679SAndreas Boehler function testSyncNoSyncCollection() { 335*a1a3b679SAndreas Boehler 336*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 337*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 338*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/normalcoll/', 339*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 340*a1a3b679SAndreas Boehler ]); 341*a1a3b679SAndreas Boehler 342*a1a3b679SAndreas Boehler $body = <<<BLA 343*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 344*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 345*a1a3b679SAndreas Boehler <D:sync-token/> 346*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 347*a1a3b679SAndreas Boehler <D:prop> 348*a1a3b679SAndreas Boehler <D:getcontentlength/> 349*a1a3b679SAndreas Boehler </D:prop> 350*a1a3b679SAndreas Boehler</D:sync-collection> 351*a1a3b679SAndreas BoehlerBLA; 352*a1a3b679SAndreas Boehler 353*a1a3b679SAndreas Boehler $request->setBody($body); 354*a1a3b679SAndreas Boehler 355*a1a3b679SAndreas Boehler $response = $this->request($request); 356*a1a3b679SAndreas Boehler 357*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 358*a1a3b679SAndreas Boehler // be supported. 359*a1a3b679SAndreas Boehler $this->assertEquals(415, $response->status, 'Full response body:' . $response->body); 360*a1a3b679SAndreas Boehler 361*a1a3b679SAndreas Boehler } 362*a1a3b679SAndreas Boehler 363*a1a3b679SAndreas Boehler function testSyncInvalidToken() { 364*a1a3b679SAndreas Boehler 365*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 366*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 367*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 368*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 369*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 370*a1a3b679SAndreas Boehler ]); 371*a1a3b679SAndreas Boehler 372*a1a3b679SAndreas Boehler $body = <<<BLA 373*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 374*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 375*a1a3b679SAndreas Boehler <D:sync-token>http://sabre.io/ns/sync/invalid</D:sync-token> 376*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 377*a1a3b679SAndreas Boehler <D:prop> 378*a1a3b679SAndreas Boehler <D:getcontentlength/> 379*a1a3b679SAndreas Boehler </D:prop> 380*a1a3b679SAndreas Boehler</D:sync-collection> 381*a1a3b679SAndreas BoehlerBLA; 382*a1a3b679SAndreas Boehler 383*a1a3b679SAndreas Boehler $request->setBody($body); 384*a1a3b679SAndreas Boehler 385*a1a3b679SAndreas Boehler $response = $this->request($request); 386*a1a3b679SAndreas Boehler 387*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 388*a1a3b679SAndreas Boehler // be supported. 389*a1a3b679SAndreas Boehler $this->assertEquals(403, $response->status, 'Full response body:' . $response->body); 390*a1a3b679SAndreas Boehler 391*a1a3b679SAndreas Boehler } 392*a1a3b679SAndreas Boehler function testSyncInvalidTokenNoPrefix() { 393*a1a3b679SAndreas Boehler 394*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 395*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 396*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 397*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 398*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 399*a1a3b679SAndreas Boehler ]); 400*a1a3b679SAndreas Boehler 401*a1a3b679SAndreas Boehler $body = <<<BLA 402*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 403*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 404*a1a3b679SAndreas Boehler <D:sync-token>invalid</D:sync-token> 405*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 406*a1a3b679SAndreas Boehler <D:prop> 407*a1a3b679SAndreas Boehler <D:getcontentlength/> 408*a1a3b679SAndreas Boehler </D:prop> 409*a1a3b679SAndreas Boehler</D:sync-collection> 410*a1a3b679SAndreas BoehlerBLA; 411*a1a3b679SAndreas Boehler 412*a1a3b679SAndreas Boehler $request->setBody($body); 413*a1a3b679SAndreas Boehler 414*a1a3b679SAndreas Boehler $response = $this->request($request); 415*a1a3b679SAndreas Boehler 416*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 417*a1a3b679SAndreas Boehler // be supported. 418*a1a3b679SAndreas Boehler $this->assertEquals(403, $response->status, 'Full response body:' . $response->body); 419*a1a3b679SAndreas Boehler 420*a1a3b679SAndreas Boehler } 421*a1a3b679SAndreas Boehler 422*a1a3b679SAndreas Boehler function testSyncNoSyncToken() { 423*a1a3b679SAndreas Boehler 424*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 425*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 426*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 427*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 428*a1a3b679SAndreas Boehler ]); 429*a1a3b679SAndreas Boehler 430*a1a3b679SAndreas Boehler $body = <<<BLA 431*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 432*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 433*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 434*a1a3b679SAndreas Boehler <D:prop> 435*a1a3b679SAndreas Boehler <D:getcontentlength/> 436*a1a3b679SAndreas Boehler </D:prop> 437*a1a3b679SAndreas Boehler</D:sync-collection> 438*a1a3b679SAndreas BoehlerBLA; 439*a1a3b679SAndreas Boehler 440*a1a3b679SAndreas Boehler $request->setBody($body); 441*a1a3b679SAndreas Boehler 442*a1a3b679SAndreas Boehler $response = $this->request($request); 443*a1a3b679SAndreas Boehler 444*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 445*a1a3b679SAndreas Boehler // be supported. 446*a1a3b679SAndreas Boehler $this->assertEquals(400, $response->status, 'Full response body:' . $response->body); 447*a1a3b679SAndreas Boehler 448*a1a3b679SAndreas Boehler } 449*a1a3b679SAndreas Boehler 450*a1a3b679SAndreas Boehler function testSyncNoProp() { 451*a1a3b679SAndreas Boehler 452*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 453*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 454*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 455*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/', 456*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/xml', 457*a1a3b679SAndreas Boehler ]); 458*a1a3b679SAndreas Boehler 459*a1a3b679SAndreas Boehler $body = <<<BLA 460*a1a3b679SAndreas Boehler<?xml version="1.0" encoding="utf-8" ?> 461*a1a3b679SAndreas Boehler<D:sync-collection xmlns:D="DAV:"> 462*a1a3b679SAndreas Boehler <D:sync-token /> 463*a1a3b679SAndreas Boehler <D:sync-level>1</D:sync-level> 464*a1a3b679SAndreas Boehler</D:sync-collection> 465*a1a3b679SAndreas BoehlerBLA; 466*a1a3b679SAndreas Boehler 467*a1a3b679SAndreas Boehler $request->setBody($body); 468*a1a3b679SAndreas Boehler 469*a1a3b679SAndreas Boehler $response = $this->request($request); 470*a1a3b679SAndreas Boehler 471*a1a3b679SAndreas Boehler // The default state has no sync-token, so this report should not yet 472*a1a3b679SAndreas Boehler // be supported. 473*a1a3b679SAndreas Boehler $this->assertEquals(400, $response->status, 'Full response body:' . $response->body); 474*a1a3b679SAndreas Boehler 475*a1a3b679SAndreas Boehler } 476*a1a3b679SAndreas Boehler 477*a1a3b679SAndreas Boehler function testIfConditions() { 478*a1a3b679SAndreas Boehler 479*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 480*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 481*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'DELETE', 482*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/file1.txt', 483*a1a3b679SAndreas Boehler 'HTTP_IF' => '</coll> (<http://sabre.io/ns/sync/1>)', 484*a1a3b679SAndreas Boehler ]); 485*a1a3b679SAndreas Boehler $response = $this->request($request); 486*a1a3b679SAndreas Boehler 487*a1a3b679SAndreas Boehler // If a 403 is thrown this works correctly. The file in questions 488*a1a3b679SAndreas Boehler // doesn't allow itself to be deleted. 489*a1a3b679SAndreas Boehler // If the If conditions failed, it would have been a 412 instead. 490*a1a3b679SAndreas Boehler $this->assertEquals(403, $response->status); 491*a1a3b679SAndreas Boehler 492*a1a3b679SAndreas Boehler } 493*a1a3b679SAndreas Boehler 494*a1a3b679SAndreas Boehler function testIfConditionsNot() { 495*a1a3b679SAndreas Boehler 496*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 497*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 498*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'DELETE', 499*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/file1.txt', 500*a1a3b679SAndreas Boehler 'HTTP_IF' => '</coll> (Not <http://sabre.io/ns/sync/2>)', 501*a1a3b679SAndreas Boehler ]); 502*a1a3b679SAndreas Boehler $response = $this->request($request); 503*a1a3b679SAndreas Boehler 504*a1a3b679SAndreas Boehler // If a 403 is thrown this works correctly. The file in questions 505*a1a3b679SAndreas Boehler // doesn't allow itself to be deleted. 506*a1a3b679SAndreas Boehler // If the If conditions failed, it would have been a 412 instead. 507*a1a3b679SAndreas Boehler $this->assertEquals(403, $response->status); 508*a1a3b679SAndreas Boehler 509*a1a3b679SAndreas Boehler } 510*a1a3b679SAndreas Boehler 511*a1a3b679SAndreas Boehler function testIfConditionsNoSyncToken() { 512*a1a3b679SAndreas Boehler 513*a1a3b679SAndreas Boehler $this->collection->addChange(['file1.txt'], [], []); 514*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray([ 515*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'DELETE', 516*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/coll/file1.txt', 517*a1a3b679SAndreas Boehler 'HTTP_IF' => '</coll> (<opaquelocktoken:foo>)', 518*a1a3b679SAndreas Boehler ]); 519*a1a3b679SAndreas Boehler $response = $this->request($request); 520*a1a3b679SAndreas Boehler 521*a1a3b679SAndreas Boehler $this->assertEquals(412, $response->status); 522*a1a3b679SAndreas Boehler 523*a1a3b679SAndreas Boehler } 524*a1a3b679SAndreas Boehler} 525