diff options
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/Locks')
4 files changed, 277 insertions, 661 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php deleted file mode 100644 index 651abf786..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -namespace Sabre\DAV\Locks\Backend; - -require_once 'Sabre/TestUtil.php'; - -class FSTest extends AbstractTest { - - function getBackend() { - - \Sabre\TestUtil::clearTempDir(); - mkdir(SABRE_TEMPDIR . '/locks'); - $backend = new FS(SABRE_TEMPDIR . '/locks/'); - return $backend; - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testGetLocksChildren() { - - // We're skipping this test. This doesn't work, and it will - // never. The class is deprecated anyway. - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php deleted file mode 100644 index 7b2cd0db0..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php +++ /dev/null @@ -1,375 +0,0 @@ -<?php - -namespace Sabre\DAV\Locks; - -use Sabre\DAV; -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; - -class GetIfConditionsTest extends DAV\AbstractServer { - - /** - * @var Sabre\DAV\Locks\Plugin - */ - protected $locksPlugin; - - function setUp() { - - parent::setUp(); - $locksPlugin = new Plugin(); - $this->server->addPlugin($locksPlugin); - $this->locksPlugin = $locksPlugin; - - } - - function testNoConditions() { - - $serverVars = array( - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - $this->assertEquals(array(),$conditions); - - } - - function testLockToken() { - - $serverVars = array( - 'HTTP_IF' => '(<opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - - $this->assertEquals($compare,$conditions); - - } - - function testNotLockToken() { - - $serverVars = array( - 'HTTP_IF' => '(Not <opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testLockTokenUrl() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.com/> (<opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.com/', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2LockTokens() { - - $serverVars = array( - 'HTTP_IF' => '(<opaquelocktoken:token1>) (Not <opaquelocktoken:token2>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - array( - 0, - 'opaquelocktoken:token2', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2UriLockTokens() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) <http://www.example.org/node2> (Not <opaquelocktoken:token2>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token2', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2UriMultiLockTokens() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) (<opaquelocktoken:token2>) <http://www.example.org/node2> (Not <opaquelocktoken:token3>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - array( - 1, - 'opaquelocktoken:token2', - '', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token3', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testEtag() { - - $serverVars = array( - 'HTTP_IF' => '([etag1])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - '', - 'etag1', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2Etags() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/> ([etag1]) ([etag2])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/', - 'tokens' => array( - array( - 1, - '', - 'etag1', - ), - array( - 1, - '', - 'etag2', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testComplexIf() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1> [etag1]) ' . - '(Not <opaquelocktoken:token2>) ([etag2]) <http://www.example.org/node2> ' . - '(<opaquelocktoken:token3>) (Not <opaquelocktoken:token4>) ([etag3])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - 'etag1', - ), - array( - 0, - 'opaquelocktoken:token2', - '', - ), - array( - 1, - '', - 'etag2', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token3', - '', - ), - array( - 0, - 'opaquelocktoken:token4', - '', - ), - array( - 1, - '', - 'etag3', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php index b3d7d447b..23f283796 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php @@ -10,6 +10,12 @@ require_once 'Sabre/TestUtil.php'; class MSWordTest extends \PHPUnit_Framework_TestCase { + function tearDown() { + + \Sabre\TestUtil::clearTempDir(); + + } + function testLockEtc() { mkdir(SABRE_TEMPDIR . '/mstest'); @@ -25,11 +31,12 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpRequest = $this->getLockRequest(); $server->httpResponse = $response1; + $server->sapi = new HTTP\SapiMock(); $server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status); - $this->assertTrue(isset($server->httpResponse->headers['Lock-Token'])); - $lockToken = $server->httpResponse->headers['Lock-Token']; + $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString()); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + $lockToken = $server->httpResponse->getHeader('Lock-Token'); //sleep(10); @@ -39,8 +46,8 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpResponse = $response2; $server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status); - $this->assertTrue(isset($server->httpResponse->headers['Lock-Token'])); + $this->assertEquals(201, $server->httpResponse->status); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); //sleep(10); @@ -49,19 +56,13 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpResponse = $response3; $server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); + $this->assertEquals(204, $server->httpResponse->status); } function getLockRequest() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', 'HTTP_TIMEOUT' => 'Second-3600', @@ -85,7 +86,7 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { } function getLockRequest2() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', 'HTTP_TIMEOUT' => 'Second-3600', @@ -110,7 +111,7 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { function getPutRequest($lockToken) { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', 'HTTP_IF' => 'If: ('.$lockToken.')', diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php index caa1d0118..ef0e473ae 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php @@ -10,7 +10,7 @@ require_once 'Sabre/DAV/AbstractServer.php'; class PluginTest extends DAV\AbstractServer { /** - * @var Sabre\DAV\Locks\Plugin + * @var Plugin */ protected $locksPlugin; @@ -24,62 +24,47 @@ class PluginTest extends DAV\AbstractServer { } - function testGetFeatures() { - - $this->assertEquals(array(2),$this->locksPlugin->getFeatures()); - - } + function testGetInfo() { - function testGetHTTPMethods() { - - $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods('')); + $this->assertArrayHasKey( + 'name', + $this->locksPlugin->getPluginInfo() + ); } - function testGetHTTPMethodsNoBackend() { + function testGetFeatures() { - $locksPlugin = new Plugin(); - $this->server->addPlugin($locksPlugin); - $this->assertEquals(array(),$locksPlugin->getHTTPMethods('')); + $this->assertEquals(array(2),$this->locksPlugin->getFeatures()); } - function testUnknownMethodPassthough() { + function testGetHTTPMethods() { - $this->assertNull($this->locksPlugin->unknownMethod('BLA','/')); + $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods('')); } function testLockNoBody() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(''); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('LOCK', '/test.txt'); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], ), - $this->response->headers + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); + $this->assertEquals(400, $this->response->status); } function testLock() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -92,10 +77,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$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); $xml = simplexml_load_string($body); @@ -127,7 +112,7 @@ class PluginTest extends DAV\AbstractServer { $this->assertEquals('infinity',(string)$depth[0]); $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href'); - $this->assertEquals($this->response->headers['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.'); } @@ -136,12 +121,7 @@ class PluginTest extends DAV\AbstractServer { */ function testDoubleLock() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -159,9 +139,9 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + $this->assertEquals(423, $this->response->status, 'Full response: ' . $this->response->body); } @@ -170,12 +150,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockRefresh() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -188,25 +163,55 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $lockToken = $this->response->headers['Lock-Token']; + $lockToken = $this->response->getHeader('Lock-Token'); $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - 'HTTP_IF' => '(' . $lockToken . ')', - ); - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . ')' ]); $request->setBody(''); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $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()); + + } + + /** + * @depends testLock + */ + function testLockRefreshBadToken() { + + $request = new HTTP\Request('LOCK', '/test.txt'); + $request->setBody('<?xml version="1.0"?> +<D:lockinfo xmlns:D="DAV:"> + <D:lockscope><D:exclusive/></D:lockscope> + <D:locktype><D:write/></D:locktype> + <D:owner> + <D:href>http://example.org/~ejw/contact.html</D:href> + </D:owner> +</D:lockinfo>'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $lockToken = $this->response->getHeader('Lock-Token'); + $this->response = new HTTP\ResponseMock(); + $this->server->httpResponse = $this->response; + + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . 'foobar) (<opaquelocktoken:anotherbadtoken>)' ]); + $request->setBody(''); + + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals(423, $this->response->getStatus(),'We received an incorrect status code. Full response body: ' . $this->response->getBody()); } @@ -215,12 +220,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockNoFile() { - $serverVars = array( - 'REQUEST_URI' => '/notfound.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/notfound.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -233,10 +233,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); } @@ -245,22 +245,18 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockNoToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'UNLOCK', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); + $this->assertEquals(400, $this->response->status); } @@ -269,23 +265,18 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockBadToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'UNLOCK', - 'HTTP_LOCK_TOKEN' => '<opaquelocktoken:blablabla>', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => '<opaquelocktoken:blablabla>']); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 409 Conflict',$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); } @@ -294,12 +285,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockPutNoToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -312,25 +298,20 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt'); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + $this->assertEquals(423, $this->response->status); } @@ -339,7 +320,7 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlock() { - $request = new HTTP\Request(array()); + $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -351,23 +332,20 @@ class PluginTest extends DAV\AbstractServer { </D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; - - $serverVars = array( - 'HTTP_LOCK_TOKEN' => $lockToken, - ); + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); + $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod('UNLOCK', 'test.txt'); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->server->httpResponse->headers + $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([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ], + $this->server->httpResponse->getHeaders() ); @@ -378,7 +356,7 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockWindowsBug() { - $request = new HTTP\Request(array()); + $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -390,26 +368,23 @@ class PluginTest extends DAV\AbstractServer { </D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); // See Issue 123 $lockToken = trim($lockToken,'<>'); - $serverVars = array( - 'HTTP_LOCK_TOKEN' => $lockToken, - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); + $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod('UNLOCK', 'test.txt'); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->server->httpResponse->headers + $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([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ], + $this->server->httpResponse->getHeaders() ); @@ -420,7 +395,10 @@ class PluginTest extends DAV\AbstractServer { */ function testLockRetainOwner() { - $request = new HTTP\Request(array()); + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ]); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -430,8 +408,8 @@ class PluginTest extends DAV\AbstractServer { <D:owner>Evert</D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); $locks = $this->locksPlugin->getLocks('test.txt'); $this->assertEquals(1,count($locks)); @@ -450,7 +428,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -463,10 +441,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/test.txt', @@ -474,15 +452,16 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_IF' => '(<opaquelocktoken:token1>)', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + // $this->assertEquals('412 Precondition failed',$this->response->status); + $this->assertEquals(423, $this->response->status); } @@ -496,7 +475,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -509,22 +488,22 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir', 'REQUEST_METHOD' => 'DELETE', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(423, $this->response->status); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } /** @@ -537,7 +516,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -550,23 +529,23 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(204, $this->response->status); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } @@ -580,7 +559,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -593,10 +572,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -604,12 +583,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$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->headers['Content-Type']); + $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')); } /** @@ -622,7 +601,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -635,10 +614,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -646,12 +625,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$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->headers['Content-Type']); + $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')); } @@ -665,7 +644,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -678,10 +657,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -689,12 +668,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$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->headers['Content-Type']); + $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')); } @@ -708,7 +687,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -721,23 +700,23 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'MOVE', 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$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); } @@ -751,7 +730,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -764,10 +743,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -775,12 +754,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$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->headers['Content-Type']); + $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')); } /** @@ -794,7 +773,7 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DEPTH' => 'infinite', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -807,24 +786,24 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200,$this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'MOVE', 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '</dir> (' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '</dir> (' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$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->headers['Content-Type']); + $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')); } @@ -838,7 +817,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -851,26 +830,65 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '('.$this->response->headers['Lock-Token'].')', + 'HTTP_IF' => '('.$this->response->getHeader('Lock-Token').')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $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->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); + + } + + /** + * @depends testLock + */ + function testLockPutUnrelatedToken() { + + $request = new HTTP\Request('LOCK', '/unrelated.txt'); + $request->setBody('<?xml version="1.0"?> +<D:lockinfo xmlns:D="DAV:"> + <D:lockscope><D:exclusive/></D:lockscope> + <D:locktype><D:write/></D:locktype> + <D:owner> + <D:href>http://example.org/~ejw/contact.html</D:href> + </D:owner> +</D:lockinfo>'); + + $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->assertEquals(201, $this->response->getStatus()); + + $request = new HTTP\Request( + 'PUT', + '/test.txt', + ['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->assertEquals(204, $this->response->status); } @@ -882,11 +900,11 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_IF' => '(["etag1"])', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); } @@ -895,22 +913,27 @@ class PluginTest extends DAV\AbstractServer { */ function testPutWithCorrectETag() { - // We need an etag-enabled file node. - $tree = new DAV\ObjectTree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); + // We need an ETag-enabled file node. + $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); $this->server->tree = $tree; - $etag = md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')); + $filename = SABRE_TEMPDIR . '/test.txt'; + $etag = sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ); $serverVars = array( 'REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT', 'HTTP_IF' => '(["'.$etag.'"])', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$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); } @@ -921,18 +944,17 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'DELETE', 'HTTP_IF' => '(["etag1"])', ); + $request = HTTP\Sapi::createFromServerArray($serverVars); - $request = new HTTP\Request($serverVars); - $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); } function testGetTimeoutHeader() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'HTTP_TIMEOUT' => 'second-100', )); @@ -941,22 +963,21 @@ class PluginTest extends DAV\AbstractServer { } + function testGetTimeoutHeaderTwoItems() { - function testGetTimeoutHeaderNotSet() { - - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( + 'HTTP_TIMEOUT' => 'second-5, infinite', )); $this->server->httpRequest = $request; - $this->assertEquals(0, $this->locksPlugin->getTimeoutHeader()); + $this->assertEquals(5, $this->locksPlugin->getTimeoutHeader()); } - function testGetTimeoutHeaderInfinite() { - $request = new HTTP\Request(array( - 'HTTP_TIMEOUT' => 'infinite', + $request = HTTP\Sapi::createFromServerArray(array( + 'HTTP_TIMEOUT' => 'infinite, second-5', )); $this->server->httpRequest = $request; @@ -969,7 +990,7 @@ class PluginTest extends DAV\AbstractServer { */ function testGetTimeoutHeaderInvalid() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'HTTP_TIMEOUT' => 'yourmom', )); |