1<?php 2 3namespace Sabre\DAV\Locks\Backend; 4 5use Sabre\DAV; 6 7abstract class AbstractTest extends \PHPUnit_Framework_TestCase { 8 9 /** 10 * @abstract 11 * @return AbstractBackend 12 */ 13 abstract function getBackend(); 14 15 function testSetup() { 16 17 $backend = $this->getBackend(); 18 $this->assertInstanceOf('Sabre\\DAV\\Locks\\Backend\\AbstractBackend', $backend); 19 20 } 21 22 /** 23 * @depends testSetup 24 */ 25 function testGetLocks() { 26 27 $backend = $this->getBackend(); 28 29 $lock = new DAV\Locks\LockInfo(); 30 $lock->owner = 'Sinterklaas'; 31 $lock->timeout = 60; 32 $lock->created = time(); 33 $lock->token = 'MY-UNIQUE-TOKEN'; 34 $lock->uri ='someuri'; 35 36 $this->assertTrue($backend->lock('someuri', $lock)); 37 38 $locks = $backend->getLocks('someuri', false); 39 40 $this->assertEquals(1,count($locks)); 41 $this->assertEquals('Sinterklaas',$locks[0]->owner); 42 $this->assertEquals('someuri',$locks[0]->uri); 43 44 } 45 46 /** 47 * @depends testGetLocks 48 */ 49 function testGetLocksParent() { 50 51 $backend = $this->getBackend(); 52 53 $lock = new DAV\Locks\LockInfo(); 54 $lock->owner = 'Sinterklaas'; 55 $lock->timeout = 60; 56 $lock->created = time(); 57 $lock->depth = DAV\Server::DEPTH_INFINITY; 58 $lock->token = 'MY-UNIQUE-TOKEN'; 59 60 $this->assertTrue($backend->lock('someuri', $lock)); 61 62 $locks = $backend->getLocks('someuri/child', false); 63 64 $this->assertEquals(1,count($locks)); 65 $this->assertEquals('Sinterklaas',$locks[0]->owner); 66 $this->assertEquals('someuri',$locks[0]->uri); 67 68 } 69 70 71 /** 72 * @depends testGetLocks 73 */ 74 function testGetLocksParentDepth0() { 75 76 $backend = $this->getBackend(); 77 78 $lock = new DAV\Locks\LockInfo(); 79 $lock->owner = 'Sinterklaas'; 80 $lock->timeout = 60; 81 $lock->created = time(); 82 $lock->depth = 0; 83 $lock->token = 'MY-UNIQUE-TOKEN'; 84 85 $this->assertTrue($backend->lock('someuri', $lock)); 86 87 $locks = $backend->getLocks('someuri/child', false); 88 89 $this->assertEquals(0,count($locks)); 90 91 } 92 93 function testGetLocksChildren() { 94 95 $backend = $this->getBackend(); 96 97 $lock = new DAV\Locks\LockInfo(); 98 $lock->owner = 'Sinterklaas'; 99 $lock->timeout = 60; 100 $lock->created = time(); 101 $lock->depth = 0; 102 $lock->token = 'MY-UNIQUE-TOKEN'; 103 104 $this->assertTrue($backend->lock('someuri/child', $lock)); 105 106 $locks = $backend->getLocks('someuri/child', false); 107 $this->assertEquals(1,count($locks)); 108 109 $locks = $backend->getLocks('someuri', false); 110 $this->assertEquals(0,count($locks)); 111 112 $locks = $backend->getLocks('someuri', true); 113 $this->assertEquals(1,count($locks)); 114 115 } 116 117 /** 118 * @depends testGetLocks 119 */ 120 function testLockRefresh() { 121 122 $backend = $this->getBackend(); 123 124 $lock = new DAV\Locks\LockInfo(); 125 $lock->owner = 'Sinterklaas'; 126 $lock->timeout = 60; 127 $lock->created = time(); 128 $lock->token = 'MY-UNIQUE-TOKEN'; 129 130 $this->assertTrue($backend->lock('someuri', $lock)); 131 /* Second time */ 132 133 $lock->owner = 'Santa Clause'; 134 $this->assertTrue($backend->lock('someuri', $lock)); 135 136 $locks = $backend->getLocks('someuri', false); 137 138 $this->assertEquals(1,count($locks)); 139 140 $this->assertEquals('Santa Clause',$locks[0]->owner); 141 $this->assertEquals('someuri',$locks[0]->uri); 142 143 } 144 145 /** 146 * @depends testGetLocks 147 */ 148 function testUnlock() { 149 150 $backend = $this->getBackend(); 151 152 $lock = new DAV\Locks\LockInfo(); 153 $lock->owner = 'Sinterklaas'; 154 $lock->timeout = 60; 155 $lock->created = time(); 156 $lock->token = 'MY-UNIQUE-TOKEN'; 157 158 $this->assertTrue($backend->lock('someuri', $lock)); 159 160 $locks = $backend->getLocks('someuri', false); 161 $this->assertEquals(1,count($locks)); 162 163 $this->assertTrue($backend->unlock('someuri',$lock)); 164 165 $locks = $backend->getLocks('someuri', false); 166 $this->assertEquals(0,count($locks)); 167 168 } 169 170 /** 171 * @depends testUnlock 172 */ 173 function testUnlockUnknownToken() { 174 175 $backend = $this->getBackend(); 176 177 $lock = new DAV\Locks\LockInfo(); 178 $lock->owner = 'Sinterklaas'; 179 $lock->timeout = 60; 180 $lock->created = time(); 181 $lock->token = 'MY-UNIQUE-TOKEN'; 182 183 $this->assertTrue($backend->lock('someuri', $lock)); 184 185 $locks = $backend->getLocks('someuri', false); 186 $this->assertEquals(1,count($locks)); 187 188 $lock->token = 'SOME-OTHER-TOKEN'; 189 $this->assertFalse($backend->unlock('someuri',$lock)); 190 191 $locks = $backend->getLocks('someuri', false); 192 $this->assertEquals(1,count($locks)); 193 194 } 195 196} 197