summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-10-28 14:52:45 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-04-12 12:32:04 +0200
commit72f5c539e887d2671641222d33848e28a936d771 (patch)
tree180194907ca16d3dffd1aa0ab037fa75d259e46e /apps/dav/tests/unit
parent276b8a583112203b9b71e4ac2b372e50ca62df9b (diff)
downloadnextcloud-server-72f5c539e887d2671641222d33848e28a936d771.tar.gz
nextcloud-server-72f5c539e887d2671641222d33848e28a936d771.zip
Initial implementation of the new chunked upload - as specified in https://dragotin.wordpress.com/2015/06/22/owncloud-chunking-ng/
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r--apps/dav/tests/unit/upload/assemblystreamtest.php47
-rw-r--r--apps/dav/tests/unit/upload/futurefiletest.php89
2 files changed, 136 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/upload/assemblystreamtest.php b/apps/dav/tests/unit/upload/assemblystreamtest.php
new file mode 100644
index 00000000000..373d525a9dd
--- /dev/null
+++ b/apps/dav/tests/unit/upload/assemblystreamtest.php
@@ -0,0 +1,47 @@
+<?php
+
+class AssemblyStreamTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider providesNodes()
+ */
+ public function testGetContents($expected, $nodes) {
+ $stream = \OCA\DAV\Upload\AssemblyStream::wrap($nodes);
+ $content = stream_get_contents($stream);
+
+ $this->assertEquals($expected, $content);
+ }
+
+ function providesNodes() {
+ return[
+ 'one node only' => ['1234567890', [
+ $this->buildNode('0', '1234567890')
+ ]],
+ 'two nodes' => ['1234567890', [
+ $this->buildNode('1', '67890'),
+ $this->buildNode('0', '12345')
+ ]]
+ ];
+ }
+
+ private function buildNode($name, $data) {
+ $node = $this->getMockBuilder('\Sabre\DAV\File')
+ ->setMethods(['getName', 'get', 'getSize'])
+ ->getMockForAbstractClass();
+
+ $node->expects($this->any())
+ ->method('getName')
+ ->willReturn($name);
+
+ $node->expects($this->any())
+ ->method('get')
+ ->willReturn($data);
+
+ $node->expects($this->any())
+ ->method('getSize')
+ ->willReturn(strlen($data));
+
+ return $node;
+ }
+}
+
diff --git a/apps/dav/tests/unit/upload/futurefiletest.php b/apps/dav/tests/unit/upload/futurefiletest.php
new file mode 100644
index 00000000000..c0c14bf04d7
--- /dev/null
+++ b/apps/dav/tests/unit/upload/futurefiletest.php
@@ -0,0 +1,89 @@
+<?php
+
+class FutureFileTest extends \PHPUnit_Framework_TestCase {
+
+ public function testGetContentType() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('application/octet-stream', $f->getContentType());
+ }
+
+ public function testGetETag() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('1234567890', $f->getETag());
+ }
+
+ public function testGetName() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('foo.txt', $f->getName());
+ }
+
+ public function testGetLastModified() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals(12121212, $f->getLastModified());
+ }
+
+ public function testGetSize() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals(0, $f->getSize());
+ }
+
+ public function testGet() {
+ $f = $this->mockFutureFile();
+ $stream = $f->get();
+ $this->assertTrue(is_resource($stream));
+ }
+
+ public function testDelete() {
+ $d = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->setMethods(['delete'])
+ ->getMock();
+
+ $d->expects($this->once())
+ ->method('delete');
+
+ $f = new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
+ $f->delete();
+ }
+
+ /**
+ * @expectedException Sabre\DAV\Exception\Forbidden
+ */
+ public function testPut() {
+ $f = $this->mockFutureFile();
+ $f->put('');
+ }
+
+ /**
+ * @expectedException Sabre\DAV\Exception\Forbidden
+ */
+ public function testSetName() {
+ $f = $this->mockFutureFile();
+ $f->setName('');
+ }
+
+ /**
+ * @return \OCA\DAV\Upload\FutureFile
+ */
+ private function mockFutureFile() {
+ $d = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->setMethods(['getETag', 'getLastModified', 'getChildren'])
+ ->getMock();
+
+ $d->expects($this->any())
+ ->method('getETag')
+ ->willReturn('1234567890');
+
+ $d->expects($this->any())
+ ->method('getLastModified')
+ ->willReturn(12121212);
+
+ $d->expects($this->any())
+ ->method('getChildren')
+ ->willReturn([]);
+
+ return new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
+ }
+}
+