summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authortomneedham <tom@owncloud.com>2014-01-04 13:46:08 +0000
committertomneedham <tom@owncloud.com>2014-01-04 13:46:08 +0000
commit1824ae12225a32d29d5738215f169c1aa3534e8b (patch)
tree328c3f3c8cf9819174872d687c3d3a00dd0040ca /tests/lib
parentac85dea267261a58ae815c257098a3ae6ed42b80 (diff)
parentaaa48576eec42388bc923a60aeb9c92ef2ff9ca4 (diff)
downloadnextcloud-server-1824ae12225a32d29d5738215f169c1aa3534e8b.tar.gz
nextcloud-server-1824ae12225a32d29d5738215f169c1aa3534e8b.zip
Merge branch 'master' into fix-5388-master
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/app.php13
-rw-r--r--tests/lib/appconfig.php2
-rw-r--r--tests/lib/avatar.php18
-rw-r--r--tests/lib/db.php71
-rw-r--r--tests/lib/db/mdb2schemareader.php5
-rw-r--r--tests/lib/db/testschema.xml6
-rw-r--r--tests/lib/dbschema.php2
-rw-r--r--tests/lib/preferences.php8
-rw-r--r--tests/lib/user/user.php5
9 files changed, 109 insertions, 21 deletions
diff --git a/tests/lib/app.php b/tests/lib/app.php
index 52eade90a6e..49f40f089bb 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -79,4 +79,17 @@ class Test_App extends PHPUnit_Framework_TestCase {
$this->assertFalse(OC_App::isAppVersionCompatible($oc, $app));
}
+ /**
+ * Tests that the app order is correct
+ */
+ public function testGetEnabledAppsIsSorted() {
+ $apps = \OC_App::getEnabledApps(true);
+ // copy array
+ $sortedApps = $apps;
+ sort($sortedApps);
+ // 'files' is always on top
+ unset($sortedApps[array_search('files', $sortedApps)]);
+ array_unshift($sortedApps, 'files');
+ $this->assertEquals($sortedApps, $apps);
+ }
}
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 4d82cd5ba7b..23dd2549e32 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -35,7 +35,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
}
public function testGetApps() {
- $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
+ $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
$result = $query->execute();
$expected = array();
while ($row = $result->fetchRow()) {
diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php
index 9cc14865a29..0334639afa8 100644
--- a/tests/lib/avatar.php
+++ b/tests/lib/avatar.php
@@ -1,20 +1,28 @@
<?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_Avatar extends PHPUnit_Framework_TestCase {
+ private $user;
+
+ public function setUp() {
+ $this->user = uniqid();
+ $storage = new \OC\Files\Storage\Temporary(array());
+ \OC\Files\Filesystem::mount($storage, array(), '/' . $this->user . '/');
+ }
+
public function testAvatar() {
- $avatar = new \OC_Avatar(\OC_User::getUser());
+ $avatar = new \OC_Avatar($this->user);
$this->assertEquals(false, $avatar->get());
- $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png');
+ $expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$expected->resize(64);
$avatar->set($expected->data());
$this->assertEquals($expected->data(), $avatar->get()->data());
@@ -25,11 +33,11 @@ class Test_Avatar extends PHPUnit_Framework_TestCase {
public function testAvatarApi() {
$avatarManager = \OC::$server->getAvatarManager();
- $avatar = $avatarManager->getAvatar(\OC_User::getUser());
+ $avatar = $avatarManager->getAvatar($this->user);
$this->assertEquals(false, $avatar->get());
- $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png');
+ $expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$expected->resize(64);
$avatar->set($expected->data());
$this->assertEquals($expected->data(), $avatar->get()->data());
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 1977025cf12..f0b271a36f1 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -12,6 +12,21 @@ class Test_DB extends PHPUnit_Framework_TestCase {
protected static $schema_file = 'static://test_db_scheme';
protected $test_prefix;
+ /**
+ * @var string
+ */
+ private $table1;
+
+ /**
+ * @var string
+ */
+ private $table2;
+
+ /**
+ * @var string
+ */
+ private $table3;
+
public function setUp() {
$dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml';
@@ -25,6 +40,7 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$this->table1 = $this->test_prefix.'cntcts_addrsbks';
$this->table2 = $this->test_prefix.'cntcts_cards';
$this->table3 = $this->test_prefix.'vcategory';
+ $this->table4 = $this->test_prefix.'decimal';
}
public function tearDown() {
@@ -121,10 +137,10 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?');
$result = $query->execute(array($uri));
$this->assertTrue((bool)$result);
- $row = $result->fetchRow();
- $this->assertArrayHasKey('carddata', $row);
- $this->assertEquals($carddata, $row['carddata']);
- $this->assertEquals(1, $result->numRows());
+ $rowset = $result->fetchAll();
+ $this->assertEquals(1, count($rowset));
+ $this->assertArrayHasKey('carddata', $rowset[0]);
+ $this->assertEquals($carddata, $rowset[0]['carddata']);
// Try to insert a new row
$result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
@@ -137,12 +153,51 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?');
$result = $query->execute(array($uri));
$this->assertTrue((bool)$result);
- $row = $result->fetchRow();
- $this->assertArrayHasKey('carddata', $row);
// Test that previously inserted data isn't overwritten
- $this->assertEquals($carddata, $row['carddata']);
// And that a new row hasn't been inserted.
- $this->assertEquals(1, $result->numRows());
+ $rowset = $result->fetchAll();
+ $this->assertEquals(1, count($rowset));
+ $this->assertArrayHasKey('carddata', $rowset[0]);
+ $this->assertEquals($carddata, $rowset[0]['carddata']);
+ }
+
+ public function testUtf8Data() {
+ $table = "*PREFIX*{$this->table2}";
+ $expected = "Ћö雙喜\xE2\x80\xA2";
+
+ $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
+ $result = $query->execute(array($expected, 'uri_1', 'This is a vCard'));
+ $this->assertEquals(1, $result);
+ $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne();
+ $this->assertSame($expected, $actual);
}
+
+ public function testDecimal() {
+ $table = "*PREFIX*" . $this->table4;
+ $rowname = 'decimaltest';
+
+ // Insert, select and delete decimal(12,2) values
+ $inserts = array('1337133713.37', '1234567890');
+ $expects = array('1337133713.37', '1234567890.00');
+
+ for ($i = 0; $i < count($inserts); $i++) {
+ $insert = $inserts[$i];
+ $expect = $expects[$i];
+
+ $query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)');
+ $result = $query->execute(array($insert));
+ $this->assertEquals(1, $result);
+ $query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`');
+ $result = $query->execute();
+ $this->assertTrue((bool)$result);
+ $row = $result->fetchRow();
+ $this->assertArrayHasKey($rowname, $row);
+ $this->assertEquals($expect, $row[$rowname]);
+ $query = OC_DB::prepare('DELETE FROM `' . $table . '`');
+ $result = $query->execute();
+ $this->assertTrue((bool)$result);
+ }
+ }
+
}
diff --git a/tests/lib/db/mdb2schemareader.php b/tests/lib/db/mdb2schemareader.php
index 57cafa7c76b..f08996cbeaf 100644
--- a/tests/lib/db/mdb2schemareader.php
+++ b/tests/lib/db/mdb2schemareader.php
@@ -39,7 +39,7 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase {
$this->assertCount(1, $schema->getTables());
$table = $schema->getTable('test_table');
- $this->assertCount(7, $table->getColumns());
+ $this->assertCount(8, $table->getColumns());
$this->assertEquals(4, $table->getColumn('integerfield')->getLength());
$this->assertTrue($table->getColumn('integerfield')->getAutoincrement());
@@ -69,6 +69,9 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase {
$this->assertTrue($table->getColumn('booleanfield_true')->getDefault());
$this->assertFalse($table->getColumn('booleanfield_false')->getDefault());
+ $this->assertEquals(12, $table->getColumn('decimalfield_precision_scale')->getPrecision());
+ $this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale());
+
$this->assertCount(2, $table->getIndexes());
$this->assertEquals(array('integerfield'), $table->getIndex('primary')->getUnquotedColumns());
$this->assertTrue($table->getIndex('primary')->isPrimary());
diff --git a/tests/lib/db/testschema.xml b/tests/lib/db/testschema.xml
index 509b55ee81f..dfca920a0ef 100644
--- a/tests/lib/db/testschema.xml
+++ b/tests/lib/db/testschema.xml
@@ -53,6 +53,12 @@
<type>boolean</type>
<default>false</default>
</field>
+ <field>
+ <name>decimalfield_precision_scale</name>
+ <type>decimal</type>
+ <precision>12</precision>
+ <scale>2</scale>
+ </field>
<index>
<name>index_primary</name>
diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php
index 7de90c047ca..4a7b7f7aac0 100644
--- a/tests/lib/dbschema.php
+++ b/tests/lib/dbschema.php
@@ -103,7 +103,7 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase {
break;
}
- $name = $result->fetchOne(); //FIXME checking with '$result->numRows() === 1' does not seem to work?
+ $name = $result->fetchOne();
if ($name === $table) {
return true;
} else {
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index 68b794e9ea9..a8236909ded 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -101,28 +101,28 @@ class Test_Preferences extends PHPUnit_Framework_TestCase {
$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());
+ $this->assertEquals(0, count($result->fetchAll()));
}
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());
+ $this->assertEquals(0, count($result->fetchAll()));
}
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());
+ $this->assertEquals(0, count($result->fetchAll()));
}
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());
+ $this->assertEquals(0, count($result->fetchAll()));
}
}
diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php
index 0bbcda013ce..3f90432c6b0 100644
--- a/tests/lib/user/user.php
+++ b/tests/lib/user/user.php
@@ -9,6 +9,7 @@
namespace Test\User;
+use OC\AllConfig;
use OC\Hooks\PublicEmitter;
class User extends \PHPUnit_Framework_TestCase {
@@ -205,7 +206,9 @@ class User extends \PHPUnit_Framework_TestCase {
->method('implementsActions')
->will($this->returnValue(false));
- $user = new \OC\User\User('foo', $backend);
+ $allConfig = new AllConfig();
+
+ $user = new \OC\User\User('foo', $backend, null, $allConfig);
$this->assertEquals(\OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data") . '/foo', $user->getHome());
}