summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2014-02-10 21:32:17 +0100
committerBart Visscher <bartv@thisnet.nl>2014-02-10 21:32:17 +0100
commit082abdc62080730f70ac0fac67628e4d3bb0cc7b (patch)
tree0054fcb95d954b31933aaafbbdcd69d66a6c944e /tests
parent5c3c379f351be913fe7abd500fadd69a83687ebc (diff)
parentbea80ffe2060407e5d849a86f71fae2eed80b08e (diff)
downloadnextcloud-server-082abdc62080730f70ac0fac67628e4d3bb0cc7b.tar.gz
nextcloud-server-082abdc62080730f70ac0fac67628e4d3bb0cc7b.zip
Merge branch 'master' into migration_unit_tests
Diffstat (limited to 'tests')
-rw-r--r--tests/data/db_structure.xml1
-rw-r--r--tests/enable_all.php24
-rw-r--r--tests/karma.config.js189
-rw-r--r--tests/lib/api.php35
-rw-r--r--tests/lib/errorHandler.php62
-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.php59
-rw-r--r--tests/lib/request.php65
-rw-r--r--tests/lib/share/share.php100
-rw-r--r--tests/lib/user/manager.php72
-rw-r--r--tests/lib/util.php9
-rw-r--r--tests/testcleanuplistener.php6
16 files changed, 672 insertions, 37 deletions
diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml
index bfff2143349..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>
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..529bd31338f
--- /dev/null
+++ b/tests/karma.config.js
@@ -0,0 +1,189 @@
+/**
+* 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.
+ *
+ * Setting the environment variable NOCOVERAGE to 1 will disable the coverage
+ * preprocessor, which is needed to be able to debug tests properly in a browser.
+ */
+
+/* jshint node: true */
+module.exports = function(config) {
+
+ function findApps() {
+ /*
+ var fs = require('fs');
+ var apps = fs.readdirSync('apps');
+ return apps;
+ */
+ // other apps tests don't run yet... needs further research / clean up
+ return ['files'];
+ }
+
+ // respect NOCOVERAGE env variable
+ // it is useful to disable coverage for debugging
+ // because the coverage preprocessor will wrap the JS files somehow
+ var enableCoverage = !parseInt(process.env.NOCOVERAGE, 10);
+ console.log('Coverage preprocessor: ', enableCoverage?'enabled':'disabled');
+
+ // default apps to test when none is specified (TODO: read from filesystem ?)
+ var appsToTest = process.env.KARMA_TESTSUITE;
+ if (appsToTest) {
+ appsToTest = appsToTest.split(' ');
+ }
+ else {
+ appsToTest = ['core'].concat(findApps());
+ }
+
+ console.log('Apps to test: ', appsToTest);
+
+ // 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 coreModule = require('../' + corePath + 'core.json');
+ var testCore = false;
+ var files = [];
+ var index;
+ var preprocessors = {};
+
+ // find out what apps to test from appsToTest
+ 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 library files
+ for ( var i = 0; i < coreModule.libraries.length; i++ ) {
+ var srcFile = corePath + coreModule.libraries[i];
+ files.push(srcFile);
+ }
+
+ // add core modules files
+ for ( var i = 0; i < coreModule.modules.length; i++ ) {
+ var srcFile = corePath + coreModule.modules[i];
+ files.push(srcFile);
+ if (enableCoverage) {
+ preprocessors[srcFile] = 'coverage';
+ }
+ }
+
+ // TODO: settings pages
+
+ // 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
+ var srcFile = 'apps/' + appsToTest[i] + '/js/*.js';
+ files.push(srcFile);
+ if (enableCoverage) {
+ preprocessors[srcFile] = 'coverage';
+ }
+ // 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: preprocessors,
+
+ 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/errorHandler.php b/tests/lib/errorHandler.php
new file mode 100644
index 00000000000..68b87deccb6
--- /dev/null
+++ b/tests/lib/errorHandler.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle@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/>.
+ *
+ */
+
+class Test_ErrorHandler extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @brief provide username, password combinations for testRemovePassword
+ * @return array
+ */
+ function passwordProvider() {
+ return array(
+ array('user', 'password'),
+ array('user@owncloud.org', 'password'),
+ array('user', 'pass@word'),
+ array('us:er', 'password'),
+ array('user', 'pass:word'),
+ );
+
+ }
+
+ /**
+ * @dataProvider passwordProvider
+ * @param string $username
+ * @param string $password
+ */
+ function testRemovePassword($username, $password) {
+ $url = 'http://'.$username.':'.$password.'@owncloud.org';
+ $expectedResult = 'http://xxx:xxx@owncloud.org';
+ $result = TestableErrorHandler::testRemovePassword($url);
+
+ $this->assertEquals($expectedResult, $result);
+ }
+
+}
+
+/**
+ * @brief dummy class to access protected methods of \OC\Log\ErrorHandler
+ */
+class TestableErrorHandler extends \OC\Log\ErrorHandler {
+ public static function testRemovePassword($msg) {
+ return self::removePassword($msg);
+ }
+}
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 b59cef9f0da..72a2f854cb2 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -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');
@@ -503,4 +545,21 @@ class View extends \PHPUnit_Framework_TestCase {
$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/request.php b/tests/lib/request.php
index 090cebc9231..1d77acc70ae 100644
--- a/tests/lib/request.php
+++ b/tests/lib/request.php
@@ -70,4 +70,69 @@ 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
+ ),
+ array(
+ 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ false
+ ),
+ array(
+ 'Mozilla/5.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ true
+ ),
+ array(
+ 'Fake Mozilla/5.0',
+ OC_Request::USER_AGENT_FREEBOX,
+ false
+ ),
+ );
+ }
}
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/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/testcleanuplistener.php b/tests/testcleanuplistener.php
index 368ea7bc8f4..a969ece6dd5 100644
--- a/tests/testcleanuplistener.php
+++ b/tests/testcleanuplistener.php
@@ -58,7 +58,7 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
}
private function unlinkDir($dir) {
- if ($dh = opendir($dir)) {
+ if ($dh = @opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file === '..' || $file === '.') {
continue;
@@ -68,12 +68,12 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
$this->unlinkDir($path);
}
else {
- unlink($path);
+ @unlink($path);
}
}
closedir($dh);
}
- rmdir($dir);
+ @rmdir($dir);
}
private function cleanStrayDataFiles() {