aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPellaeon Lin <nfsmwlin@gmail.com>2014-01-30 22:50:20 +0800
committerPellaeon Lin <nfsmwlin@gmail.com>2014-01-30 22:50:20 +0800
commit099b71c712c38de7dac7e386252da02bb0cadf12 (patch)
tree84bcf83efdc4cc759a5ff184fa5148195abaab51 /tests
parent929c930b0afd682bb98eb389d7ebad91bb34d643 (diff)
parent299a8285bd2601ccbac988b2e3e9b067d47921a2 (diff)
downloadnextcloud-server-099b71c712c38de7dac7e386252da02bb0cadf12.tar.gz
nextcloud-server-099b71c712c38de7dac7e386252da02bb0cadf12.zip
Merge branch 'master' into pr-exceed_upload_limit_msg
Conflicts: apps/files/templates/index.php apps/files_sharing/templates/public.php
Diffstat (limited to 'tests')
-rw-r--r--tests/data/db_structure.xml4
-rw-r--r--tests/data/db_structure2.xml3
-rw-r--r--tests/data/l10n/cs.php2
-rw-r--r--tests/data/l10n/de.php2
-rw-r--r--tests/data/l10n/ru.php2
-rw-r--r--tests/enable_all.php24
-rw-r--r--tests/karma.config.js149
-rw-r--r--tests/lib/api.php35
-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/cache/cache.php46
-rw-r--r--tests/lib/files/cache/homecache.php18
-rw-r--r--tests/lib/files/cache/scanner.php2
-rw-r--r--tests/lib/files/cache/updater.php2
-rw-r--r--tests/lib/files/storage/wrapper/quota.php19
-rw-r--r--tests/lib/files/view.php91
-rw-r--r--tests/lib/memcache/memcached.php12
-rw-r--r--tests/lib/preferences.php8
-rw-r--r--tests/lib/request.php50
-rw-r--r--tests/lib/share/share.php100
-rw-r--r--tests/lib/user/manager.php72
-rw-r--r--tests/lib/user/session.php15
-rw-r--r--tests/lib/user/user.php5
-rw-r--r--tests/lib/util.php9
-rw-r--r--tests/phpunit-autotest.xml7
-rw-r--r--tests/testcleanuplistener.php139
31 files changed, 867 insertions, 66 deletions
diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml
index 5f2edbbc516..d98066c4b7e 100644
--- a/tests/data/db_structure.xml
+++ b/tests/data/db_structure.xml
@@ -21,6 +21,7 @@
<autoincrement>1</autoincrement>
<unsigned>true</unsigned>
<length>4</length>
+ <comments>This is the id</comments>
</field>
<field>
@@ -216,7 +217,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/data/l10n/cs.php b/tests/data/l10n/cs.php
index 1c5907bc148..de106ede026 100644
--- a/tests/data/l10n/cs.php
+++ b/tests/data/l10n/cs.php
@@ -1,5 +1,5 @@
<?php
$TRANSLATIONS = array(
- "_%n window__%n windows_" => array("%n okno", "%n okna", "%n oken")
+ "_%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
index 858ec8af49c..93c9ab4209e 100644
--- a/tests/data/l10n/de.php
+++ b/tests/data/l10n/de.php
@@ -1,5 +1,5 @@
<?php
$TRANSLATIONS = array(
- "_%n file__%n files_" => array("%n Datei", "%n Dateien")
+ "_%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
index dd46293db6c..b778e8d79af 100644
--- a/tests/data/l10n/ru.php
+++ b/tests/data/l10n/ru.php
@@ -1,5 +1,5 @@
<?php
$TRANSLATIONS = array(
- "_%n file__%n files_" => array("%n файл", "%n файла", "%n файлов")
+ "_%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/enable_all.php b/tests/enable_all.php
index 43ee16a72f8..efb43cae508 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -8,15 +8,17 @@
require_once __DIR__.'/../lib/base.php';
-OC_App::enable('files_sharing');
-OC_App::enable('files_encryption');
-OC_App::enable('calendar');
-OC_App::enable('contacts');
-OC_App::enable('apptemplateadvanced');
-OC_App::enable('appframework');
-#OC_App::enable('files_archive');
-#OC_App::enable('mozilla_sync');
-#OC_App::enable('news');
-#OC_App::enable('provisioning_api');
-#OC_App::enable('user_external');
+function enableApp($app) {
+ try {
+ OC_App::enable($app);
+ } catch (Exception $e) {
+ echo $e;
+ }
+}
+
+enableApp('files_sharing');
+enableApp('files_encryption');
+//enableApp('files_external');
+enableApp('user_ldap');
+enableApp('files_versions');
diff --git a/tests/karma.config.js b/tests/karma.config.js
new file mode 100644
index 00000000000..f73ade0f3c6
--- /dev/null
+++ b/tests/karma.config.js
@@ -0,0 +1,149 @@
+/**
+* ownCloud
+*
+* @author Vincent Petry
+* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * This node module is run by the karma executable to specify its configuration.
+ *
+ * The list of files from all needed JavaScript files including the ones from the
+ * apps to test, and the test specs will be passed as configuration object.
+ *
+ * Note that it is possible to test a single app by setting the KARMA_TESTSUITE
+ * environment variable to the apps name, for example "core" or "files_encryption".
+ * Multiple apps can be specified by separating them with space.
+ *
+ */
+module.exports = function(config) {
+
+ // default apps to test when none is specified (TODO: read from filesystem ?)
+ var defaultApps = 'core files';
+ var appsToTest = process.env.KARMA_TESTSUITE || defaultApps;
+
+ // read core files from core.json,
+ // these are required by all apps so always need to be loaded
+ // note that the loading order is important that's why they
+ // are specified in a separate file
+ var corePath = 'core/js/';
+ var coreFiles = require('../' + corePath + 'core.json').modules;
+ var testCore = false;
+ var files = [];
+ var index;
+
+ // find out what apps to test from appsToTest
+ appsToTest = appsToTest.split(' ');
+ index = appsToTest.indexOf('core');
+ if (index > -1) {
+ appsToTest.splice(index, 1);
+ testCore = true;
+ }
+
+ // extra test libs
+ files.push(corePath + 'tests/lib/sinon-1.7.3.js');
+
+ // core mocks
+ files.push(corePath + 'tests/specHelper.js');
+
+ // add core files
+ for ( var i = 0; i < coreFiles.length; i++ ) {
+ files.push( corePath + coreFiles[i] );
+ }
+
+ // need to test the core app as well ?
+ if (testCore) {
+ // core tests
+ files.push(corePath + 'tests/specs/*.js');
+ }
+
+ for ( var i = 0; i < appsToTest.length; i++ ) {
+ // add app JS
+ files.push('apps/' + appsToTest[i] + '/js/*.js');
+ // add test specs
+ files.push('apps/' + appsToTest[i] + '/tests/js/*.js');
+ }
+
+ config.set({
+
+ // base path, that will be used to resolve files and exclude
+ basePath: '..',
+
+
+ // frameworks to use
+ frameworks: ['jasmine'],
+
+ // list of files / patterns to load in the browser
+ files: files,
+
+ // list of files to exclude
+ exclude: [
+
+ ],
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
+ reporters: ['dots', 'junit', 'coverage'],
+
+ junitReporter: {
+ outputFile: 'tests/autotest-results-js.xml'
+ },
+
+ // web server port
+ port: 9876,
+
+ preprocessors: {
+ 'apps/files/js/*.js': 'coverage'
+ },
+
+ coverageReporter: {
+ dir:'tests/karma-coverage',
+ reporters: [
+ { type: 'html' },
+ { type: 'cobertura' }
+ ]
+ },
+
+ // enable / disable colors in the output (reporters and logs)
+ colors: true,
+
+
+ // level of logging
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+ logLevel: config.LOG_INFO,
+
+ // enable / disable watching file and executing tests whenever any file changes
+ autoWatch: false,
+
+ // Start these browsers, currently available:
+ // - Chrome
+ // - ChromeCanary
+ // - Firefox
+ // - Opera (has to be installed with `npm install karma-opera-launcher`)
+ // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
+ // - PhantomJS
+ // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
+ browsers: ['PhantomJS'],
+
+ // If browser does not capture in given timeout [ms], kill it
+ captureTimeout: 60000,
+
+ // Continuous Integration mode
+ // if true, it capture browsers, run tests and exit
+ singleRun: false
+ });
+};
diff --git a/tests/lib/api.php b/tests/lib/api.php
index 95d75f15311..9c4324e63e0 100644
--- a/tests/lib/api.php
+++ b/tests/lib/api.php
@@ -7,12 +7,12 @@
*/
class Test_API extends PHPUnit_Framework_TestCase {
-
+
// Helps build a response variable
- function buildResponse($shipped, $data, $code) {
+ function buildResponse($shipped, $data, $code, $message=null) {
return array(
'shipped' => $shipped,
- 'response' => new OC_OCS_Result($data, $code),
+ 'response' => new OC_OCS_Result($data, $code, $message),
'app' => uniqid('testapp_', true),
);
}
@@ -64,24 +64,24 @@ class Test_API extends PHPUnit_Framework_TestCase {
// Two shipped success results
array(true, 100, true, 100, true),
// Two shipped results, one success and one failure
- array(true, 100, true, 997, false),
+ array(true, 100, true, 998, false),
// Two shipped results, both failure
- array(true, 997, true, 997, false),
+ array(true, 997, true, 998, false),
// Two third party success results
array(false, 100, false, 100, true),
// Two third party results, one success and one failure
- array(false, 100, false, 997, false),
+ array(false, 100, false, 998, false),
// Two third party results, both failure
- array(false, 997, false, 997, false),
+ array(false, 997, false, 998, false),
// One of each, both success
array(false, 100, true, 100, true),
array(true, 100, false, 100, true),
// One of each, both failure
- array(false, 997, true, 997, false),
+ array(false, 997, true, 998, false),
// One of each, shipped success
array(false, 997, true, 100, true),
// One of each, third party success
- array(false, 100, true, 997, false),
+ array(false, 100, true, 998, false),
);
}
/**
@@ -117,12 +117,25 @@ class Test_API extends PHPUnit_Framework_TestCase {
// Two shipped success results
$result = OC_API::mergeResponses(array(
- $this->buildResponse($shipped1, $data1, $statusCode1),
- $this->buildResponse($shipped2, $data2, $statusCode2),
+ $this->buildResponse($shipped1, $data1, $statusCode1, "message1"),
+ $this->buildResponse($shipped2, $data2, $statusCode2, "message2"),
));
$this->checkResult($result, $succeeded);
$resultData = $result->getData();
+ $resultMeta = $result->getMeta();
+ $resultStatusCode = $result->getStatusCode();
+
$this->assertArrayHasKey('jan', $resultData['users']);
+
+ // check if the returned status message matches the selected status code
+ if ($resultStatusCode === 997) {
+ $this->assertEquals('message1', $resultMeta['message']);
+ } elseif ($resultStatusCode === 998) {
+ $this->assertEquals('message2', $resultMeta['message']);
+ } elseif ($resultStatusCode === 100) {
+ $this->assertEquals(null, $resultMeta['message']);
+ }
+
}
}
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/cache/cache.php b/tests/lib/files/cache/cache.php
index 052d70dd0b4..5d876932479 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -137,6 +137,52 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar'));
}
+ public function testEncryptedFolder() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+ $fileData = array();
+ $fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['bar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $content = $this->cache->getFolderContents($file1);
+ $this->assertEquals(count($content), 2);
+ foreach ($content as $cachedData) {
+ $data = $fileData[$cachedData['name']];
+ // indirect retrieval swaps unencrypted_size and size
+ $this->assertEquals($data['unencrypted_size'], $cachedData['size']);
+ }
+
+ $file4 = 'folder/unkownSize';
+ $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(-1, $this->cache->calculateFolderSize($file1));
+
+ $fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(916, $this->cache->calculateFolderSize($file1));
+ // direct cache entry retrieval returns the original values
+ $entry = $this->cache->get($file1);
+ $this->assertEquals(1025, $entry['size']);
+ $this->assertEquals(916, $entry['unencrypted_size']);
+
+ $this->cache->remove($file2);
+ $this->cache->remove($file3);
+ $this->cache->remove($file4);
+ $this->assertEquals(0, $this->cache->calculateFolderSize($file1));
+
+ $this->cache->remove('folder');
+ $this->assertFalse($this->cache->inCache('folder/foo'));
+ $this->assertFalse($this->cache->inCache('folder/bar'));
+ }
+
public function testRootFolderSizeForNonHomeStorage() {
$dir1 = 'knownsize';
$dir2 = 'unknownsize';
diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php
index 2fa7f1ba92e..87fd0dba4c6 100644
--- a/tests/lib/files/cache/homecache.php
+++ b/tests/lib/files/cache/homecache.php
@@ -62,33 +62,39 @@ class HomeCache extends \PHPUnit_Framework_TestCase {
}
/**
- * Tests that the root folder size calculation ignores the subdirs that have an unknown
- * size. This makes sure that quota calculation still works as it's based on the root
- * folder size.
+ * Tests that the root and files folder size calculation ignores the subdirs
+ * that have an unknown size. This makes sure that quota calculation still
+ * works as it's based on the "files" folder size.
*/
public function testRootFolderSizeIgnoresUnknownUpdate() {
- $dir1 = 'knownsize';
- $dir2 = 'unknownsize';
+ $dir1 = 'files/knownsize';
+ $dir2 = 'files/unknownsize';
$fileData = array();
$fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
+ $fileData['files'] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory');
$fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory');
$this->cache->put('', $fileData['']);
+ $this->cache->put('files', $fileData['files']);
$this->cache->put($dir1, $fileData[$dir1]);
$this->cache->put($dir2, $fileData[$dir2]);
+ $this->assertTrue($this->cache->inCache('files'));
$this->assertTrue($this->cache->inCache($dir1));
$this->assertTrue($this->cache->inCache($dir2));
- // check that root size ignored the unknown sizes
+ // check that files and root size ignored the unknown sizes
+ $this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
$this->assertEquals(1000, $this->cache->calculateFolderSize(''));
// clean up
$this->cache->remove('');
+ $this->cache->remove('files');
$this->cache->remove($dir1);
$this->cache->remove($dir2);
+ $this->assertFalse($this->cache->inCache('files'));
$this->assertFalse($this->cache->inCache($dir1));
$this->assertFalse($this->cache->inCache($dir2));
}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index 3f3a045377a..3f5604b4d45 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -147,7 +147,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->scanner->scan('');
$oldData = $this->cache->get('');
$this->storage->unlink('folder/bar.txt');
- $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder')));
+ $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder')));
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertNotEquals($oldData['etag'], $newData['etag']);
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 91e384e12af..48986149a73 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -88,7 +88,7 @@ class Updater extends \PHPUnit_Framework_TestCase {
public function testWrite() {
$textSize = strlen("dummy file data\n");
$imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
- $this->cache->put('foo.txt', array('mtime' => 100));
+ $this->cache->put('foo.txt', array('mtime' => 100, 'storage_mtime' => 150));
$rootCachedData = $this->cache->get('');
$this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 9b14335782f..87bafb64d41 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -59,6 +59,20 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertEquals('foobarqwe', $instance->file_get_contents('foo'));
}
+ public function testReturnFalseWhenFopenFailed(){
+ $failStorage = $this->getMock(
+ '\OC\Files\Storage\Local',
+ array('fopen'),
+ array(array('datadir' => $this->tmpDir)));
+ $failStorage->expects($this->any())
+ ->method('fopen')
+ ->will($this->returnValue(false));
+
+ $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $failStorage, 'quota' => 1000));
+
+ $this->assertFalse($instance->fopen('failedfopen', 'r'));
+ }
+
public function testReturnRegularStreamOnRead(){
$instance = $this->getLimitedStorage(9);
@@ -71,6 +85,11 @@ class Quota extends \Test\Files\Storage\Storage {
$meta = stream_get_meta_data($stream);
$this->assertEquals('plainfile', $meta['wrapper_type']);
fclose($stream);
+
+ $stream = $instance->fopen('foo', 'rb');
+ $meta = stream_get_meta_data($stream);
+ $this->assertEquals('plainfile', $meta['wrapper_type']);
+ fclose($stream);
}
public function testReturnQuotaStreamOnWrite(){
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index f358c15dd50..72a2f854cb2 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();
@@ -309,6 +309,48 @@ class View extends \PHPUnit_Framework_TestCase {
/**
* @medium
*/
+ function testUnlink() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->file_put_contents('/foo.txt', 'asd');
+ $rootView->file_put_contents('/substorage/bar.txt', 'asd');
+
+ $this->assertTrue($rootView->file_exists('foo.txt'));
+ $this->assertTrue($rootView->file_exists('substorage/bar.txt'));
+
+ $this->assertTrue($rootView->unlink('foo.txt'));
+ $this->assertTrue($rootView->unlink('substorage/bar.txt'));
+
+ $this->assertFalse($rootView->file_exists('foo.txt'));
+ $this->assertFalse($rootView->file_exists('substorage/bar.txt'));
+ }
+
+ /**
+ * @medium
+ */
+ function testUnlinkRootMustFail() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $rootView->file_put_contents('/foo.txt', 'asd');
+ $rootView->file_put_contents('/substorage/bar.txt', 'asd');
+
+ $this->assertFalse($rootView->unlink(''));
+ $this->assertFalse($rootView->unlink('/'));
+ $this->assertFalse($rootView->unlink('substorage'));
+ $this->assertFalse($rootView->unlink('/substorage'));
+ }
+
+ /**
+ * @medium
+ */
function testTouch() {
$storage = $this->getTestStorage(true, '\Test\Files\TemporaryNoTouch');
@@ -473,4 +515,51 @@ 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);
+ }
+ }
+
+ public function testTouchNotSupported() {
+ $storage = new TemporaryNoTouch(array());
+ $scanner = $storage->getScanner();
+ \OC\Files\Filesystem::mount($storage, array(), '/test/');
+ $past = time() - 100;
+ $storage->file_put_contents('test', 'foobar');
+ $scanner->scan('');
+ $view = new \OC\Files\View('');
+ $info = $view->getFileInfo('/test/test');
+
+ $view->touch('/test/test', $past);
+ $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
+
+ $info2 = $view->getFileInfo('/test/test');
+ $this->assertEquals($info['etag'], $info2['etag']);
+ }
}
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/request.php b/tests/lib/request.php
index 090cebc9231..c6401a57144 100644
--- a/tests/lib/request.php
+++ b/tests/lib/request.php
@@ -70,4 +70,54 @@ class Test_Request extends PHPUnit_Framework_TestCase {
array('/oc/core1', '/oc/core/index.php'),
);
}
+
+ /**
+ * @dataProvider userAgentProvider
+ */
+ public function testUserAgent($testAgent, $userAgent, $matches) {
+ $_SERVER['HTTP_USER_AGENT'] = $testAgent;
+ $this->assertEquals($matches, OC_Request::isUserAgent($userAgent));
+ }
+
+ function userAgentProvider() {
+ return array(
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ OC_Request::USER_AGENT_IE,
+ true
+ ),
+ array(
+ 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
+ OC_Request::USER_AGENT_IE,
+ false
+ ),
+ array(
+ 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ true
+ ),
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ false
+ ),
+ // test two values
+ array(
+ 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
+ array(
+ OC_Request::USER_AGENT_IE,
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ ),
+ true
+ ),
+ array(
+ 'Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
+ array(
+ OC_Request::USER_AGENT_IE,
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ ),
+ true
+ ),
+ );
+ }
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 84e2e5c63eb..d6acee6c924 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -25,6 +25,8 @@ class Test_Share extends PHPUnit_Framework_TestCase {
protected $userBackend;
protected $user1;
protected $user2;
+ protected $user3;
+ protected $user4;
protected $groupBackend;
protected $group1;
protected $group2;
@@ -149,6 +151,26 @@ class Test_Share extends PHPUnit_Framework_TestCase {
);
}
+ protected function shareUserTestFileWithUser($sharer, $receiver) {
+ OC_User::setUserId($sharer);
+ $this->assertTrue(
+ OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $receiver, OCP\PERMISSION_READ | OCP\PERMISSION_SHARE),
+ 'Failed asserting that ' . $sharer . ' successfully shared text.txt with ' . $receiver . '.'
+ );
+ $this->assertContains(
+ 'test.txt',
+ OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
+ 'Failed asserting that test.txt is a shared file of ' . $sharer . '.'
+ );
+
+ OC_User::setUserId($receiver);
+ $this->assertContains(
+ 'test.txt',
+ OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
+ 'Failed asserting that ' . $receiver . ' has access to test.txt after initial sharing.'
+ );
+ }
+
public function testShareWithUser() {
// Invalid shares
$message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner';
@@ -585,25 +607,95 @@ class Test_Share extends PHPUnit_Framework_TestCase {
}
public function testUnshareAll() {
- $this->shareUserOneTestFileWithUserTwo();
+ $this->shareUserTestFileWithUser($this->user1, $this->user2);
+ $this->shareUserTestFileWithUser($this->user2, $this->user3);
+ $this->shareUserTestFileWithUser($this->user3, $this->user4);
$this->shareUserOneTestFileWithGroupOne();
OC_User::setUserId($this->user1);
$this->assertEquals(
array('test.txt', 'test.txt'),
OCP\Share::getItemsShared('test', 'test.txt'),
- 'Failed asserting that the test.txt file is shared exactly two times.'
+ 'Failed asserting that the test.txt file is shared exactly two times by user1.'
+ );
+
+ OC_User::setUserId($this->user2);
+ $this->assertEquals(
+ array('test.txt'),
+ OCP\Share::getItemsShared('test', 'test.txt'),
+ 'Failed asserting that the test.txt file is shared exactly once by user2.'
+ );
+
+ OC_User::setUserId($this->user3);
+ $this->assertEquals(
+ array('test.txt'),
+ OCP\Share::getItemsShared('test', 'test.txt'),
+ 'Failed asserting that the test.txt file is shared exactly once by user3.'
);
$this->assertTrue(
OCP\Share::unshareAll('test', 'test.txt'),
- 'Failed asserting that user 1 successfully unshared all shares of the test.txt share.'
+ 'Failed asserting that user 3 successfully unshared all shares of the test.txt share.'
+ );
+
+ $this->assertEquals(
+ array(),
+ OCP\Share::getItemsShared('test'),
+ 'Failed asserting that the share of the test.txt file by user 3 has been removed.'
+ );
+
+ OC_User::setUserId($this->user1);
+ $this->assertEquals(
+ array(),
+ OCP\Share::getItemsShared('test'),
+ 'Failed asserting that both shares of the test.txt file by user 1 have been removed.'
);
+ OC_User::setUserId($this->user2);
$this->assertEquals(
array(),
OCP\Share::getItemsShared('test'),
- 'Failed asserting that both shares of the test.txt file have been removed.'
+ 'Failed asserting that the share of the test.txt file by user 2 has been removed.'
+ );
+ }
+
+ /**
+ * @dataProvider checkPasswordProtectedShareDataProvider
+ * @param $expected
+ * @param $item
+ */
+ public function testCheckPasswordProtectedShare($expected, $item) {
+ \OC::$session->set('public_link_authenticated', 100);
+ $result = \OCP\Share::checkPasswordProtectedShare($item);
+ $this->assertEquals($expected, $result);
+ }
+
+ function checkPasswordProtectedShareDataProvider() {
+ return array(
+ array(true, array()),
+ array(true, array('share_with' => null)),
+ array(true, array('share_with' => '')),
+ array(true, array('share_with' => '1234567890', 'share_type' => '1')),
+ array(true, array('share_with' => '1234567890', 'share_type' => 1)),
+ array(true, array('share_with' => '1234567890', 'share_type' => '3', 'id' => 100)),
+ array(true, array('share_with' => '1234567890', 'share_type' => 3, 'id' => 100)),
+ array(false, array('share_with' => '1234567890', 'share_type' => '3', 'id' => 101)),
+ array(false, array('share_with' => '1234567890', 'share_type' => 3, 'id' => 101)),
);
+
+ /*
+ if (!isset($linkItem['share_with'])) {
+ return true;
+ }
+
+ if ($linkItem['share_type'] != \OCP\Share::SHARE_TYPE_LINK) {
+ return true;
+ }
+
+ if ( \OC::$session->exists('public_link_authenticated')
+ && \OC::$session->get('public_link_authenticated') === $linkItem['id'] ) {
+ return true;
+ }
+ * */
}
}
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index 00901dd4115..ad1ac9e12f2 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -346,4 +346,76 @@ class Manager extends \PHPUnit_Framework_TestCase {
$manager->createUser('foo', 'bar');
}
+
+ public function testCountUsersNoBackend() {
+ $manager = new \OC\User\Manager();
+
+ $result = $manager->countUsers();
+ $this->assertTrue(is_array($result));
+ $this->assertTrue(empty($result));
+ }
+
+ public function testCountUsersOneBackend() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $result = $manager->countUsers();
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ $this->assertEquals(7, $users);
+ }
+
+ public function testCountUsersTwoBackends() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend1 = $this->getMock('\OC_User_Dummy');
+ $backend1->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend1->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $backend2 = $this->getMock('\OC_User_Dummy');
+ $backend2->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(16));
+
+ $backend2->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend1);
+ $manager->registerBackend($backend2);
+
+ $result = $manager->countUsers();
+ //because the backends have the same class name, only one value expected
+ $this->assertEquals(1, count($result));
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ //users from backends shall be summed up
+ $this->assertEquals(7+16, $users);
+ }
}
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/lib/util.php b/tests/lib/util.php
index 852caaeccc3..bfe68f5f680 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -88,6 +88,15 @@ class Test_Util extends PHPUnit_Framework_TestCase {
OC_Config::deleteKey('mail_domain');
}
+ function testGetConfiguredEmailAddressFromConfig() {
+ OC_Config::setValue('mail_domain', 'example.com');
+ OC_Config::setValue('mail_from_address', 'owncloud');
+ $email = \OCP\Util::getDefaultEmailAddress("no-reply");
+ $this->assertEquals('owncloud@example.com', $email);
+ OC_Config::deleteKey('mail_domain');
+ OC_Config::deleteKey('mail_from_address');
+ }
+
function testGetInstanceIdGeneratesValidId() {
OC_Config::deleteKey('instanceid');
$this->assertStringStartsWith('oc', OC_Util::getInstanceId());
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..a969ece6dd5
--- /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;
+ }
+}
+?>