summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-08-22 17:59:39 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-08-22 17:59:39 +0200
commit9e1016f7d2aa7c23fc6287a563e6551809edcbe8 (patch)
tree2ec3b29c78b88581aa12df4bee3262fee939907d /tests/lib
parentfed1792510ff11941765783653573f45fadc4c70 (diff)
parent02b2b5a808b135007d8d54b837e70c38f02729fd (diff)
downloadnextcloud-server-9e1016f7d2aa7c23fc6287a563e6551809edcbe8.tar.gz
nextcloud-server-9e1016f7d2aa7c23fc6287a563e6551809edcbe8.zip
Merge branch 'master' into fixing-4343-master
Conflicts: lib/connector/sabre/quotaplugin.php
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/app.php2
-rw-r--r--tests/lib/archive/zip.php2
-rw-r--r--tests/lib/db.php2
-rw-r--r--tests/lib/files/cache/scanner.php18
-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/files/utils/scanner.php74
-rw-r--r--tests/lib/geo.php2
-rw-r--r--tests/lib/l10n.php67
-rw-r--r--tests/lib/preferences.php11
-rw-r--r--tests/lib/vobject.php2
12 files changed, 312 insertions, 11 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/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/db.php b/tests/lib/db.php
index 79e05f30a1c..51edbf7b309 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -76,13 +76,11 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
$result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1'));
$id1 = OC_DB::insertid('*PREFIX*'.$this->table2);
- $this->assertInternalType('int', $id1);
// we don't know the id we should expect, so insert another row
$result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2'));
$id2 = OC_DB::insertid('*PREFIX*'.$this->table2);
// now we can check if the two ids are in correct order
- $this->assertInternalType('int', $id2);
$this->assertGreaterThan($id1, $id2);
}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index 263ceadccc7..f6deb93a49e 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -143,6 +143,24 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$newData = $this->cache->get('');
$this->assertEquals($oldData['etag'], $newData['etag']);
$this->assertEquals(-1, $newData['size']);
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
+ $oldData = $this->cache->get('');
+ $this->assertNotEquals(-1, $oldData['size']);
+ $this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+ $newData = $this->cache->get('');
+ $this->assertEquals($oldData['etag'], $newData['etag']);
+ $this->assertEquals($oldData['size'], $newData['size']);
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+ $newData = $this->cache->get('');
+ $this->assertEquals($oldData['etag'], $newData['etag']);
+ $this->assertEquals($oldData['size'], $newData['size']);
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
+ $newData = $this->cache->get('');
+ $this->assertEquals($oldData['etag'], $newData['etag']);
+ $this->assertEquals($oldData['size'], $newData['size']);
}
public function testRemovedFile() {
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/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
new file mode 100644
index 00000000000..a021d215ae5
--- /dev/null
+++ b/tests/lib/files/utils/scanner.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2012 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\Utils;
+
+use OC\Files\Mount\Mount;
+use OC\Files\Storage\Temporary;
+
+class TestScanner extends \OC\Files\Utils\Scanner {
+ /**
+ * @var \OC\Files\Mount\Mount[] $mounts
+ */
+ private $mounts = array();
+
+ /**
+ * @param \OC\Files\Mount\Mount $mount
+ */
+ public function addMount($mount) {
+ $this->mounts[] = $mount;
+ }
+
+ protected function getMounts($dir) {
+ return $this->mounts;
+ }
+}
+
+class Scanner extends \PHPUnit_Framework_TestCase {
+ public function testReuseExistingRoot() {
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '');
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $oldRoot = $cache->get('');
+
+ $scanner->scan('');
+ $newRoot = $cache->get('');
+ $this->assertEquals($oldRoot, $newRoot);
+ }
+
+ public function testReuseExistingFile() {
+ $storage = new Temporary(array());
+ $mount = new Mount($storage, '');
+ $cache = $storage->getCache();
+
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', 'qwerty');
+ $storage->file_put_contents('folder/bar.txt', 'qwerty');
+
+ $scanner = new TestScanner('');
+ $scanner->addMount($mount);
+
+ $scanner->scan('');
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $old = $cache->get('folder/bar.txt');
+
+ $scanner->scan('');
+ $new = $cache->get('folder/bar.txt');
+ $this->assertEquals($old, $new);
+ }
+}
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/l10n.php b/tests/lib/l10n.php
new file mode 100644
index 00000000000..12eac818f84
--- /dev/null
+++ b/tests/lib/l10n.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_L10n extends PHPUnit_Framework_TestCase {
+
+ public function testGermanPluralTranslations() {
+ $l = new OC_L10N('test');
+ $transFile = OC::$SERVERROOT.'/tests/data/l10n/de.php';
+
+ $l->load($transFile);
+ $this->assertEquals('1 Datei', (string)$l->n('%n file', '%n files', 1));
+ $this->assertEquals('2 Dateien', (string)$l->n('%n file', '%n files', 2));
+ }
+
+ public function testRussianPluralTranslations() {
+ $l = new OC_L10N('test');
+ $transFile = OC::$SERVERROOT.'/tests/data/l10n/ru.php';
+
+ $l->load($transFile);
+ $this->assertEquals('1 файл', (string)$l->n('%n file', '%n files', 1));
+ $this->assertEquals('2 файла', (string)$l->n('%n file', '%n files', 2));
+ $this->assertEquals('6 файлов', (string)$l->n('%n file', '%n files', 6));
+ $this->assertEquals('21 файл', (string)$l->n('%n file', '%n files', 21));
+ $this->assertEquals('22 файла', (string)$l->n('%n file', '%n files', 22));
+ $this->assertEquals('26 файлов', (string)$l->n('%n file', '%n files', 26));
+
+ /*
+ 1 file 1 файл 1 папка
+ 2-4 files 2-4 файла 2-4 папки
+ 5-20 files 5-20 файлов 5-20 папок
+ 21 files 21 файл 21 папка
+ 22-24 files 22-24 файла 22-24 папки
+ 25-30 files 25-30 файлов 25-30 папок
+ etc
+ 100 files 100 файлов, 100 папок
+ 1000 files 1000 файлов 1000 папок
+ */
+ }
+
+ public function testCzechPluralTranslations() {
+ $l = new OC_L10N('test');
+ $transFile = OC::$SERVERROOT.'/tests/data/l10n/cs.php';
+
+ $l->load($transFile);
+ $this->assertEquals('1 okno', (string)$l->n('%n window', '%n windows', 1));
+ $this->assertEquals('2 okna', (string)$l->n('%n window', '%n windows', 2));
+ $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5));
+ }
+
+ /**
+ * Issue #4360: Do not call strtotime() on numeric strings.
+ */
+ public function testNumericStringToDateTime() {
+ $l = new OC_L10N('test');
+ $this->assertSame('February 13, 2009 23:31', $l->l('datetime', '1234567890'));
+ }
+
+ public function testNumericToDateTime() {
+ $l = new OC_L10N('test');
+ $this->assertSame('February 13, 2009 23:31', $l->l('datetime', 1234567890));
+ }
+}
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index d39555aa01d..612cc81926b 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -7,7 +7,7 @@
*/
class Test_Preferences extends PHPUnit_Framework_TestCase {
- private function fillDb() {
+ public static function setUpBeforeClass() {
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)');
$query->execute(array("Someuser", "someapp", "somekey", "somevalue"));
@@ -28,9 +28,14 @@ class Test_Preferences extends PHPUnit_Framework_TestCase {
$query->execute(array("Deleteuser", "someapp", "somekey", "somevalue"));
}
- public function testGetUsers() {
- $this->fillDb();
+ public static function tearDownAfterClass() {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $query->execute(array('Someuser'));
+ $query->execute(array('Anotheruser'));
+ $query->execute(array('Anuser'));
+ }
+ public function testGetUsers() {
$query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`');
$result = $query->execute();
$expected = array();
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
+}