aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/Locks
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
committerfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
commitb35122f7a6ad42756c35bb60ba1f06c3dcd45c77 (patch)
treeccdf373ce6475d264778523259cc32899b732fe7 /vendor/sabre/dav/tests/Sabre/DAV/Locks
parente3504df514d306cfe6b83e44a11f550664564af4 (diff)
downloadvolse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.gz
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.bz2
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.zip
add sabre (1.8.x) via composer in the !@#$ place it wants to be
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/Locks')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php196
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php31
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php24
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php32
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php29
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php375
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php123
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php966
8 files changed, 1776 insertions, 0 deletions
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 @@
+<?php
+
+namespace Sabre\DAV\Locks\Backend;
+
+use Sabre\DAV;
+
+abstract class AbstractTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @abstract
+ * @return AbstractBackend
+ */
+ abstract function getBackend();
+
+ function testSetup() {
+
+ $backend = $this->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 @@
+<?php
+
+namespace Sabre\DAV\Locks\Backend;
+
+require_once 'Sabre/TestUtil.php';
+
+class FSTest extends AbstractTest {
+
+ function getBackend() {
+
+ \Sabre\TestUtil::clearTempDir();
+ mkdir(SABRE_TEMPDIR . '/locks');
+ $backend = new FS(SABRE_TEMPDIR . '/locks/');
+ return $backend;
+
+ }
+
+ function tearDown() {
+
+ \Sabre\TestUtil::clearTempDir();
+
+ }
+
+ function testGetLocksChildren() {
+
+ // We're skipping this test. This doesn't work, and it will
+ // never. The class is deprecated anyway.
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php
new file mode 100644
index 000000000..537996f3b
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Sabre\DAV\Locks\Backend;
+
+require_once 'Sabre/TestUtil.php';
+
+class FileTest extends AbstractTest {
+
+ function getBackend() {
+
+ \Sabre\TestUtil::clearTempDir();
+ $backend = new File(SABRE_TEMPDIR . '/lockdb');
+ return $backend;
+
+ }
+
+
+ function tearDown() {
+
+ \Sabre\TestUtil::clearTempDir();
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php
new file mode 100644
index 000000000..b6f06224c
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Sabre\DAV\Locks\Backend;
+
+require_once 'Sabre/TestUtil.php';
+
+class PDOMySQLTest extends AbstractTest {
+
+ function getBackend() {
+
+ if (!SABRE_HASMYSQL) $this->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 @@
+<?php
+
+namespace Sabre\DAV\Locks\Backend;
+
+require_once 'Sabre/TestUtil.php';
+require_once 'Sabre/DAV/Locks/Backend/AbstractTest.php';
+
+class PDOTest extends AbstractTest {
+
+ function getBackend() {
+
+ if (!SABRE_HASSQLITE) $this->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 @@
+<?php
+
+namespace Sabre\DAV\Locks;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+require_once 'Sabre/DAV/AbstractServer.php';
+
+class GetIfConditionsTest extends DAV\AbstractServer {
+
+ /**
+ * @var Sabre\DAV\Locks\Plugin
+ */
+ protected $locksPlugin;
+
+ function setUp() {
+
+ parent::setUp();
+ $locksPlugin = new Plugin();
+ $this->server->addPlugin($locksPlugin);
+ $this->locksPlugin = $locksPlugin;
+
+ }
+
+ function testNoConditions() {
+
+ $serverVars = array(
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+ $this->assertEquals(array(),$conditions);
+
+ }
+
+ function testLockToken() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '(<opaquelocktoken:token1>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => '',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function testNotLockToken() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '(Not <opaquelocktoken:token1>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => '',
+ 'tokens' => array(
+ array(
+ 0,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function testLockTokenUrl() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '<http://www.example.com/> (<opaquelocktoken:token1>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => 'http://www.example.com/',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function test2LockTokens() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '(<opaquelocktoken:token1>) (Not <opaquelocktoken:token2>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => '',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ array(
+ 0,
+ 'opaquelocktoken:token2',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function test2UriLockTokens() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) <http://www.example.org/node2> (Not <opaquelocktoken:token2>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => 'http://www.example.org/node1',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ ),
+ ),
+ array(
+ 'uri' => 'http://www.example.org/node2',
+ 'tokens' => array(
+ array(
+ 0,
+ 'opaquelocktoken:token2',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function test2UriMultiLockTokens() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) (<opaquelocktoken:token2>) <http://www.example.org/node2> (Not <opaquelocktoken:token3>)',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => 'http://www.example.org/node1',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ '',
+ ),
+ array(
+ 1,
+ 'opaquelocktoken:token2',
+ '',
+ ),
+ ),
+ ),
+ array(
+ 'uri' => 'http://www.example.org/node2',
+ 'tokens' => array(
+ array(
+ 0,
+ 'opaquelocktoken:token3',
+ '',
+ ),
+ ),
+
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function testEtag() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '([etag1])',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => '',
+ 'tokens' => array(
+ array(
+ 1,
+ '',
+ 'etag1',
+ ),
+ ),
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function test2Etags() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '<http://www.example.org/> ([etag1]) ([etag2])',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => 'http://www.example.org/',
+ 'tokens' => array(
+ array(
+ 1,
+ '',
+ 'etag1',
+ ),
+ array(
+ 1,
+ '',
+ 'etag2',
+ ),
+ ),
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+ function testComplexIf() {
+
+ $serverVars = array(
+ 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1> [etag1]) ' .
+ '(Not <opaquelocktoken:token2>) ([etag2]) <http://www.example.org/node2> ' .
+ '(<opaquelocktoken:token3>) (Not <opaquelocktoken:token4>) ([etag3])',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+
+ $conditions = $this->locksPlugin->getIfConditions();
+
+ $compare = array(
+
+ array(
+ 'uri' => 'http://www.example.org/node1',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token1',
+ 'etag1',
+ ),
+ array(
+ 0,
+ 'opaquelocktoken:token2',
+ '',
+ ),
+ array(
+ 1,
+ '',
+ 'etag2',
+ ),
+ ),
+ ),
+ array(
+ 'uri' => 'http://www.example.org/node2',
+ 'tokens' => array(
+ array(
+ 1,
+ 'opaquelocktoken:token3',
+ '',
+ ),
+ array(
+ 0,
+ 'opaquelocktoken:token4',
+ '',
+ ),
+ array(
+ 1,
+ '',
+ 'etag3',
+ ),
+ ),
+ ),
+
+ );
+ $this->assertEquals($compare,$conditions);
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php
new file mode 100644
index 000000000..b3d7d447b
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Sabre\DAV\Locks;
+
+use Sabre\HTTP;
+use Sabre\DAV;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+require_once 'Sabre/TestUtil.php';
+
+class MSWordTest extends \PHPUnit_Framework_TestCase {
+
+ function testLockEtc() {
+
+ mkdir(SABRE_TEMPDIR . '/mstest');
+ $tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
+
+ $server = new DAV\Server($tree);
+ $server->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('<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope>
+ <D:exclusive />
+ </D:lockscope>
+ <D:locktype>
+ <D:write />
+ </D:locktype>
+ <D:owner>
+ <D:href>PC-Vista\User</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ 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('<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope>
+ <D:exclusive />
+ </D:lockscope>
+ <D:locktype>
+ <D:write />
+ </D:locktype>
+ <D:owner>
+ <D:href>PC-Vista\User</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ 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 @@
+<?php
+
+namespace Sabre\DAV\Locks;
+
+use Sabre\HTTP;
+use Sabre\DAV;
+
+require_once 'Sabre/DAV/AbstractServer.php';
+
+class PluginTest extends DAV\AbstractServer {
+
+ /**
+ * @var Sabre\DAV\Locks\Plugin
+ */
+ protected $locksPlugin;
+
+ function setUp() {
+
+ parent::setUp();
+ $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
+ $locksPlugin = new Plugin($locksBackend);
+ $this->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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $lockToken = $this->response->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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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' => '<opaquelocktoken:blablabla>',
+ );
+
+ $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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('/^<opaquelocktoken:(.*)>$/',$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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>Evert</D:owner>
+</D:lockinfo>');
+
+ $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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'PUT',
+ 'HTTP_IF' => '(<opaquelocktoken:token1>)',
+ );
+
+ $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('/^<opaquelocktoken:(.*)>$/',$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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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' => '</dir> (' . $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('<?xml version="1.0"?>
+<D:lockinfo xmlns:D="DAV:">
+ <D:lockscope><D:exclusive/></D:lockscope>
+ <D:locktype><D:write/></D:locktype>
+ <D:owner>
+ <D:href>http://example.org/~ejw/contact.html</D:href>
+ </D:owner>
+</D:lockinfo>');
+
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
+ $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
+
+ $this->assertEquals('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('/^<opaquelocktoken:(.*)>$/',$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();
+
+ }
+
+
+}