moved deprecated communityhome, dav and yourls to the deprecated-addons repository

This commit is contained in:
Tobias Diekershoff 2018-06-02 11:23:11 +02:00
commit 31520f804d
675 changed files with 195144 additions and 0 deletions

View file

@ -0,0 +1,76 @@
<?php
require_once 'Sabre/TestUtil.php';
class Sabre_DAV_FSExt_FileTest extends PHPUnit_Framework_TestCase {
function setUp() {
file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents');
}
function tearDown() {
Sabre_TestUtil::clearTempDir();
}
function testPut() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$result = $file->put('New contents');
$this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
$this->assertEquals('"' . md5('New contents') . '"', $result);
}
function testRange() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$file->put('0000000');
$file->putRange('111',3);
$this->assertEquals('0011100',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
}
function testGet() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$this->assertEquals('Contents',stream_get_contents($file->get()));
}
function testDelete() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$file->delete();
$this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
}
function testGetETag() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$this->assertEquals('"' . md5('Contents') . '"',$file->getETag());
}
function testGetContentType() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$this->assertNull($file->getContentType());
}
function testGetSize() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/file.txt');
$this->assertEquals(8,$file->getSize());
}
}

View file

@ -0,0 +1,175 @@
<?php
require_once 'Sabre/TestUtil.php';
class Sabre_DAV_FSExt_NodeTest extends PHPUnit_Framework_TestCase {
function setUp() {
mkdir(SABRE_TEMPDIR . '/dir');
file_put_contents(SABRE_TEMPDIR . '/dir/file.txt', 'Contents');
file_put_contents(SABRE_TEMPDIR . '/dir/file2.txt', 'Contents2');
}
function tearDown() {
Sabre_TestUtil::clearTempDir();
}
function testUpdateProperties() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$properties = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
);
$result = $file->updateProperties($properties);
$expected = true;
$this->assertEquals($expected, $result);
$getProperties = $file->getProperties(array_keys($properties));
$this->assertEquals($properties, $getProperties);
}
/**
* @depends testUpdateProperties
*/
function testUpdatePropertiesAgain() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test3' => 'baz',
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
}
/**
* @depends testUpdateProperties
*/
function testUpdatePropertiesDelete() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => null,
'{http://sabredav.org/NS/2010}test3' => null
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
$properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
$this->assertEquals(array(
'{http://sabredav.org/NS/2010}test2' => 'bar',
), $properties);
}
/**
* @depends testUpdateProperties
*/
function testUpdatePropertiesMove() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
$properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
$this->assertEquals(array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
), $properties);
// Renaming
$file->setName('file3.txt');
$this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
$this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir/file3.txt'));
$this->assertEquals('file3.txt',$file->getName());
$newFile = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file3.txt');
$this->assertEquals('file3.txt',$newFile->getName());
$properties = $newFile->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
$this->assertEquals(array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
), $properties);
}
/**
* @depends testUpdatePropertiesMove
*/
function testUpdatePropertiesDeleteBleed() {
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$mutations = array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
);
$result = $file->updateProperties($mutations);
$this->assertEquals(true, $result);
$properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
$this->assertEquals(array(
'{http://sabredav.org/NS/2010}test1' => 'foo',
'{http://sabredav.org/NS/2010}test2' => 'bar',
), $properties);
// Deleting
$file->delete();
$this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
// Creating it again
file_put_contents(SABRE_TEMPDIR . '/dir/file.txt','New Contents');
$file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
$properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
$this->assertEquals(array(), $properties);
}
}

View file

@ -0,0 +1,219 @@
<?php
require_once 'Sabre/DAV/AbstractServer.php';
class Sabre_DAV_FSExt_ServerTest extends Sabre_DAV_AbstractServer{
protected function getRootNode() {
return new Sabre_DAV_FSExt_Directory($this->tempDir);
}
function testGet() {
$serverVars = array(
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'GET',
);
$request = new Sabre_HTTP_Request($serverVars);
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Type' => 'application/octet-stream',
'Content-Length' => 13,
'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"',
),
$this->response->headers
);
$this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
$this->assertEquals('Test contents', stream_get_contents($this->response->body));
}
function testHEAD() {
$serverVars = array(
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'HEAD',
);
$request = new Sabre_HTTP_Request($serverVars);
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Type' => 'application/octet-stream',
'Content-Length' => 13,
'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
),
$this->response->headers
);
$this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
$this->assertEquals('', $this->response->body);
}
function testPut() {
$serverVars = array(
'REQUEST_URI' => '/testput.txt',
'REQUEST_METHOD' => 'PUT',
);
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('Testing new file');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Length' => 0,
'ETag' => '"' . md5('Testing new file') . '"',
), $this->response->headers);
$this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
}
function testPutAlreadyExists() {
$serverVars = array(
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'PUT',
'HTTP_IF_NONE_MATCH' => '*',
);
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('Testing new file');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Type' => 'application/xml; charset=utf-8',
),$this->response->headers);
$this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
$this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
}
function testMkcol() {
$serverVars = array(
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
);
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody("");
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Length' => '0',
),$this->response->headers);
$this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertTrue(is_dir($this->tempDir . '/testcol'));
}
function testPutUpdate() {
$serverVars = array(
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'PUT',
);
$request = new Sabre_HTTP_Request($serverVars);
$request->setBody('Testing updated file');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals('0', $this->response->headers['Content-Length']);
$this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt'));
}
function testDelete() {
$serverVars = array(
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'DELETE',
);
$request = new Sabre_HTTP_Request($serverVars);
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Length' => '0',
),$this->response->headers);
$this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertFalse(file_exists($this->tempDir . '/test.txt'));
}
function testDeleteDirectory() {
$serverVars = array(
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'DELETE',
);
mkdir($this->tempDir.'/testcol');
file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
$request = new Sabre_HTTP_Request($serverVars);
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'Content-Length' => '0',
),$this->response->headers);
$this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
$this->assertEquals('', $this->response->body);
$this->assertFalse(file_exists($this->tempDir . '/col'));
}
function testOptions() {
$serverVars = array(
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'OPTIONS',
);
$request = new Sabre_HTTP_Request($serverVars);
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(array(
'DAV' => '1, 3, extended-mkcol',
'MS-Author-Via' => 'DAV',
'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
'Accept-Ranges' => 'bytes',
'Content-Length' => '0',
'X-Sabre-Version'=> Sabre_DAV_Version::VERSION,
),$this->response->headers);
$this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
$this->assertEquals('', $this->response->body);
}
}