summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/files/storage/wrapper/quota.php22
-rw-r--r--tests/lib/files/stream/quota.php72
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 3702f8154f5..9b14335782f 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -58,4 +58,26 @@ class Quota extends \Test\Files\Storage\Storage {
fclose($stream);
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
}
+
+ public function testReturnRegularStreamOnRead(){
+ $instance = $this->getLimitedStorage(9);
+
+ // create test file first
+ $stream = $instance->fopen('foo', 'w+');
+ fwrite($stream, 'blablacontent');
+ fclose($stream);
+
+ $stream = $instance->fopen('foo', 'r');
+ $meta = stream_get_meta_data($stream);
+ $this->assertEquals('plainfile', $meta['wrapper_type']);
+ fclose($stream);
+ }
+
+ public function testReturnQuotaStreamOnWrite(){
+ $instance = $this->getLimitedStorage(9);
+ $stream = $instance->fopen('foo', 'w+');
+ $meta = stream_get_meta_data($stream);
+ $this->assertEquals('user-space', $meta['wrapper_type']);
+ fclose($stream);
+ }
}
diff --git a/tests/lib/files/stream/quota.php b/tests/lib/files/stream/quota.php
index 22d3e93592c..b11f0ac74c0 100644
--- a/tests/lib/files/stream/quota.php
+++ b/tests/lib/files/stream/quota.php
@@ -75,4 +75,76 @@ class Quota extends \PHPUnit_Framework_TestCase {
rewind($stream);
$this->assertEquals('qwerty', fread($stream, 100));
}
+
+ public function testFseekReturnsSuccess() {
+ $stream = $this->getStream('w+', 100);
+ fwrite($stream, '0123456789');
+ $this->assertEquals(0, fseek($stream, 3, SEEK_SET));
+ $this->assertEquals(0, fseek($stream, -1, SEEK_CUR));
+ $this->assertEquals(0, fseek($stream, -4, SEEK_END));
+ }
+
+ public function testWriteAfterSeekEndWithEnoughSpace() {
+ $stream = $this->getStream('w+', 100);
+ fwrite($stream, '0123456789');
+ fseek($stream, -3, SEEK_END);
+ $this->assertEquals(11, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdefghijk', fread($stream, 100));
+ }
+
+ public function testWriteAfterSeekEndWithNotEnoughSpace() {
+ $stream = $this->getStream('w+', 13);
+ fwrite($stream, '0123456789');
+ // seek forward first to potentially week out
+ // potential limit calculation errors
+ fseek($stream, 4, SEEK_SET);
+ // seek to the end
+ fseek($stream, -3, SEEK_END);
+ $this->assertEquals(6, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdef', fread($stream, 100));
+ }
+
+ public function testWriteAfterSeekSetWithEnoughSpace() {
+ $stream = $this->getStream('w+', 100);
+ fwrite($stream, '0123456789');
+ fseek($stream, 7, SEEK_SET);
+ $this->assertEquals(11, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdefghijk', fread($stream, 100));
+ }
+
+ public function testWriteAfterSeekSetWithNotEnoughSpace() {
+ $stream = $this->getStream('w+', 13);
+ fwrite($stream, '0123456789');
+ fseek($stream, 7, SEEK_SET);
+ $this->assertEquals(6, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdef', fread($stream, 100));
+ }
+
+ public function testWriteAfterSeekCurWithEnoughSpace() {
+ $stream = $this->getStream('w+', 100);
+ fwrite($stream, '0123456789');
+ rewind($stream);
+ fseek($stream, 3, SEEK_CUR);
+ fseek($stream, 5, SEEK_CUR);
+ fseek($stream, -1, SEEK_CUR);
+ $this->assertEquals(11, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdefghijk', fread($stream, 100));
+ }
+
+ public function testWriteAfterSeekCurWithNotEnoughSpace() {
+ $stream = $this->getStream('w+', 13);
+ fwrite($stream, '0123456789');
+ rewind($stream);
+ fseek($stream, 3, SEEK_CUR);
+ fseek($stream, 5, SEEK_CUR);
+ fseek($stream, -1, SEEK_CUR);
+ $this->assertEquals(6, fwrite($stream, 'abcdefghijk'));
+ rewind($stream);
+ $this->assertEquals('0123456abcdef', fread($stream, 100));
+ }
}