aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/db_structure.xml3
-rw-r--r--tests/data/db_structure2.xml3
-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/files/view.php32
-rw-r--r--tests/lib/memcache/memcached.php12
-rw-r--r--tests/lib/preferences.php8
-rw-r--r--tests/lib/user/session.php15
-rw-r--r--tests/lib/user/user.php5
-rw-r--r--tests/phpunit-autotest.xml7
-rw-r--r--tests/testcleanuplistener.php139
16 files changed, 312 insertions, 29 deletions
diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml
index 5f2edbbc516..bfff2143349 100644
--- a/tests/data/db_structure.xml
+++ b/tests/data/db_structure.xml
@@ -216,7 +216,8 @@
<type>decimal</type>
<default/>
<notnull>true</notnull>
- <length>15</length>
+ <precision>12</precision>
+ <scale>2</scale>
</field>
</declaration>
</table>
diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml
index 6cd071451df..ae5f22e9573 100644
--- a/tests/data/db_structure2.xml
+++ b/tests/data/db_structure2.xml
@@ -113,7 +113,8 @@
<type>decimal</type>
<default/>
<notnull>true</notnull>
- <length>15</length>
+ <precision>12</precision>
+ <scale>2</scale>
</field>
</declaration>
</table>
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/files/view.php b/tests/lib/files/view.php
index f358c15dd50..b59cef9f0da 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -15,7 +15,7 @@ class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
class View extends \PHPUnit_Framework_TestCase {
/**
- * @var \OC\Files\Storage\Storage[] $storages;
+ * @var \OC\Files\Storage\Storage[] $storages
*/
private $storages = array();
@@ -473,4 +473,34 @@ class View extends \PHPUnit_Framework_TestCase {
array('', '/'),
);
}
+
+ public function testUTF8Names() {
+ $names = array('虚', '和知しゃ和で', 'regular ascii', 'sɨˈrɪlɪk', 'ѨѬ', 'أنا أحب القراءة كثيرا');
+
+ $storage = new \OC\Files\Storage\Temporary(array());
+ \OC\Files\Filesystem::mount($storage, array(), '/');
+
+ $rootView = new \OC\Files\View('');
+ foreach ($names as $name) {
+ $rootView->file_put_contents('/' . $name, 'dummy content');
+ }
+
+ $list = $rootView->getDirectoryContent('/');
+
+ $this->assertCount(count($names), $list);
+ foreach ($list as $item) {
+ $this->assertContains($item['name'], $names);
+ }
+
+ $cache = $storage->getCache();
+ $scanner = $storage->getScanner();
+ $scanner->scan('');
+
+ $list = $cache->getFolderContents('');
+
+ $this->assertCount(count($names), $list);
+ foreach ($list as $item) {
+ $this->assertContains($item['name'], $names);
+ }
+ }
}
diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php
index 4b38ae8ef3c..fdab32693ff 100644
--- a/tests/lib/memcache/memcached.php
+++ b/tests/lib/memcache/memcached.php
@@ -10,11 +10,17 @@
namespace Test\Memcache;
class Memcached extends Cache {
- public function setUp() {
+ static public function setUpBeforeClass() {
if (!\OC\Memcache\Memcached::isAvailable()) {
- $this->markTestSkipped('The memcached extension is not available.');
- return;
+ self::markTestSkipped('The memcached extension is not available.');
+ }
+ $instance = new \OC\Memcache\Memcached(uniqid());
+ if ($instance->set(uniqid(), uniqid()) === false) {
+ self::markTestSkipped('memcached server seems to be down.');
}
+ }
+
+ public function setUp() {
$this->instance = new \OC\Memcache\Memcached(uniqid());
}
}
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/session.php b/tests/lib/user/session.php
index e457a7bda30..46b268b3624 100644
--- a/tests/lib/user/session.php
+++ b/tests/lib/user/session.php
@@ -52,9 +52,20 @@ class Session extends \PHPUnit_Framework_TestCase {
public function testLoginValidPasswordEnabled() {
$session = $this->getMock('\OC\Session\Memory', array(), array(''));
- $session->expects($this->once())
+ $session->expects($this->exactly(2))
->method('set')
- ->with('user_id', 'foo');
+ ->with($this->callback(function($key) {
+ switch($key) {
+ case 'user_id':
+ case 'loginname':
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ }
+ },
+ 'foo'));
$manager = $this->getMock('\OC\User\Manager');
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());
}
diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml
index a893e96ad97..1a2ab35491b 100644
--- a/tests/phpunit-autotest.xml
+++ b/tests/phpunit-autotest.xml
@@ -35,5 +35,12 @@
</exclude>
</whitelist>
</filter>
+ <listeners>
+ <listener class="TestCleanupListener" file="testcleanuplistener.php">
+ <arguments>
+ <string>detail</string>
+ </arguments>
+ </listener>
+ </listeners>
</phpunit>
diff --git a/tests/testcleanuplistener.php b/tests/testcleanuplistener.php
new file mode 100644
index 00000000000..368ea7bc8f4
--- /dev/null
+++ b/tests/testcleanuplistener.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * Copyright (c) 2013 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Detects tests that didn't clean up properly, show a warning, then clean up after them.
+ */
+class TestCleanupListener implements PHPUnit_Framework_TestListener {
+ private $verbosity;
+
+ public function __construct($verbosity = 'verbose') {
+ $this->verbosity = $verbosity;
+ }
+
+ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
+ }
+
+ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function startTest(PHPUnit_Framework_Test $test) {
+ }
+
+ public function endTest(PHPUnit_Framework_Test $test, $time) {
+ }
+
+ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
+ }
+
+ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
+ if ($this->cleanStrayDataFiles() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up data dir\n", $suite->getName());
+ }
+ if ($this->cleanStrayHooks() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up hooks\n", $suite->getName());
+ }
+ if ($this->cleanProxies() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up proxies\n", $suite->getName());
+ }
+ }
+
+ private function isShowSuiteWarning() {
+ return $this->verbosity === 'suite' || $this->verbosity === 'detail';
+ }
+
+ private function isShowDetail() {
+ return $this->verbosity === 'detail';
+ }
+
+ private function unlinkDir($dir) {
+ if ($dh = opendir($dir)) {
+ while (($file = readdir($dh)) !== false) {
+ if ($file === '..' || $file === '.') {
+ continue;
+ }
+ $path = $dir . '/' . $file;
+ if (is_dir($path)) {
+ $this->unlinkDir($path);
+ }
+ else {
+ unlink($path);
+ }
+ }
+ closedir($dh);
+ }
+ rmdir($dir);
+ }
+
+ private function cleanStrayDataFiles() {
+ $knownEntries = array(
+ 'owncloud.log' => true,
+ 'owncloud.db' => true,
+ '..' => true,
+ '.' => true
+ );
+ $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
+ $entries = array();
+ if ($dh = opendir($datadir)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!isset($knownEntries[$file])) {
+ $entries[] = $file;
+ }
+ }
+ closedir($dh);
+ }
+
+ if (count($entries) > 0) {
+ foreach ($entries as $entry) {
+ $this->unlinkDir($datadir . '/' . $entry);
+ if ($this->isShowDetail()) {
+ printf("Stray datadir entry: %s\n", $entry);
+ }
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ private function cleanStrayHooks() {
+ $hasHooks = false;
+ $hooks = OC_Hook::getHooks();
+ if (!$hooks || sizeof($hooks) === 0) {
+ return false;
+ }
+
+ foreach ($hooks as $signalClass => $signals) {
+ if (sizeof($signals)) {
+ foreach ($signals as $signalName => $handlers ) {
+ if (sizeof($handlers) > 0) {
+ $hasHooks = true;
+ OC_Hook::clear($signalClass, $signalName);
+ if ($this->isShowDetail()) {
+ printf("Stray hook: \"%s\" \"%s\"\n", $signalClass, $signalName);
+ }
+ }
+ }
+ }
+ }
+ return $hasHooks;
+ }
+
+ private function cleanProxies() {
+ $proxies = OC_FileProxy::getProxies();
+ OC_FileProxy::clearProxies();
+ return count($proxies) > 0;
+ }
+}
+?>