aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/FSExt
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/FSExt
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/FSExt')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php95
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php178
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php224
3 files changed, 497 insertions, 0 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php
new file mode 100644
index 000000000..265f9f1c1
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Sabre\DAV\FSExt;
+
+use Sabre\DAV;
+
+require_once 'Sabre/TestUtil.php';
+
+class FileTest extends \PHPUnit_Framework_TestCase {
+
+ function setUp() {
+
+ file_put_contents(SABRE_TEMPDIR . '/file.txt', 'Contents');
+
+ }
+
+ function tearDown() {
+
+ \Sabre\TestUtil::clearTempDir();
+
+ }
+
+ function testPut() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $result = $file->put('New contents');
+
+ $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+ $this->assertEquals('"' . md5('New contents') . '"', $result);
+
+ }
+
+ function testRange() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $file->put('0000000');
+ $file->putRange('111',3);
+
+ $this->assertEquals('0011100',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+
+ }
+
+ function testRangeStream() {
+
+ $stream = fopen('php://memory','r+');
+ fwrite($stream, "222");
+ rewind($stream);
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $file->put('0000000');
+ $file->putRange($stream,3);
+
+ $this->assertEquals('0022200',file_get_contents(SABRE_TEMPDIR . '/file.txt'));
+
+ }
+
+
+ function testGet() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $this->assertEquals('Contents',stream_get_contents($file->get()));
+
+ }
+
+ function testDelete() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $file->delete();
+
+ $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt'));
+
+ }
+
+ function testGetETag() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $this->assertEquals('"' . md5('Contents') . '"',$file->getETag());
+
+ }
+
+ function testGetContentType() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $this->assertNull($file->getContentType());
+
+ }
+
+ function testGetSize() {
+
+ $file = new File(SABRE_TEMPDIR . '/file.txt');
+ $this->assertEquals(8,$file->getSize());
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php
new file mode 100644
index 000000000..275075b4c
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php
@@ -0,0 +1,178 @@
+<?php
+
+namespace Sabre\DAV\FSExt;
+use Sabre\DAV;
+
+require_once 'Sabre/TestUtil.php';
+
+class NodeTest extends \PHPUnit_Framework_TestCase {
+
+ function setUp() {
+
+ mkdir(SABRE_TEMPDIR . '/dir');
+ file_put_contents(SABRE_TEMPDIR . '/dir/file.txt', 'Contents');
+ file_put_contents(SABRE_TEMPDIR . '/dir/file2.txt', 'Contents2');
+
+ }
+
+ function tearDown() {
+
+ \Sabre\TestUtil::clearTempDir();
+
+ }
+
+ function testUpdateProperties() {
+
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+ $properties = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ );
+
+ $result = $file->updateProperties($properties);
+ $expected = true;
+
+ $this->assertEquals($expected, $result);
+
+ $getProperties = $file->getProperties(array_keys($properties));
+
+ $this->assertEquals($properties, $getProperties);
+
+ }
+
+ /**
+ * @depends testUpdateProperties
+ */
+ function testUpdatePropertiesAgain() {
+
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test3' => 'baz',
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+ }
+
+ /**
+ * @depends testUpdateProperties
+ */
+ function testUpdatePropertiesDelete() {
+
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => null,
+ '{http://sabredav.org/NS/2010}test3' => null
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+
+ $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
+
+ $this->assertEquals(array(
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ ), $properties);
+ }
+
+ /**
+ * @depends testUpdateProperties
+ */
+ function testUpdatePropertiesMove() {
+
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+
+ $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
+
+ $this->assertEquals(array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ ), $properties);
+
+ // Renaming
+ $file->setName('file3.txt');
+
+ $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
+ $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir/file3.txt'));
+ $this->assertEquals('file3.txt',$file->getName());
+
+ $newFile = new File(SABRE_TEMPDIR . '/dir/file3.txt');
+ $this->assertEquals('file3.txt',$newFile->getName());
+
+ $properties = $newFile->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
+
+ $this->assertEquals(array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ ), $properties);
+ }
+
+ /**
+ * @depends testUpdatePropertiesMove
+ */
+ function testUpdatePropertiesDeleteBleed() {
+
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+ $mutations = array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ );
+
+ $result = $file->updateProperties($mutations);
+
+ $this->assertEquals(true, $result);
+
+ $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
+
+ $this->assertEquals(array(
+ '{http://sabredav.org/NS/2010}test1' => 'foo',
+ '{http://sabredav.org/NS/2010}test2' => 'bar',
+ ), $properties);
+
+ // Deleting
+ $file->delete();
+
+ $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
+
+ // Creating it again
+ file_put_contents(SABRE_TEMPDIR . '/dir/file.txt','New Contents');
+ $file = new File(SABRE_TEMPDIR . '/dir/file.txt');
+
+ $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
+
+ $this->assertEquals(array(), $properties);
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php
new file mode 100644
index 000000000..907ede40b
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php
@@ -0,0 +1,224 @@
+<?php
+
+namespace Sabre\DAV\FSExt;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+
+require_once 'Sabre/DAV/AbstractServer.php';
+
+class ServerTest extends DAV\AbstractServer{
+
+ protected function getRootNode() {
+
+ return new Directory($this->tempDir);
+
+ }
+
+ function testGet() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'GET',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Length' => 13,
+ 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
+ 'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"',
+ ),
+ $this->response->headers
+ );
+
+ $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
+ $this->assertEquals('Test contents', stream_get_contents($this->response->body));
+
+ }
+
+ function testHEAD() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'HEAD',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Length' => 13,
+ 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
+ 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
+ ),
+ $this->response->headers
+ );
+
+ $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+
+ }
+
+ function testPut() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/testput.txt',
+ 'REQUEST_METHOD' => 'PUT',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $request->setBody('Testing new file');
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Length' => 0,
+ 'ETag' => '"' . md5('Testing new file') . '"',
+ ), $this->response->headers);
+
+ $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+ $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
+
+ }
+
+ function testPutAlreadyExists() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'PUT',
+ 'HTTP_IF_NONE_MATCH' => '*',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $request->setBody('Testing new file');
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Type' => 'application/xml; charset=utf-8',
+ ),$this->response->headers);
+
+ $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
+ $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
+
+ }
+
+ function testMkcol() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/testcol',
+ 'REQUEST_METHOD' => 'MKCOL',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $request->setBody("");
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Length' => '0',
+ ),$this->response->headers);
+
+ $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+ $this->assertTrue(is_dir($this->tempDir . '/testcol'));
+
+ }
+
+ function testPutUpdate() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'PUT',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $request->setBody('Testing updated file');
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals('0', $this->response->headers['Content-Length']);
+
+ $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+ $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt'));
+
+ }
+
+ function testDelete() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/test.txt',
+ 'REQUEST_METHOD' => 'DELETE',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Length' => '0',
+ ),$this->response->headers);
+
+ $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+ $this->assertFalse(file_exists($this->tempDir . '/test.txt'));
+
+ }
+
+ function testDeleteDirectory() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/testcol',
+ 'REQUEST_METHOD' => 'DELETE',
+ );
+
+ mkdir($this->tempDir.'/testcol');
+ file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'Content-Length' => '0',
+ ),$this->response->headers);
+ $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+ $this->assertFalse(file_exists($this->tempDir . '/col'));
+
+ }
+
+ function testOptions() {
+
+ $serverVars = array(
+ 'REQUEST_URI' => '/',
+ 'REQUEST_METHOD' => 'OPTIONS',
+ );
+
+ $request = new HTTP\Request($serverVars);
+ $this->server->httpRequest = ($request);
+ $this->server->exec();
+
+ $this->assertEquals(array(
+ 'DAV' => '1, 3, extended-mkcol',
+ 'MS-Author-Via' => 'DAV',
+ 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
+ 'Accept-Ranges' => 'bytes',
+ 'Content-Length' => '0',
+ 'X-Sabre-Version'=> DAV\Version::VERSION,
+ ),$this->response->headers);
+
+ $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
+ $this->assertEquals('', $this->response->body);
+
+ }
+
+}