diff options
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php')
-rw-r--r-- | vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php | 497 |
1 files changed, 179 insertions, 318 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php index dbbf6757a..b3a0ac9af 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV\Locks; use Sabre\DAV; @@ -7,63 +9,58 @@ use Sabre\HTTP; require_once 'Sabre/DAV/AbstractServer.php'; -class PluginTest extends DAV\AbstractServer { - +class PluginTest extends DAV\AbstractServer +{ /** * @var Plugin */ protected $locksPlugin; - function setUp() { - + public function setUp() + { parent::setUp(); - $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb'); + $locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb'); $locksPlugin = new Plugin($locksBackend); $this->server->addPlugin($locksPlugin); $this->locksPlugin = $locksPlugin; - } - function testGetInfo() { - + public function testGetInfo() + { $this->assertArrayHasKey( 'name', $this->locksPlugin->getPluginInfo() ); - } - function testGetFeatures() { - + public function testGetFeatures() + { $this->assertEquals([2], $this->locksPlugin->getFeatures()); - } - function testGetHTTPMethods() { - + public function testGetHTTPMethods() + { $this->assertEquals(['LOCK', 'UNLOCK'], $this->locksPlugin->getHTTPMethods('')); - } - function testLockNoBody() { - + public function testLockNoBody() + { $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals([ 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], + 'Content-Type' => ['application/xml; charset=utf-8'], ], $this->response->getHeaders() ); $this->assertEquals(400, $this->response->status); - } - function testLock() { - + public function testLock() + { $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -78,11 +75,11 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - $this->assertEquals(200, $this->response->status, 'Got an incorrect status back. Response body: ' . $this->response->body); + $this->assertEquals(200, $this->response->status, 'Got an incorrect status back. Response body: '.$this->response->body); - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->body); $xml = simplexml_load_string($body); $xml->registerXPathNamespace('d', 'urn:DAV'); @@ -105,22 +102,21 @@ class PluginTest extends DAV\AbstractServer { foreach ($elements as $elem) { $data = $xml->xpath($elem); - $this->assertEquals(1, count($data), 'We expected 1 match for the xpath expression "' . $elem . '". ' . count($data) . ' were found. Full response body: ' . $this->response->body); + $this->assertEquals(1, count($data), 'We expected 1 match for the xpath expression "'.$elem.'". '.count($data).' were found. Full response body: '.$this->response->body); } $depth = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:depth'); - $this->assertEquals('infinity', (string)$depth[0]); + $this->assertEquals('infinity', (string) $depth[0]); $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href'); - $this->assertEquals($this->response->getHeader('Lock-Token'), '<' . (string)$token[0] . '>', 'Token in response body didn\'t match token in response header.'); - + $this->assertEquals($this->response->getHeader('Lock-Token'), '<'.(string) $token[0].'>', 'Token in response body didn\'t match token in response header.'); } /** * @depends testLock */ - function testDoubleLock() { - + public function testDoubleLock() + { $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -141,15 +137,14 @@ class PluginTest extends DAV\AbstractServer { $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertEquals(423, $this->response->status, 'Full response: ' . $this->response->body); - + $this->assertEquals(423, $this->response->status, 'Full response: '.$this->response->body); } /** * @depends testLock */ - function testLockRefresh() { - + public function testLockRefresh() + { $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -168,7 +163,7 @@ class PluginTest extends DAV\AbstractServer { $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; - $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . ')']); + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '('.$lockToken.')']); $request->setBody(''); $this->server->httpRequest = $request; @@ -176,15 +171,14 @@ class PluginTest extends DAV\AbstractServer { $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertEquals(200, $this->response->status, 'We received an incorrect status code. Full response body: ' . $this->response->getBody()); - + $this->assertEquals(200, $this->response->status, 'We received an incorrect status code. Full response body: '.$this->response->getBody()); } /** * @depends testLock */ - function testLockRefreshBadToken() { - + public function testLockRefreshBadToken() + { $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -203,7 +197,7 @@ class PluginTest extends DAV\AbstractServer { $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; - $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . 'foobar) (<opaquelocktoken:anotherbadtoken>)']); + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '('.$lockToken.'foobar) (<opaquelocktoken:anotherbadtoken>)']); $request->setBody(''); $this->server->httpRequest = $request; @@ -211,15 +205,14 @@ class PluginTest extends DAV\AbstractServer { $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertEquals(423, $this->response->getStatus(), 'We received an incorrect status code. Full response body: ' . $this->response->getBody()); - + $this->assertEquals(423, $this->response->getStatus(), 'We received an incorrect status code. Full response body: '.$this->response->getBody()); } /** * @depends testLock */ - function testLockNoFile() { - + public function testLockNoFile() + { $request = new HTTP\Request('LOCK', '/notfound.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -234,57 +227,54 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(201, $this->response->status); - } /** * @depends testLock */ - function testUnlockNoToken() { - + public function testUnlockNoToken() + { $request = new HTTP\Request('UNLOCK', '/test.txt'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals([ 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], + 'Content-Type' => ['application/xml; charset=utf-8'], ], $this->response->getHeaders() ); $this->assertEquals(400, $this->response->status); - } /** * @depends testLock */ - function testUnlockBadToken() { - + public function testUnlockBadToken() + { $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => '<opaquelocktoken:blablabla>']); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals([ 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], + 'Content-Type' => ['application/xml; charset=utf-8'], ], $this->response->getHeaders() ); - $this->assertEquals(409, $this->response->status, 'Got an incorrect status code. Full response body: ' . $this->response->body); - + $this->assertEquals(409, $this->response->status, 'Got an incorrect status code. Full response body: '.$this->response->body); } /** * @depends testLock */ - function testLockPutNoToken() { - + public function testLockPutNoToken() + { $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -299,7 +289,7 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); @@ -309,17 +299,16 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(423, $this->response->status); - } /** * @depends testLock */ - function testUnlock() { - + public function testUnlock() + { $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; @@ -340,22 +329,20 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpResponse = new HTTP\ResponseMock(); $this->server->invokeMethod($request, $this->server->httpResponse); - $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->body); $this->assertEquals([ 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Length' => ['0'], + 'Content-Length' => ['0'], ], $this->server->httpResponse->getHeaders() ); - - } /** * @depends testLock */ - function testUnlockWindowsBug() { - + public function testUnlockWindowsBug() + { $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; @@ -379,26 +366,21 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpResponse = new HTTP\ResponseMock(); $this->server->invokeMethod($request, $this->server->httpResponse); - $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->body); $this->assertEquals([ 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Length' => ['0'], + 'Content-Length' => ['0'], ], $this->server->httpResponse->getHeaders() ); - - } /** * @depends testLock */ - function testLockRetainOwner() { - - $request = HTTP\Sapi::createFromServerArray([ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ]); + public function testLockRetainOwner() + { + $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -414,21 +396,14 @@ class PluginTest extends DAV\AbstractServer { $locks = $this->locksPlugin->getLocks('test.txt'); $this->assertEquals(1, count($locks)); $this->assertEquals('Evert', $locks[0]->owner); - - } /** * @depends testLock */ - function testLockPutBadToken() { - - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockPutBadToken() + { + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -442,40 +417,30 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '(<opaquelocktoken:token1>)', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('PUT', '/test.txt', [ + 'If' => '(<opaquelocktoken:token1>)', + ]); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); // $this->assertEquals('412 Precondition failed',$this->response->status); $this->assertEquals(423, $this->response->status); - } /** * @depends testLock */ - function testLockDeleteParent() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockDeleteParent() + { + $request = new HTTP\Request('LOCK', '/dir/child.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -489,34 +454,24 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'DELETE', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('DELETE', '/dir'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(423, $this->response->status); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } + /** * @depends testLock */ - function testLockDeleteSucceed() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockDeleteSucceed() + { + $request = new HTTP\Request('LOCK', '/dir/child.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -530,36 +485,26 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('DELETE', '/dir/child.txt', [ + 'If' => '('.$this->response->getHeader('Lock-Token').')', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(204, $this->response->status); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } /** * @depends testLock */ - function testLockCopyLockSource() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockCopyLockSource() + { + $request = new HTTP\Request('LOCK', '/dir/child.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -573,35 +518,27 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/dir/child2.txt', - ]; + $request = new HTTP\Request('COPY', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + ]); - $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(201, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } + /** * @depends testLock */ - function testLockCopyLockDestination() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child2.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockCopyLockDestination() + { + $request = new HTTP\Request('LOCK', '/dir/child2.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -615,36 +552,26 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(201, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/dir/child2.txt', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('COPY', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } /** * @depends testLock */ - function testLockMoveLockSourceLocked() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockMoveLockSourceLocked() + { + $request = new HTTP\Request('LOCK', '/dir/child.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -658,36 +585,26 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/dir/child2.txt', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('MOVE', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } /** * @depends testLock */ - function testLockMoveLockSourceSucceed() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockMoveLockSourceSucceed() + { + $request = new HTTP\Request('LOCK', '/dir/child.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -701,36 +618,26 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('MOVE', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + 'If' => '('.$this->response->getHeader('Lock-Token').')', + ]); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(201, $this->response->status, 'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: ' . $this->response->body); - + $this->assertEquals(201, $this->response->status, 'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: '.$this->response->body); } /** * @depends testLock */ - function testLockMoveLockDestination() { - - $serverVars = [ - 'REQUEST_URI' => '/dir/child2.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockMoveLockDestination() + { + $request = new HTTP\Request('LOCK', '/dir/child2.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -744,36 +651,28 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(201, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/dir/child2.txt', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('MOVE', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } + /** * @depends testLock */ - function testLockMoveLockParent() { - - $serverVars = [ - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'LOCK', - 'HTTP_DEPTH' => 'infinite', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockMoveLockParent() + { + $request = new HTTP\Request('LOCK', '/dir', [ + 'Depth' => 'infinite', + ]); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -787,37 +686,27 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/dir/child.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '</dir> (' . $this->response->getHeader('Lock-Token') . ')', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('MOVE', '/dir/child.txt', [ + 'Destination' => '/dir/child2.txt', + 'If' => '</dir> ('.$this->response->getHeader('Lock-Token').')', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(201, $this->response->status, 'We locked the parent of both the source and destination, but the move didn\'t succeed.'); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } /** * @depends testLock */ - function testLockPutGoodToken() { - - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testLockPutGoodToken() + { + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -831,33 +720,28 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(200, $this->response->status); - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('PUT', '/test.txt', [ + 'If' => '('.$this->response->getHeader('Lock-Token').')', + ]); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(204, $this->response->status); - } /** * @depends testLock */ - function testLockPutUnrelatedToken() { - + public function testLockPutUnrelatedToken() + { $request = new HTTP\Request('LOCK', '/unrelated.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> @@ -872,132 +756,109 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(201, $this->response->getStatus()); $request = new HTTP\Request( 'PUT', '/test.txt', - ['If' => '</unrelated.txt> (' . $this->response->getHeader('Lock-Token') . ')'] + ['If' => '</unrelated.txt> ('.$this->response->getHeader('Lock-Token').')'] ); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')) === 1, 'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); $this->assertEquals(204, $this->response->status); - } - function testPutWithIncorrectETag() { - - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '(["etag1"])', - ]; - - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testPutWithIncorrectETag() + { + $request = new HTTP\Request('PUT', '/test.txt', [ + 'If' => '(["etag1"])', + ]); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(412, $this->response->status); - } /** * @depends testPutWithIncorrectETag */ - function testPutWithCorrectETag() { - + public function testPutWithCorrectETag() + { // We need an ETag-enabled file node. $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); $this->server->tree = $tree; - $filename = SABRE_TEMPDIR . '/test.txt'; + $filename = SABRE_TEMPDIR.'/test.txt'; $etag = sha1( - fileinode($filename) . - filesize($filename) . + fileinode($filename). + filesize($filename). filemtime($filename) ); - $serverVars = [ - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '(["' . $etag . '"])', - ]; - $request = HTTP\Sapi::createFromServerArray($serverVars); + $request = new HTTP\Request('PUT', '/test.txt', [ + 'If' => '(["'.$etag.'"])', + ]); $request->setBody('newbody'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:' . $this->response->body); - + $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:'.$this->response->body); } - function testDeleteWithETagOnCollection() { - - $serverVars = [ - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF' => '(["etag1"])', - ]; - $request = HTTP\Sapi::createFromServerArray($serverVars); + public function testDeleteWithETagOnCollection() + { + $request = new HTTP\Request('DELETE', '/dir', [ + 'If' => '(["etag1"])', + ]); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(412, $this->response->status); - } - function testGetTimeoutHeader() { - - $request = HTTP\Sapi::createFromServerArray([ - 'HTTP_TIMEOUT' => 'second-100', + public function testGetTimeoutHeader() + { + $request = new HTTP\Request('LOCK', '/foo/bar', [ + 'Timeout' => 'second-100', ]); $this->server->httpRequest = $request; $this->assertEquals(100, $this->locksPlugin->getTimeoutHeader()); - } - function testGetTimeoutHeaderTwoItems() { - - $request = HTTP\Sapi::createFromServerArray([ - 'HTTP_TIMEOUT' => 'second-5, infinite', + public function testGetTimeoutHeaderTwoItems() + { + $request = new HTTP\Request('LOCK', '/foo/bar', [ + 'Timeout' => 'second-5, infinite', ]); - $this->server->httpRequest = $request; $this->assertEquals(5, $this->locksPlugin->getTimeoutHeader()); - } - function testGetTimeoutHeaderInfinite() { - - $request = HTTP\Sapi::createFromServerArray([ - 'HTTP_TIMEOUT' => 'infinite, second-5', + public function testGetTimeoutHeaderInfinite() + { + $request = new HTTP\Request('LOCK', '/foo/bar', [ + 'Timeout' => 'infinite, second-5', ]); - $this->server->httpRequest = $request; $this->assertEquals(LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader()); - } /** - * @expectedException Sabre\DAV\Exception\BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ - function testGetTimeoutHeaderInvalid() { - - $request = HTTP\Sapi::createFromServerArray([ - 'HTTP_TIMEOUT' => 'yourmom', - ]); + public function testGetTimeoutHeaderInvalid() + { + $request = new HTTP\Request('GET', '/', ['Timeout' => 'yourmom']); $this->server->httpRequest = $request; $this->locksPlugin->getTimeoutHeader(); - } - - } |