summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-07-02 17:45:34 +0200
committerRobin Appelman <icewind@owncloud.com>2013-07-25 00:31:51 +0200
commit10d3e63ce5f3923dc629ac3c16f3cd6324bf96ed (patch)
treed4af433d74fdaad9433677db6d9c46c16eccc8d1 /tests
parent94560c68ba8974e72098e525ff1d96f11a3ae2e0 (diff)
downloadnextcloud-server-10d3e63ce5f3923dc629ac3c16f3cd6324bf96ed.tar.gz
nextcloud-server-10d3e63ce5f3923dc629ac3c16f3cd6324bf96ed.zip
add quota streamwrapper that limits the amount of data that can be written to a stream
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/stream/quota.php78
1 files changed, 78 insertions, 0 deletions
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));
+ }
+}