mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-10 18:38:49 +00:00
Initial Release of the calendar plugin
This commit is contained in:
parent
45cc9885fc
commit
7115197a33
561 changed files with 189494 additions and 0 deletions
192
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/AbstractTest.php
Normal file
192
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/AbstractTest.php
Normal file
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
|
||||
abstract class Sabre_DAV_Locks_Backend_AbstractTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return Sabre_DAV_Locks_Backend_Abstract
|
||||
*/
|
||||
abstract function getBackend();
|
||||
|
||||
function testSetup() {
|
||||
|
||||
$backend = $this->getBackend();
|
||||
$this->assertInstanceOf('Sabre_DAV_Locks_Backend_Abstract', $backend);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetLocks() {
|
||||
|
||||
$backend = $this->getBackend();
|
||||
|
||||
$lock = new Sabre_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 Sabre_DAV_Locks_LockInfo();
|
||||
$lock->owner = 'Sinterklaas';
|
||||
$lock->timeout = 60;
|
||||
$lock->created = time();
|
||||
$lock->depth = Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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));
|
||||
|
||||
}
|
||||
|
||||
}
|
29
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/FSTest.php
Normal file
29
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/FSTest.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_DAV_Locks_Backend_FSTest extends Sabre_DAV_Locks_Backend_AbstractTest {
|
||||
|
||||
function getBackend() {
|
||||
|
||||
Sabre_TestUtil::clearTempDir();
|
||||
mkdir(SABRE_TEMPDIR . '/locks');
|
||||
$backend = new Sabre_DAV_Locks_Backend_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.
|
||||
|
||||
}
|
||||
|
||||
}
|
22
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/FileTest.php
Normal file
22
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/FileTest.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_DAV_Locks_Backend_FileTest extends Sabre_DAV_Locks_Backend_AbstractTest {
|
||||
|
||||
function getBackend() {
|
||||
|
||||
Sabre_TestUtil::clearTempDir();
|
||||
$backend = new Sabre_DAV_Locks_Backend_File(SABRE_TEMPDIR . '/lockdb');
|
||||
return $backend;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
|
||||
Sabre_TestUtil::clearTempDir();
|
||||
|
||||
}
|
||||
|
||||
}
|
30
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php
Normal file
30
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_DAV_Locks_Backend_PDOMySQLTest extends Sabre_DAV_Locks_Backend_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 Sabre_DAV_Locks_Backend_PDO($pdo);
|
||||
return $backend;
|
||||
|
||||
}
|
||||
|
||||
}
|
27
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/PDOTest.php
Normal file
27
dav/SabreDAV/tests/Sabre/DAV/Locks/Backend/PDOTest.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
require_once 'Sabre/DAV/Locks/Backend/AbstractTest.php';
|
||||
|
||||
class Sabre_DAV_Locks_Backend_PDOTest extends Sabre_DAV_Locks_Backend_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 Sabre_DAV_Locks_Backend_PDO($pdo);
|
||||
return $backend;
|
||||
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
||||
Sabre_TestUtil::clearTempDir();
|
||||
|
||||
}
|
||||
|
||||
}
|
370
dav/SabreDAV/tests/Sabre/DAV/Locks/GetIfConditionsTest.php
Normal file
370
dav/SabreDAV/tests/Sabre/DAV/Locks/GetIfConditionsTest.php
Normal file
|
@ -0,0 +1,370 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
require_once 'Sabre/DAV/AbstractServer.php';
|
||||
|
||||
class Sabre_DAV_Locks_GetIfConditionsTest extends Sabre_DAV_AbstractServer {
|
||||
|
||||
/**
|
||||
* @var Sabre_DAV_Locks_Plugin
|
||||
*/
|
||||
protected $locksPlugin;
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$locksPlugin = new Sabre_DAV_Locks_Plugin();
|
||||
$this->server->addPlugin($locksPlugin);
|
||||
$this->locksPlugin = $locksPlugin;
|
||||
|
||||
}
|
||||
|
||||
function testNoConditions() {
|
||||
|
||||
$serverVars = array(
|
||||
);
|
||||
|
||||
$request = new Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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);
|
||||
|
||||
}
|
||||
|
||||
}
|
118
dav/SabreDAV/tests/Sabre/DAV/Locks/MSWordTest.php
Normal file
118
dav/SabreDAV/tests/Sabre/DAV/Locks/MSWordTest.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_DAV_Locks_MSWordTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testLockEtc() {
|
||||
|
||||
mkdir(SABRE_TEMPDIR . '/mstest');
|
||||
$tree = new Sabre_DAV_FS_Directory(SABRE_TEMPDIR . '/mstest');
|
||||
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->debugExceptions = true;
|
||||
$locksBackend = new Sabre_DAV_Locks_Backend_File(SABRE_TEMPDIR . '/locksdb');
|
||||
$locksPlugin = new Sabre_DAV_Locks_Plugin($locksBackend);
|
||||
$server->addPlugin($locksPlugin);
|
||||
|
||||
$response1 = new Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_HTTP_Request(array(
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx',
|
||||
'HTTP_IF' => 'If: ('.$lockToken.')',
|
||||
));
|
||||
$request->setBody('FAKE BODY');
|
||||
return $request;
|
||||
|
||||
}
|
||||
|
||||
}
|
961
dav/SabreDAV/tests/Sabre/DAV/Locks/PluginTest.php
Normal file
961
dav/SabreDAV/tests/Sabre/DAV/Locks/PluginTest.php
Normal file
|
@ -0,0 +1,961 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/DAV/AbstractServer.php';
|
||||
|
||||
class Sabre_DAV_Locks_PluginTest extends Sabre_DAV_AbstractServer {
|
||||
|
||||
/**
|
||||
* @var Sabre_DAV_Locks_Plugin
|
||||
*/
|
||||
protected $locksPlugin;
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$locksBackend = new Sabre_DAV_Locks_Backend_File(SABRE_TEMPDIR . '/locksdb');
|
||||
$locksPlugin = new Sabre_DAV_Locks_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 Sabre_DAV_Locks_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_HTTP_ResponseMock();
|
||||
$this->server->httpResponse = $this->response;
|
||||
|
||||
$serverVars = array(
|
||||
'REQUEST_URI' => '/test.txt',
|
||||
'REQUEST_METHOD' => 'LOCK',
|
||||
'HTTP_IF' => '(' . $lockToken . ')',
|
||||
);
|
||||
$request = new Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_HTTP_Request($serverVars);
|
||||
$this->server->httpRequest = ($request);
|
||||
$this->server->httpResponse = new Sabre_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 Sabre_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 Sabre_HTTP_Request($serverVars);
|
||||
$this->server->httpRequest = ($request);
|
||||
$this->server->httpResponse = new Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_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 Sabre_DAV_ObjectTree(new Sabre_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 Sabre_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 Sabre_HTTP_Request(array(
|
||||
'HTTP_TIMEOUT' => 'second-100',
|
||||
));
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->assertEquals(100, $this->locksPlugin->getTimeoutHeader());
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testGetTimeoutHeaderNotSet() {
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
));
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->assertEquals(0, $this->locksPlugin->getTimeoutHeader());
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testGetTimeoutHeaderInfinite() {
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'HTTP_TIMEOUT' => 'infinite',
|
||||
));
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->assertEquals(Sabre_DAV_Locks_LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_BadRequest
|
||||
*/
|
||||
function testGetTimeoutHeaderInvalid() {
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'HTTP_TIMEOUT' => 'yourmom',
|
||||
));
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->locksPlugin->getTimeoutHeader();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue