summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2013-08-14 20:56:44 +0200
committerGeorg Ehrke <developer@georgehrke.com>2013-08-14 20:56:44 +0200
commit4b5fb08c2cda4a13a1b81699f308d21b89f1723b (patch)
treea1f40bb6c6bcaf4e9093c2153d0a32fefecf2b79 /tests
parente5761d90ef223a04205ad93eea7706439ef0b60e (diff)
parent994537a5b94826294e61231768f27964bc736ced (diff)
downloadnextcloud-server-4b5fb08c2cda4a13a1b81699f308d21b89f1723b.tar.gz
nextcloud-server-4b5fb08c2cda4a13a1b81699f308d21b89f1723b.zip
Merge master into oc_preview
Diffstat (limited to 'tests')
-rw-r--r--tests/data/l10n/cs.php5
-rw-r--r--tests/data/l10n/de.php5
-rw-r--r--tests/data/l10n/ru.php5
-rw-r--r--tests/lib/db.php2
-rw-r--r--tests/lib/files/cache/scanner.php18
-rw-r--r--tests/lib/files/utils/scanner.php74
-rw-r--r--tests/lib/l10n.php67
-rw-r--r--tests/lib/preferences.php126
-rw-r--r--tests/lib/util.php30
9 files changed, 330 insertions, 2 deletions
diff --git a/tests/data/l10n/cs.php b/tests/data/l10n/cs.php
new file mode 100644
index 00000000000..1c5907bc148
--- /dev/null
+++ b/tests/data/l10n/cs.php
@@ -0,0 +1,5 @@
+<?php
+$TRANSLATIONS = array(
+ "_%n window__%n windows_" => array("%n okno", "%n okna", "%n oken")
+);
+$PLURAL_FORMS = "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;";
diff --git a/tests/data/l10n/de.php b/tests/data/l10n/de.php
new file mode 100644
index 00000000000..858ec8af49c
--- /dev/null
+++ b/tests/data/l10n/de.php
@@ -0,0 +1,5 @@
+<?php
+$TRANSLATIONS = array(
+ "_%n file__%n files_" => array("%n Datei", "%n Dateien")
+);
+$PLURAL_FORMS = "nplurals=2; plural=(n != 1);";
diff --git a/tests/data/l10n/ru.php b/tests/data/l10n/ru.php
new file mode 100644
index 00000000000..dd46293db6c
--- /dev/null
+++ b/tests/data/l10n/ru.php
@@ -0,0 +1,5 @@
+<?php
+$TRANSLATIONS = array(
+ "_%n file__%n files_" => array("%n файл", "%n файла", "%n файлов")
+);
+$PLURAL_FORMS = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);";
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/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/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
new file mode 100644
index 00000000000..612cc81926b
--- /dev/null
+++ b/tests/lib/preferences.php
@@ -0,0 +1,126 @@
+<?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_Preferences extends PHPUnit_Framework_TestCase {
+ public static function setUpBeforeClass() {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)');
+ $query->execute(array("Someuser", "someapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getusersapp", "somekey", "somevalue"));
+ $query->execute(array("Anotheruser", "getusersapp", "somekey", "someothervalue"));
+ $query->execute(array("Anuser", "getusersapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getappsapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getkeysapp", "firstkey", "somevalue"));
+ $query->execute(array("Someuser", "getkeysapp", "anotherkey", "somevalue"));
+ $query->execute(array("Someuser", "getkeysapp", "key-tastic", "somevalue"));
+
+ $query->execute(array("Someuser", "getvalueapp", "key", "a value for a key"));
+
+ $query->execute(array("Deleteuser", "deleteapp", "deletekey", "somevalue"));
+ $query->execute(array("Deleteuser", "deleteapp", "somekey", "somevalue"));
+ $query->execute(array("Deleteuser", "someapp", "somekey", "somevalue"));
+ }
+
+ 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();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['userid'];
+ }
+
+ $this->assertEquals($expected, \OC_Preferences::getUsers());
+ }
+
+ public function testGetApps() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $result = $query->execute(array('Someuser'));
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['appid'];
+ }
+
+ $this->assertEquals($expected, \OC_Preferences::getApps('Someuser'));
+ }
+
+ public function testGetKeys() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
+ $result = $query->execute(array('Someuser', 'getkeysapp'));
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['configkey'];
+ }
+
+ $this->assertEquals($expected, \OC_Preferences::getKeys('Someuser', 'getkeysapp'));
+ }
+
+ public function testGetValue() {
+ $this->assertNull(\OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant'));
+
+ $this->assertEquals('default', \OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant', 'default'));
+
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'getvalueapp', 'key'));
+ $row = $result->fetchRow();
+ $expected = $row['configvalue'];
+ $this->assertEquals($expected, \OC_Preferences::getValue('Someuser', 'getvalueapp', 'key'));
+ }
+
+ public function testSetValue() {
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('newvalue', $value);
+
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('othervalue', $value);
+ }
+
+ public function testDeleteKey() {
+ $this->assertTrue(\OC_Preferences::deleteKey('Deleteuser', 'deleteapp', 'deletekey'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Deleteuser', 'deleteapp', 'deletekey'));
+ $this->assertEquals(0, $result->numRows());
+ }
+
+ public function testDeleteApp() {
+ $this->assertTrue(\OC_Preferences::deleteApp('Deleteuser', 'deleteapp'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
+ $result = $query->execute(array('Deleteuser', 'deleteapp'));
+ $this->assertEquals(0, $result->numRows());
+ }
+
+ public function testDeleteUser() {
+ $this->assertTrue(\OC_Preferences::deleteUser('Deleteuser'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $result = $query->execute(array('Deleteuser'));
+ $this->assertEquals(0, $result->numRows());
+ }
+
+ public function testDeleteAppFromAllUsers() {
+ $this->assertTrue(\OC_Preferences::deleteAppFromAllUsers('someapp'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `appid` = ?');
+ $result = $query->execute(array('someapp'));
+ $this->assertEquals(0, $result->numRows());
+ }
+}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index a038538d7ea..13aa49c8c6f 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -7,6 +7,23 @@
*/
class Test_Util extends PHPUnit_Framework_TestCase {
+ public function testGetVersion() {
+ $version = \OC_Util::getVersion();
+ $this->assertTrue(is_array($version));
+ foreach ($version as $num) {
+ $this->assertTrue(is_int($num));
+ }
+ }
+
+ public function testGetVersionString() {
+ $version = \OC_Util::getVersionString();
+ $this->assertTrue(is_string($version));
+ }
+
+ public function testGetEditionString() {
+ $edition = \OC_Util::getEditionString();
+ $this->assertTrue(is_string($edition));
+ }
function testFormatDate() {
date_default_timezone_set("UTC");
@@ -41,6 +58,19 @@ class Test_Util extends PHPUnit_Framework_TestCase {
$this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result);
}
+ public function testFileInfoLoaded() {
+ $expected = function_exists('finfo_open');
+ $this->assertEquals($expected, \OC_Util::fileInfoLoaded());
+ }
+
+ public function testIsInternetConnectionEnabled() {
+ \OC_Config::setValue("has_internet_connection", false);
+ $this->assertFalse(\OC_Util::isInternetConnectionEnabled());
+
+ \OC_Config::setValue("has_internet_connection", true);
+ $this->assertTrue(\OC_Util::isInternetConnectionEnabled());
+ }
+
function testGenerate_random_bytes() {
$result = strlen(OC_Util::generate_random_bytes(59));
$this->assertEquals(59, $result);