summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-08-26 21:31:15 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-08-26 21:31:15 +0200
commita995e81686cd1255d8f43e13026f43d814dd64f4 (patch)
treed0ef4065dec033922bfd0c751d8d84470d279fff /tests
parent38f9df429397619482e3e3f7ffb0db5274222e4c (diff)
parent7d141656ee837199f58d6a29033ded7d5c2a4632 (diff)
downloadnextcloud-server-a995e81686cd1255d8f43e13026f43d814dd64f4.tar.gz
nextcloud-server-a995e81686cd1255d8f43e13026f43d814dd64f4.zip
Merge branch 'master' into appframework-master
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/app.php2
-rw-r--r--tests/lib/appconfig.php132
-rw-r--r--tests/lib/archive/zip.php2
-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
-rw-r--r--tests/lib/geo.php2
-rw-r--r--tests/lib/vobject.php2
8 files changed, 277 insertions, 6 deletions
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 5396db8143e..52eade90a6e 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -79,4 +79,4 @@ class Test_App extends PHPUnit_Framework_TestCase {
$this->assertFalse(OC_App::isAppVersionCompatible($oc, $app));
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
new file mode 100644
index 00000000000..4d82cd5ba7b
--- /dev/null
+++ b/tests/lib/appconfig.php
@@ -0,0 +1,132 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Appconfig extends PHPUnit_Framework_TestCase {
+ public static function setUpBeforeClass() {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
+
+ $query->execute(array('testapp', 'enabled', 'true'));
+ $query->execute(array('testapp', 'installed_version', '1.2.3'));
+ $query->execute(array('testapp', 'depends_on', 'someapp'));
+ $query->execute(array('testapp', 'deletethis', 'deletethis'));
+ $query->execute(array('testapp', 'key', 'value'));
+
+ $query->execute(array('someapp', 'key', 'value'));
+ $query->execute(array('someapp', 'otherkey', 'othervalue'));
+
+ $query->execute(array('123456', 'key', 'value'));
+ $query->execute(array('123456', 'enabled', 'false'));
+
+ $query->execute(array('anotherapp', 'key', 'value'));
+ $query->execute(array('anotherapp', 'enabled', 'false'));
+ }
+
+ public static function tearDownAfterClass() {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('testapp'));
+ $query->execute(array('someapp'));
+ $query->execute(array('123456'));
+ $query->execute(array('anotherapp'));
+ }
+
+ public function testGetApps() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
+ $result = $query->execute();
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['appid'];
+ }
+ $apps = \OC_Appconfig::getApps();
+ $this->assertEquals($expected, $apps);
+ }
+
+ public function testGetKeys() {
+ $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $result = $query->execute(array('testapp'));
+ $expected = array();
+ while($row = $result->fetchRow()) {
+ $expected[] = $row["configkey"];
+ }
+ $keys = \OC_Appconfig::getKeys('testapp');
+ $this->assertEquals($expected, $keys);
+ }
+
+ public function testGetValue() {
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('testapp', 'installed_version'));
+ $expected = $result->fetchRow();
+ $value = \OC_Appconfig::getValue('testapp', 'installed_version');
+ $this->assertEquals($expected['configvalue'], $value);
+
+ $value = \OC_Appconfig::getValue('testapp', 'nonexistant');
+ $this->assertNull($value);
+
+ $value = \OC_Appconfig::getValue('testapp', 'nonexistant', 'default');
+ $this->assertEquals('default', $value);
+ }
+
+ public function testHasKey() {
+ $value = \OC_Appconfig::hasKey('testapp', 'installed_version');
+ $this->assertTrue($value);
+
+ $value = \OC_Appconfig::hasKey('nonexistant', 'nonexistant');
+ $this->assertFalse($value);
+ }
+
+ public function testSetValue() {
+ \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('testapp', 'installed_version'));
+ $value = $result->fetchRow();
+ $this->assertEquals('1.33.7', $value['configvalue']);
+
+ \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('someapp', 'somekey'));
+ $value = $result->fetchRow();
+ $this->assertEquals('somevalue', $value['configvalue']);
+ }
+
+ public function testDeleteKey() {
+ \OC_Appconfig::deleteKey('testapp', 'deletethis');
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $query->execute(array('testapp', 'deletethis'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ public function testDeleteApp() {
+ \OC_Appconfig::deleteApp('someapp');
+ $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('someapp'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ public function testGetValues() {
+ $this->assertFalse(\OC_Appconfig::getValues('testapp', 'enabled'));
+
+ $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('testapp'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['configkey']] = $row['configvalue'];
+ }
+ $values = \OC_Appconfig::getValues('testapp', false);
+ $this->assertEquals($expected, $values);
+
+ $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
+ $query->execute(array('enabled'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['appid']] = $row['configvalue'];
+ }
+ $values = \OC_Appconfig::getValues(false, 'enabled');
+ $this->assertEquals($expected, $values);
+ }
+}
diff --git a/tests/lib/archive/zip.php b/tests/lib/archive/zip.php
index e049a899d88..195e3450f3f 100644
--- a/tests/lib/archive/zip.php
+++ b/tests/lib/archive/zip.php
@@ -19,4 +19,4 @@ class Test_Archive_ZIP extends Test_Archive {
return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
}
}
-} \ No newline at end of file
+}
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));
+ }
+}
diff --git a/tests/lib/geo.php b/tests/lib/geo.php
index 2c3611c092e..1c56a976129 100644
--- a/tests/lib/geo.php
+++ b/tests/lib/geo.php
@@ -20,4 +20,4 @@ class Test_Geo extends PHPUnit_Framework_TestCase {
$expected = 'Pacific/Enderbury';
$this->assertEquals($expected, $result);
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/vobject.php b/tests/lib/vobject.php
index f28d22a1fcd..db5b0f99f06 100644
--- a/tests/lib/vobject.php
+++ b/tests/lib/vobject.php
@@ -35,4 +35,4 @@ class Test_VObject extends PHPUnit_Framework_TestCase {
$parts = $property->getParts();
$this->assertEquals('Marketing;Sales', $parts[2]);
}
-} \ No newline at end of file
+}