diff options
author | Georg Ehrke <developer@georgehrke.com> | 2013-08-23 23:10:37 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2013-08-23 23:10:37 +0200 |
commit | 6ffa2a28d0ae63b061e1e88ee3b12726d31c3f9d (patch) | |
tree | b564539f21866e6049d69da6d011647ff46540f7 /tests | |
parent | 1dab0767502013b5e86e8e24e3b12a2a8939f7a8 (diff) | |
parent | 02b2b5a808b135007d8d54b837e70c38f02729fd (diff) | |
download | nextcloud-server-6ffa2a28d0ae63b061e1e88ee3b12726d31c3f9d.tar.gz nextcloud-server-6ffa2a28d0ae63b061e1e88ee3b12726d31c3f9d.zip |
Merge branch 'master' into oc_preview
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/storage/wrapper/quota.php | 61 | ||||
-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.php | 78 |
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)); + } +} |