diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-07-02 18:22:49 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-07-25 00:31:51 +0200 |
commit | cd8f0c21ced2283a8cf8b48af1c91d665a1dab49 (patch) | |
tree | abf4ccdea85973172ee7af04992d704a3579714a /tests | |
parent | a853968f7dddcbb18e815f0323ed3046e048e4b1 (diff) | |
download | nextcloud-server-cd8f0c21ced2283a8cf8b48af1c91d665a1dab49.tar.gz nextcloud-server-cd8f0c21ced2283a8cf8b48af1c91d665a1dab49.zip |
add quota storage wrapper
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/storage/wrapper/quota.php | 61 |
1 files changed, 61 insertions, 0 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')); + } +} |