summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-13 14:37:10 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-13 14:37:10 +0200
commit3c0a1d4241c16c13b3fd93406402320284d153d9 (patch)
treefd79c48c483c5e03437480665cd93996d9a2e304 /apps/dav/tests
parent15397a9c910925ac368001545ab96509a12cb0ad (diff)
parente21642ca31d69f2f9c5328c7eb804fb45a8c4c23 (diff)
downloadnextcloud-server-3c0a1d4241c16c13b3fd93406402320284d153d9.tar.gz
nextcloud-server-3c0a1d4241c16c13b3fd93406402320284d153d9.zip
Merge pull request #20118 from owncloud/chunked-upload-dav
Initial implementation of the new chunked upload
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesplugin.php33
-rw-r--r--apps/dav/tests/unit/upload/assemblystreamtest.php47
-rw-r--r--apps/dav/tests/unit/upload/futurefiletest.php89
3 files changed, 156 insertions, 13 deletions
diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php
index fb08ee170c4..63ee5a53c17 100644
--- a/apps/dav/tests/unit/connector/sabre/filesplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php
@@ -23,6 +23,9 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
use OCP\Files\StorageNotAvailableException;
+use Sabre\DAV\PropFind;
+use Sabre\DAV\PropPatch;
+use Test\TestCase;
/**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
@@ -30,7 +33,7 @@ use OCP\Files\StorageNotAvailableException;
* later.
* See the COPYING-README file.
*/
-class FilesPlugin extends \Test\TestCase {
+class FilesPlugin extends TestCase {
const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME;
const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME;
const INTERNAL_FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::INTERNAL_FILEID_PROPERTYNAME;
@@ -42,12 +45,12 @@ class FilesPlugin extends \Test\TestCase {
const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
/**
- * @var \Sabre\DAV\Server
+ * @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
*/
private $server;
/**
- * @var \Sabre\DAV\Tree
+ * @var \Sabre\DAV\Tree | \PHPUnit_Framework_MockObject_MockObject
*/
private $tree;
@@ -57,7 +60,7 @@ class FilesPlugin extends \Test\TestCase {
private $plugin;
/**
- * @var \OC\Files\View
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject
*/
private $view;
@@ -79,6 +82,7 @@ class FilesPlugin extends \Test\TestCase {
/**
* @param string $class
+ * @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createTestNode($class) {
$node = $this->getMockBuilder($class)
@@ -111,9 +115,10 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesForFile() {
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -165,11 +170,12 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesForFileHome() {
+ /** @var \OCA\DAV\Files\FilesHome | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->getMockBuilder('\OCA\DAV\Files\FilesHome')
->disableOriginalConstructor()
->getMock();
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -214,9 +220,10 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesStorageNotAvailable() {
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::DOWNLOADURL_PROPERTYNAME,
@@ -240,7 +247,7 @@ class FilesPlugin extends \Test\TestCase {
$this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
$this->plugin->initialize($this->server);
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
[
self::PERMISSIONS_PROPERTYNAME,
@@ -248,6 +255,7 @@ class FilesPlugin extends \Test\TestCase {
0
);
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node->expects($this->any())
->method('getDavPermissions')
@@ -262,9 +270,10 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesForDirectory() {
+ /** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -308,7 +317,7 @@ class FilesPlugin extends \Test\TestCase {
->will($this->returnValue(true));
// properties to set
- $propPatch = new \Sabre\DAV\PropPatch(array(
+ $propPatch = new PropPatch(array(
self::GETETAG_PROPERTYNAME => 'newetag',
self::LASTMODIFIED_PROPERTYNAME => $testDate
));
@@ -328,9 +337,7 @@ class FilesPlugin extends \Test\TestCase {
}
public function testUpdatePropsForbidden() {
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
-
- $propPatch = new \Sabre\DAV\PropPatch(array(
+ $propPatch = new PropPatch(array(
self::OWNER_ID_PROPERTYNAME => 'user2',
self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
self::FILEID_PROPERTYNAME => 12345,
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');
+ }
+}
+