diff options
author | redmatrix <git@macgirvin.com> | 2016-05-10 17:26:44 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-10 17:26:44 -0700 |
commit | 0b02a6d123b2014705998c94ddf3d460948d3eac (patch) | |
tree | 78ff2cab9944a4f5ab3f80ec93cbe1120de90bb2 /vendor/sabre/dav/tests/Sabre/DAV | |
parent | 40b5b6e9d2da7ab65c8b4d38cdceac83a4d78deb (diff) | |
download | volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.gz volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.bz2 volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.zip |
initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import)
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV')
55 files changed, 2316 insertions, 5215 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php index 4bf5b343e..b5b8d64ee 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php @@ -4,8 +4,6 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - abstract class AbstractServer extends \PHPUnit_Framework_TestCase { /** @@ -23,6 +21,7 @@ abstract class AbstractServer extends \PHPUnit_Framework_TestCase { $this->response = new HTTP\ResponseMock(); $this->server = new Server($this->getRootNode()); + $this->server->sapi = new HTTP\SapiMock(); $this->server->httpResponse = $this->response; $this->server->debugExceptions = true; $this->deleteTree(SABRE_TEMPDIR,false); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php index 36d23c5c0..7d7a59898 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php @@ -5,67 +5,68 @@ namespace Sabre\DAV\Auth\Backend; use Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - class AbstractBasicTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateNoHeaders() { + function testCheckNoHeaders() { - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $backend->authenticate($server,'myRealm'); - } + $this->assertFalse( + $backend->check($request, $response)[0] + ); - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateUnknownUser() { + } - $response = new HTTP\ResponseMock(); - $tree = new DAV\ObjectTree(new DAV\SimpleCollection('bla')); - $server = new DAV\Server($tree); - $server->httpResponse = $response; + function testCheckUnknownUser() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'wrongpassword', )); - $server->httpRequest = $request; + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $backend->authenticate($server,'myRealm'); - } + $this->assertFalse( + $backend->check($request, $response)[0] + ); - public function testAuthenticate() { + } - $response = new HTTP\ResponseMock(); - $tree = new DAV\ObjectTree(new DAV\SimpleCollection('bla')); - $server = new DAV\Server($tree); - $server->httpResponse = $response; + function testCheckSuccess() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'password', )); - $server->httpRequest = $request; + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $this->assertTrue($backend->authenticate($server,'myRealm')); + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); - $result = $backend->getCurrentUser(); + } - $this->assertEquals('username', $result); + function testRequireAuth() { - } + $request = new HTTP\Request(); + $response = new HTTP\Response(); + $backend = new AbstractBasicMock(); + $backend->setRealm('writing unittests on a saturday night'); + $backend->challenge($request, $response); + + $this->assertEquals( + 'Basic realm="writing unittests on a saturday night"', + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php index 495690c4e..8ef416c37 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php @@ -5,130 +5,120 @@ namespace Sabre\DAV\Auth\Backend; use Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - class AbstractDigestTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateNoHeaders() { + function testCheckNoHeaders() { - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - /** - * @expectedException Sabre\DAV\Exception - */ - public function testAuthenticateBadGetUserInfoResponse() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadGetUserInfoResponse() { $header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } /** * @expectedException Sabre\DAV\Exception */ - public function testAuthenticateBadGetUserInfoResponse2() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadGetUserInfoResponse2() { $header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $backend->check($request, $response); } - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateUnknownUser() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckUnknownUser() { $header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateBadPassword() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadPassword() { $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, 'REQUEST_METHOD' => 'PUT', - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - public function testAuthenticate() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheck() { $digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/')); $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response='.$digestHash.', opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'GET', 'PHP_AUTH_DIGEST' => $header, 'REQUEST_URI' => '/', )); - $server->httpRequest = $request; + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $this->assertTrue($backend->authenticate($server,'myRealm')); + $this->assertEquals( + [true, 'principals/user'], + $backend->check($request, $response) + ); - $result = $backend->getCurrentUser(); + } - $this->assertEquals('user', $result); - $this->assertEquals('HELLO', $backend->getDigestHash('myRealm', $result)); + function testRequireAuth() { - } + $request = new HTTP\Request(); + $response = new HTTP\Response(); + $backend = new AbstractDigestMock(); + $backend->setRealm('writing unittests on a saturday night'); + $backend->challenge($request, $response); + + $this->assertStringStartsWith( + 'Digest realm="writing unittests on a saturday night"', + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php index b1ed555d4..697b593db 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php @@ -10,36 +10,63 @@ class ApacheTest extends \PHPUnit_Framework_TestCase { function testConstruct() { $backend = new Apache(); + $this->assertInstanceOf('Sabre\DAV\Auth\Backend\Apache', $backend); } - /** - * @expectedException Sabre\DAV\Exception - */ function testNoHeader() { - $server = new DAV\Server(); + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new Apache(); - $backend->authenticate($server,'Realm'); + + $this->assertFalse( + $backend->check($request, $response)[0] + ); } function testRemoteUser() { + $request = HTTP\Sapi::createFromServerArray([ + 'REMOTE_USER' => 'username', + ]); + $response = new HTTP\Response(); $backend = new Apache(); - $server = new DAV\Server(); - $request = new HTTP\Request(array( - 'REMOTE_USER' => 'username', - )); - $server->httpRequest = $request; + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); - $this->assertTrue($backend->authenticate($server, 'Realm')); + } + + function testRedirectRemoteUser() { - $userInfo = 'username'; + $request = HTTP\Sapi::createFromServerArray([ + 'REDIRECT_REMOTE_USER' => 'username', + ]); + $response = new HTTP\Response(); + $backend = new Apache(); - $this->assertEquals($userInfo, $backend->getCurrentUser()); + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); } + function testRequireAuth() { + + $request = new HTTP\Request(); + $response = new HTTP\Response(); + + $backend = new Apache(); + $backend->challenge($request, $response); + + $this->assertNull( + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php index 72f150ab6..d2e5fe49b 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php @@ -35,7 +35,7 @@ class FileTest extends \PHPUnit_Framework_TestCase { $file->loadFile(SABRE_TEMPDIR . '/backend'); $this->assertFalse($file->getDigestHash('realm','blabla')); - $this->assertEquals(md5('user:realm:password'), $file->getDigesthash('realm','user')); + $this->assertEquals(md5('user:realm:password'), $file->getDigestHash('realm','user')); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php index fdad8a605..a782cb74d 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php @@ -2,35 +2,85 @@ namespace Sabre\DAV\Auth\Backend; -use Sabre\DAV; +use + Sabre\DAV, + Sabre\HTTP\RequestInterface, + Sabre\HTTP\ResponseInterface; class Mock implements BackendInterface { - protected $currentUser; + public $fail = false; - public $defaultUser = 'admin'; + public $invalidCheckResponse = false; - /** - * @param Sabre\DAV\Server $server - * @param string $realm - * @throws Sabre\DAV\Exception\NotAuthenticated - */ - function authenticate(DAV\Server $server, $realm) { + public $principal = 'principals/admin'; - if ($realm=='failme') throw new DAV\Exception\NotAuthenticated('deliberate fail'); - $this->currentUser = $this->defaultUser; + function setPrincipal($principal) { + + $this->principal = $principal; } - function setCurrentUser($user) { + /** + * When this method is called, the backend must check if authentication was + * successful. + * + * The returned value must be one of the following + * + * [true, "principals/username"] + * [false, "reason for failure"] + * + * If authentication was successful, it's expected that the authentication + * backend returns a so-called principal url. + * + * Examples of a principal url: + * + * principals/admin + * principals/user1 + * principals/users/joe + * principals/uid/123457 + * + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply + * return a string such as: + * + * principals/users/[username] + * + * @param RequestInterface $request + * @param ResponseInterface $response + * @return array + */ + function check(RequestInterface $request, ResponseInterface $response) { - $this->currentUser = $user; + if ($this->invalidCheckResponse) { + return 'incorrect!'; + } + if ($this->fail) { + return [false, "fail!"]; + } + return [true, $this->principal]; } - function getCurrentUser() { - - return $this->currentUser; + /** + * This method is called when a user could not be authenticated, and + * authentication was required for the current request. + * + * This gives you the oppurtunity to set authentication headers. The 401 + * status code will already be set. + * + * In this case of Basic Auth, this would for example mean that the + * following header needs to be set: + * + * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); + * + * Keep in mind that in the case of multiple authentication backends, other + * WWW-Authenticate headers may already have been set, and you'll want to + * append your own WWW-Authenticate header instead of overwriting the + * existing one. + * + * @return void + */ + function challenge(RequestInterface $request, ResponseInterface $response) { } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php index ede432de2..8de2be667 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php @@ -12,15 +12,17 @@ class PDOMySQLTest extends AbstractPDOTest { $pdo = \Sabre\TestUtil::getMySQLDB(); if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); $pdo->query("DROP TABLE IF EXISTS users"); - $pdo->query(" + $pdo->query(<<<SQL create table users ( - id integer unsigned not null primary key auto_increment, - username varchar(50), - digesta1 varchar(32), - email varchar(80), - displayname varchar(80), - unique(username) -);"); + id integer unsigned not null primary key auto_increment, + username varchar(50), + digesta1 varchar(32), + email varchar(80), + displayname varchar(80), + unique(username) +) +SQL + ); $pdo->query("INSERT INTO users (username,digesta1,email,displayname) VALUES ('user','hash','user@example.org','User')"); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php index 2096a04d7..0ac9e0613 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php @@ -12,10 +12,11 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testInit() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $this->assertTrue($plugin instanceof Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('auth')); + $this->assertInternalType('array', $plugin->getPluginInfo()); } @@ -25,14 +26,14 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testAuthenticate() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $this->assertTrue( + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]) + ); } - - /** * @depends testInit * @expectedException Sabre\DAV\Exception\NotAuthenticated @@ -40,42 +41,87 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testAuthenticateFail() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'failme'); + $backend = new Backend\Mock(); + $backend->fail = true; + + $plugin = new Plugin($backend); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); } - function testReportPassThrough() { + /** + * @depends testAuthenticate + */ + function testMultipleBackend() { - $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); - $fakeServer->addPlugin($plugin); + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $backend1 = new Backend\Mock(); + $backend2 = new Backend\Mock(); + $backend2->fail = true; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/', - )); - $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />'); + $plugin = new Plugin(); + $plugin->addBackend($backend1); + $plugin->addBackend($backend2); - $fakeServer->httpRequest = $request; - $fakeServer->httpResponse = new HTTP\ResponseMock(); - $fakeServer->exec(); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); - $this->assertEquals('HTTP/1.1 403 Forbidden', $fakeServer->httpResponse->status); + $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal()); } /** * @depends testInit + * @expectedException Sabre\DAV\Exception + */ + function testNoAuthBackend() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + + } + /** + * @depends testInit + * @expectedException Sabre\DAV\Exception + */ + function testInvalidCheckResponse() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $backend = new Backend\Mock(); + $backend->invalidCheckResponse = true; + + $plugin = new Plugin($backend); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + + } + + /** + * @depends testAuthenticate + */ + function testGetCurrentPrincipal() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock()); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal()); + + } + + /** + * @depends testAuthenticate */ - function testGetCurrentUserPrincipal() { + function testGetCurrentUser() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); $this->assertEquals('admin', $plugin->getCurrentUser()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php index fdc2403db..155c785f8 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php @@ -131,6 +131,7 @@ class BasicNodeTest extends \PHPUnit_Framework_TestCase { public function testSimpleDirectoryConstruct() { $dir = new SimpleCollection('simpledir',array()); + $this->assertInstanceOf('Sabre\DAV\SimpleCollection', $dir); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php index 6fc65f9e8..157c2170a 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php @@ -10,6 +10,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { function setUp() { parent::setUp(); + \Sabre\TestUtil::clearTempDir(); file_put_contents(SABRE_TEMPDIR . '/somefile.jpg','blabla'); file_put_contents(SABRE_TEMPDIR . '/somefile.hoi','blabla'); @@ -17,7 +18,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { function tearDown() { - unlink(SABRE_TEMPDIR . '/somefile.jpg'); + \Sabre\TestUtil::clearTempDir(); parent::tearDown(); } @@ -44,7 +45,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { ); $result = $this->server->getPropertiesForPath('/somefile.jpg',$properties); $this->assertArrayHasKey(0,$result); - $this->assertArrayHasKey(200,$result[0]); + $this->assertArrayHasKey(200,$result[0], 'We received: ' . print_r($result,true)); $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][200]); $this->assertEquals('image/jpeg',$result[0][200]['{DAV:}getcontenttype']); @@ -61,8 +62,9 @@ class GuessContentTypeTest extends DAV\AbstractServer { ); $result = $this->server->getPropertiesForPath('/somefile.hoi',$properties); $this->assertArrayHasKey(0,$result); - $this->assertArrayHasKey(404,$result[0]); - $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][404]); + $this->assertArrayHasKey(200,$result[0]); + $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][200]); + $this->assertEquals('application/octet-stream',$result[0][200]['{DAV:}getcontenttype']); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php index 169675e7e..9d9fbb319 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php @@ -23,21 +23,21 @@ class MapGetToPropFindTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'GET', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); + $this->assertEquals(207, $this->response->status,'Incorrect status response received. Full response body: ' . $this->response->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'DAV' => '1, 3, extended-mkcol', - 'Vary' => 'Brief,Prefer', + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol'], + 'Vary' => ['Brief,Prefer'], ), - $this->response->headers + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Incorrect status response received. Full response body: ' . $this->response->body); - } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php index c3c4bdebb..00beea9f2 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php @@ -9,80 +9,114 @@ require_once 'Sabre/DAV/AbstractServer.php'; class PluginTest extends DAV\AbstractServer{ + protected $plugin; + function setUp() { parent::setUp(); - $this->server->addPlugin(new Plugin()); + $this->server->addPlugin($this->plugin = new Plugin()); + $this->server->tree->getNodeForPath('')->createDirectory('dir2'); } function testCollectionGet() { - $serverVars = array( - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('GET', '/dir'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'text/html; charset=utf-8', - ), - $this->response->headers + $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() ); - $this->assertTrue(strpos($this->response->body, 'Index for dir/') !== false); - $this->assertTrue(strpos($this->response->body, '<a href="/dir/child.txt"><img src="/?sabreAction=asset&assetName=icons%2Ffile.png" alt="" width="24" />')!==false); + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, '<title>dir') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); } - function testNotFound() { + /** + * Adding the If-None-Match should have 0 effect, but it threw an error. + */ + function testCollectionGetIfNoneMatch() { - $serverVars = array( - 'REQUEST_URI' => '/random', - 'REQUEST_METHOD' => 'GET', + $request = new HTTP\Request('GET', '/dir'); + $request->setHeader('If-None-Match', '"foo-bar"'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() ); - $request = new HTTP\Request($serverVars); + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, '<title>dir') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); + + } + function testCollectionGetRoot() { + + $request = new HTTP\Request('GET', '/'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); + $this->assertEquals(200, $this->response->status, "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() + ); + + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, '<title>/') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/">')!==false); + $this->assertTrue(strpos($body, '<span class="btn disabled">')!==false); } - function testPostOtherContentType() { + function testGETPassthru() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'POST', - 'CONTENT_TYPE' => 'text/xml', + $request = new HTTP\Request('GET', '/random'); + $response = new HTTP\Response(); + $this->assertNull( + $this->plugin->httpGet($request, $response) ); - $request = new HTTP\Request($serverVars); + + } + + function testPostOtherContentType() { + + $request = new HTTP\Request('POST', '/', ['Content-Type' => 'text/xml']); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status); + $this->assertEquals(501, $this->response->status); } function testPostNoSabreAction() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'POST', - 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', - ); - $postVars = array(); - - $request = new HTTP\Request($serverVars,$postVars); + $request = new HTTP\Request('POST', '/', ['Content-Type' => 'application/x-www-form-urlencoded']); + $request->setPostData([]); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status); + $this->assertEquals(501, $this->response->status); } @@ -98,17 +132,55 @@ class PluginTest extends DAV\AbstractServer{ 'name' => 'new_collection', ); - $request = new HTTP\Request($serverVars,$postVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); + $request->setPostData($postVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 302 Found', $this->response->status); + $this->assertEquals(302, $this->response->status); $this->assertEquals(array( - 'Location' => '/', - ), $this->response->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Location' => ['/'], + ), $this->response->getHeaders()); $this->assertTrue(is_dir(SABRE_TEMPDIR . '/new_collection')); } + function testGetAsset() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=favicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(200, $this->response->getStatus(), 'Error: ' . $this->response->body); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['image/vnd.microsoft.icon'], + 'Content-Length' => ['4286'], + 'Cache-Control' => ['public, max-age=1209600'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], $this->response->getHeaders()); + + } + + function testGetAsset404() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=flavicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); + + } + + function testGetAssetEscapeBasePath() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=./../assets/favicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php index 6e74e6ec0..d8b53a5a1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php @@ -2,21 +2,16 @@ namespace Sabre\DAV; +use Sabre\HTTP\RequestInterface; + class ClientMock extends Client { + public $request; public $response; public $url; public $curlSettings; - protected function curlRequest($url, $curlSettings) { - - $this->url = $url; - $this->curlSettings = $curlSettings; - return $this->response; - - } - /** * Just making this method public * @@ -29,4 +24,11 @@ class ClientMock extends Client { } + public function doRequest(RequestInterface $request) { + + $this->request = $request; + return $this->response; + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php index 9c3532a47..4cf27dfaa 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php @@ -2,15 +2,27 @@ namespace Sabre\DAV; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; + require_once 'Sabre/DAV/ClientMock.php'; class ClientTest extends \PHPUnit_Framework_TestCase { + function setUp() { + + if (!function_exists('curl_init')) { + $this->markTestSkipped('CURL must be installed to test the client'); + } + + } + function testConstruct() { - $client = new ClientMock(array( + $client = new ClientMock([ 'baseUri' => '/', - )); + ]); + $this->assertInstanceOf('Sabre\DAV\ClientMock', $client); } @@ -19,931 +31,276 @@ class ClientTest extends \PHPUnit_Framework_TestCase { */ function testConstructNoBaseUri() { - $client = new ClientMock(array()); + $client = new ClientMock([]); } - function testRequest() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - ), $client->curlSettings); + function testAuth() { - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + ]); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_BASIC | CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]); } + function testBasicAuth() { - function testRequestProxy() { + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_BASIC + ]); - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'proxy' => 'http://localhost:8000/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_PROXY => 'http://localhost:8000/', - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_BASIC, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestCAInfo() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + function testDigestAuth() { - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_DIGEST + ]); - $client->addTrustedCertificates('bla'); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_CAINFO => 'bla', - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - ), $client->curlSettings); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestSslPeer() { + function testNTLMAuth() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_NTLM + ]); - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $client->setVerifyPeer(true); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_SSL_VERIFYPEER => true - ), $client->curlSettings); - - } - - function testRequestAuth() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_DIGEST, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); - - } - - function testRequestAuthBasic() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - 'authType' => Client::AUTH_BASIC, - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_NTLM, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestAuthDigest() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - 'authType' => Client::AUTH_DIGEST, - )); + function testProxy() { - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_DIGEST, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); - - } - function testRequestError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - CURLE_COULDNT_CONNECT, - "Could not connect, or something" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'proxy' => 'localhost:8888', + ]); - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception $e) { - $caught = true; - } - if (!$caught) { - $this->markTestFailed('Exception was not thrown'); - } + $this->assertEquals("localhost:8888", $client->curlSettings[CURLOPT_PROXY]); } - function testRequestHTTPError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + function testEncoding() { - $responseBlob = array( - "HTTP/1.1 400 Bad Request", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 400, - ), - 0, - "" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'encoding' => Client::ENCODING_IDENTITY | Client::ENCODING_GZIP | Client::ENCODING_DEFLATE, + ]); - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception $e) { - $caught = true; - } - if (!$caught) { - $this->fail('Exception was not thrown'); - } + $this->assertEquals("identity,deflate,gzip", $client->curlSettings[CURLOPT_ENCODING]); } - function testRequestHTTP404() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 404 Not Found", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 404, - ), - 0, - "" - ); + function testPropFind() { - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception\NotFound $e) { - $caught = true; - } - if (!$caught) { - $this->fail('Exception was not thrown'); - } + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']); + + $this->assertEquals(['{DAV:}displayname' => 'bar'], $result); + + $request = $client->request; + $this->assertEquals('PROPFIND', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Depth' => ['0'], + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } /** - * @dataProvider supportedHTTPCodes + * @expectedException \Sabre\HTTP\ClientHttpException */ - function testSpecificHTTPErrors($error) { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 $error blabla", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 42, - 'http_code' => $error, - ), - 0, - "" - ); - - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - $this->fail('Exception was not thrown'); - } catch (Exception $e) { - $this->assertEquals($e->getHTTPCode(), $error); - } - - - } - - public function supportedHTTPCodes() { - - return array( - array(400), - array(401), - array(402), - array(403), - array(404), - array(405), - array(409), - array(412), - array(416), - array(500), - array(501), - array(507), - ); - - } - - function testUnsupportedHTTPError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 580 blabla", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 42, - 'http_code' => "580" - ), - 0, - "" - ); - - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - $this->fail('Exception was not thrown'); - } catch (Exception $e) { - $this->assertEquals(500, $e->getHTTPCode()); - } - - - } - - function testGetAbsoluteUrl() { + function testPropFindError() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/', - )); - - $this->assertEquals( - 'http://example.org/foo/bar', - $client->getAbsoluteUrl('bar') - ); - - $this->assertEquals( - 'http://example.org/bar', - $client->getAbsoluteUrl('/bar') - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $this->assertEquals( - 'http://example.com/bar', - $client->getAbsoluteUrl('http://example.com/bar') - ); + $client->response = new Response(405, []); + $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']); } - function testOptions() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "DAV: feature1, feature2", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 40, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropFindDepth1() { - $result = $client->options(); - $this->assertEquals( - array('feature1', 'feature2'), - $result - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], 1); + + $this->assertEquals([ + '/foo' => [ + '{DAV:}displayname' => 'bar' + ], + ], $result); + + $request = $client->request; + $this->assertEquals('PROPFIND', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Depth' => ['1'], + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } - function testOptionsNoDav() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropPatch() { - $result = $client->options(); - $this->assertEquals( - array(), - $result - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); + $this->assertTrue($result); + $request = $client->request; + $this->assertEquals('PROPPATCH', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } /** - * @expectedException InvalidArgumentException + * @depends testPropPatch + * @expectedException \Sabre\HTTP\ClientHttpException */ - function testPropFindNoXML() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropPatchHTTPError() { - $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - } - - function testPropFind() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:foo>hello</d:foo>", - " </d:prop>", - " <d:status>HTTP/1.1 200 OK</d:status>", - " </d:propstat>", - " <d:propstat>", - " <d:prop>", - " <d:bar />", - " </d:prop>", - " <d:status>HTTP/1.1 404 Not Found</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - $this->assertEquals(array( - '{DAV:}foo' => 'hello', - ), $result); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propfind xmlns:d="DAV:">', - ' <d:prop>', - ' <d:foo />', - ' <d:bar />', - ' </d:prop>', - '</d:propfind>' - ); - $requestBody = implode("\n", $requestBody); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); + $client->response = new Response(403, [], ''); + $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); } /** - * This was reported in Issue 235. - * - * If no '200 Ok' properties are returned, the client will throw an - * E_NOTICE. + * @depends testPropPatch + * @expectedException Sabre\HTTP\ClientException */ - function testPropFindNo200s() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:bar />", - " </d:prop>", - " <d:status>HTTP/1.1 404 Not Found</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - $this->assertEquals(array( - ), $result); - - } - - function testPropFindDepth1CustomProp() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\" xmlns:x=\"urn:custom\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:foo>hello</d:foo>", - " <x:bar>world</x:bar>", - " </d:prop>", - " <d:status>HTTP/1.1 200 OK</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{urn:custom}bar'),1); - - $this->assertEquals(array( - "/foo/bar/" => array( - '{DAV:}foo' => 'hello', - '{urn:custom}bar' => 'world', - ), - ), $result); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propfind xmlns:d="DAV:">', - ' <d:prop>', - ' <d:foo />', - ' <x:bar xmlns:x="urn:custom"/>', - ' </d:prop>', - '</d:propfind>' - ); - $requestBody = implode("\n", $requestBody); - - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); - - } - - function testPropPatch() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); - - $client->proppatch('', array( - '{DAV:}foo' => 'newvalue', - '{urn:custom}foo' => 'newvalue2', - '{DAV:}bar' => null, - '{urn:custom}bar' => null, - )); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propertyupdate xmlns:d="DAV:">', - '<d:set><d:prop>', - ' <d:foo>newvalue</d:foo>', - '</d:prop></d:set>', - '<d:set><d:prop>', - ' <x:foo xmlns:x="urn:custom">newvalue2</x:foo>', - '</d:prop></d:set>', - '<d:remove><d:prop>', - ' <d:bar />', - '</d:prop></d:remove>', - '<d:remove><d:prop>', - ' <x:bar xmlns:x="urn:custom"/>', - '</d:prop></d:remove>', - '</d:propertyupdate>' - ); - $requestBody = implode("\n", $requestBody); - - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); - - } - - function testHEADRequest() { + function testPropPatchMultiStatusError() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('HEAD', 'baz'); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'HEAD', - CURLOPT_NOBODY => true, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array(), - CURLOPT_POSTFIELDS => null, - ), $client->curlSettings); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> +<response> + <href>/foo</href> + <propstat> + <prop> + <displayname /> + </prop> + <status>HTTP/1.1 403 Forbidden</status> + </propstat> +</response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); } - function testPUTRequest() { + function testOPTIONS() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); + $client->response = new Response(207, [ + 'DAV' => 'calendar-access, extended-mkcol', + ]); + $result = $client->options(); - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" + $this->assertEquals( + ['calendar-access', 'extended-mkcol'], + $result ); - $result = $client->request('PUT', 'bar','newcontent'); - - $this->assertEquals('http://example.org/foo/bar/bar', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => "PUT", - CURLOPT_POSTFIELDS => 'newcontent', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array(), - ), $client->curlSettings); + $request = $client->request; + $this->assertEquals('OPTIONS', $request->getMethod()); + $this->assertEquals('/', $request->getUrl()); + $this->assertEquals([ + ], $request->getHeaders()); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php index 8947c6688..3708594e0 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php @@ -22,73 +22,90 @@ class FileTest extends \PHPUnit_Framework_TestCase { function testPut() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $result = $file->put('New contents'); - - $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); - $this->assertEquals('"' . md5('New contents') . '"', $result); + $filename = SABRE_TEMPDIR . '/file.txt'; + $file = new File($filename); + $result = $file->put('New contents'); + + $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals( + '"' . + sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ) . '"', + $result + ); } function testRange() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->put('0000000'); - $file->patch('111', 2, 3); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->patch('111', 2, 3); - $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } function testRangeStream() { - $stream = fopen('php://memory','r+'); - fwrite($stream, "222"); - rewind($stream); + $stream = fopen('php://memory','r+'); + fwrite($stream, "222"); + rewind($stream); - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->put('0000000'); - $file->patch($stream, 2, 3); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->patch($stream, 2, 3); - $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } function testGet() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals('Contents',stream_get_contents($file->get())); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertEquals('Contents',stream_get_contents($file->get())); } function testDelete() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->delete(); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->delete(); - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); + $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); } function testGetETag() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals('"' . md5('Contents') . '"',$file->getETag()); - + $filename = SABRE_TEMPDIR . '/file.txt'; + $file = new File($filename); + $this->assertEquals( + '"' . + sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ) . '"', + $file->getETag() + ); } function testGetContentType() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertNull($file->getContentType()); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertNull($file->getContentType()); } function testGetSize() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals(8,$file->getSize()); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertEquals(8,$file->getSize()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php deleted file mode 100644 index 275075b4c..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php +++ /dev/null @@ -1,178 +0,0 @@ -<?php - -namespace Sabre\DAV\FSExt; -use Sabre\DAV; - -require_once 'Sabre/TestUtil.php'; - -class NodeTest extends \PHPUnit_Framework_TestCase { - - function setUp() { - - mkdir(SABRE_TEMPDIR . '/dir'); - file_put_contents(SABRE_TEMPDIR . '/dir/file.txt', 'Contents'); - file_put_contents(SABRE_TEMPDIR . '/dir/file2.txt', 'Contents2'); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testUpdateProperties() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $properties = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($properties); - $expected = true; - - $this->assertEquals($expected, $result); - - $getProperties = $file->getProperties(array_keys($properties)); - - $this->assertEquals($properties, $getProperties); - - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesAgain() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test3' => 'baz', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesDelete() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => null, - '{http://sabredav.org/NS/2010}test3' => null - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesMove() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - - // Renaming - $file->setName('file3.txt'); - - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt')); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir/file3.txt')); - $this->assertEquals('file3.txt',$file->getName()); - - $newFile = new File(SABRE_TEMPDIR . '/dir/file3.txt'); - $this->assertEquals('file3.txt',$newFile->getName()); - - $properties = $newFile->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - } - - /** - * @depends testUpdatePropertiesMove - */ - function testUpdatePropertiesDeleteBleed() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - - // Deleting - $file->delete(); - - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt')); - - // Creating it again - file_put_contents(SABRE_TEMPDIR . '/dir/file.txt','New Contents'); - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array(), $properties); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php index 907ede40b..63d858de1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php @@ -17,116 +17,98 @@ class ServerTest extends DAV\AbstractServer{ function testGet() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('GET', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"', - ), - $this->response->headers + $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.'); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('Test contents', stream_get_contents($this->response->body)); } function testHEAD() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('HEAD', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200,$this->response->status); $this->assertEquals('', $this->response->body); } function testPut() { - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/testput.txt'); + $filename = $this->tempDir . '/testput.txt'; $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => 0, - 'ETag' => '"' . md5('Testing new file') . '"', - ), $this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); + $this->assertEquals('Testing new file',file_get_contents($filename)); } function testPutAlreadyExists() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt', ['If-None-Match' => '*']); $request->setBody('Testing new file'); $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 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); } function testMkcol() { - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'MKCOL', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(""); + $request = new HTTP\Request('MKCOL', '/testcol'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertTrue(is_dir($this->tempDir . '/testcol')); @@ -134,19 +116,14 @@ class ServerTest extends DAV\AbstractServer{ function testPutUpdate() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt'); $request->setBody('Testing updated file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('0', $this->response->headers['Content-Length']); + $this->assertEquals('0', $this->response->getHeader('Content-Length')); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); @@ -154,20 +131,16 @@ class ServerTest extends DAV\AbstractServer{ function testDelete() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'DELETE', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/test.txt'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertFalse(file_exists($this->tempDir . '/test.txt')); @@ -175,50 +148,99 @@ class ServerTest extends DAV\AbstractServer{ function testDeleteDirectory() { - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'DELETE', - ); - mkdir($this->tempDir.'/testcol'); file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan'); - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/testcol'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertFalse(file_exists($this->tempDir . '/col')); + $this->assertFalse(file_exists($this->tempDir . '/testcol')); } function testOptions() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'OPTIONS', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('OPTIONS', '/'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version'=> DAV\Version::VERSION, - ),$this->response->headers); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); } + function testMove() { + + mkdir($this->tempDir.'/testcol'); + + $request = new HTTP\Request('MOVE', '/test.txt', ['Destination' => '/testcol/test2.txt']); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals(201, $this->response->status); + $this->assertEquals('', $this->response->body); + + $this->assertEquals([ + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ],$this->response->getHeaders()); + + $this->assertTrue( + is_file($this->tempDir . '/testcol/test2.txt') + ); + + + } + + /** + * This test checks if it's possible to move a non-FSExt collection into a + * FSExt collection. + * + * The moveInto function *should* ignore the object and let sabredav itself + * execute the slow move. + */ + function testMoveOtherObject() { + + mkdir($this->tempDir.'/tree1'); + mkdir($this->tempDir.'/tree2'); + + $tree = new DAV\Tree(new DAV\SimpleCollection('root', [ + new DAV\FS\Directory($this->tempDir . '/tree1'), + new DAV\FSExt\Directory($this->tempDir . '/tree2'), + ])); + $this->server->tree = $tree; + + $request = new HTTP\Request('MOVE', '/tree1', ['Destination' => '/tree2/tree1']); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals(201, $this->response->status); + $this->assertEquals('', $this->response->body); + + $this->assertEquals([ + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ],$this->response->getHeaders()); + + $this->assertTrue( + is_dir($this->tempDir . '/tree2/tree1') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php index 45865b2a1..cd8bee968 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php @@ -4,105 +4,96 @@ namespace Sabre\DAV; use Sabre\HTTP; -class HTTPPReferParsingTest extends \Sabre\DAVServerTest { +class HTTPPreferParsingTest extends \Sabre\DAVServerTest { function testParseSimple() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'return-asynch', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => true, - 'return-minimal' => false, - 'return-representation' => false, - 'strict' => false, - 'lenient' => false, - 'wait' => null, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => true, + 'return' => null, + 'handling' => null, + 'wait' => null, + ], $server->getHTTPPrefer()); } function testParseValue() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'wait=10', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => false, - 'return-minimal' => false, - 'return-representation' => false, - 'strict' => false, - 'lenient' => false, - 'wait' => 10, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => null, + 'handling' => null, + 'wait' => '10', + ], $server->getHTTPPrefer()); } function testParseMultiple() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'return-minimal, strict,lenient', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => false, - 'return-minimal' => true, - 'return-representation' => false, - 'strict' => true, - 'lenient' => true, - 'wait' => null, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => 'minimal', + 'handling' => 'lenient', + 'wait' => null, + ], $server->getHTTPPrefer()); } function testParseWeirdValue() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'BOOOH', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'strict' => false, - 'lenient' => false, - 'wait' => null, - 'return-asynch' => false, - 'return-minimal' => false, - 'return-representation' => false, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => null, + 'handling' => null, + 'wait' => null, + 'boooh' => true, + ], $server->getHTTPPrefer()); } function testBrief() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_BRIEF' => 't', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'strict' => false, - 'lenient' => false, - 'wait' => null, - 'return-asynch' => false, - 'return-minimal' => true, - 'return-representation' => false, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => 'minimal', + 'handling' => null, + 'wait' => null, + ], $server->getHTTPPrefer()); } @@ -113,11 +104,11 @@ class HTTPPReferParsingTest extends \Sabre\DAVServerTest { */ function testpropfindMinimal() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + 'HTTP_PREFER' => 'return-minimal', + ]); $request->setBody(<<<BLA <?xml version="1.0"?> <d:propfind xmlns:d="DAV:"> @@ -131,70 +122,67 @@ BLA $response = $this->request($request); - $this->assertTrue(strpos($response->body, 'resourcetype')!==false); - $this->assertTrue(strpos($response->body, 'something')===false); + $body = $response->getBodyAsString(); + + $this->assertEquals(207, $response->getStatus(), $body); + + $this->assertTrue(strpos($body, 'resourcetype') !== false, $body); + $this->assertTrue(strpos($body, 'something') === false, $body); } function testproppatchMinimal() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PROPPATCH', - 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']); $request->setBody(<<<BLA <?xml version="1.0"?> -<d:proppatch xmlns:d="DAV:"> +<d:propertyupdate xmlns:d="DAV:"> <d:set> <d:prop> <d:something>nope!</d:something> </d:prop> </d:set> -</d:proppatch> +</d:propertyupdate> BLA ); - $this->server->subscribeEvent('updateProperties', function(&$props, &$result) { + $this->server->on('propPatch', function($path, PropPatch $propPatch) { - if (isset($props['{DAV:}something'])) { - unset($props['{DAV:}something']); - $result[200]['{DAV:}something'] = null; - } + $propPatch->handle('{DAV:}something', function($props) { + return true; + }); }); $response = $this->request($request); $this->assertEquals(0, strlen($response->body), 'Expected empty body: ' . $response->body); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); } function testproppatchMinimalError() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PROPPATCH', - 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']); $request->setBody(<<<BLA <?xml version="1.0"?> -<d:proppatch xmlns:d="DAV:"> +<d:propertyupdate xmlns:d="DAV:"> <d:set> <d:prop> <d:something>nope!</d:something> </d:prop> </d:set> -</d:proppatch> +</d:propertyupdate> BLA ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status); - $this->assertTrue(strpos($response->body, 'something')!==false); - $this->assertTrue(strpos($response->body, 'HTTP/1.1 403 Forbidden')!==false); + $body = $response->getBodyAsString(); + + $this->assertEquals(207, $response->status); + $this->assertTrue(strpos($body, 'something') !== false); + $this->assertTrue(strpos($body, '403 Forbidden') !== false, $body); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php index da28b6979..6c10afa9f 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php @@ -8,7 +8,7 @@ use Sabre\HTTP; /** * Tests related to the PUT request. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -21,13 +21,13 @@ class HttpDeleteTest extends DAVServerTest { */ public function setUpTree() { - $this->tree = new Mock\Collection('root', array( + $this->tree = new Mock\Collection('root', [ 'file1' => 'foo', - 'dir' => array( + 'dir' => [ 'subfile' => 'bar', 'subfile2' => 'baz', - ), - )); + ], + ]); } @@ -36,24 +36,22 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDelete() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - )); + $request = new HTTP\Request('DELETE', '/file1'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); $this->assertEquals( - array( - 'Content-Length' => '0', - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ], + $response->getHeaders() ); } @@ -63,24 +61,22 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeleteDirectory() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'DELETE', - )); + $request = new HTTP\Request('DELETE', '/dir'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); $this->assertEquals( - array( - 'Content-Length' => '0', - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ], + $response->getHeaders() ); } @@ -90,17 +86,13 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeleteNotFound() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'DELETE', - )); - + $request = new HTTP\Request('DELETE', '/file2'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 404 Not Found', - $response->status, - "Incorrect status code. Response body: " . $response->body + 404, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } @@ -110,18 +102,16 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeletePreconditions() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', - )); + $request = new HTTP\Request('DELETE', '/file1', [ + 'If-Match' => '"' . md5('foo') . '"', + ]); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } @@ -131,18 +121,16 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeletePreconditionsFailed() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF_MATCH' => '"' . md5('bar') . '"', - )); + $request = new HTTP\Request('DELETE', '/file1', [ + 'If-Match' => '"' . md5('bar') . '"', + ]); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 412 Precondition failed', - $response->status, - "Incorrect status code. Response body: " . $response->body + 412, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php index b14554595..eddaf3f22 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php @@ -8,12 +8,9 @@ use Sabre\HTTP; /** * Tests related to the PUT request. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License - * @covers Sabre\DAV\Server::httpPut - * @covers Sabre\DAV\Server::createFile - * @covers Sabre\DAV\Server::checkPreconditions */ class HttpPutTest extends DAVServerTest { @@ -22,28 +19,24 @@ class HttpPutTest extends DAVServerTest { * * @return void */ - public function setUpTree() { + function setUpTree() { - $this->tree = new Mock\Collection('root', array( + $this->tree = new Mock\Collection('root', [ 'file1' => 'foo', - )); + ]); } /** * A successful PUT of a new file. */ - public function testPut() { + function testPut() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $request = new HTTP\Request('PUT', '/file2', [], 'hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus(), 'Incorrect status code received. Full response body:' . $response->getBodyAsString()); $this->assertEquals( 'hello', @@ -51,11 +44,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -65,17 +59,13 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutExisting() { + function testPutExisting() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('bar'); + $request = new HTTP\Request('PUT', '/file1', [], 'bar'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->getStatus()); $this->assertEquals( 'bar', @@ -83,11 +73,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('bar') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('bar') . '"'] + ], + $response->getHeaders() ); } @@ -97,18 +88,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPutExisting */ - public function testPutExistingIfMatchStar() { + function testPutExistingIfMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->getStatus()); $this->assertEquals( 'hello', @@ -116,11 +107,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -130,18 +122,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPutExisting */ - public function testPutExistingIfMatchCorrect() { + function testPutExistingIfMatchCorrect() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-Match' => '"' . md5('foo') . '"'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); $this->assertEquals( 'hello', @@ -149,11 +141,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'], + ], + $response->getHeaders() ); } @@ -163,17 +156,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutContentRange() { + function testPutContentRange() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_CONTENT_RANGE' => 'bytes/100-200', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['Content-Range' => 'bytes/100-200'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status); + $this->assertEquals(400, $response->getStatus()); } @@ -182,18 +175,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutIfNoneMatchStar() { + function testPutIfNoneMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['If-None-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus()); $this->assertEquals( 'hello', @@ -201,11 +194,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -215,18 +209,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutIfMatchStar() { + function testPutIfMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['If-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + $this->assertEquals(412, $response->getStatus()); } @@ -235,18 +229,19 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutExistingIfNoneMatchStar() { + function testPutExistingIfNoneMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - )); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-None-Match' => '*'], + 'hello' + ); $request->setBody('hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + $this->assertEquals(412, $response->getStatus()); } @@ -255,16 +250,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutNoParent() { + function testPutNoParent() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1/file2', + [], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 409 Conflict', $response->status); + $this->assertEquals(409, $response->getStatus()); } @@ -275,18 +271,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testFinderPutSuccess() { - - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', - )); - $request->setBody('hello'); + function testFinderPutSuccess() { + $request = new HTTP\Request( + 'PUT', + '/file2', + ['X-Expected-Entity-Length' => '5'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus()); $this->assertEquals( 'hello', @@ -294,11 +289,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'], + ], + $response->getHeaders() ); } @@ -308,54 +304,45 @@ class HttpPutTest extends DAVServerTest { * * @depends testFinderPutSuccess */ - public function testFinderPutFail() { + function testFinderPutFail() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', - )); - $request->setBody(''); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['X-Expected-Entity-Length' => '5'], + '' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status); + $this->assertEquals(403, $response->getStatus()); } /** * Plugins can intercept PUT. We need to make sure that works. + * + * @depends testPut */ - public function testPutIntercept() { - - $this->server->subscribeEvent('beforeBind', array($this, 'beforeBind')); + function testPutIntercept() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $this->server->on('beforeBind', function($uri) { + $this->server->httpResponse->setStatus(418); + return false; + }); + $request = new HTTP\Request('PUT', '/file2', [], 'hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 418 I\'m a teapot', $response->status); + $this->assertEquals(418, $response->getStatus(), 'Incorrect status code received. Full response body: ' .$response->getBodyAsString()); $this->assertFalse( $this->server->tree->nodeExists('file2') ); - $this->assertEquals( - array( - ), - $response->headers - ); - - } - - public function beforeBind() { - - $this->server->httpResponse->sendStatus(418); - return false; + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + ], $response->getHeaders()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php index c3fba4aae..4ccb42fbb 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php @@ -28,11 +28,11 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { 'HTTP_OVERWRITE' => 'F', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $server->httpRequest = $request; - $info = $server->getCopyAndMoveInfo(); + $info = $server->getCopyAndMoveInfo($request); $this->assertEquals('%C3%A0fo%C3%B3', urlencode($info['destination'])); $this->assertFalse($info['destinationExists']); @@ -47,7 +47,7 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { $dir->createDirectory('bar'); - $tree = new ObjectTree($dir); + $tree = new Tree($dir); $tree->move('bar',urldecode('%C3%A0fo%C3%B3')); $node = $tree->getNodeForPath(urldecode('%C3%A0fo%C3%B3')); @@ -78,7 +78,7 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { 'HTTP_OVERWRITE' => 'F', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $response = new HTTP\ResponseMock(); @@ -89,13 +89,14 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { $dir->createDirectory('bar'); - $tree = new ObjectTree($dir); + $tree = new Tree($dir); $server = new Server($tree); $server->setBaseUri('/webdav/'); $server->httpRequest = $request; $server->httpResponse = $response; + $server->sapi = new HTTP\SapiMock(); $server->exec(); $this->assertTrue(file_exists(SABRE_TEMPDIR . '/issue33/' . urldecode('%C3%A0fo%C3%B3'))); 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', )); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php index b2613ec9f..6ccab4f66 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php @@ -15,7 +15,7 @@ use Sabre\DAV; * * a string, for a file * * An instance of \Sabre\DAV\INode. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -32,10 +32,20 @@ class Collection extends DAV\Collection { * @param array $children * @return void */ - public function __construct($name, array $children = array(), Collection $parent = null) { + function __construct($name, array $children = [], Collection $parent = null) { $this->name = $name; - $this->children = $children; + foreach ($children as $key => $value) { + if (is_string($value)) { + $this->children[] = new File($key, $value, $this); + } elseif (is_array($value)) { + $this->children[] = new self($key, $value, $this); + } elseif ($value instanceof \Sabre\DAV\INode) { + $this->children[] = $value; + } else { + throw new \InvalidArgumentException('Unknown value passed in $children'); + } + } $this->parent = $parent; } @@ -47,7 +57,7 @@ class Collection extends DAV\Collection { * * @return string */ - public function getName() { + function getName() { return $this->name; @@ -77,12 +87,12 @@ class Collection extends DAV\Collection { * @param resource|string $data Initial payload * @return null|string */ - public function createFile($name, $data = null) { + function createFile($name, $data = null) { if (is_resource($data)) { $data = stream_get_contents($data); } - $this->children[$name] = $data; + $this->children[] = new File($name, $data, $this); return '"' . md5($data) . '"'; } @@ -93,9 +103,9 @@ class Collection extends DAV\Collection { * @param string $name * @return void */ - public function createDirectory($name) { + function createDirectory($name) { - $this->children[$name] = array(); + $this->children[] = new self($name); } @@ -104,22 +114,18 @@ class Collection extends DAV\Collection { * * @return \Sabre\DAV\INode[] */ - public function getChildren() { + function getChildren() { - $result = array(); - foreach($this->children as $key=>$value) { + return $this->children; - if ($value instanceof DAV\INode) { - $result[] = $value; - } elseif (is_array($value)) { - $result[] = new Collection($key, $value, $this); - } else { - $result[] = new File($key, $value, $this); - } + } - } + /** + * Adds an already existing node to this collection. + */ + function addNode(\Sabre\DAV\INode $node) { - return $result; + $this->children[] = $node; } @@ -129,16 +135,11 @@ class Collection extends DAV\Collection { * @param string $name * @return void */ - public function deleteChild($name) { + function deleteChild($name) { - foreach($this->children as $key=>$value) { + foreach ($this->children as $key => $value) { - if ($value instanceof DAV\INode) { - if ($value->getName() == $name) { - unset($this->children[$key]); - return; - } - } elseif ($key === $name) { + if ($value->getName() == $name) { unset($this->children[$key]); return; } @@ -152,9 +153,9 @@ class Collection extends DAV\Collection { * * @return void */ - public function delete() { + function delete() { - foreach($this->getChildren() as $child) { + foreach ($this->getChildren() as $child) { $this->deleteChild($child->getName()); } $this->parent->deleteChild($this->getName()); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php index 2b25bbb88..23855e3c5 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php @@ -9,7 +9,7 @@ use Sabre\DAV; * * See the Collection in this directory for more details. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -18,6 +18,7 @@ class File extends DAV\File { protected $name; protected $contents; protected $parent; + protected $lastModified; /** * Creates the object @@ -26,12 +27,18 @@ class File extends DAV\File { * @param array $children * @return void */ - public function __construct($name, $contents, Collection $parent) { + function __construct($name, $contents, Collection $parent = null, $lastModified = -1) { $this->name = $name; $this->put($contents); $this->parent = $parent; + if ($lastModified === -1) { + $lastModified = time(); + } + + $this->lastModified = $lastModified; + } /** @@ -41,13 +48,24 @@ class File extends DAV\File { * * @return string */ - public function getName() { + function getName() { return $this->name; } /** + * Changes the name of the node. + * + * @return void + */ + function setName($name) { + + $this->name = $name; + + } + + /** * Updates the data * * The data argument is a readable stream resource. @@ -67,7 +85,7 @@ class File extends DAV\File { * @param resource $data * @return string|null */ - public function put($data) { + function put($data) { if (is_resource($data)) { $data = stream_get_contents($data); @@ -84,7 +102,7 @@ class File extends DAV\File { * * @return mixed */ - public function get() { + function get() { return $this->contents; @@ -99,7 +117,7 @@ class File extends DAV\File { * * @return void */ - public function getETag() { + function getETag() { return '"' . md5($this->contents) . '"'; @@ -110,7 +128,7 @@ class File extends DAV\File { * * @return int */ - public function getSize() { + function getSize() { return strlen($this->contents); @@ -121,10 +139,22 @@ class File extends DAV\File { * * @return void */ - public function delete() { + function delete() { $this->parent->deleteChild($this->name); } + /** + * Returns the last modification time as a unix timestamp. + * If the information is not available, return null. + * + * @return int + */ + function getLastModified() { + + return $this->lastModified; + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php index e818fe043..e6415792c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php @@ -23,11 +23,11 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'GET', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status,'We expected GET to not be implemented for Directories. Response body: ' . $this->response->body); + $this->assertEquals(501, $this->response->status,'We expected GET to not be implemented for Directories. Response body: ' . $this->response->body); } @@ -40,14 +40,14 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_HOST' => 'example.org', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $xml = simplexml_load_string($this->response->body); - $this->assertTrue($xml==true,'Response was not a valid xml document'); + $this->assertInstanceOf('SimpleXMLElement',$xml, 'Response was not a valid xml document. The list of errors:' . print_r(libxml_get_errors(),true) . '. xml body: ' . $this->response->body . '. What type we got: ' . gettype($xml) . ' class, if object: ' . get_class($xml)); $xml->registerXPathNamespace('dm','http://purl.org/NET/webdav/mount'); $url = $xml->xpath('//dm:url'); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php index 330058b6d..9b7eeb90c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php @@ -16,7 +16,7 @@ class ObjectTreeTest extends \PHPUnit_Framework_TestCase { file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents'); file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents'); $rootNode = new FSExt\Directory(SABRE_TEMPDIR . '/root'); - $this->tree = new ObjectTree($rootNode); + $this->tree = new Tree($rootNode); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php index e8cdc1666..d6cc406be 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php @@ -3,7 +3,7 @@ namespace Sabre\DAV\PartialUpdate; use Sabre\DAV; -class FileMock implements IFile { +class FileMock implements IPatchSupport { protected $data = ''; @@ -16,14 +16,56 @@ class FileMock implements IFile { } - function putRange($str,$start) { - - if (is_resource($str)) { - $str = stream_get_contents($str); + /** + * Updates the file based on a range specification. + * + * The first argument is the data, which is either a readable stream + * resource or a string. + * + * The second argument is the type of update we're doing. + * This is either: + * * 1. append + * * 2. update based on a start byte + * * 3. update based on an end byte + *; + * The third argument is the start or end byte. + * + * After a successful put operation, you may choose to return an ETag. The + * etag must always be surrounded by double-quotes. These quotes must + * appear in the actual string you're returning. + * + * Clients may use the ETag from a PUT request to later on make sure that + * when they update the file, the contents haven't changed in the mean + * time. + * + * @param resource|string $data + * @param int $rangeType + * @param int $offset + * @return string|null + */ + function patch($data, $rangeType, $offset = null) { + + if (is_resource($data)) { + $data = stream_get_contents($data); } - $this->data = substr($this->data, 0, $start) . $str . substr($this->data, $start + strlen($str)); + switch($rangeType) { + + case 1 : + $this->data.=$data; + break; + case 3 : + // Turn the offset into an offset-offset. + $offset = strlen($this->data) - $offset; + // No break is intentional + case 2 : + $this->data = + substr($this->data, 0, $offset) . + $data . + substr($this->data, $offset + strlen($data)); + break; + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php index 32f7e4e2c..5bd696416 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php @@ -12,7 +12,7 @@ class PluginTest extends \Sabre\DAVServerTest { protected $node; protected $plugin; - public function setUp() { + function setUp() { $this->node = new FileMock(); $this->tree[] = $this->node; @@ -26,124 +26,109 @@ class PluginTest extends \Sabre\DAVServerTest { } - public function testInit() { + function testInit() { $this->assertEquals('partialupdate', $this->plugin->getPluginName()); - $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures()); - $this->assertEquals(array( + $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures()); + $this->assertEquals([ 'PATCH' - ), $this->plugin->getHTTPMethods('partial')); - $this->assertEquals(array( - ), $this->plugin->getHTTPMethods('')); - - $this->assertNull($this->plugin->unknownMethod('FOO','partial')); + ], $this->plugin->getHTTPMethods('partial')); + $this->assertEquals([ + ], $this->plugin->getHTTPMethods('')); } - public function testPatchNoRange() { + function testPatchNoRange() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( + $this->node->put('aaaaaaaa'); + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', - )); + ]); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(400, $response->status, 'Full response body:' . $response->body); } - public function testPatchNotSupported() { - - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/', - 'X_UPDATE_RANGE' => '3-4', + function testPatchNotSupported() { - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(405, $response->status, 'Full response body:' . $response->body); } - public function testPatchNoContentType() { + function testPatchNoContentType() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4', + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4']); + $request->setBody( + 'bbb' + ); + $response = $this->request($request); - )); + $this->assertEquals(415, $response->status, 'Full response body:' . $response->body); + + } + + function testPatchBadRange() { + + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(416, $response->status, 'Full response body:' . $response->body); } - public function testPatchBadRange() { + function testPatchNoLength() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 411 Length Required', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(411, $response->status, 'Full response body:' . $response->body); } - public function testPatchSuccess() { + function testPatchSuccess() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_CONTENT_LENGTH' => 3, - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => 3]); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); - $this->assertEquals('00011100', $this->node->get()); + $this->assertEquals(204, $response->status, 'Full response body:' . $response->body); + $this->assertEquals('aaabbbaa', $this->node->get()); } - public function testPatchNoEndRange() { + function testPatchNoEndRange() { - $this->node->put('00000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_CONTENT_LENGTH' => 3, - )); + $this->node->put('aaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']); $request->setBody( - '111' + 'bbb' ); + $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); - $this->assertEquals('00111', $this->node->get()); + $this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString()); + $this->assertEquals('aaabbb', $this->node->get()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php index 7abe69c55..31be2a1b1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php @@ -42,21 +42,21 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase { */ public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) { - $vars = array( - 'REQUEST_METHOD' => 'PATCH', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_X_UPDATE_RANGE' => $headerValue, - 'REQUEST_URI' => '/foobar.txt', - ); + $headers = [ + 'Content-Type' => 'application/x-sabredav-partialupdate', + 'X-Update-Range' => $headerValue, + ]; + if ($contentLength) { - $vars['HTTP_CONTENT_LENGTH'] = (string)$contentLength; + $headers['Content-Length'] = (string)$contentLength; } - $request = new HTTP\Request($vars); + $request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----'); $request->setBody('----'); $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); + $this->server->sapi = new HTTP\SapiMock(); $this->server->exec(); $this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body); @@ -70,17 +70,17 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase { return array( // Problems - array('foo', 'HTTP/1.1 400 Bad request', null), - array('bytes=0-3', 'HTTP/1.1 411 Length Required', null, 0), - array('bytes=4-1', 'HTTP/1.1 416 Requested Range Not Satisfiable', null), - - array('bytes=0-3', 'HTTP/1.1 204 No Content', '----567890'), - array('bytes=1-4', 'HTTP/1.1 204 No Content', '1----67890'), - array('bytes=0-', 'HTTP/1.1 204 No Content', '----567890'), - array('bytes=-4', 'HTTP/1.1 204 No Content', '123456----'), - array('bytes=-2', 'HTTP/1.1 204 No Content', '12345678----'), - array('bytes=2-', 'HTTP/1.1 204 No Content', '12----7890'), - array('append', 'HTTP/1.1 204 No Content', '1234567890----'), + array('foo', 400, null), + array('bytes=0-3', 411, null, 0), + array('bytes=4-1', 416, null), + + array('bytes=0-3', 204, '----567890'), + array('bytes=1-4', 204, '1----67890'), + array('bytes=0-', 204, '----567890'), + array('bytes=-4', 204, '123456----'), + array('bytes=-2', 204, '12345678----'), + array('bytes=2-', 204, '12----7890'), + array('append', 204, '1234567890----'), ); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php deleted file mode 100644 index de8ca1283..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -class GetLastModifiedTest extends \PHPUnit_Framework_TestCase { - - function testConstructDateTime() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified($dt); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testConstructString() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified('2010-03-14 16:35'); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testConstructInt() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified((int)$dt->format('U')); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testSerialize() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified($dt); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:getlastmodified'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $lastMod->serialize($server, $root); - - $xml = $doc->saveXML(); - - /* - $this->assertEquals( -'<?xml version="1.0"?> -<d:getlastmodified xmlns:d="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">' . -HTTP\Util::toHTTPDate($dt) . -'</d:getlastmodified> -', $xml); - */ - $this->assertEquals( -'<?xml version="1.0"?> -<d:getlastmodified xmlns:d="DAV:">' . -HTTP\Util::toHTTPDate($dt) . -'</d:getlastmodified> -', $xml); - - $ok = false; - try { - GetLastModified::unserialize(DAV\XMLUtil::loadDOMDocument($xml)->firstChild); - } catch (DAV\Exception $e) { - $ok = true; - } - if (!$ok) $this->markTestFailed('Unserialize should not be supported'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php deleted file mode 100644 index fe2bc81f9..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php +++ /dev/null @@ -1,91 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; -use Sabre\DAV; - -class HrefListTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $href = new HrefList(array('foo','bar')); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - } - - function testSerialize() { - - $href = new HrefList(array('foo','bar')); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything> -', $xml); - - } - - function testSerializeNoPrefix() { - - $href = new HrefList(array('foo','bar'), false); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>foo</d:href><d:href>bar</d:href></d:anything> -', $xml); - - } - - function testUnserialize() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = HrefList::unserialize($dom->firstChild); - $this->assertEquals(array('/bla/foo','/bla/bar'),$href->getHrefs()); - - } - - function testUnserializeIncompatible() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href2>/bla/foo</d:href2></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = HrefList::unserialize($dom->firstChild); - $this->assertEquals(array(), $href->getHrefs()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php deleted file mode 100644 index e5607f51b..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class HrefTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $href = new Href('path'); - $this->assertEquals('path',$href->getHref()); - - } - - function testSerialize() { - - $href = new Href('path'); - $this->assertEquals('path',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything> -', $xml); - - } - - function testSerializeNoPrefix() { - - $href = new Href('path',false); - $this->assertEquals('path',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>path</d:href></d:anything> -', $xml); - - } - - function testUnserialize() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href>/bla/path</d:href></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = Href::unserialize($dom->firstChild); - $this->assertEquals('/bla/path',$href->getHref()); - - } - - function testUnserializeIncompatible() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href2>/bla/path</d:href2></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = Href::unserialize($dom->firstChild); - $this->assertNull($href); - - } - - /** - * This method tests if hrefs containing & are correctly encoded. - */ - function testSerializeEntity() { - - $href = new Href('http://example.org/?a&b', false); - $this->assertEquals('http://example.org/?a&b',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>http://example.org/?a&b</d:href></d:anything> -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php deleted file mode 100644 index 8a579baec..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class ResourceTypeTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $resourceType = new ResourceType(array('{DAV:}collection')); - $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue()); - - $resourceType = new ResourceType(DAV\Server::NODE_FILE); - $this->assertEquals(array(),$resourceType->getValue()); - - $resourceType = new ResourceType(DAV\Server::NODE_DIRECTORY); - $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue()); - - $resourceType = new ResourceType('{DAV:}principal'); - $this->assertEquals(array('{DAV:}principal'),$resourceType->getValue()); - - } - - /** - * @depends testConstruct - */ - function testSerialize() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $resourceType->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything> -', $xml); - - } - - /** - * @depends testSerialize - */ - function testSerializeCustomNS() { - - $resourceType = new ResourceType(array('{http://example.org/NS}article')); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $resourceType->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><custom:article xmlns:custom="http://example.org/NS"/></d:anything> -', $xml); - - } - - /** - * @depends testConstruct - */ - function testIs() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - $this->assertTrue($resourceType->is('{DAV:}collection')); - $this->assertFalse($resourceType->is('{DAV:}blabla')); - - } - - /** - * @depends testConstruct - */ - function testAdd() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - $resourceType->add('{DAV:}foo'); - $this->assertEquals(array('{DAV:}collection','{DAV:}principal','{DAV:}foo'), $resourceType->getValue()); - - } - - /** - * @depends testConstruct - */ - function testUnserialize() { - - $xml ='<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $resourceType = ResourceType::unserialize($dom->firstChild); - $this->assertEquals(array('{DAV:}collection','{DAV:}principal'),$resourceType->getValue()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php deleted file mode 100644 index d13066b80..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -class ResponseListTest extends \PHPUnit_Framework_TestCase { - - /** - * This was the only part not yet covered by other tests, so I'm going to - * be lazy and (for now) only test this case. - * - * @expectedException InvalidArgumentException - */ - public function testInvalidArg() { - - $response = new ResponseList(array(1,2)); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php deleted file mode 100644 index 073cbb2ce..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php +++ /dev/null @@ -1,230 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class ResponseTest extends \PHPUnit_Framework_TestCase { - - function testSimple() { - - $innerProps = array( - 200 => array( - '{DAV:}displayname' => 'my file', - ), - 404 => array( - '{DAV:}owner' => null, - ) - ); - - $property = new Response('uri',$innerProps); - - $this->assertEquals('uri',$property->getHref()); - $this->assertEquals($innerProps,$property->getResponseProperties()); - - - } - - /** - * @depends testSimple - */ - function testSerialize() { - - $innerProps = array( - 200 => array( - '{DAV:}displayname' => 'my file', - ), - 404 => array( - '{DAV:}owner' => null, - ) - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<d:displayname>my file</d:displayname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'<d:propstat>' . -'<d:prop>' . -'<d:owner/>' . -'</d:prop>' . -'<d:status>HTTP/1.1 404 Not Found</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * This one is specifically for testing properties with no namespaces, which is legal xml - * - * @depends testSerialize - */ - function testSerializeEmptyNamespace() { - - $innerProps = array( - 200 => array( - '{}propertyname' => 'value', - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<propertyname xmlns="">value</propertyname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * This one is specifically for testing properties with no namespaces, which is legal xml - * - * @depends testSerialize - */ - function testSerializeCustomNamespace() { - - $innerProps = array( - 200 => array( - '{http://sabredav.org/NS/example}propertyname' => 'value', - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<x2:propertyname xmlns:x2="http://sabredav.org/NS/example">value</x2:propertyname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * @depends testSerialize - */ - function testSerializeComplexProperty() { - - $innerProps = array( - 200 => array( - '{DAV:}link' => new Href('http://sabredav.org/', false) - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<d:link><d:href>http://sabredav.org/</d:href></d:link>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * @depends testSerialize - * @expectedException Sabre\DAV\Exception - */ - function testSerializeBreak() { - - $innerProps = array( - 200 => array( - '{DAV:}link' => new \STDClass() - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php deleted file mode 100644 index 445e22ab3..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php +++ /dev/null @@ -1,128 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; - -class SupportedReportSetTest extends DAV\AbstractServer { - - public function sendPROPFIND($body) { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPFIND', - 'HTTP_DEPTH' => '0', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody($body); - - $this->server->httpRequest = ($request); - $this->server->exec(); - - } - - /** - * @covers Sabre\DAV\Property\SupportedReportSet - */ - function testNoReports() { - - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:"> - <d:prop> - <d:supported-report-set /> - </d:prop> -</d:propfind>'; - - $this->sendPROPFIND($xml); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full 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); - $xml->registerXPathNamespace('d','urn:DAV'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set'); - $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element'); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200'); - - } - - /** - * @covers Sabre\DAV\Property\SupportedReportSet - * @depends testNoReports - */ - function testCustomReport() { - - // Intercepting the report property - $this->server->subscribeEvent('afterGetProperties',array($this,'addProp')); - - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:"> - <d:prop> - <d:supported-report-set /> - </d:prop> -</d:propfind>'; - - $this->sendPROPFIND($xml); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full 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); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('x','http://www.rooftopsolutions.nl/testnamespace'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set'); - $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report'); - $this->assertEquals(2,count($data),'We expected 2 \'d:supported-report\' elements'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report'); - $this->assertEquals(2,count($data),'We expected 2 \'d:report\' elements'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/x:myreport'); - $this->assertEquals(1,count($data),'We expected 1 \'x:myreport\' element. Full body: ' . $this->response->body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/d:anotherreport'); - $this->assertEquals(1,count($data),'We expected 1 \'d:anotherreport\' element. Full body: ' . $this->response->body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element'); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200'); - - } - - /** - * This method is used as a callback for afterGetProperties - */ - function addProp($path, &$properties) { - - if (isset($properties[200]['{DAV:}supported-report-set'])) { - $properties[200]['{DAV:}supported-report-set']->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport'); - $properties[200]['{DAV:}supported-report-set']->addReport('{DAV:}anotherreport'); - } - - } - - - -} - -?> diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php deleted file mode 100644 index 88e107c19..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php +++ /dev/null @@ -1,268 +0,0 @@ -<?php - -namespace Sabre\DAV; - -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class ServerCopyMoveTest extends \PHPUnit_Framework_TestCase { - - private $response; - /** - * @var Server - */ - private $server; - - function setUp() { - - $this->response = new HTTP\ResponseMock(); - $dir = new FS\Directory(SABRE_TEMPDIR); - $tree = new ObjectTree($dir); - $this->server = new Server($tree); - $this->server->debugExceptions = true; - $this->server->httpResponse = $this->response; - file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents'); - file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2'); - mkdir(SABRE_TEMPDIR . '/col'); - file_put_contents(SABRE_TEMPDIR . 'col/test.txt', 'Test contents'); - - } - - function tearDown() { - - $cleanUp = array('test.txt','testput.txt','testcol','test2.txt','test3.txt','col/test.txt','col','col2/test.txt','col2'); - foreach($cleanUp as $file) { - $tmpFile = SABRE_TEMPDIR . '/' . $file; - if (file_exists($tmpFile)) { - - if (is_dir($tmpFile)) { - rmdir($tmpFile); - } else { - unlink($tmpFile); - } - - } - } - - } - - - function testCopyOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test2.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test2.txt')); - - } - - function testCopyToSelf() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test.txt')); - - } - - function testMoveToSelf() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/test.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test.txt')); - - } - - function testMoveOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/test2.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => 0, - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/test2.txt')); - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/test.txt'),'The sourcefile test.txt should no longer exist at this point'); - - } - - function testBlockedOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test2.txt', - 'HTTP_OVERWRITE' => 'F', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); - $this->assertEquals('Test contents2',file_get_contents(SABRE_TEMPDIR . '/test2.txt')); - - - } - - function testNonExistantParent() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/testcol2/test2.txt', - 'HTTP_OVERWRITE' => 'F', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status); - - } - - function testRandomOverwriteHeader() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/testcol2/test2.txt', - 'HTTP_OVERWRITE' => 'SURE!', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); - - } - - function testCopyDirectory() { - - $serverVars = array( - 'REQUEST_URI' => '/col', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/col2', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt')); - - } - - function testSimpleCopyFile() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test3.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/test3.txt')); - - } - - function testSimpleCopyCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/col', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/col2', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Incorrect status received. Full response body: ' . $this->response->body); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt')); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php index 2c7a074df..6ac20d2da 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php @@ -1,6 +1,7 @@ <?php namespace Sabre\DAV; + use Sabre\HTTP; require_once 'Sabre/DAV/AbstractServer.php'; @@ -13,11 +14,11 @@ class ServerEventsTest extends AbstractServer { function testAfterBind() { - $this->server->subscribeEvent('afterBind',array($this,'afterBindHandler')); + $this->server->on('afterBind', [$this, 'afterBindHandler']); $newPath = 'afterBind'; $this->tempPath = ''; - $this->server->createFile($newPath,'body'); + $this->server->createFile($newPath, 'body'); $this->assertEquals($newPath, $this->tempPath); } @@ -28,25 +29,41 @@ class ServerEventsTest extends AbstractServer { } + function testAfterResponse() { + + $mock = $this->getMock('stdClass', ['afterResponseCallback']); + $mock->expects($this->once())->method('afterResponseCallback'); + + $this->server->on('afterResponse', [$mock, 'afterResponseCallback']); + + $this->server->httpRequest = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => '/test.txt', + ]); + + $this->server->exec(); + + } + function testBeforeBindCancel() { - $this->server->subscribeEvent('beforeBind', array($this,'beforeBindCancelHandler')); - $this->assertFalse($this->server->createFile('bla','body')); + $this->server->on('beforeBind', [$this, 'beforeBindCancelHandler']); + $this->assertFalse($this->server->createFile('bla', 'body')); // Also testing put() - $req = new HTTP\Request(array( + $req = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/barbar', - )); + 'REQUEST_URI' => '/barbar', + ]); $this->server->httpRequest = $req; $this->server->exec(); - $this->assertEquals('',$this->server->httpResponse->status); + $this->assertEquals(500, $this->server->httpResponse->getStatus()); } - function beforeBindCancelHandler() { + function beforeBindCancelHandler($path) { return false; @@ -54,12 +71,12 @@ class ServerEventsTest extends AbstractServer { function testException() { - $this->server->subscribeEvent('exception', array($this, 'exceptionHandler')); + $this->server->on('exception', [$this, 'exceptionHandler']); - $req = new HTTP\Request(array( + $req = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'GET', - 'REQUEST_URI' => '/not/exisitng', - )); + 'REQUEST_URI' => '/not/exisitng', + ]); $this->server->httpRequest = $req; $this->server->exec(); @@ -73,4 +90,35 @@ class ServerEventsTest extends AbstractServer { } + function testMethod() { + + $k = 1; + $this->server->on('method', function($request, $response) use (&$k) { + + $k += 1; + + return false; + + }); + $this->server->on('method', function($request, $response) use (&$k) { + + $k += 2; + + return false; + + }); + + try { + $this->server->invokeMethod( + new HTTP\Request('BLABLA', '/'), + new HTTP\Response(), + false + ); + } catch (Exception $e) {} + + $this->assertEquals(2, $k); + + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php index 34b084dcd..e35189ec3 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php @@ -4,10 +4,6 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; -require_once 'Sabre/DAV/Exception.php'; - class ServerMKCOLTest extends AbstractServer { function testMkcol() { @@ -17,16 +13,17 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(""); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertTrue(is_dir($this->tempDir . '/testcol')); @@ -42,16 +39,17 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody("Hello"); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status); + $this->assertEquals(415, $this->response->status); } @@ -66,16 +64,17 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody("Hello"); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [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->getStatus(), $this->response->getBodyAsString() ); } @@ -90,16 +89,17 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?><html></html>'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status); + $this->assertEquals(400, $this->response->getStatus()); } @@ -114,7 +114,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -127,15 +127,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLNoResourceType + * @depends testMkcol */ function testMKCOLIncorrectResourceType() { @@ -145,38 +146,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); - $request->setBody('<?xml version="1.0"?> -<mkcol xmlns="DAV:"> - <set> - <prop> - <resourcetype><blabla /></resourcetype> - </prop> - </set> -</mkcol>'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); - - } - - /** - * @depends testMKCOLIncorrectResourceType - */ - function testMKCOLIncorrectResourceType2() { - - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'MKCOL', - 'HTTP_CONTENT_TYPE' => 'application/xml', - ); - - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -189,15 +159,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLSuccess() { @@ -207,7 +178,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -220,15 +191,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLWhiteSpaceResourceType() { @@ -238,7 +210,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -253,15 +225,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLNoParent() { @@ -270,22 +243,23 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLParentIsNoCollection() { @@ -294,22 +268,23 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLAlreadyExists() { @@ -318,18 +293,19 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } @@ -345,7 +321,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -358,13 +334,12 @@ class ServerMKCOLTest extends AbstractServer { $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php index 8f1451b49..ab0ad295e 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php @@ -24,13 +24,19 @@ class ServerPluginTest extends AbstractServer { } /** - * @covers \Sabre\DAV\ServerPlugin */ function testBaseClass() { $p = new ServerPluginMock(); - $this->assertEquals(array(),$p->getFeatures()); - $this->assertEquals(array(),$p->getHTTPMethods('')); + $this->assertEquals([],$p->getFeatures()); + $this->assertEquals([],$p->getHTTPMethods('')); + $this->assertEquals( + [ + 'name' => 'Sabre\DAV\ServerPluginMock', + 'description' => null, + 'link' => null + ], $p->getPluginInfo() + ); } @@ -41,20 +47,20 @@ class ServerPluginTest extends AbstractServer { 'REQUEST_METHOD' => 'OPTIONS', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol, drinking', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version' => Version::VERSION, - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + 'DAV' => ['1, 3, extended-mkcol, drinking'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ),$this->response->getHeaders()); + + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('OPTIONS',$this->testPlugin->beforeMethod); @@ -82,7 +88,10 @@ class ServerPluginTest extends AbstractServer { function testGetPlugins() { $this->assertEquals( - array(get_class($this->testPlugin) => $this->testPlugin), + array( + get_class($this->testPlugin) => $this->testPlugin, + 'core' => $this->server->getPlugin('core'), + ), $this->server->getPlugins() ); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php index ea09852a7..1dc8d8a37 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php @@ -9,362 +9,311 @@ require_once 'Sabre/HTTP/ResponseMock.php'; class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase { /** - * @covers Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfMatchNoNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '*', - 'REQUEST_URI' => '/bar' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('GET', '/bar', ['If-Match' => '*']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchHasNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '*', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '*']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfMatchWrongEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '1234', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '1234']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchCorrectEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"abc123"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** * Evolution sometimes uses \" instead of " for If-Match headers. * - * @covers \Sabre\DAV\Server::checkPreconditions * @depends testIfMatchCorrectEtag */ function testIfMatchEvolutionEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '\\"abc123\\"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '\\"abc123\\"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '"hellothere", "abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"hellothere", "abc123"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchNoNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '*', - 'REQUEST_URI' => '/bar' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/bar', ['If-None-Match' => '*']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfNoneMatchHasNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '*', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '*']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchWrongEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchWrongEtagMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234", "5678"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234", "5678"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfNoneMatchCorrectEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"abc123"']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfNoneMatchCorrectEtagMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234", "abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234, "abc123"']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfNoneMatchCorrectEtagAsGet() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']); + $server->httpResponse = new HTTP\ResponseMock(); + + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); + $this->assertEquals(304, $server->httpResponse->getStatus()); + $this->assertEquals(['ETag' => ['"abc123"']], $server->httpResponse->getHeaders()); + + } + + /** + * This was a test written for issue #515. + */ + public function testNoneMatchCorrectEtagEnsureSapiSent() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $server->sapi = new HTTP\SapiMock(); + HTTP\SapiMock::$sent = 0; + $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']); $server->httpRequest = $httpRequest; $server->httpResponse = new HTTP\ResponseMock(); - $this->assertFalse($server->checkPreconditions(true)); - $this->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + $server->exec(); + + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); + $this->assertEquals(304, $server->httpResponse->getStatus()); + $this->assertEquals([ + 'ETag' => ['"abc123"'], + 'X-Sabre-Version' => [Version::VERSION], + ], $server->httpResponse->getHeaders()); + $this->assertEquals(1, HTTP\SapiMock::$sent); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceUnModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; $server->httpResponse = new HTTP\ResponseMock(); - $this->assertFalse($server->checkPreconditions()); + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); - $this->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + $this->assertEquals(304, $server->httpResponse->status); $this->assertEquals(array( - 'Last-Modified' => 'Sat, 06 Apr 1985 23:30:00 GMT', - ), $server->httpResponse->headers); + 'Last-Modified' => ['Sat, 06 Apr 1985 23:30:00 GMT'], + ), $server->httpResponse->getHeaders()); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceInvalidDate() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Your mother', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); + $httpResponse = new HTTP\ResponseMock(); // Invalid dates must be ignored, so this should return true - $this->assertTrue($server->checkPreconditions()); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceInvalidDate2() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 EST', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfUnmodifiedSinceUnModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfUnmodifiedSinceModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $server->checkPreconditions(); + $httpResponse = new HTTP\ResponseMock(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfUnmodifiedSinceInvalidDate() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php index 859a91070..253200be7 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php @@ -1,6 +1,7 @@ <?php namespace Sabre\DAV; + use Sabre\HTTP; require_once 'Sabre/HTTP/ResponseMock.php'; @@ -16,7 +17,7 @@ class ServerPropsTest extends AbstractServer { function setUp() { - if (file_exists(SABRE_TEMPDIR.'../.sabredav')) unlink(SABRE_TEMPDIR.'../.sabredav'); + if (file_exists(SABRE_TEMPDIR . '../.sabredav')) unlink(SABRE_TEMPDIR . '../.sabredav'); parent::setUp(); file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2'); mkdir(SABRE_TEMPDIR . '/col'); @@ -28,64 +29,68 @@ class ServerPropsTest extends AbstractServer { function tearDown() { parent::tearDown(); - if (file_exists(SABRE_TEMPDIR.'../.locksdb')) unlink(SABRE_TEMPDIR.'../.locksdb'); + if (file_exists(SABRE_TEMPDIR . '../.locksdb')) unlink(SABRE_TEMPDIR . '../.locksdb'); } - private function sendRequest($body) { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPFIND', - 'HTTP_DEPTH' => '0', - ); + private function sendRequest($body, $path = '/', $headers = ['Depth' => '0']) { - $request = new HTTP\Request($serverVars); - $request->setBody($body); + $request = new HTTP\Request('PROPFIND', $path, $headers, $body); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); } - public function testPropFindEmptyBody() { + function testPropFindEmptyBody() { - $hasFired = false; + $this->sendRequest(""); + $this->assertEquals(207, $this->response->status); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol, 2'], + 'Vary' => ['Brief,Prefer'], + ], + $this->response->getHeaders() + ); - $self = $this; - // Also testing the beforeGetPropertiesForPath event. - $this->server->subscribeEvent('beforeGetPropertiesForPath', function($path, $properties, $depth) use ($self, &$hasFired) { + $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'); - $hasFired = true; - $self->assertEquals('', $path); - $self->assertEquals(array(), $properties); - $self->assertEquals(0, $depth); + list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); + $this->assertEquals('/', (string)$data, 'href element should have been /'); - }); + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); + $this->assertEquals(1, count($data)); - $this->sendRequest(""); + } - $this->assertTrue($hasFired); + function testPropFindEmptyBodyFile() { - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status); + $this->sendRequest("", '/test2.txt', []); + $this->assertEquals(207, $this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'DAV' => '1, 3, extended-mkcol, 2', - 'Vary' => 'Brief,Prefer', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol, 2'], + 'Vary' => ['Brief,Prefer'], + ], + $this->response->getHeaders() ); - $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'); + $xml->registerXPathNamespace('d', 'urn:DAV'); list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); - $this->assertEquals('/',(string)$data,'href element should have been /'); + $this->assertEquals('/test2.txt', (string)$data, 'href element should have been /test2.txt'); - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); - $this->assertEquals(1,count($data)); + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength'); + $this->assertEquals(1, count($data)); } @@ -100,27 +105,27 @@ class ServerPropsTest extends AbstractServer { $this->sendRequest($xml); - $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'); + $xml->registerXPathNamespace('d', 'urn:DAV'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry'); - $this->assertEquals(2,count($data),'We expected two \'d:lockentry\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:lockentry\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope'); - $this->assertEquals(2,count($data),'We expected two \'d:lockscope\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:lockscope\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype'); - $this->assertEquals(2,count($data),'We expected two \'d:locktype\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:locktype\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared'); - $this->assertEquals(1,count($data),'We expected a \'d:shared\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:shared\' tag'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive'); - $this->assertEquals(1,count($data),'We expected a \'d:exclusive\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:exclusive\' tag'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write'); - $this->assertEquals(2,count($data),'We expected two \'d:write\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:write\' tags'); } function testLockDiscovery() { @@ -134,12 +139,12 @@ class ServerPropsTest extends AbstractServer { $this->sendRequest($xml); - $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'); + $xml->registerXPathNamespace('d', 'urn:DAV'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery'); - $this->assertEquals(1,count($data),'We expected a \'d:lockdiscovery\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:lockdiscovery\' tag'); } @@ -153,31 +158,28 @@ class ServerPropsTest extends AbstractServer { </d:propfind>'; $this->sendRequest($xml); - $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'); - $pathTests = array( + $xml->registerXPathNamespace('d', 'urn:DAV'); + $pathTests = [ '/d:multistatus', '/d:multistatus/d:response', '/d:multistatus/d:response/d:propstat', '/d:multistatus/d:response/d:propstat/d:status', '/d:multistatus/d:response/d:propstat/d:prop', '/d:multistatus/d:response/d:propstat/d:prop/d:macaroni', - ); - foreach($pathTests as $test) { - $this->assertTrue(count($xml->xpath($test))==true,'We expected the ' . $test . ' element to appear in the response, we got: ' . $body); + ]; + foreach ($pathTests as $test) { + $this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body); } $val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($val),$body); - $this->assertEquals('HTTP/1.1 404 Not Found',(string)$val[0]); + $this->assertEquals(1, count($val), $body); + $this->assertEquals('HTTP/1.1 404 Not Found', (string)$val[0]); } - /** - * @covers Sabre\DAV\Server::parsePropPatchRequest - */ - public function testParsePropPatchRequest() { + function testParsePropPatchRequest() { $body = '<?xml version="1.0"?> <d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test"> @@ -187,226 +189,12 @@ class ServerPropsTest extends AbstractServer { <d:remove><d:prop><s:someprop3 /></d:prop></d:remove> </d:propertyupdate>'; - $result = $this->server->parsePropPatchRequest($body); - $this->assertEquals(array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', + $result = $this->server->xml->parse($body); + $this->assertEquals([ + '{http://sabredav.org/NS/test}someprop' => 'somevalue', '{http://sabredav.org/NS/test}someprop2' => null, '{http://sabredav.org/NS/test}someprop3' => null, - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - */ - public function testUpdateProperties() { - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/test2.txt',$props); - - $this->assertEquals(array( - '200' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/test2.txt', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesProtected() { - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - '{DAV:}getcontentlength' => 50, - ); - - $result = $this->server->updateProperties('/test2.txt',$props); - - $this->assertEquals(array( - '424' => array('{http://sabredav.org/NS/test}someprop' => null), - '403' => array('{DAV:}getcontentlength' => null), - 'href' => '/test2.txt', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesFail1() { - - $dir = new PropTestDirMock('updatepropsfalse'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - $this->assertEquals(array( - '403' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesFail2() { - - $dir = new PropTestDirMock('updatepropsarray'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - $this->assertEquals(array( - '402' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - * @expectedException Sabre\DAV\Exception - */ - public function testUpdatePropertiesFail3() { - - $dir = new PropTestDirMock('updatepropsobj'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - } - - /** - * @depends testParsePropPatchRequest - * @depends testUpdateProperties - * @covers Sabre\DAV\Server::httpPropPatch - */ - public function testPropPatch() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPPATCH', - ); - - $body = '<?xml version="1.0"?> -<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://www.rooftopsolutions.nl/testnamespace"> - <d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set> -</d:propertyupdate>'; - - $request = new HTTP\Request($serverVars); - $request->setBody($body); - - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Vary' => 'Brief,Prefer', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We got the wrong status. Full XML response: ' . $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'); - $xml->registerXPathNamespace('bla','http://www.rooftopsolutions.nl/testnamespace'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected one \'d:prop\' element. Response body: ' . $body); - - $data = $xml->xpath('//bla:someprop'); - $this->assertEquals(1,count($data),'We expected one \'s:someprop\' element. Response body: ' . $body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected one \'s:status\' element. Response body: ' . $body); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0]); - - } - - /** - * @depends testPropPatch - */ - public function testPropPatchAndFetch() { - - $this->testPropPatch(); - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:" xmlns:s="http://www.rooftopsolutions.nl/testnamespace"> - <d:prop> - <s:someprop /> - </d:prop> -</d:propfind>'; - - $this->sendRequest($xml); - - $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'); - $xml->registerXPathNamespace('bla','http://www.rooftopsolutions.nl/testnamespace'); - - $xpath='//bla:someprop'; - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result),'We couldn\'t find our new property in the response. Full response body:' . "\n" . $body); - $this->assertEquals('somevalue',(string)$result[0],'We couldn\'t find our new property in the response. Full response body:' . "\n" . $body); - - } - -} - -class PropTestDirMock extends SimpleCollection implements IProperties { - - public $type; - - function __construct($type) { - - $this->type =$type; - parent::__construct('root'); - - } - - function updateProperties($updateProperties) { - - switch($this->type) { - case 'updatepropsfalse' : return false; - case 'updatepropsarray' : - $r = array(402 => array()); - foreach($updateProperties as $k=>$v) $r[402][$k] = null; - return $r; - case 'updatepropsobj' : - return new \STDClass(); - } - - } - - function getProperties($requestedPropeties) { - - return array(); + ], $result->properties); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php index a06fcb0be..bafbef6e4 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php @@ -1,42 +1,62 @@ <?php namespace Sabre\DAV; -use Sabre\HTTP; -require_once 'Sabre/DAV/AbstractServer.php'; +use DateTime; +use Sabre\HTTP; -class ServerRangeTest extends AbstractServer{ +/** + * This file tests HTTP requests that use the Range: header. + * + * @copyright Copyright (C) fruux GmbH. (https://fruux.com/) + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ +class ServerRangeTest extends \Sabre\DAVServerTest { - protected function getRootNode() { + protected $setupFiles = true; - return new FSExt\Directory(SABRE_TEMPDIR); + /** + * We need this string a lot + */ + protected $lastModified; - } + function setUp() { - function testRange() { + parent::setUp(); + $this->server->createFile('files/test.txt', 'Test contents'); - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', + $this->lastModified = HTTP\Util::toHTTPDate( + new DateTime('@' . $this->server->tree->getNodeForPath('files/test.txt')->getLastModified()) ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $stream = popen('echo "Test contents"', 'r'); + $streamingFile = new Mock\StreamingFile( + 'no-seeking.txt', + $stream + ); + $streamingFile->setSize(12); + $this->server->tree->getNodeForPath('files')->addNode($streamingFile); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); + } - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + function testRange() { + + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } @@ -45,28 +65,22 @@ class ServerRangeTest extends AbstractServer{ */ function testStartRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [11], + 'Content-Range' => ['bytes 2-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 11, - 'Content-Range' => 'bytes 2-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st contents', $response->getBodyAsString()); } @@ -75,28 +89,22 @@ class ServerRangeTest extends AbstractServer{ */ function testEndRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=-8', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=-8']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [8], + 'Content-Range' => ['bytes 5-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 8, - 'Content-Range' => 'bytes 5-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('contents', $response->getBodyAsString()); } @@ -105,17 +113,10 @@ class ServerRangeTest extends AbstractServer{ */ function testTooHighRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=100-200', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=100-200']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + $this->assertEquals(416, $response->getStatus()); } @@ -124,151 +125,138 @@ class ServerRangeTest extends AbstractServer{ */ function testCrazyRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=8-4', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=8-4']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $this->assertEquals(416, $response->getStatus()); - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + } + + function testNonSeekableStream() { + + $request = new HTTP\Request('GET', '/files/no-seeking.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals(206, $response->getStatus(), $response); + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/12'], + // 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + + $this->assertEquals('st c', $response->getBodyAsString()); } /** * @depends testRange - * @covers \Sabre\DAV\Server::httpGet */ function testIfRangeEtag() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag(), + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"' . md5('Test contents') . '"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeEtagIncorrect() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag() . 'blabla', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"foobar"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeModificationDate() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => 'tomorrow', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => 'tomorrow', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeModificationDate */ function testIfRangeModificationDateModified() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => '-2 years', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '-2 years', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php index 21e0ab2ea..66dde9db8 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php @@ -4,17 +4,13 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; -require_once 'Sabre/DAV/Exception.php'; - class ServerSimpleTest extends AbstractServer{ function testConstructArray() { - $nodes = array( + $nodes = [ new SimpleCollection('hello') - ); + ]; $server = new Server($nodes); $this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello')); @@ -26,10 +22,10 @@ class ServerSimpleTest extends AbstractServer{ */ function testConstructIncorrectObj() { - $nodes = array( + $nodes = [ new SimpleCollection('hello'), new \STDClass(), - ); + ]; $server = new Server($nodes); @@ -44,253 +40,108 @@ class ServerSimpleTest extends AbstractServer{ } - function testGet() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - function testGetHttp10() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'SERVER_PROTOCOL' => 'HTTP/1.0', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.0 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - - function testGetDoesntExist() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt_randomblbla', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); - - } - - function testGetDoesntExist2() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt/randomblbla', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); - - } - - /** - * This test should have the exact same result as testGet. - * - * The idea is that double slashes // are converted to single ones / - * - */ - function testGetDoubleSlash() { - - $serverVars = array( - 'REQUEST_URI' => '//test.txt', - 'REQUEST_METHOD' => 'GET', - ); + function testOptions() { - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('OPTIONS', '/'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - - - function testHEAD() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); } - function testOptions() { + function testOptionsUnmapped() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'OPTIONS', - ); + $request = new HTTP\Request('OPTIONS', '/unmapped'); + $this->server->httpRequest = $request; - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version' => Version::VERSION, - ),$this->response->headers); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, MKCOL'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); - } + function testNonExistantMethod() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'BLABLA', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $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' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); + $this->assertEquals(501, $this->response->status); } - function testGETOnCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); - - } - - function testHEADOnCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - - } - function testBaseUri() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET', - ); + ]; + $filename = $this->tempDir . '/test.txt'; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->setBaseUri('/blabla/'); - $this->assertEquals('/blabla/',$this->server->getBaseUri()); + $this->assertEquals('/blabla/', $this->server->getBaseUri()); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], + 'ETag' => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('Test contents', stream_get_contents($this->response->body)); } function testBaseUriAddSlash() { - $tests = array( + $tests = [ '/' => '/', '/foo' => '/foo/', '/foo/' => '/foo/', '/foo/bar' => '/foo/bar/', '/foo/bar/' => '/foo/bar/', - ); + ]; - foreach($tests as $test=>$result) { + foreach ($tests as $test => $result) { $this->server->setBaseUri($test); $this->assertEquals($result, $this->server->getBaseUri()); @@ -301,25 +152,25 @@ class ServerSimpleTest extends AbstractServer{ function testCalculateUri() { - $uris = array( + $uris = [ 'http://www.example.org/root/somepath', '/root/somepath', '/root/somepath/', - ); + ]; $this->server->setBaseUri('/root/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals('somepath',$this->server->calculateUri($uri)); + $this->assertEquals('somepath', $this->server->calculateUri($uri)); } $this->server->setBaseUri('/root'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals('somepath',$this->server->calculateUri($uri)); + $this->assertEquals('somepath', $this->server->calculateUri($uri)); } @@ -329,72 +180,60 @@ class ServerSimpleTest extends AbstractServer{ function testCalculateUriSpecialChars() { - $uris = array( + $uris = [ 'http://www.example.org/root/%C3%A0fo%C3%B3', '/root/%C3%A0fo%C3%B3', '/root/%C3%A0fo%C3%B3/' - ); + ]; $this->server->setBaseUri('/root/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } $this->server->setBaseUri('/root'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } $this->server->setBaseUri('/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("root/\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("root/\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } } - function testBaseUriCheck() { - - $uris = array( - 'http://www.example.org/root/somepath', - '/root/somepath', - '/root/somepath/' - ); - - try { - - $this->server->setBaseUri('root/'); - $this->server->calculateUri('/root/testuri'); - - $this->fail('Expected an exception'); - - } catch (Exception\Forbidden $e) { + /** + * @expectedException \Sabre\DAV\Exception\Forbidden + */ + function testCalculateUriBreakout() { - // This was expected + $uri = '/path1/'; - } + $this->server->setBaseUri('/path2/'); + $this->server->calculateUri($uri); } /** - * @covers \Sabre\DAV\Server::guessBaseUri */ function testGuessBaseUri() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -404,16 +243,15 @@ class ServerSimpleTest extends AbstractServer{ /** * @depends testGuessBaseUri - * @covers Sabre\DAV\Server::guessBaseUri */ function testGuessBaseUriPercentEncoding() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces', 'PATH_INFO' => '/dir/path2/path with spaces', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -423,18 +261,17 @@ class ServerSimpleTest extends AbstractServer{ /** * @depends testGuessBaseUri - * @covers \Sabre\DAV\Server::guessBaseUri */ /* function testGuessBaseUriPercentEncoding2() { $this->markTestIncomplete('This behaviour is not yet implemented'); - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces', 'PATH_INFO' => '/dir/path2/path with spaces', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -444,12 +281,12 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUri2() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root/', 'PATH_INFO' => '/root/', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -459,11 +296,11 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUriNoPathInfo() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -473,11 +310,11 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUriNoPathInfo2() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/a/b/c/test.php', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -487,17 +324,16 @@ class ServerSimpleTest extends AbstractServer{ /** - * @covers \Sabre\DAV\Server::guessBaseUri * @depends testGuessBaseUri */ function testGuessBaseUriQueryString() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root?query_string=blabla', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -506,18 +342,17 @@ class ServerSimpleTest extends AbstractServer{ } /** - * @covers \Sabre\DAV\Server::guessBaseUri * @depends testGuessBaseUri * @expectedException \Sabre\DAV\Exception */ function testGuessBaseUriBadConfig() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root/heyyy', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -527,25 +362,25 @@ class ServerSimpleTest extends AbstractServer{ function testTriggerException() { - $serverVars = array( - 'REQUEST_URI' => '/', + $serverVars = [ + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'FOO', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $httpRequest; - $this->server->subscribeEvent('beforeMethod',array($this,'exceptionTrigger')); + $this->server->on('beforeMethod', [$this, 'exceptionTrigger']); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + $this->assertEquals([ + 'Content-Type' => ['application/xml; charset=utf-8'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 500 Internal Server Error',$this->response->status); + $this->assertEquals(500, $this->response->status); } - function exceptionTrigger() { + function exceptionTrigger($request, $response) { throw new Exception('Hola'); @@ -553,54 +388,56 @@ class ServerSimpleTest extends AbstractServer{ function testReportNotFound() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>'); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body); + $this->assertEquals(415, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body); } function testReportIntercepted() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>'); - $this->server->subscribeEvent('report',array($this,'reportHandler')); + $this->server->on('report', [$this, 'reportHandler']); $this->server->exec(); - $this->assertEquals(array( - 'testheader' => 'testvalue', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'testheader' => ['testvalue'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 418 I\'m a teapot',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body); + $this->assertEquals(418, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body); } - function reportHandler($reportName) { + function reportHandler($reportName, $result, $path) { - if ($reportName=='{http://www.rooftopsolutions.nl/NS}myreport') { - $this->server->httpResponse->sendStatus(418); - $this->server->httpResponse->setHeader('testheader','testvalue'); + if ($reportName == '{http://www.rooftopsolutions.nl/NS}myreport') { + $this->server->httpResponse->setStatus(418); + $this->server->httpResponse->setHeader('testheader', 'testvalue'); return false; } else return; @@ -609,16 +446,29 @@ class ServerSimpleTest extends AbstractServer{ function testGetPropertiesForChildren() { - $result = $this->server->getPropertiesForChildren('',array( + $result = $this->server->getPropertiesForChildren('', [ '{DAV:}getcontentlength', - )); + ]); - $expected = array( - 'test.txt' => array('{DAV:}getcontentlength' => 13), - 'dir/' => array(), - ); + $expected = [ + 'test.txt' => ['{DAV:}getcontentlength' => 13], + 'dir/' => [], + ]; + + $this->assertEquals($expected, $result); + + } - $this->assertEquals($expected,$result); + /** + * There are certain cases where no HTTP status may be set. We need to + * intercept these and set it to a default error message. + */ + function testNoHTTPSTatusSet() { + + $this->server->on('method:GET', function() { return false; }, 1); + $this->server->httpRequest = new HTTP\Request('GET', '/'); + $this->server->exec(); + $this->assertEquals(500, $this->response->getStatus()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php index a73e8d13f..7fde11b22 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php @@ -17,10 +17,7 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}foo' => null, - ), + '{DAV:}foo' => 403, ); $this->assertEquals($expected, $result); @@ -33,19 +30,17 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { ); $server = new Server($tree); + $server->on('propPatch', function($path, PropPatch $propPatch) { + $propPatch->handleRemaining(function() { return true; }); + }); $result = $server->updateProperties('foo', array( '{DAV:}getetag' => 'bla', '{DAV:}foo' => 'bar' )); $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}getetag' => null, - ), - '424' => array( - '{DAV:}foo' => null, - ), + '{DAV:}getetag' => 403, + '{DAV:}foo' => 424, ); $this->assertEquals($expected, $result); @@ -57,7 +52,10 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { new SimpleCollection('foo'), ); $server = new Server($tree); - $server->subscribeEvent('updateProperties', array($this,'updatepropfail')); + $server->on('propPatch', function($path, PropPatch $propPatch) { + $propPatch->setResultCode('{DAV:}foo', 404); + $propPatch->handleRemaining(function() { return true; }); + }); $result = $server->updateProperties('foo', array( '{DAV:}foo' => 'bar', @@ -65,36 +63,29 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '404' => array( - '{DAV:}foo' => null, - ), - '424' => array( - '{DAV:}foo2' => null, - ), + '{DAV:}foo' => 404, + '{DAV:}foo2' => 424, ); $this->assertEquals($expected, $result); } - function updatePropFail(&$propertyDelta, &$result, $node) { - - $result[404] = array( - '{DAV:}foo' => null, - ); - unset($propertyDelta['{DAV:}foo']); - return false; - - } - - function testUpdatePropertiesEventSuccess() { $tree = array( new SimpleCollection('foo'), ); $server = new Server($tree); - $server->subscribeEvent('updateProperties', array($this,'updatepropsuccess')); + $server->on('propPatch', function($path, PropPatch $propPatch) { + + $propPatch->handle(['{DAV:}foo', '{DAV:}foo2'], function() { + return [ + '{DAV:}foo' => 200, + '{DAV:}foo2' => 201, + ]; + }); + + }); $result = $server->updateProperties('foo', array( '{DAV:}foo' => 'bar', @@ -102,29 +93,11 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '200' => array( - '{DAV:}foo' => null, - ), - '201' => array( - '{DAV:}foo2' => null, - ), + '{DAV:}foo' => 200, + '{DAV:}foo2' => 201, ); $this->assertEquals($expected, $result); } - function updatePropSuccess(&$propertyDelta, &$result, $node) { - - $result[200] = array( - '{DAV:}foo' => null, - ); - $result[201] = array( - '{DAV:}foo2' => null, - ); - unset($propertyDelta['{DAV:}foo']); - unset($propertyDelta['{DAV:}foo2']); - return; - - } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php index de8b05734..9b083b998 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php @@ -10,8 +10,8 @@ class SimpleFileTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals('contents', $file->get()); - $this->assertEquals('8', $file->getSize()); - $this->assertEquals('"' . md5('contents') . '"', $file->getETag()); + $this->assertEquals(8, $file->getSize()); + $this->assertEquals('"' . sha1('contents') . '"', $file->getETag()); $this->assertEquals('text/plain', $file->getContentType()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php index d136eeb17..7122f4a01 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php @@ -16,19 +16,14 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutNormal() { - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('0', $this->response->headers['Content-Length']); + $this->assertEquals(201, $this->response->status); + $this->assertEquals('0', $this->response->getHeader('Content-Length')); $this->assertEquals('Testing new file',file_get_contents(SABRE_TEMPDIR . '/testput.txt')); @@ -37,21 +32,16 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutTemp() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.'); @@ -60,70 +50,54 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutTempIfNoneMatch() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); + $request = new HTTP\Request('PUT', '/._testput.txt', ['If-None-Match' => '*'], 'Testing new file'); + $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.'); $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); } function testPutGet() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'GET', - ); + $request = new HTTP\Request('GET', '/._testput.txt'); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Length' => 16, - 'Content-Type' => 'application/octet-stream', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Length' => [16], + 'Content-Type' => ['application/octet-stream'], + ),$this->response->getHeaders()); $this->assertEquals('Testing new file',stream_get_contents($this->response->body)); @@ -132,18 +106,12 @@ class TemporaryFileFilterTest extends AbstractServer { function testLockNonExistant() { mkdir(SABRE_TEMPDIR . '/locksdir'); - $locksBackend = new Locks\Backend\FS(SABRE_TEMPDIR . '/locksdir'); + $locksBackend = new Locks\Backend\File(SABRE_TEMPDIR . '/locks'); $locksPlugin = new Locks\Plugin($locksBackend); $this->server->addPlugin($locksPlugin); // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testlock.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); - + $request = new HTTP\Request('LOCK', '/._testput.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -156,10 +124,10 @@ class TemporaryFileFilterTest extends AbstractServer { $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $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('true',$this->response->headers['X-Sabre-Temp']); + $this->assertEquals(201, $this->response->status); + $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('true',$this->response->getHeader('X-Sabre-Temp')); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testlock.txt'),'._testlock.txt should not exist in the regular file structure.'); @@ -168,35 +136,25 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutDelete() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); - - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'DELETE', - ); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('DELETE', '/._testput.txt'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status, "Incorrect status code received. Full body:\n". $this->response->body); + $this->assertEquals(204, $this->response->status, "Incorrect status code received. Full body:\n". $this->response->body); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertEquals('',$this->response->body); @@ -205,37 +163,26 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutPropfind() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PROPFIND', - ); + $request = new HTTP\Request('PROPFIND', '/._testput.txt'); - $request = new HTTP\Request($serverVars); - $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Incorrect status code returned. Body: ' . $this->response->body); + $this->assertEquals(207, $this->response->status,'Incorrect status code returned. Body: ' . $this->response->body); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); $xml = simplexml_load_string($body); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php index 9cf5edbb0..bb5ea6acc 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php @@ -2,31 +2,35 @@ namespace Sabre\DAV; +use + Sabre\HTTP\RequestInterface, + Sabre\HTTP\ResponseInterface; + class TestPlugin extends ServerPlugin { public $beforeMethod; function getFeatures() { - return array('drinking'); + return ['drinking']; } function getHTTPMethods($uri) { - return array('BEER','WINE'); + return ['BEER','WINE']; } function initialize(Server $server) { - $server->subscribeEvent('beforeMethod',array($this,'beforeMethod')); + $server->on('beforeMethod', [$this,'beforeMethod']); } - function beforeMethod($method) { + function beforeMethod(RequestInterface $request, ResponseInterface $response) { - $this->beforeMethod = $method; + $this->beforeMethod = $request->getMethod(); return true; } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php deleted file mode 100644 index 19b08460f..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -namespace Sabre\DAV\Tree; - -use Sabre\DAV; - -/** - * @covers Sabre\DAV\Tree - * @covers Sabre\DAV\Tree\Filesystem - * @covers Sabre\DAV\FS\Node - * @covers Sabre\DAV\FS\File - * @covers Sabre\DAV\FS\Directory - */ -class FilesystemTest extends \PHPUnit_Framework_TestCase { - - function setUp() { - - \Sabre\TestUtil::clearTempDir(); - file_put_contents(SABRE_TEMPDIR. '/file.txt','Body'); - mkdir(SABRE_TEMPDIR.'/dir'); - file_put_contents(SABRE_TEMPDIR.'/dir/subfile.txt','Body'); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testGetNodeForPath_File() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('file.txt'); - $this->assertTrue($node instanceof DAV\FS\File); - - } - - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ - function testGetNodeForPath_DoesntExist() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('whoop/file.txt'); - - } - - function testGetNodeForPath_Directory() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('dir'); - $this->assertTrue($node instanceof DAV\FS\Directory); - $this->assertEquals('dir', $node->getName()); - $this->assertInternalType('array', $node->getChildren()); - - } - - function testCopy() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->copy('file.txt','file2.txt'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/file2.txt')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/file2.txt')); - - } - - function testCopyDir() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->copy('dir','dir2'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir2')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/dir2/subfile.txt')); - - } - - function testMove() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->move('file.txt','file2.txt'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/file2.txt')); - $this->assertTrue(!file_exists(SABRE_TEMPDIR . '/file.txt')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/file2.txt')); - - } - - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php index 90df6427e..9516c2390 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php @@ -2,9 +2,6 @@ namespace Sabre\DAV; -/** - * @covers \Sabre\DAV\Tree - */ class TreeTest extends \PHPUnit_Framework_TestCase { function testNodeExists() { @@ -59,11 +56,31 @@ class TreeTest extends \PHPUnit_Framework_TestCase { $tree = new TreeMock(); $children = $tree->getChildren(''); - $this->assertEquals(1,count($children)); + $this->assertEquals(2,count($children)); $this->assertEquals('hi', $children[0]->getName()); } + function testGetMultipleNodes() { + + $tree = new TreeMock(); + $result = $tree->getMultipleNodes(['hi/sub', 'hi/file']); + $this->assertArrayHasKey('hi/sub', $result); + $this->assertArrayHasKey('hi/file', $result); + + $this->assertEquals('sub', $result['hi/sub']->getName()); + $this->assertEquals('file', $result['hi/file']->getName()); + + } + function testGetMultipleNodes2() { + + $tree = new TreeMock(); + $result = $tree->getMultipleNodes(['multi/1', 'multi/2']); + $this->assertArrayHasKey('multi/1', $result); + $this->assertArrayHasKey('multi/2', $result); + + } + } class TreeMock extends Tree { @@ -72,19 +89,23 @@ class TreeMock extends Tree { function __construct() { - $this->nodes['hi/sub'] = new TreeDirectoryTester('sub'); - $this->nodes['hi/file'] = new TreeFileTester('file'); - $this->nodes['hi/file']->properties = array('test1' => 'value'); - $this->nodes['hi/file']->data = 'foobar'; - $this->nodes['hi'] = new TreeDirectoryTester('hi',array($this->nodes['hi/sub'], $this->nodes['hi/file'])); - $this->nodes[''] = new TreeDirectoryTester('hi', array($this->nodes['hi'])); - - } - - function getNodeForPath($path) { + $file = new TreeFileTester('file'); + $file->properties = ['test1'=>'value']; + $file->data = 'foobar'; - if (isset($this->nodes[$path])) return $this->nodes[$path]; - throw new Exception\NotFound('item not found'); + parent::__construct( + new TreeDirectoryTester('root', [ + new TreeDirectoryTester('hi', [ + new TreeDirectoryTester('sub'), + $file, + ]), + new TreeMultiGetTester('multi', [ + new TreeFileTester('1'), + new TreeFileTester('2'), + new TreeFileTester('3'), + ]) + ]) + ); } @@ -117,6 +138,12 @@ class TreeDirectoryTester extends SimpleCollection { } + function childExists($name) { + + return !!$this->getChild($name); + + } + function delete() { $this->isDeleted = true; @@ -164,12 +191,51 @@ class TreeFileTester extends File implements IProperties { } - function updateProperties($properties) { + /** + * Updates properties on this node. + * + * This method received a PropPatch object, which contains all the + * information about the update. + * + * To update specific properties, call the 'handle' method on this object. + * Read the PropPatch documentation for more information. + * + * @param array $mutations + * @return bool|array + */ + function propPatch(PropPatch $propPatch) { - $this->properties = $properties; - return true; + $this->properties = $propPatch->getMutations(); + $propPatch->setRemainingResultCode(200); } } +class TreeMultiGetTester extends TreeDirectoryTester implements IMultiGet { + + /** + * This method receives a list of paths in it's first argument. + * It must return an array with Node objects. + * + * If any children are not found, you do not have to return them. + * + * @return array + */ + function getMultipleChildren(array $paths) { + + $result = []; + foreach($paths as $path) { + try { + $child = $this->getChild($path); + $result[] = $child; + } catch (Exception\NotFound $e) { + // Do nothing + } + } + + return $result; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php deleted file mode 100644 index 5d1380865..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php - -namespace Sabre\DAV; - -class URLUtilTest extends \PHPUnit_Framework_TestCase{ - - function testEncodePath() { - - $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); - - $newStr = URLUtil::encodePath($str); - - $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-./'. - '0123456789:%3b%3c%3d%3e%3f'. - '%40ABCDEFGHIJKLMNO' . - 'PQRSTUVWXYZ%5b%5c%5d%5e_' . - '%60abcdefghijklmno' . - 'pqrstuvwxyz%7b%7c%7d~%7f', - $newStr); - - $this->assertEquals($str,URLUtil::decodePath($newStr)); - - } - - function testEncodePathSegment() { - - $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); - - $newStr = URLUtil::encodePathSegment($str); - - // Note: almost exactly the same as the last test, with the - // exception of the encoding of / (ascii code 2f) - $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f'. - '0123456789:%3b%3c%3d%3e%3f'. - '%40ABCDEFGHIJKLMNO' . - 'PQRSTUVWXYZ%5b%5c%5d%5e_' . - '%60abcdefghijklmno' . - 'pqrstuvwxyz%7b%7c%7d~%7f', - $newStr); - - $this->assertEquals($str,URLUtil::decodePathSegment($newStr)); - - } - - function testDecode() { - - $str = 'Hello%20Test+Test2.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals('Hello Test+Test2.txt',$newStr); - - } - - /** - * @depends testDecode - */ - function testDecodeUmlaut() { - - $str = 'Hello%C3%BC.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); - - } - - /** - * @depends testDecodeUmlaut - */ - function testDecodeUmlautLatin1() { - - $str = 'Hello%FC.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); - - } - - /** - * This testcase was sent by a bug reporter - * - * @depends testDecode - */ - function testDecodeAccentsWindows7() { - - $str = '/webdav/%C3%A0fo%C3%B3'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals(strtolower($str),URLUtil::encodePath($newStr)); - - } - - function testSplitPath() { - - $strings = array( - - // input // expected result - '/foo/bar' => array('/foo','bar'), - '/foo/bar/' => array('/foo','bar'), - 'foo/bar/' => array('foo','bar'), - 'foo/bar' => array('foo','bar'), - 'foo/bar/baz' => array('foo/bar','baz'), - 'foo/bar/baz/' => array('foo/bar','baz'), - 'foo' => array('','foo'), - 'foo/' => array('','foo'), - '/foo/' => array('','foo'), - '/foo' => array('','foo'), - '' => array(null,null), - - // UTF-8 - "/\xC3\xA0fo\xC3\xB3/bar" => array("/\xC3\xA0fo\xC3\xB3",'bar'), - "/\xC3\xA0foo/b\xC3\xBCr/" => array("/\xC3\xA0foo","b\xC3\xBCr"), - "foo/\xC3\xA0\xC3\xBCr" => array("foo","\xC3\xA0\xC3\xBCr"), - - ); - - foreach($strings as $input => $expected) { - - $output = URLUtil::splitPath($input); - $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect'); - - - } - - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php deleted file mode 100644 index 1d2bfd133..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php +++ /dev/null @@ -1,284 +0,0 @@ -<?php - -namespace Sabre\DAV; - -class XMLUtilTest extends \PHPUnit_Framework_TestCase { - - function testToClarkNotation() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><test1 xmlns="http://www.example.org/">Testdoc</test1>'); - - $this->assertEquals( - '{http://www.example.org/}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotation2() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="http://www.example.org/">Testdoc</s:test1>'); - - $this->assertEquals( - '{http://www.example.org/}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotationDAVNamespace() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>'); - - $this->assertEquals( - '{DAV:}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotationNoElem() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>'); - - $this->assertNull( - XMLUtil::toClarkNotation($dom->firstChild->firstChild) - ); - - } - - function testConvertDAVNamespace() { - - $xml='<?xml version="1.0"?><document xmlns="DAV:">blablabla</document>'; - $this->assertEquals( - '<?xml version="1.0"?><document xmlns="urn:DAV">blablabla</document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace2() { - - $xml='<?xml version="1.0"?><s:document xmlns:s="DAV:">blablabla</s:document>'; - $this->assertEquals( - '<?xml version="1.0"?><s:document xmlns:s="urn:DAV">blablabla</s:document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace3() { - - $xml='<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="DAV:" xmlns:z="http://othernamespace">blablabla</s:document>'; - $this->assertEquals( - '<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="urn:DAV" xmlns:z="http://othernamespace">blablabla</s:document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace4() { - - $xml='<?xml version="1.0"?><document xmlns=\'DAV:\'>blablabla</document>'; - $this->assertEquals( - '<?xml version="1.0"?><document xmlns=\'urn:DAV\'>blablabla</document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespaceMixedQuotes() { - - $xml='<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>'; - $this->assertEquals( - $xml, - XMLUtil::convertDAVNamespace($xml) - ); - - } - - /** - * @depends testConvertDAVNamespace - */ - function testLoadDOMDocument() { - - $xml='<?xml version="1.0"?><document></document>'; - $dom = XMLUtil::loadDOMDocument($xml); - $this->assertTrue($dom instanceof \DOMDocument); - - } - - /** - * @depends testLoadDOMDocument - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testLoadDOMDocumentEmpty() { - - XMLUtil::loadDOMDocument(''); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - * @depends testConvertDAVNamespace - */ - function testLoadDOMDocumentInvalid() { - - $xml='<?xml version="1.0"?><document></docu'; - $dom = XMLUtil::loadDOMDocument($xml); - - } - - /** - * @depends testLoadDOMDocument - */ - function testLoadDOMDocumentUTF16() { - - $xml='<?xml version="1.0" encoding="UTF-16"?><root xmlns="DAV:">blabla</root>'; - $xml = iconv('UTF-8','UTF-16LE',$xml); - $dom = XMLUtil::loadDOMDocument($xml); - $this->assertEquals('blabla',$dom->firstChild->nodeValue); - - } - - - function testParseProperties() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - ), $properties); - - - - } - - /** - * @depends testParseProperties - */ - function testParsePropertiesEmpty() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:" xmlns:s="http://www.rooftopsolutions.nl/example"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <s:example /> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{http://www.rooftopsolutions.nl/example}example' => null - ), $properties); - - } - - - /** - * @depends testParseProperties - */ - function testParsePropertiesComplex() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <someprop>Complex value <b>right here</b></someprop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{DAV:}someprop' => 'Complex value right here', - ), $properties); - - } - - - /** - * @depends testParseProperties - */ - function testParsePropertiesNoProperties() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array(), $properties); - - } - - function testParsePropertiesMapHref() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <someprop><href>http://sabredav.org/</href></someprop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild,array('{DAV:}someprop'=>'Sabre\\DAV\\Property\\Href')); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{DAV:}someprop' => new Property\Href('http://sabredav.org/',false), - ), $properties); - - } - - function testParseClarkNotation() { - - $this->assertEquals(array( - 'DAV:', - 'foo', - ), XMLUtil::parseClarkNotation('{DAV:}foo')); - - $this->assertEquals(array( - 'http://example.org/ns/bla', - 'bar-soap', - ), XMLUtil::parseClarkNotation('{http://example.org/ns/bla}bar-soap')); - } - - /** - * @expectedException InvalidArgumentException - */ - function testParseClarkNotationFail() { - - XMLUtil::parseClarkNotation('}foo'); - - } - -} - |