From b35122f7a6ad42756c35bb60ba1f06c3dcd45c77 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 21 Oct 2013 15:46:31 -0700 Subject: add sabre (1.8.x) via composer in the !@#$ place it wants to be --- .../sabre/dav/tests/Sabre/DAV/AbstractServer.php | 64 ++ .../Sabre/DAV/Auth/Backend/AbstractBasicTest.php | 91 ++ .../Sabre/DAV/Auth/Backend/AbstractDigestTest.php | 149 ++++ .../Sabre/DAV/Auth/Backend/AbstractPDOTest.php | 35 + .../tests/Sabre/DAV/Auth/Backend/ApacheTest.php | 45 + .../dav/tests/Sabre/DAV/Auth/Backend/FileTest.php | 42 + .../dav/tests/Sabre/DAV/Auth/Backend/Mock.php | 37 + .../tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php | 31 + .../tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php | 28 + .../sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php | 84 ++ vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php | 234 +++++ .../Sabre/DAV/Browser/GuessContentTypeTest.php | 68 ++ .../Sabre/DAV/Browser/MapGetToPropFindTest.php | 44 + .../dav/tests/Sabre/DAV/Browser/PluginTest.php | 114 +++ vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php | 32 + vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php | 949 ++++++++++++++++++++ .../dav/tests/Sabre/DAV/Exception/LockedTest.php | 68 ++ .../Sabre/DAV/Exception/PaymentRequiredTest.php | 14 + vendor/sabre/dav/tests/Sabre/DAV/ExceptionTest.php | 30 + .../sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php | 95 ++ .../sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php | 178 ++++ .../sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php | 224 +++++ .../dav/tests/Sabre/DAV/HTTPPreferParsingTest.php | 200 +++++ vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php | 105 +++ .../tests/Sabre/DAV/Locks/Backend/AbstractTest.php | 196 +++++ .../dav/tests/Sabre/DAV/Locks/Backend/FSTest.php | 31 + .../dav/tests/Sabre/DAV/Locks/Backend/FileTest.php | 24 + .../tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php | 32 + .../dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php | 29 + .../tests/Sabre/DAV/Locks/GetIfConditionsTest.php | 375 ++++++++ .../sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php | 123 +++ .../sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php | 966 +++++++++++++++++++++ .../sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php | 58 ++ .../sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php | 100 +++ .../dav/tests/Sabre/DAV/PartialUpdate/FileMock.php | 79 ++ .../tests/Sabre/DAV/PartialUpdate/PluginTest.php | 130 +++ .../Sabre/DAV/Property/GetLastModifiedTest.php | 75 ++ .../dav/tests/Sabre/DAV/Property/HrefListTest.php | 91 ++ .../dav/tests/Sabre/DAV/Property/HrefTest.php | 119 +++ .../tests/Sabre/DAV/Property/ResourceTypeTest.php | 111 +++ .../tests/Sabre/DAV/Property/ResponseListTest.php | 19 + .../dav/tests/Sabre/DAV/Property/ResponseTest.php | 230 +++++ .../Sabre/DAV/Property/SupportedReportSetTest.php | 128 +++ .../dav/tests/Sabre/DAV/ServerCopyMoveTest.php | 268 ++++++ .../sabre/dav/tests/Sabre/DAV/ServerEventsTest.php | 76 ++ .../dav/tests/Sabre/DAV/ServerFinderBlockTest.php | 53 ++ .../sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php | 371 ++++++++ .../sabre/dav/tests/Sabre/DAV/ServerPluginTest.php | 98 +++ .../dav/tests/Sabre/DAV/ServerPreconditionTest.php | 395 +++++++++ .../sabre/dav/tests/Sabre/DAV/ServerPropsTest.php | 413 +++++++++ .../sabre/dav/tests/Sabre/DAV/ServerRangeTest.php | 274 ++++++ .../sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php | 767 ++++++++++++++++ .../tests/Sabre/DAV/ServerUpdatePropertiesTest.php | 130 +++ .../sabre/dav/tests/Sabre/DAV/SimpleFileTest.php | 19 + .../sabre/dav/tests/Sabre/DAV/StringUtilTest.php | 122 +++ .../tests/Sabre/DAV/TemporaryFileFilterTest.php | 252 ++++++ vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php | 34 + .../dav/tests/Sabre/DAV/Tree/FilesystemTest.php | 88 ++ vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php | 175 ++++ vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php | 131 +++ vendor/sabre/dav/tests/Sabre/DAV/UUIDUtilTest.php | 25 + vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php | 284 ++++++ 62 files changed, 9852 insertions(+) create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractPDOTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Exception/LockedTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Exception/PaymentRequiredTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ExceptionTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/StringUtilTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/UUIDUtilTest.php create mode 100644 vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php (limited to 'vendor/sabre/dav/tests/Sabre/DAV') diff --git a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php new file mode 100644 index 000000000..357675686 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php @@ -0,0 +1,64 @@ +response = new HTTP\ResponseMock(); + $this->server = new Server($this->getRootNode()); + $this->server->httpResponse = $this->response; + $this->server->debugExceptions = true; + file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents'); + mkdir(SABRE_TEMPDIR . '/dir'); + file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents'); + + + } + + function tearDown() { + + $this->deleteTree(SABRE_TEMPDIR,false); + + } + + protected function getRootNode() { + + return new FS\Directory(SABRE_TEMPDIR); + + } + + private function deleteTree($path,$deleteRoot = true) { + + foreach(scandir($path) as $node) { + + if ($node=='.' || $node=='.svn' || $node=='..') continue; + $myPath = $path.'/'. $node; + if (is_file($myPath)) { + unlink($myPath); + } else { + $this->deleteTree($myPath); + } + + } + if ($deleteRoot) rmdir($path); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php new file mode 100644 index 000000000..36d23c5c0 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php @@ -0,0 +1,91 @@ +httpResponse = $response; + + $backend = new AbstractBasicMock(); + $backend->authenticate($server,'myRealm'); + + } + + /** + * @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; + + $request = new HTTP\Request(array( + 'PHP_AUTH_USER' => 'username', + 'PHP_AUTH_PW' => 'wrongpassword', + )); + $server->httpRequest = $request; + + $backend = new AbstractBasicMock(); + $backend->authenticate($server,'myRealm'); + + } + + public function testAuthenticate() { + + $response = new HTTP\ResponseMock(); + $tree = new DAV\ObjectTree(new DAV\SimpleCollection('bla')); + $server = new DAV\Server($tree); + $server->httpResponse = $response; + + $request = new HTTP\Request(array( + 'PHP_AUTH_USER' => 'username', + 'PHP_AUTH_PW' => 'password', + )); + $server->httpRequest = $request; + + $backend = new AbstractBasicMock(); + $this->assertTrue($backend->authenticate($server,'myRealm')); + + $result = $backend->getCurrentUser(); + + $this->assertEquals('username', $result); + + } + + +} + + +class AbstractBasicMock extends AbstractBasic { + + /** + * Validates a username and password + * + * This method should return true or false depending on if login + * succeeded. + * + * @param string $username + * @param string $password + * @return bool + */ + function validateUserPass($username, $password) { + + return ($username == 'username' && $password == 'password'); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php new file mode 100644 index 000000000..495690c4e --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php @@ -0,0 +1,149 @@ +httpResponse = $response; + + $backend = new AbstractDigestMock(); + $backend->authenticate($server,'myRealm'); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + public function testAuthenticateBadGetUserInfoResponse() { + + $response = new HTTP\ResponseMock(); + $server = new DAV\Server(); + $server->httpResponse = $response; + + $header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; + $request = new HTTP\Request(array( + 'PHP_AUTH_DIGEST' => $header, + )); + $server->httpRequest = $request; + + $backend = new AbstractDigestMock(); + $backend->authenticate($server,'myRealm'); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + public function testAuthenticateBadGetUserInfoResponse2() { + + $response = new HTTP\ResponseMock(); + $server = new DAV\Server(); + $server->httpResponse = $response; + + $header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; + $request = new HTTP\Request(array( + 'PHP_AUTH_DIGEST' => $header, + )); + $server->httpRequest = $request; + + $backend = new AbstractDigestMock(); + $backend->authenticate($server,'myRealm'); + + } + + /** + * @expectedException Sabre\DAV\Exception\NotAuthenticated + */ + public function testAuthenticateUnknownUser() { + + $response = new HTTP\ResponseMock(); + $server = new DAV\Server(); + $server->httpResponse = $response; + + $header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; + $request = new HTTP\Request(array( + 'PHP_AUTH_DIGEST' => $header, + )); + $server->httpRequest = $request; + + $backend = new AbstractDigestMock(); + $backend->authenticate($server,'myRealm'); + + } + + /** + * @expectedException Sabre\DAV\Exception\NotAuthenticated + */ + public function testAuthenticateBadPassword() { + + $response = new HTTP\ResponseMock(); + $server = new DAV\Server(); + $server->httpResponse = $response; + + $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; + $request = new HTTP\Request(array( + 'PHP_AUTH_DIGEST' => $header, + 'REQUEST_METHOD' => 'PUT', + )); + $server->httpRequest = $request; + + $backend = new AbstractDigestMock(); + $backend->authenticate($server,'myRealm'); + + } + + public function testAuthenticate() { + + $response = new HTTP\ResponseMock(); + $server = new DAV\Server(); + $server->httpResponse = $response; + + $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_METHOD' => 'GET', + 'PHP_AUTH_DIGEST' => $header, + 'REQUEST_URI' => '/', + )); + $server->httpRequest = $request; + + $backend = new AbstractDigestMock(); + $this->assertTrue($backend->authenticate($server,'myRealm')); + + $result = $backend->getCurrentUser(); + + $this->assertEquals('user', $result); + $this->assertEquals('HELLO', $backend->getDigestHash('myRealm', $result)); + + } + + +} + + +class AbstractDigestMock extends AbstractDigest { + + function getDigestHash($realm, $userName) { + + switch($userName) { + case 'null' : return null; + case 'false' : return false; + case 'array' : return array(); + case 'user' : return 'HELLO'; + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractPDOTest.php new file mode 100644 index 000000000..d22923d51 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractPDOTest.php @@ -0,0 +1,35 @@ +getPDO(); + $backend = new PDO($pdo); + $this->assertTrue($backend instanceof PDO); + + } + + /** + * @depends testConstruct + */ + function testUserInfo() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + + $this->assertNull($backend->getDigestHash('realm','blabla')); + + $expected = 'hash'; + + $this->assertEquals($expected, $backend->getDigestHash('realm','user')); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php new file mode 100644 index 000000000..b1ed555d4 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php @@ -0,0 +1,45 @@ +authenticate($server,'Realm'); + + } + + function testRemoteUser() { + + $backend = new Apache(); + + $server = new DAV\Server(); + $request = new HTTP\Request(array( + 'REMOTE_USER' => 'username', + )); + $server->httpRequest = $request; + + $this->assertTrue($backend->authenticate($server, 'Realm')); + + $userInfo = 'username'; + + $this->assertEquals($userInfo, $backend->getCurrentUser()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php new file mode 100644 index 000000000..72f150ab6 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php @@ -0,0 +1,42 @@ +assertTrue($file instanceof File); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + function testLoadFileBroken() { + + file_put_contents(SABRE_TEMPDIR . '/backend','user:realm:hash'); + $file = new File(); + $file->loadFile(SABRE_TEMPDIR .'/backend'); + + } + + function testLoadFile() { + + file_put_contents(SABRE_TEMPDIR . '/backend','user:realm:' . md5('user:realm:password')); + $file = new File(); + $file->loadFile(SABRE_TEMPDIR . '/backend'); + + $this->assertFalse($file->getDigestHash('realm','blabla')); + $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 new file mode 100644 index 000000000..fdad8a605 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php @@ -0,0 +1,37 @@ +currentUser = $this->defaultUser; + + } + + function setCurrentUser($user) { + + $this->currentUser = $user; + + } + + function getCurrentUser() { + + return $this->currentUser; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php new file mode 100644 index 000000000..ede432de2 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php @@ -0,0 +1,31 @@ +markTestSkipped('MySQL driver is not available, or not properly configured'); + $pdo = \Sabre\TestUtil::getMySQLDB(); + if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); + $pdo->query("DROP TABLE IF EXISTS users"); + $pdo->query(" +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) +);"); + + $pdo->query("INSERT INTO users (username,digesta1,email,displayname) VALUES ('user','hash','user@example.org','User')"); + + return $pdo; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php new file mode 100644 index 000000000..abfb031bb --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php @@ -0,0 +1,28 @@ +markTestSkipped('SQLite driver is not available'); + $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); + $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); + $pdo->query('CREATE TABLE users (username TEXT, digesta1 TEXT, email VARCHAR(80), displayname VARCHAR(80))'); + $pdo->query('INSERT INTO users VALUES ("user","hash","user@example.org","User")'); + + return $pdo; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php new file mode 100644 index 000000000..2096a04d7 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php @@ -0,0 +1,84 @@ +assertTrue($plugin instanceof Plugin); + $fakeServer->addPlugin($plugin); + $this->assertEquals($plugin, $fakeServer->getPlugin('auth')); + + } + + /** + * @depends testInit + */ + function testAuthenticate() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock(),'realm'); + $fakeServer->addPlugin($plugin); + $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + + } + + + + /** + * @depends testInit + * @expectedException Sabre\DAV\Exception\NotAuthenticated + */ + function testAuthenticateFail() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock(),'failme'); + $fakeServer->addPlugin($plugin); + $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + + } + + function testReportPassThrough() { + + $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock(),'realm'); + $fakeServer->addPlugin($plugin); + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'REQUEST_URI' => '/', + )); + $request->setBody(''); + + $fakeServer->httpRequest = $request; + $fakeServer->httpResponse = new HTTP\ResponseMock(); + $fakeServer->exec(); + + $this->assertEquals('HTTP/1.1 403 Forbidden', $fakeServer->httpResponse->status); + + } + + /** + * @depends testInit + */ + function testGetCurrentUserPrincipal() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock(),'realm'); + $fakeServer->addPlugin($plugin); + $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $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 new file mode 100644 index 000000000..fdc2403db --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php @@ -0,0 +1,234 @@ +put('hi'); + + } + + /** + * @expectedException Sabre\DAV\Exception\Forbidden + */ + public function testGet() { + + $file = new FileMock(); + $file->get(); + + } + + public function testGetSize() { + + $file = new FileMock(); + $this->assertEquals(0,$file->getSize()); + + } + + + public function testGetETag() { + + $file = new FileMock(); + $this->assertNull($file->getETag()); + + } + + public function testGetContentType() { + + $file = new FileMock(); + $this->assertNull($file->getContentType()); + + } + + /** + * @expectedException Sabre\DAV\Exception\Forbidden + */ + public function testDelete() { + + $file = new FileMock(); + $file->delete(); + + } + + /** + * @expectedException Sabre\DAV\Exception\Forbidden + */ + public function testSetName() { + + $file = new FileMock(); + $file->setName('hi'); + + } + + public function testGetLastModified() { + + $file = new FileMock(); + // checking if lastmod is within the range of a few seconds + $lastMod = $file->getLastModified(); + $compareTime = ($lastMod + 1)-time(); + $this->assertTrue($compareTime < 3); + + } + + public function testGetChild() { + + $dir = new DirectoryMock(); + $file = $dir->getChild('mockfile'); + $this->assertTrue($file instanceof FileMock); + + } + + public function testChildExists() { + + $dir = new DirectoryMock(); + $this->assertTrue($dir->childExists('mockfile')); + + } + + public function testChildExistsFalse() { + + $dir = new DirectoryMock(); + $this->assertFalse($dir->childExists('mockfile2')); + + } + + /** + * @expectedException Sabre\DAV\Exception\NotFound + */ + public function testGetChild404() { + + $dir = new DirectoryMock(); + $file = $dir->getChild('blabla'); + + } + + /** + * @expectedException Sabre\DAV\Exception\Forbidden + */ + public function testCreateFile() { + + $dir = new DirectoryMock(); + $dir->createFile('hello','data'); + + } + + /** + * @expectedException Sabre\DAV\Exception\Forbidden + */ + public function testCreateDirectory() { + + $dir = new DirectoryMock(); + $dir->createDirectory('hello'); + + } + + public function testSimpleDirectoryConstruct() { + + $dir = new SimpleCollection('simpledir',array()); + + } + + /** + * @depends testSimpleDirectoryConstruct + */ + public function testSimpleDirectoryConstructChild() { + + $file = new FileMock(); + $dir = new SimpleCollection('simpledir',array($file)); + $file2 = $dir->getChild('mockfile'); + + $this->assertEquals($file,$file2); + + } + + /** + * @expectedException Sabre\DAV\Exception + * @depends testSimpleDirectoryConstruct + */ + public function testSimpleDirectoryBadParam() { + + $dir = new SimpleCollection('simpledir',array('string shouldn\'t be here')); + + } + + /** + * @depends testSimpleDirectoryConstruct + */ + public function testSimpleDirectoryAddChild() { + + $file = new FileMock(); + $dir = new SimpleCollection('simpledir'); + $dir->addChild($file); + $file2 = $dir->getChild('mockfile'); + + $this->assertEquals($file,$file2); + + } + + /** + * @depends testSimpleDirectoryConstruct + * @depends testSimpleDirectoryAddChild + */ + public function testSimpleDirectoryGetChildren() { + + $file = new FileMock(); + $dir = new SimpleCollection('simpledir'); + $dir->addChild($file); + + $this->assertEquals(array($file),$dir->getChildren()); + + } + + /* + * @depends testSimpleDirectoryConstruct + */ + public function testSimpleDirectoryGetName() { + + $dir = new SimpleCollection('simpledir'); + $this->assertEquals('simpledir',$dir->getName()); + + } + + /** + * @depends testSimpleDirectoryConstruct + * @expectedException Sabre\DAV\Exception\NotFound + */ + public function testSimpleDirectoryGetChild404() { + + $dir = new SimpleCollection('simpledir'); + $dir->getChild('blabla'); + + } +} + +class DirectoryMock extends Collection { + + function getName() { + + return 'mockdir'; + + } + + function getChildren() { + + return array(new FileMock()); + + } + +} + +class FileMock extends File { + + function getName() { + + return 'mockfile'; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php new file mode 100644 index 000000000..6fc65f9e8 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php @@ -0,0 +1,68 @@ +server->getPropertiesForPath('/somefile.jpg',$properties); + $this->assertArrayHasKey(0,$result); + $this->assertArrayHasKey(404,$result[0]); + $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][404]); + + } + + /** + * @depends testGetProperties + */ + function testGetPropertiesPluginEnabled() { + + $this->server->addPlugin(new GuessContentType()); + $properties = array( + '{DAV:}getcontenttype', + ); + $result = $this->server->getPropertiesForPath('/somefile.jpg',$properties); + $this->assertArrayHasKey(0,$result); + $this->assertArrayHasKey(200,$result[0]); + $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][200]); + $this->assertEquals('image/jpeg',$result[0][200]['{DAV:}getcontenttype']); + + } + + /** + * @depends testGetPropertiesPluginEnabled + */ + function testGetPropertiesUnknown() { + + $this->server->addPlugin(new GuessContentType()); + $properties = array( + '{DAV:}getcontenttype', + ); + $result = $this->server->getPropertiesForPath('/somefile.hoi',$properties); + $this->assertArrayHasKey(0,$result); + $this->assertArrayHasKey(404,$result[0]); + $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][404]); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php new file mode 100644 index 000000000..169675e7e --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php @@ -0,0 +1,44 @@ +server->addPlugin(new MapGetToPropFind()); + + } + + function testCollectionGet() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'GET', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + 'DAV' => '1, 3, extended-mkcol', + 'Vary' => 'Brief,Prefer', + ), + $this->response->headers + ); + + $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 new file mode 100644 index 000000000..c3c4bdebb --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php @@ -0,0 +1,114 @@ +server->addPlugin(new Plugin()); + + } + + function testCollectionGet() { + + $serverVars = array( + 'REQUEST_URI' => '/dir', + 'REQUEST_METHOD' => 'GET', + ); + + $request = new HTTP\Request($serverVars); + $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->assertTrue(strpos($this->response->body, 'Index for dir/') !== false); + $this->assertTrue(strpos($this->response->body, '')!==false); + + } + + function testNotFound() { + + $serverVars = array( + 'REQUEST_URI' => '/random', + '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 testPostOtherContentType() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'text/xml', + ); + $request = new HTTP\Request($serverVars); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 501 Not Implemented', $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); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status); + + } + + function testPostMkCol() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', + ); + $postVars = array( + 'sabreAction' => 'mkcol', + 'name' => 'new_collection', + ); + + $request = new HTTP\Request($serverVars,$postVars); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 302 Found', $this->response->status); + $this->assertEquals(array( + 'Location' => '/', + ), $this->response->headers); + + $this->assertTrue(is_dir(SABRE_TEMPDIR . '/new_collection')); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php new file mode 100644 index 000000000..6e74e6ec0 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php @@ -0,0 +1,32 @@ +url = $url; + $this->curlSettings = $curlSettings; + return $this->response; + + } + + /** + * Just making this method public + * + * @param string $url + * @return string + */ + public function getAbsoluteUrl($url) { + + return parent::getAbsoluteUrl($url); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php new file mode 100644 index 000000000..9c3532a47 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php @@ -0,0 +1,949 @@ + '/', + )); + + } + + /** + * @expectedException InvalidArgumentException + */ + function testConstructNoBaseUri() { + + $client = new ClientMock(array()); + + } + + 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); + + $this->assertEquals(array( + 'statusCode' => 200, + 'headers' => array( + 'content-type' => 'text/plain', + ), + 'body' => 'Hello there!' + ), $result); + + + } + + + function testRequestProxy() { + + $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); + + } + + function testRequestCAInfo() { + + $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, + "" + ); + + $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); + + } + + function testRequestSslPeer() { + + $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, + "" + ); + + $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); + + } + + function testRequestAuthDigest() { + + $client = new ClientMock(array( + 'baseUri' => 'http://example.org/foo/bar/', + 'userName' => 'user', + 'password' => 'password', + 'authType' => Client::AUTH_DIGEST, + )); + + $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" + ); + + $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'); + } + + } + + function testRequestHTTPError() { + + $client = new ClientMock(array( + 'baseUri' => 'http://example.org/foo/bar/', + )); + + $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, + "" + ); + + $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'); + } + + } + + 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, + "" + ); + + $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'); + } + + } + + /** + * @dataProvider supportedHTTPCodes + */ + 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() { + + $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') + ); + + $this->assertEquals( + 'http://example.com/bar', + $client->getAbsoluteUrl('http://example.com/bar') + ); + + } + + 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, + "" + ); + + $result = $client->options(); + $this->assertEquals( + array('feature1', 'feature2'), + $result + ); + + } + + 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, + "" + ); + + $result = $client->options(); + $this->assertEquals( + array(), + $result + ); + + } + + /** + * @expectedException InvalidArgumentException + */ + 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, + "" + ); + + $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", + "", + "", + "", + " ", + " /foo/bar/", + " ", + " ", + " hello", + " ", + " HTTP/1.1 200 OK", + " ", + " ", + " ", + " ", + " ", + " HTTP/1.1 404 Not Found", + " ", + " ", + "", + ); + + $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( + '', + '', + ' ', + ' ', + ' ', + ' ', + '' + ); + $requestBody = implode("\n", $requestBody); + + $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); + + } + + /** + * This was reported in Issue 235. + * + * If no '200 Ok' properties are returned, the client will throw an + * E_NOTICE. + */ + function testPropFindNo200s() { + + $client = new ClientMock(array( + 'baseUri' => 'http://example.org/foo/bar/', + )); + + $responseBlob = array( + "HTTP/1.1 200 OK", + "", + "", + "", + " ", + " /foo/bar/", + " ", + " ", + " ", + " ", + " HTTP/1.1 404 Not Found", + " ", + " ", + "", + ); + + $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", + "", + "", + "", + " ", + " /foo/bar/", + " ", + " ", + " hello", + " world", + " ", + " HTTP/1.1 200 OK", + " ", + " ", + "", + ); + + $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( + '', + '', + ' ', + ' ', + ' ', + ' ', + '' + ); + $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( + '', + '', + '', + ' newvalue', + '', + '', + ' newvalue2', + '', + '', + ' ', + '', + '', + ' ', + '', + '' + ); + $requestBody = implode("\n", $requestBody); + + $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); + + } + + function testHEADRequest() { + + $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); + + } + + function testPUTRequest() { + + $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('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); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Exception/LockedTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Exception/LockedTest.php new file mode 100644 index 000000000..c06d6aa1f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Exception/LockedTest.php @@ -0,0 +1,68 @@ +formatOutput = true; + $root = $dom->createElement('d:root'); + + $dom->appendChild($root); + $root->setAttribute('xmlns:d','DAV:'); + + $lockInfo = new DAV\Locks\LockInfo(); + $lockInfo->uri = '/foo'; + $locked = new Locked($lockInfo); + + $locked->serialize(new DAV\Server(), $root); + + $output = $dom->saveXML(); + + $expected = ' + + + /foo + + +'; + + $this->assertEquals($expected, $output); + + } + + function testSerializeAmpersand() { + + $dom = new DOMDocument('1.0'); + $dom->formatOutput = true; + $root = $dom->createElement('d:root'); + + $dom->appendChild($root); + $root->setAttribute('xmlns:d','DAV:'); + + $lockInfo = new DAV\Locks\LockInfo(); + $lockInfo->uri = '/foo&bar'; + $locked = new Locked($lockInfo); + + $locked->serialize(new DAV\Server(), $root); + + $output = $dom->saveXML(); + + $expected = ' + + + /foo&bar + + +'; + + $this->assertEquals($expected, $output); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Exception/PaymentRequiredTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Exception/PaymentRequiredTest.php new file mode 100644 index 000000000..7142937b4 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Exception/PaymentRequiredTest.php @@ -0,0 +1,14 @@ +assertEquals(402, $ex->getHTTPCode()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ExceptionTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ExceptionTest.php new file mode 100644 index 000000000..6d6bf5668 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ExceptionTest.php @@ -0,0 +1,30 @@ +assertEquals(500,$e->getHTTPCode()); + + } + + function testExceptionStatuses() { + + $c = array( + 'Sabre\\DAV\\Exception\\NotAuthenticated' => 401, + 'Sabre\\DAV\\Exception\\InsufficientStorage' => 507, + ); + + foreach($c as $class=>$status) { + + $obj = new $class(); + $this->assertEquals($status, $obj->getHTTPCode()); + + } + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php new file mode 100644 index 000000000..265f9f1c1 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php @@ -0,0 +1,95 @@ +put('New contents'); + + $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('"' . md5('New contents') . '"', $result); + + } + + function testRange() { + + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->putRange('111',3); + + $this->assertEquals('0011100',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + + } + + function testRangeStream() { + + $stream = fopen('php://memory','r+'); + fwrite($stream, "222"); + rewind($stream); + + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->putRange($stream,3); + + $this->assertEquals('0022200',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + + } + + + function testGet() { + + $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(); + + $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); + + } + + function testGetETag() { + + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertEquals('"' . md5('Contents') . '"',$file->getETag()); + + } + + function testGetContentType() { + + $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()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php new file mode 100644 index 000000000..275075b4c --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php @@ -0,0 +1,178 @@ + '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 new file mode 100644 index 000000000..907ede40b --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php @@ -0,0 +1,224 @@ +tempDir); + + } + + 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'))), + 'ETag' => '"' .md5_file($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(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('HTTP/1.1 200 OK',$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->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('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals('', $this->response->body); + $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); + + } + + function testPutAlreadyExists() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_NONE_MATCH' => '*', + ); + + $request = new HTTP\Request($serverVars); + $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('HTTP/1.1 412 Precondition failed',$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(""); + $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('', $this->response->body); + $this->assertTrue(is_dir($this->tempDir . '/testcol')); + + } + + function testPutUpdate() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('Testing updated file'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('0', $this->response->headers['Content-Length']); + + $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals('', $this->response->body); + $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); + + } + + function testDelete() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'DELETE', + ); + + $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('', $this->response->body); + $this->assertFalse(file_exists($this->tempDir . '/test.txt')); + + } + + 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); + $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('', $this->response->body); + $this->assertFalse(file_exists($this->tempDir . '/col')); + + } + + function testOptions() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'OPTIONS', + ); + + $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'=> DAV\Version::VERSION, + ),$this->response->headers); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('', $this->response->body); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php new file mode 100644 index 000000000..45865b2a1 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php @@ -0,0 +1,200 @@ + '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()); + + } + + function testParseValue() { + + $httpRequest = new HTTP\Request(array( + '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()); + + } + + function testParseMultiple() { + + $httpRequest = new HTTP\Request(array( + '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()); + + } + + function testParseWeirdValue() { + + $httpRequest = new HTTP\Request(array( + '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()); + + } + + function testBrief() { + + $httpRequest = new HTTP\Request(array( + '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()); + + } + + /** + * propfindMinimal + * + * @return void + */ + function testpropfindMinimal() { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PROPFIND', + 'REQUEST_URI' => '/', + 'HTTP_PREFER' => 'return-minimal', + )); + $request->setBody(<< + + + + + + +BLA + ); + + $response = $this->request($request); + + $this->assertTrue(strpos($response->body, 'resourcetype')!==false); + $this->assertTrue(strpos($response->body, 'something')===false); + + } + + function testproppatchMinimal() { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PROPPATCH', + 'REQUEST_URI' => '/', + 'HTTP_PREFER' => 'return-minimal', + )); + $request->setBody(<< + + + + nope! + + + +BLA + ); + + $this->server->subscribeEvent('updateProperties', function(&$props, &$result) { + + if (isset($props['{DAV:}something'])) { + unset($props['{DAV:}something']); + $result[200]['{DAV:}something'] = null; + } + + }); + + $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); + + } + + function testproppatchMinimalError() { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PROPPATCH', + 'REQUEST_URI' => '/', + 'HTTP_PREFER' => 'return-minimal', + )); + $request->setBody(<< + + + + nope! + + + +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); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php new file mode 100644 index 000000000..c3fba4aae --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php @@ -0,0 +1,105 @@ +setBaseUri('/webdav/'); + + $serverVars = array( + 'REQUEST_URI' => '/webdav/bar', + 'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3', + 'HTTP_OVERWRITE' => 'F', + ); + + $request = new HTTP\Request($serverVars); + + $server->httpRequest = $request; + + $info = $server->getCopyAndMoveInfo(); + + $this->assertEquals('%C3%A0fo%C3%B3', urlencode($info['destination'])); + $this->assertFalse($info['destinationExists']); + $this->assertFalse($info['destinationNode']); + + } + + function testTreeMove() { + + mkdir(SABRE_TEMPDIR . '/issue33'); + $dir = new FS\Directory(SABRE_TEMPDIR . '/issue33'); + + $dir->createDirectory('bar'); + + $tree = new ObjectTree($dir); + $tree->move('bar',urldecode('%C3%A0fo%C3%B3')); + + $node = $tree->getNodeForPath(urldecode('%C3%A0fo%C3%B3')); + $this->assertEquals(urldecode('%C3%A0fo%C3%B3'),$node->getName()); + + } + + function testDirName() { + + $dirname1 = 'bar'; + $dirname2 = urlencode('%C3%A0fo%C3%B3');; + + $this->assertTrue(dirname($dirname1)==dirname($dirname2)); + + } + + /** + * @depends testTreeMove + * @depends testCopyMoveInfo + */ + function testEverything() { + + // Request object + $serverVars = array( + 'REQUEST_METHOD' => 'MOVE', + 'REQUEST_URI' => '/webdav/bar', + 'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3', + 'HTTP_OVERWRITE' => 'F', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + + $response = new HTTP\ResponseMock(); + + // Server setup + mkdir(SABRE_TEMPDIR . '/issue33'); + $dir = new FS\Directory(SABRE_TEMPDIR . '/issue33'); + + $dir->createDirectory('bar'); + + $tree = new ObjectTree($dir); + + $server = new Server($tree); + $server->setBaseUri('/webdav/'); + + $server->httpRequest = $request; + $server->httpResponse = $response; + $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/AbstractTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php new file mode 100644 index 000000000..f39e9a036 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php @@ -0,0 +1,196 @@ +getBackend(); + $this->assertInstanceOf('Sabre\\DAV\\Locks\\Backend\\AbstractBackend', $backend); + + } + + /** + * @depends testSetup + */ + function testGetLocks() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->token = 'MY-UNIQUE-TOKEN'; + $lock->uri ='someuri'; + + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri', false); + + $this->assertEquals(1,count($locks)); + $this->assertEquals('Sinterklaas',$locks[0]->owner); + $this->assertEquals('someuri',$locks[0]->uri); + + } + + /** + * @depends testGetLocks + */ + function testGetLocksParent() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->depth = DAV\Server::DEPTH_INFINITY; + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri/child', false); + + $this->assertEquals(1,count($locks)); + $this->assertEquals('Sinterklaas',$locks[0]->owner); + $this->assertEquals('someuri',$locks[0]->uri); + + } + + + /** + * @depends testGetLocks + */ + function testGetLocksParentDepth0() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->depth = 0; + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri/child', false); + + $this->assertEquals(0,count($locks)); + + } + + function testGetLocksChildren() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->depth = 0; + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri/child', $lock)); + + $locks = $backend->getLocks('someuri/child', false); + $this->assertEquals(1,count($locks)); + + $locks = $backend->getLocks('someuri', false); + $this->assertEquals(0,count($locks)); + + $locks = $backend->getLocks('someuri', true); + $this->assertEquals(1,count($locks)); + + } + + /** + * @depends testGetLocks + */ + function testLockRefresh() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri', $lock)); + /* Second time */ + + $lock->owner = 'Santa Clause'; + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri', false); + + $this->assertEquals(1,count($locks)); + + $this->assertEquals('Santa Clause',$locks[0]->owner); + $this->assertEquals('someuri',$locks[0]->uri); + + } + + /** + * @depends testGetLocks + */ + function testUnlock() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri', false); + $this->assertEquals(1,count($locks)); + + $this->assertTrue($backend->unlock('someuri',$lock)); + + $locks = $backend->getLocks('someuri', false); + $this->assertEquals(0,count($locks)); + + } + + /** + * @depends testUnlock + */ + function testUnlockUnknownToken() { + + $backend = $this->getBackend(); + + $lock = new DAV\Locks\LockInfo(); + $lock->owner = 'Sinterklaas'; + $lock->timeout = 60; + $lock->created = time(); + $lock->token = 'MY-UNIQUE-TOKEN'; + + $this->assertTrue($backend->lock('someuri', $lock)); + + $locks = $backend->getLocks('someuri', false); + $this->assertEquals(1,count($locks)); + + $lock->token = 'SOME-OTHER-TOKEN'; + $this->assertFalse($backend->unlock('someuri',$lock)); + + $locks = $backend->getLocks('someuri', false); + $this->assertEquals(1,count($locks)); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php new file mode 100644 index 000000000..651abf786 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php @@ -0,0 +1,31 @@ +markTestSkipped('MySQL driver is not available, or it was not properly configured'); + $pdo = \Sabre\TestUtil::getMySQLDB(); + if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); + $pdo->query('DROP TABLE IF EXISTS locks;'); + $pdo->query(" +CREATE TABLE locks ( + id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + owner VARCHAR(100), + timeout INTEGER UNSIGNED, + created INTEGER, + token VARCHAR(100), + scope TINYINT, + depth TINYINT, + uri text +);"); + + $backend = new PDO($pdo); + return $backend; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php new file mode 100644 index 000000000..d6336c7b2 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php @@ -0,0 +1,29 @@ +markTestSkipped('SQLite driver is not available'); + \Sabre\TestUtil::clearTempDir(); + mkdir(SABRE_TEMPDIR . '/pdolocks'); + $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/pdolocks/db.sqlite'); + $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); + $pdo->query('CREATE TABLE locks ( id integer primary key asc, owner text, timeout text, created integer, token text, scope integer, depth integer, uri text)'); + $backend = new PDO($pdo); + return $backend; + + } + + function tearDown() { + + \Sabre\TestUtil::clearTempDir(); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php new file mode 100644 index 000000000..7b2cd0db0 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php @@ -0,0 +1,375 @@ +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' => '()', + ); + + $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 )', + ); + + $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' => ' ()', + ); + + $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' => '() (Not )', + ); + + $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' => ' () (Not )', + ); + + $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' => ' () () (Not )', + ); + + $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' => ' ([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' => ' ( [etag1]) ' . + '(Not ) ([etag2]) ' . + '() (Not ) ([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 new file mode 100644 index 000000000..b3d7d447b --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php @@ -0,0 +1,123 @@ +debugExceptions = true; + $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb'); + $locksPlugin = new Plugin($locksBackend); + $server->addPlugin($locksPlugin); + + $response1 = new HTTP\ResponseMock(); + + $server->httpRequest = $this->getLockRequest(); + $server->httpResponse = $response1; + $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']; + + //sleep(10); + + $response2 = new HTTP\ResponseMock(); + + $server->httpRequest = $this->getLockRequest2(); + $server->httpResponse = $response2; + $server->exec(); + + $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status); + $this->assertTrue(isset($server->httpResponse->headers['Lock-Token'])); + + //sleep(10); + + $response3 = new HTTP\ResponseMock(); + $server->httpRequest = $this->getPutRequest($lockToken); + $server->httpResponse = $response3; + $server->exec(); + + $this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status); + + } + + function tearDown() { + + \Sabre\TestUtil::clearTempDir(); + + } + + function getLockRequest() { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'LOCK', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + )); + + $request->setBody(' + + + + + + + + PC-Vista\User + +'); + + return $request; + + } + function getLockRequest2() { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'LOCK', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/~$Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + )); + + $request->setBody(' + + + + + + + + PC-Vista\User + +'); + + return $request; + + } + + function getPutRequest($lockToken) { + + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PUT', + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + 'HTTP_IF' => 'If: ('.$lockToken.')', + )); + $request->setBody('FAKE BODY'); + return $request; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php new file mode 100644 index 000000000..a45dafdf1 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php @@ -0,0 +1,966 @@ +server->addPlugin($locksPlugin); + $this->locksPlugin = $locksPlugin; + + } + + function testGetFeatures() { + + $this->assertEquals(array(2),$this->locksPlugin->getFeatures()); + + } + + function testGetHTTPMethods() { + + $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods('')); + + } + + function testGetHTTPMethodsNoBackend() { + + $locksPlugin = new Plugin(); + $this->server->addPlugin($locksPlugin); + $this->assertEquals(array(),$locksPlugin->getHTTPMethods('')); + + } + + function testUnknownMethodPassthough() { + + $this->assertNull($this->locksPlugin->unknownMethod('BLA','/')); + + } + + function testLockNoBody() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + $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 400 Bad request',$this->response->status); + + } + + function testLock() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$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); + $xml->registerXPathNamespace('d','urn:DAV'); + + $elements = array( + '/d:prop', + '/d:prop/d:lockdiscovery', + '/d:prop/d:lockdiscovery/d:activelock', + '/d:prop/d:lockdiscovery/d:activelock/d:locktype', + '/d:prop/d:lockdiscovery/d:activelock/d:lockroot', + '/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href', + '/d:prop/d:lockdiscovery/d:activelock/d:locktype/d:write', + '/d:prop/d:lockdiscovery/d:activelock/d:lockscope', + '/d:prop/d:lockdiscovery/d:activelock/d:lockscope/d:exclusive', + '/d:prop/d:lockdiscovery/d:activelock/d:depth', + '/d:prop/d:lockdiscovery/d:activelock/d:owner', + '/d:prop/d:lockdiscovery/d:activelock/d:timeout', + '/d:prop/d:lockdiscovery/d:activelock/d:locktoken', + '/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href', + ); + + foreach($elements as $elem) { + $data = $xml->xpath($elem); + $this->assertEquals(1,count($data),'We expected 1 match for the xpath expression "' . $elem . '". ' . count($data) . ' were found. Full response body: ' . $this->response->body); + } + + $depth = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:depth'); + $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.'); + + } + + /** + * @depends testLock + */ + function testDoubleLock() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->response = new HTTP\ResponseMock(); + $this->server->httpResponse = $this->response; + + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + + $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + + } + + /** + * @depends testLock + */ + function testLockRefresh() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $lockToken = $this->response->headers['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->setBody(''); + $this->server->httpRequest = $request; + + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->body); + + } + + /** + * @depends testLock + */ + function testLockNoFile() { + + $serverVars = array( + 'REQUEST_URI' => '/notfound.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + + } + + /** + * @depends testLock + */ + function testUnlockNoToken() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'UNLOCK', + ); + + $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 400 Bad request',$this->response->status); + + } + + /** + * @depends testLock + */ + function testUnlockBadToken() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'UNLOCK', + 'HTTP_LOCK_TOKEN' => '', + ); + + $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,'Got an incorrect status code. Full response body: ' . $this->response->body); + + } + + /** + * @depends testLock + */ + function testLockPutNoToken() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $request = new HTTP\Request($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('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + + } + + /** + * @depends testLock + */ + function testUnlock() { + + $request = new HTTP\Request(array()); + $this->server->httpRequest = $request; + + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->invokeMethod('LOCK','test.txt'); + $lockToken = $this->server->httpResponse->headers['Lock-Token']; + + $serverVars = array( + 'HTTP_LOCK_TOKEN' => $lockToken, + ); + + $request = new HTTP\Request($serverVars); + $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 + ); + + + } + + /** + * @depends testLock + */ + function testUnlockWindowsBug() { + + $request = new HTTP\Request(array()); + $this->server->httpRequest = $request; + + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->invokeMethod('LOCK','test.txt'); + $lockToken = $this->server->httpResponse->headers['Lock-Token']; + + // See Issue 123 + $lockToken = trim($lockToken,'<>'); + + $serverVars = array( + 'HTTP_LOCK_TOKEN' => $lockToken, + ); + + $request = new HTTP\Request($serverVars); + $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 + ); + + + } + + /** + * @depends testLock + */ + function testLockRetainOwner() { + + $request = new HTTP\Request(array()); + $this->server->httpRequest = $request; + + $request->setBody(' + + + + Evert +'); + + $this->server->invokeMethod('LOCK','test.txt'); + $lockToken = $this->server->httpResponse->headers['Lock-Token']; + + $locks = $this->locksPlugin->getLocks('test.txt'); + $this->assertEquals(1,count($locks)); + $this->assertEquals('Evert',$locks[0]->owner); + + + } + + /** + * @depends testLock + */ + function testLockPutBadToken() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF' => '()', + ); + + $request = new HTTP\Request($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('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + + } + + /** + * @depends testLock + */ + function testLockDeleteParent() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir', + 'REQUEST_METHOD' => 'DELETE', + ); + + $request = new HTTP\Request($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']); + + } + /** + * @depends testLock + */ + function testLockDeleteSucceed() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'DELETE', + 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')', + ); + + $request = new HTTP\Request($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']); + + } + + /** + * @depends testLock + */ + function testLockCopyLockSource() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'COPY', + 'HTTP_DESTINATION' => '/dir/child2.txt', + ); + + $request = new HTTP\Request($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']); + + } + /** + * @depends testLock + */ + function testLockCopyLockDestination() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child2.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'COPY', + 'HTTP_DESTINATION' => '/dir/child2.txt', + ); + + $request = new HTTP\Request($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']); + + } + + /** + * @depends testLock + */ + function testLockMoveLockSourceLocked() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'MOVE', + 'HTTP_DESTINATION' => '/dir/child2.txt', + ); + + $request = new HTTP\Request($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']); + + } + + /** + * @depends testLock + */ + function testLockMoveLockSourceSucceed() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$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'] . ')', + ); + + $request = new HTTP\Request($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); + + } + + /** + * @depends testLock + */ + function testLockMoveLockDestination() { + + $serverVars = array( + 'REQUEST_URI' => '/dir/child2.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/dir/child.txt', + 'REQUEST_METHOD' => 'MOVE', + 'HTTP_DESTINATION' => '/dir/child2.txt', + ); + + $request = new HTTP\Request($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']); + + } + /** + * @depends testLock + */ + function testLockMoveLockParent() { + + $serverVars = array( + 'REQUEST_URI' => '/dir', + 'REQUEST_METHOD' => 'LOCK', + 'HTTP_DEPTH' => 'infinite', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$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'] . ')', + ); + + $request = new HTTP\Request($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']); + + } + + /** + * @depends testLock + */ + function testLockPutGoodToken() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertTrue(preg_match('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF' => '('.$this->response->headers['Lock-Token'].')', + ); + + $request = new HTTP\Request($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('/^$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + + $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + + } + + function testPutWithIncorrectETag() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF' => '(["etag1"])', + ); + + $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); + + } + + /** + * @depends testPutWithIncorrectETag + */ + function testPutWithCorrectETag() { + + // We need an etag-enabled file node. + $tree = new DAV\ObjectTree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); + $this->server->tree = $tree; + + $etag = md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')); + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF' => '(["'.$etag.'"])', + ); + + $request = new HTTP\Request($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); + + } + + function testGetTimeoutHeader() { + + $request = new HTTP\Request(array( + 'HTTP_TIMEOUT' => 'second-100', + )); + + $this->server->httpRequest = $request; + $this->assertEquals(100, $this->locksPlugin->getTimeoutHeader()); + + } + + + function testGetTimeoutHeaderNotSet() { + + $request = new HTTP\Request(array( + )); + + $this->server->httpRequest = $request; + $this->assertEquals(0, $this->locksPlugin->getTimeoutHeader()); + + } + + + function testGetTimeoutHeaderInfinite() { + + $request = new HTTP\Request(array( + 'HTTP_TIMEOUT' => 'infinite', + )); + + $this->server->httpRequest = $request; + $this->assertEquals(LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader()); + + } + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + function testGetTimeoutHeaderInvalid() { + + $request = new HTTP\Request(array( + 'HTTP_TIMEOUT' => 'yourmom', + )); + + $this->server->httpRequest = $request; + $this->locksPlugin->getTimeoutHeader(); + + } + + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php new file mode 100644 index 000000000..e818fe043 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php @@ -0,0 +1,58 @@ +server->addPlugin(new Plugin()); + + } + + function testPassThrough() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'GET', + ); + + $request = new HTTP\Request($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); + + } + + function testMountResponse() { + + $serverVars = array( + 'REQUEST_URI' => '/?mount', + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => 'mount', + 'HTTP_HOST' => 'example.org', + ); + + $request = new HTTP\Request($serverVars); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + + $xml = simplexml_load_string($this->response->body); + $this->assertTrue($xml==true,'Response was not a valid xml document'); + + $xml->registerXPathNamespace('dm','http://purl.org/NET/webdav/mount'); + $url = $xml->xpath('//dm:url'); + $this->assertEquals('http://example.org/',(string)$url[0]); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php new file mode 100644 index 000000000..330058b6d --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php @@ -0,0 +1,100 @@ +tree = new ObjectTree($rootNode); + + } + + function teardown() { + + \Sabre\TestUtil::clearTempDir(); + + } + + function testGetRootNode() { + + $root = $this->tree->getNodeForPath(''); + $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root); + + } + + function testGetSubDir() { + + $root = $this->tree->getNodeForPath('subdir'); + $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root); + + } + + function testCopyFile() { + + $this->tree->copy('file.txt','file2.txt'); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); + $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); + + } + + /** + * @depends testCopyFile + */ + function testCopyDirectory() { + + $this->tree->copy('subdir','subdir2'); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + + } + + /** + * @depends testCopyFile + */ + function testMoveFile() { + + $this->tree->move('file.txt','file2.txt'); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); + $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); + $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); + + } + + /** + * @depends testMoveFile + */ + function testMoveFileNewParent() { + + $this->tree->move('file.txt','subdir/file2.txt'); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt')); + $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); + $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt')); + + } + + /** + * @depends testCopyDirectory + */ + function testMoveDirectory() { + + $this->tree->move('subdir','subdir2'); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); + $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir')); + $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php new file mode 100644 index 000000000..e8cdc1666 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php @@ -0,0 +1,79 @@ +data = $str; + + } + + function putRange($str,$start) { + + if (is_resource($str)) { + $str = stream_get_contents($str); + } + $this->data = substr($this->data, 0, $start) . $str . substr($this->data, $start + strlen($str)); + + + + } + + function get() { + + return $this->data; + + } + + function getContentType() { + + return 'text/plain'; + + } + + function getSize() { + + return strlen($this->data); + + } + + function getETag() { + + return '"' . $this->data . '"'; + + } + + function delete() { + + throw new DAV\Exception\MethodNotAllowed(); + + } + + function setName($name) { + + throw new DAV\Exception\MethodNotAllowed(); + + } + + function getName() { + + return 'partial'; + + } + + function getLastModified() { + + return null; + + } + + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php new file mode 100644 index 000000000..7b90429d4 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php @@ -0,0 +1,130 @@ +node = new FileMock(); + $this->tree[] = $this->node; + + parent::setUp(); + + $this->plugin = new Plugin(); + $this->server->addPlugin($this->plugin); + + + + } + + public function testInit() { + + $this->assertEquals('partialupdate', $this->plugin->getPluginName()); + $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures()); + $this->assertEquals(array( + 'PATCH' + ), $this->plugin->getHTTPMethods('partial')); + $this->assertEquals(array( + ), $this->plugin->getHTTPMethods('')); + + $this->assertNull($this->plugin->unknownMethod('FOO','partial')); + + } + + public function testPatchNoRange() { + + $this->node->put('00000000'); + $request = new HTTP\Request(array( + '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); + + } + + public function testPatchNotSupported() { + + $this->node->put('00000000'); + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PATCH', + 'REQUEST_URI' => '/', + 'X_UPDATE_RANGE' => '3-4', + + )); + $request->setBody( + '111' + ); + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body); + + } + + public function testPatchNoContentType() { + + $this->node->put('00000000'); + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PATCH', + 'REQUEST_URI' => '/partial', + 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4', + + )); + $request->setBody( + '111' + ); + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body); + + } + + public function testPatchBadRange() { + + $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', + )); + $request->setBody( + '111' + ); + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable', $response->status, 'Full response body:' . $response->body); + + } + + public 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, + )); + $request->setBody( + '111' + ); + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); + $this->assertEquals('00111000', $this->node->get()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php new file mode 100644 index 000000000..de8ca1283 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php @@ -0,0 +1,75 @@ +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( +' +' . +HTTP\Util::toHTTPDate($dt) . +' +', $xml); + */ + $this->assertEquals( +' +' . +HTTP\Util::toHTTPDate($dt) . +' +', $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 new file mode 100644 index 000000000..fe2bc81f9 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php @@ -0,0 +1,91 @@ +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( +' +/bla/foo/bla/bar +', $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( +' +foobar +', $xml); + + } + + function testUnserialize() { + + $xml = ' +/bla/foo/bla/bar +'; + + $dom = new \DOMDocument(); + $dom->loadXML($xml); + + $href = HrefList::unserialize($dom->firstChild); + $this->assertEquals(array('/bla/foo','/bla/bar'),$href->getHrefs()); + + } + + function testUnserializeIncompatible() { + + $xml = ' +/bla/foo +'; + + $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 new file mode 100644 index 000000000..e5607f51b --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php @@ -0,0 +1,119 @@ +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( +' +/bla/path +', $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( +' +path +', $xml); + + } + + function testUnserialize() { + + $xml = ' +/bla/path +'; + + $dom = new \DOMDocument(); + $dom->loadXML($xml); + + $href = Href::unserialize($dom->firstChild); + $this->assertEquals('/bla/path',$href->getHref()); + + } + + function testUnserializeIncompatible() { + + $xml = ' +/bla/path +'; + + $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( +' +http://example.org/?a&b +', $xml); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php new file mode 100644 index 000000000..8a579baec --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php @@ -0,0 +1,111 @@ +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); + + } + + /** + * @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); + + } + + /** + * @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 =' + +'; + + $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 new file mode 100644 index 000000000..d13066b80 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php @@ -0,0 +1,19 @@ + 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( +' +' . +'' . +'/uri' . +'' . +'' . +'my file' . +'' . +'HTTP/1.1 200 OK' . +'' . +'' . +'' . +'' . +'' . +'HTTP/1.1 404 Not Found' . +'' . +'' . +' +', $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( +' +' . +'' . +'/uri' . +'' . +'' . +'value' . +'' . +'HTTP/1.1 200 OK' . +'' . +'' . +' +', $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( +' +' . +'' . +'/uri' . +'' . +'' . +'value' . +'' . +'HTTP/1.1 200 OK' . +'' . +'' . +' +', $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( +' +' . +'' . +'/uri' . +'' . +'' . +'http://sabredav.org/' . +'' . +'HTTP/1.1 200 OK' . +'' . +'' . +' +', $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 new file mode 100644 index 000000000..445e22ab3 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php @@ -0,0 +1,128 @@ + '/', + '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 = ' + + + + +'; + + $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 = ' + + + + +'; + + $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 new file mode 100644 index 000000000..88e107c19 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php @@ -0,0 +1,268 @@ +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 new file mode 100644 index 000000000..2c7a074df --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php @@ -0,0 +1,76 @@ +server->subscribeEvent('afterBind',array($this,'afterBindHandler')); + $newPath = 'afterBind'; + + $this->tempPath = ''; + $this->server->createFile($newPath,'body'); + $this->assertEquals($newPath, $this->tempPath); + + } + + function afterBindHandler($path) { + + $this->tempPath = $path; + + } + + function testBeforeBindCancel() { + + $this->server->subscribeEvent('beforeBind', array($this,'beforeBindCancelHandler')); + $this->assertFalse($this->server->createFile('bla','body')); + + // Also testing put() + $req = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PUT', + 'REQUEST_URI' => '/barbar', + )); + + $this->server->httpRequest = $req; + $this->server->exec(); + + $this->assertEquals('',$this->server->httpResponse->status); + + } + + function beforeBindCancelHandler() { + + return false; + + } + + function testException() { + + $this->server->subscribeEvent('exception', array($this, 'exceptionHandler')); + + $req = new HTTP\Request(array( + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => '/not/exisitng', + )); + $this->server->httpRequest = $req; + $this->server->exec(); + + $this->assertInstanceOf('Sabre\\DAV\\Exception\\NotFound', $this->exception); + + } + + function exceptionHandler(Exception $exception) { + + $this->exception = $exception; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php new file mode 100644 index 000000000..180f27b2a --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php @@ -0,0 +1,53 @@ + '/testput.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('Testing finder'); + $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('Testing finder',file_get_contents(SABRE_TEMPDIR . '/testput.txt')); + + } + + function testPutFail() { + + $serverVars = array( + 'REQUEST_URI' => '/testput.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status); + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ),$this->response->headers); + + $this->assertFalse(file_exists(SABRE_TEMPDIR . '/testput.txt')); + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php new file mode 100644 index 000000000..34b084dcd --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php @@ -0,0 +1,371 @@ + '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(""); + $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('', $this->response->body); + $this->assertTrue(is_dir($this->tempDir . '/testcol')); + + } + + /** + * @depends testMkcol + */ + function testMKCOLUnknownBody() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody("Hello"); + $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 415 Unsupported Media Type',$this->response->status); + + } + + /** + * @depends testMkcol + */ + function testMKCOLBrokenXML() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody("Hello"); + $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 400 Bad request',$this->response->status); + + } + + /** + * @depends testMkcol + */ + function testMKCOLUnknownXML() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + $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 415 Unsupported Media Type',$this->response->status); + + } + + /** + * @depends testMkcol + */ + function testMKCOLNoResourceType() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + Evert + + +'); + $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 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLNoResourceType + */ + function testMKCOLIncorrectResourceType() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + + +'); + $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->setBody(' + + + + + + +'); + $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 testMKCOLIncorrectResourceType2 + */ + function testMKCOLSuccess() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + + +'); + $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,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLIncorrectResourceType2 + */ + function testMKCOLWhiteSpaceResourceType() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + + + + +'); + $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,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLIncorrectResourceType2 + */ + function testMKCOLNoParent() { + + $serverVars = array( + 'REQUEST_URI' => '/testnoparent/409me', + 'REQUEST_METHOD' => 'MKCOL', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + + $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,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLIncorrectResourceType2 + */ + function testMKCOLParentIsNoCollection() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt/409me', + 'REQUEST_METHOD' => 'MKCOL', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(''); + + $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,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLIncorrectResourceType2 + */ + function testMKCOLAlreadyExists() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'MKCOL', + ); + + $request = new HTTP\Request($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); + + $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + + } + + /** + * @depends testMKCOLSuccess + * @depends testMKCOLAlreadyExists + */ + function testMKCOLAndProps() { + + $serverVars = array( + 'REQUEST_URI' => '/testcol', + 'REQUEST_METHOD' => 'MKCOL', + 'HTTP_CONTENT_TYPE' => 'application/xml', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody(' + + + + + my new collection + + +'); + $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(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ),$this->response->headers); + + + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php new file mode 100644 index 000000000..8f1451b49 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php @@ -0,0 +1,98 @@ +server->addPlugin($testPlugin); + $this->testPlugin = $testPlugin; + + } + + /** + * @covers \Sabre\DAV\ServerPlugin + */ + function testBaseClass() { + + $p = new ServerPluginMock(); + $this->assertEquals(array(),$p->getFeatures()); + $this->assertEquals(array(),$p->getHTTPMethods('')); + + } + + function testOptions() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'OPTIONS', + ); + + $request = new HTTP\Request($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); + $this->assertEquals('', $this->response->body); + $this->assertEquals('OPTIONS',$this->testPlugin->beforeMethod); + + + } + + function testGetPlugin() { + + $this->assertEquals($this->testPlugin,$this->server->getPlugin(get_class($this->testPlugin))); + + } + + function testUnknownPlugin() { + + $this->assertNull($this->server->getPlugin('SomeRandomClassName')); + + } + + function testGetSupportedReportSet() { + + $this->assertEquals(array(), $this->testPlugin->getSupportedReportSet('/')); + + } + + function testGetPlugins() { + + $this->assertEquals( + array(get_class($this->testPlugin) => $this->testPlugin), + $this->server->getPlugins() + ); + + } + + +} + +class ServerPluginMock extends ServerPlugin { + + function initialize(Server $s) { } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php new file mode 100644 index 000000000..ea09852a7 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php @@ -0,0 +1,395 @@ + '*', + 'REQUEST_URI' => '/bar' + )); + $server->httpRequest = $httpRequest; + + $server->checkPreconditions(); + + } + + /** + * @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()); + + } + + /** + * @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(); + + } + + /** + * @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()); + + } + + /** + * 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()); + + } + + /** + * @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()); + + } + + /** + * @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()); + + } + + /** + * @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(); + + } + + /** + * @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()); + + } + + /** + * @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()); + + } + + /** + * @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(); + + } + + /** + * @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(); + + } + + /** + * @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' + )); + $server->httpRequest = $httpRequest; + $server->httpResponse = new HTTP\ResponseMock(); + + $this->assertFalse($server->checkPreconditions(true)); + $this->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + + } + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfModifiedSinceUnModified() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(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->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + $this->assertEquals(array( + 'Last-Modified' => 'Sat, 06 Apr 1985 23:30:00 GMT', + ), $server->httpResponse->headers); + + } + + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfModifiedSinceModified() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(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()); + + } + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfModifiedSinceInvalidDate() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(array( + 'HTTP_IF_MODIFIED_SINCE' => 'Your mother', + 'REQUEST_URI' => '/foo' + )); + $server->httpRequest = $httpRequest; + $server->httpResponse = new HTTP\ResponseMock(); + + // Invalid dates must be ignored, so this should return true + $this->assertTrue($server->checkPreconditions()); + + } + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfModifiedSinceInvalidDate2() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(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()); + + } + + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfUnmodifiedSinceUnModified() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(array( + 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT', + 'REQUEST_URI' => '/foo' + )); + $server->httpRequest = $httpRequest; + $this->assertTrue($server->checkPreconditions()); + + } + + + /** + * @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( + '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(); + + } + + /** + * @covers \Sabre\DAV\Server::checkPreconditions + */ + public function testIfUnmodifiedSinceInvalidDate() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $httpRequest = new HTTP\Request(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()); + + } + + +} + +class ServerPreconditionsNode extends File { + + function getETag() { + + return '"abc123"'; + + } + + function getLastModified() { + + /* my birthday & time, I believe */ + return strtotime('1985-04-07 01:30 +02:00'); + + } + + function getName() { + + return 'foo'; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php new file mode 100644 index 000000000..859a91070 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php @@ -0,0 +1,413 @@ +server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR . '/.locksdb'))); + + } + + function tearDown() { + + parent::tearDown(); + if (file_exists(SABRE_TEMPDIR.'../.locksdb')) unlink(SABRE_TEMPDIR.'../.locksdb'); + + } + + private function sendRequest($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(); + + } + + public function testPropFindEmptyBody() { + + $hasFired = false; + + $self = $this; + // Also testing the beforeGetPropertiesForPath event. + $this->server->subscribeEvent('beforeGetPropertiesForPath', function($path, $properties, $depth) use ($self, &$hasFired) { + + $hasFired = true; + $self->assertEquals('', $path); + $self->assertEquals(array(), $properties); + $self->assertEquals(0, $depth); + + }); + + $this->sendRequest(""); + + $this->assertTrue($hasFired); + + $this->assertEquals('HTTP/1.1 207 Multi-Status',$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 + ); + + $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'); + + 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)); + + } + + function testSupportedLocks() { + + $xml = ' + + + + +'; + + $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'); + + $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'); + + $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'); + + $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'); + + $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'); + + $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'); + + $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'); + } + + function testLockDiscovery() { + + $xml = ' + + + + +'; + + $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'); + + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery'); + $this->assertEquals(1,count($data),'We expected a \'d:lockdiscovery\' tag'); + + } + + function testUnknownProperty() { + + $xml = ' + + + + +'; + + $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'); + $pathTests = array( + '/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); + } + + $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]); + + } + + /** + * @covers Sabre\DAV\Server::parsePropPatchRequest + */ + public function testParsePropPatchRequest() { + + $body = ' + + somevalue + + removeme + +'; + + $result = $this->server->parsePropPatchRequest($body); + $this->assertEquals(array( + '{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 = ' + + somevalue +'; + + $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 = ' + + + + +'; + + $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(); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php new file mode 100644 index 000000000..a06fcb0be --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php @@ -0,0 +1,274 @@ + '/test.txt', + 'REQUEST_METHOD' => 'GET', + 'HTTP_RANGE' => 'bytes=2-5', + ); + + $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)); + + } + + /** + * @depends testRange + */ + function testStartRange() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'GET', + 'HTTP_RANGE' => 'bytes=2-', + ); + + $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)); + + } + + /** + * @depends testRange + */ + function testEndRange() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'GET', + 'HTTP_RANGE' => 'bytes=-8', + ); + + $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)); + + } + + /** + * @depends testRange + */ + function testTooHighRange() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'GET', + 'HTTP_RANGE' => 'bytes=100-200', + ); + + $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); + + } + + /** + * @depends testRange + */ + function testCrazyRange() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'GET', + 'HTTP_RANGE' => 'bytes=8-4', + ); + + $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); + + } + + /** + * @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($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)); + + } + + /** + * @depends testRange + * @covers \Sabre\DAV\Server::httpGet + */ + 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($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)); + + } + + /** + * @depends testRange + * @covers \Sabre\DAV\Server::httpGet + */ + 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($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)); + + } + + /** + * @depends testRange + * @covers \Sabre\DAV\Server::httpGet + */ + 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($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)); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php new file mode 100644 index 000000000..afcd5c98f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php @@ -0,0 +1,767 @@ +assertEquals($nodes[0], $server->tree->getNodeForPath('hello')); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + function testConstructIncorrectObj() { + + $nodes = array( + new SimpleCollection('hello'), + new \STDClass(), + ); + + $server = new Server($nodes); + + } + + /** + * @expectedException Sabre\DAV\Exception + */ + function testConstructInvalidArg() { + + $server = new Server(1); + + } + + 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', + ); + + $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 testHEAD() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'HEAD', + ); + + $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('', $this->response->body); + + } + + function testPut() { + + $serverVars = array( + 'REQUEST_URI' => '/testput.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $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(array( + "Content-Length" => "0", + ), $this->response->headers); + + $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); + + } + + function testPutAlreadyExists() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_NONE_MATCH' => '*', + ); + + $request = new HTTP\Request($serverVars); + $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('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); + + } + + function testPutUpdate() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('Testing updated file'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('0', $this->response->headers['Content-Length']); + + $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals('', $this->response->body); + $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); + + } + + function testPutNoParentCollection() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt/item.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('Testing updated file'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status); + + } + + function testPutContentRange() { + + $serverVars = array( + 'REQUEST_URI' => '/testput.txt', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_CONTENT_RANGE' => 'bytes/100-200', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('Testing new file'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); + + } + + + function testDelete() { + + $serverVars = array( + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'DELETE', + ); + + $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('', $this->response->body); + $this->assertFalse(file_exists($this->tempDir . '/test.txt')); + + } + + 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); + $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('', $this->response->body); + $this->assertFalse(file_exists($this->tempDir . '/col')); + + } + + function testOptions() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'OPTIONS', + ); + + $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('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('', $this->response->body); + + + } + function testNonExistantMethod() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'BLABLA', + ); + + $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 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( + 'REQUEST_URI' => '/blabla/test.txt', + 'REQUEST_METHOD' => 'GET', + ); + + $request = new HTTP\Request($serverVars); + $this->server->setBaseUri('/blabla/'); + $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('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + + } + + function testBaseUriAddSlash() { + + $tests = array( + '/' => '/', + '/foo' => '/foo/', + '/foo/' => '/foo/', + '/foo/bar' => '/foo/bar/', + '/foo/bar/' => '/foo/bar/', + ); + + foreach($tests as $test=>$result) { + $this->server->setBaseUri($test); + + $this->assertEquals($result, $this->server->getBaseUri()); + + } + + } + + function testCalculateUri() { + + $uris = array( + 'http://www.example.org/root/somepath', + '/root/somepath', + '/root/somepath/', + ); + + $this->server->setBaseUri('/root/'); + + foreach($uris as $uri) { + + $this->assertEquals('somepath',$this->server->calculateUri($uri)); + + } + + $this->server->setBaseUri('/root'); + + foreach($uris as $uri) { + + $this->assertEquals('somepath',$this->server->calculateUri($uri)); + + } + + $this->assertEquals('', $this->server->calculateUri('/root')); + + } + + function testCalculateUriSpecialChars() { + + $uris = array( + '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) { + + $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + + } + + $this->server->setBaseUri('/root'); + + foreach($uris as $uri) { + + $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + + } + + $this->server->setBaseUri('/'); + + foreach($uris as $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) { + + // This was expected + + } + + } + + /** + * @covers \Sabre\DAV\Server::guessBaseUri + */ + function testGuessBaseUri() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/root', + 'PATH_INFO' => '/root', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/index.php/', $server->guessBaseUri()); + + } + + /** + * @depends testGuessBaseUri + * @covers Sabre\DAV\Server::guessBaseUri + */ + function testGuessBaseUriPercentEncoding() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces', + 'PATH_INFO' => '/dir/path2/path with spaces', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/index.php/', $server->guessBaseUri()); + + } + + /** + * @depends testGuessBaseUri + * @covers \Sabre\DAV\Server::guessBaseUri + */ + /* + function testGuessBaseUriPercentEncoding2() { + + $this->markTestIncomplete('This behaviour is not yet implemented'); + $serverVars = array( + 'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces', + 'PATH_INFO' => '/dir/path2/path with spaces', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/some%20directory+mixed/index.php/', $server->guessBaseUri()); + + }*/ + + function testGuessBaseUri2() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/root/', + 'PATH_INFO' => '/root/', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/index.php/', $server->guessBaseUri()); + + } + + function testGuessBaseUriNoPathInfo() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/root', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/', $server->guessBaseUri()); + + } + + function testGuessBaseUriNoPathInfo2() { + + $serverVars = array( + 'REQUEST_URI' => '/a/b/c/test.php', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/', $server->guessBaseUri()); + + } + + + /** + * @covers \Sabre\DAV\Server::guessBaseUri + * @depends testGuessBaseUri + */ + function testGuessBaseUriQueryString() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/root?query_string=blabla', + 'PATH_INFO' => '/root', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $this->assertEquals('/index.php/', $server->guessBaseUri()); + + } + + /** + * @covers \Sabre\DAV\Server::guessBaseUri + * @depends testGuessBaseUri + * @expectedException \Sabre\DAV\Exception + */ + function testGuessBaseUriBadConfig() { + + $serverVars = array( + 'REQUEST_URI' => '/index.php/root/heyyy', + 'PATH_INFO' => '/root', + ); + + $httpRequest = new HTTP\Request($serverVars); + $server = new Server(); + $server->httpRequest = $httpRequest; + + $server->guessBaseUri(); + + } + + function testTriggerException() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'FOO', + ); + + $httpRequest = new HTTP\Request($serverVars); + $this->server->httpRequest = $httpRequest; + $this->server->subscribeEvent('beforeMethod',array($this,'exceptionTrigger')); + $this->server->exec(); + + $this->assertEquals(array( + 'Content-Type' => 'application/xml; charset=utf-8', + ),$this->response->headers); + + $this->assertEquals('HTTP/1.1 500 Internal Server Error',$this->response->status); + + } + + function exceptionTrigger() { + + throw new Exception('Hola'); + + } + + function testReportNotFound() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'REPORT', + ); + + $request = new HTTP\Request($serverVars); + $this->server->httpRequest = ($request); + $this->server->httpRequest->setBody(''); + $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,'We got an incorrect status back. Full response body follows: ' . $this->response->body); + + } + + function testReportIntercepted() { + + $serverVars = array( + 'REQUEST_URI' => '/', + 'REQUEST_METHOD' => 'REPORT', + ); + + $request = new HTTP\Request($serverVars); + $this->server->httpRequest = ($request); + $this->server->httpRequest->setBody(''); + $this->server->subscribeEvent('report',array($this,'reportHandler')); + $this->server->exec(); + + $this->assertEquals(array( + 'testheader' => 'testvalue', + ), + $this->response->headers + ); + + $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); + + } + + function reportHandler($reportName) { + + if ($reportName=='{http://www.rooftopsolutions.nl/NS}myreport') { + $this->server->httpResponse->sendStatus(418); + $this->server->httpResponse->setHeader('testheader','testvalue'); + return false; + } + else return; + + } + + function testGetPropertiesForChildren() { + + $result = $this->server->getPropertiesForChildren('',array( + '{DAV:}getcontentlength', + )); + + $expected = array( + 'test.txt' => array('{DAV:}getcontentlength' => 13), + 'dir/' => array(), + ); + + $this->assertEquals($expected,$result); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php new file mode 100644 index 000000000..a73e8d13f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php @@ -0,0 +1,130 @@ +updateProperties('foo', array( + '{DAV:}foo' => 'bar' + )); + + $expected = array( + 'href' => 'foo', + '403' => array( + '{DAV:}foo' => null, + ), + ); + $this->assertEquals($expected, $result); + + } + + function testUpdatePropertiesProtected() { + + $tree = array( + new SimpleCollection('foo'), + ); + $server = new Server($tree); + + $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, + ), + ); + $this->assertEquals($expected, $result); + + } + + function testUpdatePropertiesEventFail() { + + $tree = array( + new SimpleCollection('foo'), + ); + $server = new Server($tree); + $server->subscribeEvent('updateProperties', array($this,'updatepropfail')); + + $result = $server->updateProperties('foo', array( + '{DAV:}foo' => 'bar', + '{DAV:}foo2' => 'bla', + )); + + $expected = array( + 'href' => 'foo', + '404' => array( + '{DAV:}foo' => null, + ), + '424' => array( + '{DAV:}foo2' => null, + ), + ); + $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')); + + $result = $server->updateProperties('foo', array( + '{DAV:}foo' => 'bar', + '{DAV:}foo2' => 'bla', + )); + + $expected = array( + 'href' => 'foo', + '200' => array( + '{DAV:}foo' => null, + ), + '201' => array( + '{DAV:}foo2' => null, + ), + ); + $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 new file mode 100644 index 000000000..de8b05734 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php @@ -0,0 +1,19 @@ +assertEquals('filename.txt', $file->getName()); + $this->assertEquals('contents', $file->get()); + $this->assertEquals('8', $file->getSize()); + $this->assertEquals('"' . md5('contents') . '"', $file->getETag()); + $this->assertEquals('text/plain', $file->getContentType()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/StringUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/StringUtilTest.php new file mode 100644 index 000000000..941d1f913 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/StringUtilTest.php @@ -0,0 +1,122 @@ +assertEquals($result, StringUtil::textMatch($haystack, $needle, $collation, $matchType)); + + } + + function dataset() { + + return array( + array('FOOBAR', 'FOO', 'i;octet', 'contains', true), + array('FOOBAR', 'foo', 'i;octet', 'contains', false), + array('FÖÖBAR', 'FÖÖ', 'i;octet', 'contains', true), + array('FÖÖBAR', 'föö', 'i;octet', 'contains', false), + array('FOOBAR', 'FOOBAR', 'i;octet', 'equals', true), + array('FOOBAR', 'fooBAR', 'i;octet', 'equals', false), + array('FOOBAR', 'FOO', 'i;octet', 'starts-with', true), + array('FOOBAR', 'foo', 'i;octet', 'starts-with', false), + array('FOOBAR', 'BAR', 'i;octet', 'starts-with', false), + array('FOOBAR', 'bar', 'i;octet', 'starts-with', false), + array('FOOBAR', 'FOO', 'i;octet', 'ends-with', false), + array('FOOBAR', 'foo', 'i;octet', 'ends-with', false), + array('FOOBAR', 'BAR', 'i;octet', 'ends-with', true), + array('FOOBAR', 'bar', 'i;octet', 'ends-with', false), + + array('FOOBAR', 'FOO', 'i;ascii-casemap', 'contains', true), + array('FOOBAR', 'foo', 'i;ascii-casemap', 'contains', true), + array('FÖÖBAR', 'FÖÖ', 'i;ascii-casemap', 'contains', true), + array('FÖÖBAR', 'föö', 'i;ascii-casemap', 'contains', false), + array('FOOBAR', 'FOOBAR', 'i;ascii-casemap', 'equals', true), + array('FOOBAR', 'fooBAR', 'i;ascii-casemap', 'equals', true), + array('FOOBAR', 'FOO', 'i;ascii-casemap', 'starts-with', true), + array('FOOBAR', 'foo', 'i;ascii-casemap', 'starts-with', true), + array('FOOBAR', 'BAR', 'i;ascii-casemap', 'starts-with', false), + array('FOOBAR', 'bar', 'i;ascii-casemap', 'starts-with', false), + array('FOOBAR', 'FOO', 'i;ascii-casemap', 'ends-with', false), + array('FOOBAR', 'foo', 'i;ascii-casemap', 'ends-with', false), + array('FOOBAR', 'BAR', 'i;ascii-casemap', 'ends-with', true), + array('FOOBAR', 'bar', 'i;ascii-casemap', 'ends-with', true), + + array('FOOBAR', 'FOO', 'i;unicode-casemap', 'contains', true), + array('FOOBAR', 'foo', 'i;unicode-casemap', 'contains', true), + array('FÖÖBAR', 'FÖÖ', 'i;unicode-casemap', 'contains', true), + array('FÖÖBAR', 'föö', 'i;unicode-casemap', 'contains', true), + array('FOOBAR', 'FOOBAR', 'i;unicode-casemap', 'equals', true), + array('FOOBAR', 'fooBAR', 'i;unicode-casemap', 'equals', true), + array('FOOBAR', 'FOO', 'i;unicode-casemap', 'starts-with', true), + array('FOOBAR', 'foo', 'i;unicode-casemap', 'starts-with', true), + array('FOOBAR', 'BAR', 'i;unicode-casemap', 'starts-with', false), + array('FOOBAR', 'bar', 'i;unicode-casemap', 'starts-with', false), + array('FOOBAR', 'FOO', 'i;unicode-casemap', 'ends-with', false), + array('FOOBAR', 'foo', 'i;unicode-casemap', 'ends-with', false), + array('FOOBAR', 'BAR', 'i;unicode-casemap', 'ends-with', true), + array('FOOBAR', 'bar', 'i;unicode-casemap', 'ends-with', true), + ); + + } + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + public function testBadCollation() { + + StringUtil::textMatch('foobar','foo','blabla','contains'); + + } + + + /** + * @expectedException Sabre\DAV\Exception\BadRequest + */ + public function testBadMatchType() { + + StringUtil::textMatch('foobar','foo','i;octet','booh'); + + } + + public function testEnsureUTF8_ascii() { + + $inputString = "harkema"; + $outputString = "harkema"; + + $this->assertEquals( + $outputString, + StringUtil::ensureUTF8($inputString) + ); + + } + + public function testEnsureUTF8_latin1() { + + $inputString = "m\xfcnster"; + $outputString = "münster"; + + $this->assertEquals( + $outputString, + StringUtil::ensureUTF8($inputString) + ); + + } + + public function testEnsureUTF8_utf8() { + + $inputString = "m\xc3\xbcnster"; + $outputString = "münster"; + + $this->assertEquals( + $outputString, + StringUtil::ensureUTF8($inputString) + ); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php new file mode 100644 index 000000000..d136eeb17 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php @@ -0,0 +1,252 @@ +server->addPlugin($plugin); + + } + + function testPutNormal() { + + $serverVars = array( + 'REQUEST_URI' => '/testput.txt', + 'REQUEST_METHOD' => 'PUT', + ); + + $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('Testing new file',file_get_contents(SABRE_TEMPDIR . '/testput.txt')); + + } + + function testPutTemp() { + + // 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); + $this->server->exec(); + + $this->assertEquals('', $this->response->body); + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.'); + + } + + 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'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('', $this->response->body); + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $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(array( + 'X-Sabre-Temp' => 'true', + 'Content-Type' => 'application/xml; charset=utf-8', + ),$this->response->headers); + + } + + 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'); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('', $this->response->body); + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $serverVars = array( + 'REQUEST_URI' => '/._testput.txt', + 'REQUEST_METHOD' => 'GET', + ); + + $request = new HTTP\Request($serverVars); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + 'Content-Length' => 16, + 'Content-Type' => 'application/octet-stream', + ),$this->response->headers); + + $this->assertEquals('Testing new file',stream_get_contents($this->response->body)); + + } + + function testLockNonExistant() { + + mkdir(SABRE_TEMPDIR . '/locksdir'); + $locksBackend = new Locks\Backend\FS(SABRE_TEMPDIR . '/locksdir'); + $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->setBody(' + + + + + http://example.org/~ejw/contact.html + +'); + + $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('/^$/',$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->assertFalse(file_exists(SABRE_TEMPDIR . '/._testlock.txt'),'._testlock.txt should not exist in the regular file structure.'); + + } + + function testPutDelete() { + + // 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); + $this->server->exec(); + + $this->assertEquals('', $this->response->body); + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $serverVars = array( + 'REQUEST_URI' => '/._testput.txt', + 'REQUEST_METHOD' => 'DELETE', + ); + + $request = new HTTP\Request($serverVars); + $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(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $this->assertEquals('',$this->response->body); + + } + + 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); + $this->server->exec(); + + $this->assertEquals('', $this->response->body); + $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(array( + 'X-Sabre-Temp' => 'true', + ),$this->response->headers); + + $serverVars = array( + 'REQUEST_URI' => '/._testput.txt', + 'REQUEST_METHOD' => 'PROPFIND', + ); + + $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(array( + 'X-Sabre-Temp' => 'true', + 'Content-Type' => 'application/xml; charset=utf-8', + ),$this->response->headers); + + $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'); + + list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); + $this->assertEquals('/._testput.txt',(string)$data,'href element should have been /._testput.txt'); + + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); + $this->assertEquals(1,count($data)); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php new file mode 100644 index 000000000..9cf5edbb0 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php @@ -0,0 +1,34 @@ +subscribeEvent('beforeMethod',array($this,'beforeMethod')); + + } + + function beforeMethod($method) { + + $this->beforeMethod = $method; + return true; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php new file mode 100644 index 000000000..19b08460f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php @@ -0,0 +1,88 @@ +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 new file mode 100644 index 000000000..90df6427e --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php @@ -0,0 +1,175 @@ +assertTrue($tree->nodeExists('hi')); + $this->assertFalse($tree->nodeExists('hello')); + + } + + function testCopy() { + + $tree = new TreeMock(); + $tree->copy('hi','hi2'); + + $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories); + $this->assertEquals('foobar', $tree->getNodeForPath('hi/file')->get()); + $this->assertEquals(array('test1'=>'value'), $tree->getNodeForPath('hi/file')->getProperties(array())); + + } + + function testMove() { + + $tree = new TreeMock(); + $tree->move('hi','hi2'); + + $this->assertEquals('hi2', $tree->getNodeForPath('hi')->getName()); + $this->assertTrue($tree->getNodeForPath('hi')->isRenamed); + + } + + function testDeepMove() { + + $tree = new TreeMock(); + $tree->move('hi/sub','hi2'); + + $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories); + $this->assertTrue($tree->getNodeForPath('hi/sub')->isDeleted); + + } + + function testDelete() { + + $tree = new TreeMock(); + $tree->delete('hi'); + $this->assertTrue($tree->getNodeForPath('hi')->isDeleted); + + } + + function testGetChildren() { + + $tree = new TreeMock(); + $children = $tree->getChildren(''); + $this->assertEquals(1,count($children)); + $this->assertEquals('hi', $children[0]->getName()); + + } + +} + +class TreeMock extends Tree { + + private $nodes = array(); + + 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) { + + if (isset($this->nodes[$path])) return $this->nodes[$path]; + throw new Exception\NotFound('item not found'); + + } + +} + +class TreeDirectoryTester extends SimpleCollection { + + public $newDirectories = array(); + public $newFiles = array(); + public $isDeleted = false; + public $isRenamed = false; + + function createDirectory($name) { + + $this->newDirectories[$name] = true; + + } + + function createFile($name,$data = null) { + + $this->newFiles[$name] = $data; + + } + + function getChild($name) { + + if (isset($this->newDirectories[$name])) return new TreeDirectoryTester($name); + if (isset($this->newFiles[$name])) return new TreeFileTester($name, $this->newFiles[$name]); + return parent::getChild($name); + + } + + function delete() { + + $this->isDeleted = true; + + } + + function setName($name) { + + $this->isRenamed = true; + $this->name = $name; + + } + +} + +class TreeFileTester extends File implements IProperties { + + public $name; + public $data; + public $properties; + + function __construct($name, $data = null) { + + $this->name = $name; + if (is_null($data)) $data = 'bla'; + $this->data = $data; + + } + + function getName() { + + return $this->name; + + } + + function get() { + + return $this->data; + + } + + function getProperties($properties) { + + return $this->properties; + + } + + function updateProperties($properties) { + + $this->properties = $properties; + return true; + + } + +} + diff --git a/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php new file mode 100644 index 000000000..f17ca4b85 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php @@ -0,0 +1,131 @@ +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%3a%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%3a%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/UUIDUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/UUIDUtilTest.php new file mode 100644 index 000000000..f005ecc75 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/UUIDUtilTest.php @@ -0,0 +1,25 @@ +assertTrue( + UUIDUtil::validateUUID('11111111-2222-3333-4444-555555555555') + ); + $this->assertFalse( + UUIDUtil::validateUUID(' 11111111-2222-3333-4444-555555555555') + ); + $this->assertTrue( + UUIDUtil::validateUUID('ffffffff-2222-3333-4444-555555555555') + ); + $this->assertFalse( + UUIDUtil::validateUUID('fffffffg-2222-3333-4444-555555555555') + ); + + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php new file mode 100644 index 000000000..1d2bfd133 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php @@ -0,0 +1,284 @@ +loadXML('Testdoc'); + + $this->assertEquals( + '{http://www.example.org/}test1', + XMLUtil::toClarkNotation($dom->firstChild) + ); + + } + + function testToClarkNotation2() { + + $dom = new \DOMDocument(); + $dom->loadXML('Testdoc'); + + $this->assertEquals( + '{http://www.example.org/}test1', + XMLUtil::toClarkNotation($dom->firstChild) + ); + + } + + function testToClarkNotationDAVNamespace() { + + $dom = new \DOMDocument(); + $dom->loadXML('Testdoc'); + + $this->assertEquals( + '{DAV:}test1', + XMLUtil::toClarkNotation($dom->firstChild) + ); + + } + + function testToClarkNotationNoElem() { + + $dom = new \DOMDocument(); + $dom->loadXML('Testdoc'); + + $this->assertNull( + XMLUtil::toClarkNotation($dom->firstChild->firstChild) + ); + + } + + function testConvertDAVNamespace() { + + $xml='blablabla'; + $this->assertEquals( + 'blablabla', + XMLUtil::convertDAVNamespace($xml) + ); + + } + + function testConvertDAVNamespace2() { + + $xml='blablabla'; + $this->assertEquals( + 'blablabla', + XMLUtil::convertDAVNamespace($xml) + ); + + } + + function testConvertDAVNamespace3() { + + $xml='blablabla'; + $this->assertEquals( + 'blablabla', + XMLUtil::convertDAVNamespace($xml) + ); + + } + + function testConvertDAVNamespace4() { + + $xml='blablabla'; + $this->assertEquals( + 'blablabla', + XMLUtil::convertDAVNamespace($xml) + ); + + } + + function testConvertDAVNamespaceMixedQuotes() { + + $xml=''; + $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='assertEquals('blabla',$dom->firstChild->nodeValue); + + } + + + function testParseProperties() { + + $xml=' + + + Calendars + +'; + + $dom = XMLUtil::loadDOMDocument($xml); + $properties = XMLUtil::parseProperties($dom->firstChild); + + $this->assertEquals(array( + '{DAV:}displayname' => 'Calendars', + ), $properties); + + + + } + + /** + * @depends testParseProperties + */ + function testParsePropertiesEmpty() { + + $xml=' + + + Calendars + + + + +'; + + $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=' + + + Calendars + + + Complex value right here + +'; + + $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=' + + + +'; + + $dom = XMLUtil::loadDOMDocument($xml); + $properties = XMLUtil::parseProperties($dom->firstChild); + + $this->assertEquals(array(), $properties); + + } + + function testParsePropertiesMapHref() { + + $xml=' + + + Calendars + + + http://sabredav.org/ + +'; + + $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'); + + } + +} + -- cgit v1.2.3