summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoricewind1991 <icewind1991@gmail.com>2013-08-19 03:38:55 -0700
committericewind1991 <icewind1991@gmail.com>2013-08-19 03:38:55 -0700
commitd7dde3cfbcb779f831130bdc65c8570437c73a71 (patch)
tree452ae55efd45a908f7f13b975438696ddbe4f4cf /tests
parenta1d5aba5fd3795a6ee4a87c96abf0d35d3f8116d (diff)
parentd8c71ba734d95e954d4ff3af50a44b94f9f016ff (diff)
downloadnextcloud-server-d7dde3cfbcb779f831130bdc65c8570437c73a71.tar.gz
nextcloud-server-d7dde3cfbcb779f831130bdc65c8570437c73a71.zip
Merge pull request #4467 from owncloud/storage-wrapper-quota
Move quota logic from filesystem proxy to storage wrapper
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/storage/wrapper/quota.php61
-rw-r--r--tests/lib/files/storage/wrapper/wrapper.php (renamed from tests/lib/files/storage/wrapper.php)4
-rw-r--r--tests/lib/files/stream/quota.php78
3 files changed, 141 insertions, 2 deletions
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
new file mode 100644
index 00000000000..3702f8154f5
--- /dev/null
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Storage\Wrapper;
+
+//ensure the constants are loaded
+\OC::$loader->load('\OC\Files\Filesystem');
+
+class Quota extends \Test\Files\Storage\Storage {
+ /**
+ * @var string tmpDir
+ */
+ private $tmpDir;
+
+ public function setUp() {
+ $this->tmpDir = \OC_Helper::tmpFolder();
+ $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir));
+ $this->instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 10000000));
+ }
+
+ public function tearDown() {
+ \OC_Helper::rmdirr($this->tmpDir);
+ }
+
+ protected function getLimitedStorage($limit) {
+ $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir));
+ $storage->getScanner()->scan('');
+ return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $limit));
+ }
+
+ public function testFilePutContentsNotEnoughSpace() {
+ $instance = $this->getLimitedStorage(3);
+ $this->assertFalse($instance->file_put_contents('foo', 'foobar'));
+ }
+
+ public function testCopyNotEnoughSpace() {
+ $instance = $this->getLimitedStorage(9);
+ $this->assertEquals(6, $instance->file_put_contents('foo', 'foobar'));
+ $instance->getScanner()->scan('');
+ $this->assertFalse($instance->copy('foo', 'bar'));
+ }
+
+ public function testFreeSpace() {
+ $instance = $this->getLimitedStorage(9);
+ $this->assertEquals(9, $instance->free_space(''));
+ }
+
+ public function testFWriteNotEnoughSpace() {
+ $instance = $this->getLimitedStorage(9);
+ $stream = $instance->fopen('foo', 'w+');
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ $this->assertEquals(3, fwrite($stream, 'qwerty'));
+ fclose($stream);
+ $this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
+ }
+}
diff --git a/tests/lib/files/storage/wrapper.php b/tests/lib/files/storage/wrapper/wrapper.php
index 2794a0a6263..e31abfc7324 100644
--- a/tests/lib/files/storage/wrapper.php
+++ b/tests/lib/files/storage/wrapper/wrapper.php
@@ -6,9 +6,9 @@
* See the COPYING-README file.
*/
-namespace Test\Files\Storage;
+namespace Test\Files\Storage\Wrapper;
-class Wrapper extends Storage {
+class Wrapper extends \Test\Files\Storage\Storage {
/**
* @var string tmpDir
*/
diff --git a/tests/lib/files/stream/quota.php b/tests/lib/files/stream/quota.php
new file mode 100644
index 00000000000..22d3e93592c
--- /dev/null
+++ b/tests/lib/files/stream/quota.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Stream;
+
+class Quota extends \PHPUnit_Framework_TestCase {
+ public function tearDown() {
+ \OC\Files\Stream\Quota::clear();
+ }
+
+ protected function getStream($mode, $limit) {
+ $source = fopen('php://temp', $mode);
+ return \OC\Files\Stream\Quota::wrap($source, $limit);
+ }
+
+ public function testWriteEnoughSpace() {
+ $stream = $this->getStream('w+', 100);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ rewind($stream);
+ $this->assertEquals('foobar', fread($stream, 100));
+ }
+
+ public function testWriteNotEnoughSpace() {
+ $stream = $this->getStream('w+', 3);
+ $this->assertEquals(3, fwrite($stream, 'foobar'));
+ rewind($stream);
+ $this->assertEquals('foo', fread($stream, 100));
+ }
+
+ public function testWriteNotEnoughSpaceSecondTime() {
+ $stream = $this->getStream('w+', 9);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ $this->assertEquals(3, fwrite($stream, 'qwerty'));
+ rewind($stream);
+ $this->assertEquals('foobarqwe', fread($stream, 100));
+ }
+
+ public function testWriteEnoughSpaceRewind() {
+ $stream = $this->getStream('w+', 6);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ rewind($stream);
+ $this->assertEquals(3, fwrite($stream, 'qwe'));
+ rewind($stream);
+ $this->assertEquals('qwebar', fread($stream, 100));
+ }
+
+ public function testWriteNotEnoughSpaceRead() {
+ $stream = $this->getStream('w+', 6);
+ $this->assertEquals(6, fwrite($stream, 'foobar'));
+ rewind($stream);
+ $this->assertEquals('foobar', fread($stream, 6));
+ $this->assertEquals(0, fwrite($stream, 'qwe'));
+ }
+
+ public function testWriteNotEnoughSpaceExistingStream() {
+ $source = fopen('php://temp', 'w+');
+ fwrite($source, 'foobar');
+ $stream = \OC\Files\Stream\Quota::wrap($source, 3);
+ $this->assertEquals(3, fwrite($stream, 'foobar'));
+ rewind($stream);
+ $this->assertEquals('foobarfoo', fread($stream, 100));
+ }
+
+ public function testWriteNotEnoughSpaceExistingStreamRewind() {
+ $source = fopen('php://temp', 'w+');
+ fwrite($source, 'foobar');
+ $stream = \OC\Files\Stream\Quota::wrap($source, 3);
+ rewind($stream);
+ $this->assertEquals(6, fwrite($stream, 'qwerty'));
+ rewind($stream);
+ $this->assertEquals('qwerty', fread($stream, 100));
+ }
+}