diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php
index 5ed8b1931f4e..3bccaca12317 100644
--- a/apps/files/tests/ajax_rename.php
+++ b/apps/files/tests/ajax_rename.php
@@ -34,7 +34,14 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
*/
private $files;
- function setUp() {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+
// mock OC_L10n
if (!self::$user) {
self::$user = uniqid();
@@ -59,10 +66,13 @@ function setUp() {
$this->files = new \OCA\Files\App($viewMock, $l10nMock);
}
- function tearDown() {
+ protected function tearDown() {
$result = \OC_User::deleteUser(self::$user);
$this->assertTrue($result);
\OC\Files\Filesystem::tearDown();
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
}
/**
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index f74812a72539..8aa1daaa7979 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -573,6 +573,7 @@ public function stream_close() {
\OC_FileProxy::$enabled = false;
if ($this->rootView->file_exists($this->rawPath) && $this->size === 0) {
+ fclose($this->handle);
$this->rootView->unlink($this->rawPath);
}
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index 5adab9bc9200..eb4029e8e193 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -23,7 +23,7 @@
/**
* Class Test_Encryption_Crypt
*/
-class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1";
@@ -42,6 +42,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
public $genPublicKey;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -57,10 +59,12 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
+ self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// set user id
\OC_User::setUserId(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
$this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
@@ -88,7 +92,7 @@ function setUp() {
\OC_App::disable('files_trashbin');
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
@@ -98,6 +102,8 @@ function tearDown() {
$this->assertTrue(\OC_FileProxy::$enabled);
\OCP\Config::deleteSystemValue('cipher');
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
@@ -111,12 +117,14 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
* @medium
*/
- function testGenerateKey() {
+ public function testGenerateKey() {
# TODO: use more accurate (larger) string length for test confirmation
@@ -126,7 +134,7 @@ function testGenerateKey() {
}
- function testDecryptPrivateKey() {
+ public function testDecryptPrivateKey() {
// test successful decrypt
$crypted = Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
@@ -148,7 +156,7 @@ function testDecryptPrivateKey() {
/**
* @medium
*/
- function testSymmetricEncryptFileContent() {
+ public function testSymmetricEncryptFileContent() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -166,7 +174,7 @@ function testSymmetricEncryptFileContent() {
/**
* @medium
*/
- function testSymmetricEncryptFileContentAes128() {
+ public function testSymmetricEncryptFileContentAes128() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -184,9 +192,9 @@ function testSymmetricEncryptFileContentAes128() {
/**
* @medium
*/
- function testSymmetricStreamEncryptShortFileContent() {
+ public function testSymmetricStreamEncryptShortFileContent() {
- $filename = 'tmp-' . uniqid() . '.test';
+ $filename = 'tmp-' . $this->getUniqueID() . '.test';
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort);
@@ -221,9 +229,9 @@ function testSymmetricStreamEncryptShortFileContent() {
/**
* @medium
*/
- function testSymmetricStreamEncryptShortFileContentAes128() {
+ public function testSymmetricStreamEncryptShortFileContentAes128() {
- $filename = 'tmp-' . uniqid() . '.test';
+ $filename = 'tmp-' . $this->getUniqueID() . '.test';
\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');
@@ -266,10 +274,10 @@ function testSymmetricStreamEncryptShortFileContentAes128() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
- function testSymmetricStreamEncryptLongFileContent() {
+ public function testSymmetricStreamEncryptLongFileContent() {
// Generate a a random filename
- $filename = 'tmp-' . uniqid() . '.test';
+ $filename = 'tmp-' . $this->getUniqueID() . '.test';
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
@@ -310,10 +318,10 @@ function testSymmetricStreamEncryptLongFileContent() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
- function testSymmetricStreamEncryptLongFileContentAes128() {
+ public function testSymmetricStreamEncryptLongFileContentAes128() {
// Generate a a random filename
- $filename = 'tmp-' . uniqid() . '.test';
+ $filename = 'tmp-' . $this->getUniqueID() . '.test';
\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');
@@ -358,10 +366,10 @@ function testSymmetricStreamEncryptLongFileContentAes128() {
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
- function testStreamDecryptLongFileContentWithoutHeader() {
+ public function testStreamDecryptLongFileContentWithoutHeader() {
// Generate a a random filename
- $filename = 'tmp-' . uniqid() . '.test';
+ $filename = 'tmp-' . $this->getUniqueID() . '.test';
\OCP\Config::setSystemValue('cipher', 'AES-128-CFB');
@@ -406,7 +414,7 @@ function testStreamDecryptLongFileContentWithoutHeader() {
/**
* @medium
*/
- function testIsEncryptedContent() {
+ public function testIsEncryptedContent() {
$this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl));
@@ -421,7 +429,7 @@ function testIsEncryptedContent() {
/**
* @large
*/
- function testMultiKeyEncrypt() {
+ public function testMultiKeyEncrypt() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -475,9 +483,9 @@ function testLegacyDecryptLong() {
/**
* @medium
*/
- function testRenameFile() {
+ public function testRenameFile() {
- $filename = 'tmp-' . uniqid();
+ $filename = 'tmp-' . $this->getUniqueID();
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@@ -490,7 +498,7 @@ function testRenameFile() {
$this->assertEquals($this->dataLong, $decrypt);
- $newFilename = 'tmp-new-' . uniqid();
+ $newFilename = 'tmp-new-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
$view->rename($filename, $newFilename);
@@ -506,9 +514,9 @@ function testRenameFile() {
/**
* @medium
*/
- function testMoveFileIntoFolder() {
+ public function testMoveFileIntoFolder() {
- $filename = 'tmp-' . uniqid();
+ $filename = 'tmp-' . $this->getUniqueID();
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@@ -521,8 +529,8 @@ function testMoveFileIntoFolder() {
$this->assertEquals($this->dataLong, $decrypt);
- $newFolder = '/newfolder' . uniqid();
- $newFilename = 'tmp-new-' . uniqid();
+ $newFolder = '/newfolder' . $this->getUniqueID();
+ $newFilename = 'tmp-new-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
$view->mkdir($newFolder);
$view->rename($filename, $newFolder . '/' . $newFilename);
@@ -539,12 +547,12 @@ function testMoveFileIntoFolder() {
/**
* @medium
*/
- function testMoveFolder() {
+ public function testMoveFolder() {
$view = new \OC\Files\View('/' . $this->userId . '/files');
- $filename = '/tmp-' . uniqid();
- $folder = '/folder' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
+ $folder = '/folder' . $this->getUniqueID();
$view->mkdir($folder);
@@ -559,7 +567,7 @@ function testMoveFolder() {
$this->assertEquals($this->dataLong, $decrypt);
- $newFolder = '/newfolder/subfolder' . uniqid();
+ $newFolder = '/newfolder/subfolder' . $this->getUniqueID();
$view->mkdir('/newfolder');
$view->rename($folder, $newFolder);
@@ -577,8 +585,8 @@ function testMoveFolder() {
/**
* @medium
*/
- function testChangePassphrase() {
- $filename = 'tmp-' . uniqid();
+ public function testChangePassphrase() {
+ $filename = 'tmp-' . $this->getUniqueID();
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
@@ -614,9 +622,9 @@ function testChangePassphrase() {
/**
* @medium
*/
- function testViewFilePutAndGetContents() {
+ public function testViewFilePutAndGetContents() {
- $filename = '/tmp-' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -648,8 +656,8 @@ function testViewFilePutAndGetContents() {
/**
* @large
*/
- function testTouchExistingFile() {
- $filename = '/tmp-' . uniqid();
+ public function testTouchExistingFile() {
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -672,8 +680,8 @@ function testTouchExistingFile() {
/**
* @medium
*/
- function testTouchFile() {
- $filename = '/tmp-' . uniqid();
+ public function testTouchFile() {
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
$view->touch($filename);
@@ -696,8 +704,8 @@ function testTouchFile() {
/**
* @medium
*/
- function testFopenFile() {
- $filename = '/tmp-' . uniqid();
+ public function testFopenFile() {
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -714,6 +722,7 @@ function testFopenFile() {
$this->assertEquals($this->dataShort, $decrypt);
// tear down
+ fclose($handle);
$view->unlink($filename);
}
diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php
index df7ff8cdb113..9c6d165dc5da 100644
--- a/apps/files_encryption/tests/helper.php
+++ b/apps/files_encryption/tests/helper.php
@@ -5,35 +5,40 @@
* later.
* See the COPYING-README file.
*/
-
-
require_once __DIR__ . '/../lib/helper.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
/**
* Class Test_Encryption_Helper
*/
-class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_HELPER_USER1 = "test-helper-user1";
const TEST_ENCRYPTION_HELPER_USER2 = "test-helper-user2";
- public function setUp() {
+ protected function setUpUsers() {
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER2, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1, true);
+ self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER2, true);
+ self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1, true);
}
- public function tearDown() {
+ protected function cleanUpUsers() {
// cleanup test user
\OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
\OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER2);
}
- public static function tearDownAfterClass() {
+ public static function setupHooks() {
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+ }
+
+ public static function tearDownAfterClass() {
\OC_Hook::clear();
\OC_FileProxy::clearProxies();
@@ -41,6 +46,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
@@ -92,19 +99,20 @@ function testGetPathToRealFile() {
}
function testGetUser() {
+ self::setUpUsers();
$path1 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/files/foo/bar.txt";
$path2 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/cache/foo/bar.txt";
$path3 = "/" . self::TEST_ENCRYPTION_HELPER_USER2 . "/thumbnails/foo";
$path4 ="/" . "/" . self::TEST_ENCRYPTION_HELPER_USER1;
- \Test_Encryption_Util::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1);
+ self::loginHelper(self::TEST_ENCRYPTION_HELPER_USER1);
// if we are logged-in every path should return the currently logged-in user
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path3));
// now log out
- \Test_Encryption_Util::logoutHelper();
+ self::logoutHelper();
// now we should only get the user from /user/files and user/cache paths
$this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path1));
@@ -114,12 +122,13 @@ function testGetUser() {
$this->assertFalse(Encryption\Helper::getUser($path4));
// Log-in again
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
+ self::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
+ self::cleanUpUsers();
}
function userNamesProvider() {
return array(
- array('testuser' . uniqid()),
+ array('testuser' . $this->getUniqueID()),
array('user.name.with.dots'),
);
}
@@ -130,12 +139,13 @@ function userNamesProvider() {
* @dataProvider userNamesProvider
*/
function testFindShareKeys($userName) {
+ self::setUpUsers();
// note: not using dataProvider as we want to make
// sure that the correct keys are match and not any
// other ones that might happen to have similar names
- \Test_Encryption_Util::setupHooks();
- \Test_Encryption_Util::loginHelper($userName, true);
- $testDir = 'testFindShareKeys' . uniqid() . '/';
+ self::setupHooks();
+ self::loginHelper($userName, true);
+ $testDir = 'testFindShareKeys' . $this->getUniqueID() . '/';
$baseDir = $userName . '/files/' . $testDir;
$fileList = array(
't est.txt',
@@ -166,6 +176,6 @@ function testFindShareKeys($userName) {
$result
);
}
+ self::cleanUpUsers();
}
-
}
diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php
index c7353deee22f..1ff3ac6619bc 100644
--- a/apps/files_encryption/tests/hooks.php
+++ b/apps/files_encryption/tests/hooks.php
@@ -26,7 +26,6 @@
require_once __DIR__ . '/../lib/stream.php';
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
@@ -34,16 +33,16 @@
* Class Test_Encryption_Hooks
* this class provide basic hook app tests
*/
-class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_HOOKS_USER1 = "test-encryption-hooks-user1.dot";
const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2.dot";
- /**
- * @var \OC\Files\View
- */
+ /** @var \OC\Files\View */
public $user1View; // view on /data/user1/files
+ /** @var \OC\Files\View */
public $user2View; // view on /data/user2/files
+ /** @var \OC\Files\View */
public $rootView; // view on /data/user
public $data;
public $filename;
@@ -52,6 +51,8 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
private static $testFiles;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// note: not using a data provider because these
// files all need to coexist to make sure the
// share keys are found properly (pattern matching)
@@ -92,13 +93,15 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true);
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true);
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// set user id
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
// init filesystem view
@@ -108,8 +111,8 @@ function setUp() {
// init short data
$this->data = 'hats';
- $this->filename = 'enc_hooks_tests-' . uniqid() . '.txt';
- $this->folder = 'enc_hooks_tests_folder-' . uniqid();
+ $this->filename = 'enc_hooks_tests-' . $this->getUniqueID() . '.txt';
+ $this->folder = 'enc_hooks_tests_folder-' . $this->getUniqueID();
}
@@ -125,6 +128,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
function testDisableHook() {
@@ -146,7 +151,7 @@ function testDisableHook() {
// relogin user to initialize the encryption again
$user = \OCP\User::getUser();
- \Test_Encryption_Util::loginHelper($user);
+ self::loginHelper($user);
}
@@ -171,8 +176,8 @@ function testDeleteHooks() {
self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
- \Test_Encryption_Util::logoutHelper();
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ self::logoutHelper();
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
@@ -229,8 +234,8 @@ function testDeleteHooks() {
function testDeleteHooksForSharedFiles() {
- \Test_Encryption_Util::logoutHelper();
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ self::logoutHelper();
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
// remember files_trashbin state
@@ -265,8 +270,8 @@ function testDeleteHooksForSharedFiles() {
self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/'
. $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
- \Test_Encryption_Util::logoutHelper();
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
+ self::logoutHelper();
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
// user2 update the shared file
@@ -296,8 +301,8 @@ function testDeleteHooksForSharedFiles() {
// cleanup
- \Test_Encryption_Util::logoutHelper();
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
+ self::logoutHelper();
+ self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
if ($stateFilesTrashbin) {
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index ad7d2cfcd45f..d708f3e8170b 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -14,14 +14,13 @@
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../lib/helper.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
/**
* Class Test_Encryption_Keymanager
*/
-class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_USER = "test-keymanager-user.dot";
@@ -36,6 +35,8 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
public $dataShort;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -58,10 +59,11 @@ public static function setUpBeforeClass() {
// create test user
\OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true);
+ parent::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
// set content for encrypting / decrypting in tests
$this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
$this->dataShort = 'hats';
@@ -76,7 +78,7 @@ function setUp() {
$this->view = new \OC\Files\View('/');
- \Test_Encryption_Util::loginHelper(Test_Encryption_Keymanager::TEST_USER);
+ self::loginHelper(Test_Encryption_Keymanager::TEST_USER);
$this->userId = \Test_Encryption_Keymanager::TEST_USER;
$this->pass = \Test_Encryption_Keymanager::TEST_USER;
@@ -87,6 +89,8 @@ function setUp() {
function tearDown() {
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys');
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles');
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
@@ -106,6 +110,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
@@ -171,7 +177,7 @@ function testSetFileKey() {
$key = $this->randomKey;
- $file = 'unittest-' . uniqid() . '.txt';
+ $file = 'unittest-' . $this->getUniqueID() . '.txt';
$util = new Encryption\Util($this->view, $this->userId);
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php
index 56d6cd2f7367..9e84f11e5974 100644
--- a/apps/files_encryption/tests/proxy.php
+++ b/apps/files_encryption/tests/proxy.php
@@ -27,7 +27,6 @@
require_once __DIR__ . '/../lib/stream.php';
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
@@ -35,7 +34,7 @@
* Class Test_Encryption_Proxy
* this class provide basic proxy app tests
*/
-class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_PROXY_USER1 = "test-proxy-user1";
@@ -51,6 +50,8 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
public $filename;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -66,10 +67,12 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true);
+ self::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// set user id
\OC_User::setUserId(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1);
$this->userId = \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1;
@@ -82,7 +85,7 @@ function setUp() {
// init short data
$this->data = 'hats';
$this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
- $this->filename = 'enc_proxy_tests-' . uniqid() . '.txt';
+ $this->filename = 'enc_proxy_tests-' . $this->getUniqueID() . '.txt';
}
@@ -97,6 +100,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index abf8911c69c8..9be4828c60ea 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -29,14 +29,13 @@
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../lib/helper.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
/**
* Class Test_Encryption_Share
*/
-class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_SHARE_USER1 = "test-share-user1";
const TEST_ENCRYPTION_SHARE_USER2 = "test-share-user2";
@@ -56,6 +55,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
public $subsubfolder;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -82,10 +83,10 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create users
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
// create group and assign users
\OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
@@ -93,7 +94,9 @@ public static function setUpBeforeClass() {
\OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
$this->dataShort = 'hats';
$this->view = new \OC\Files\View('/');
@@ -110,16 +113,18 @@ function setUp() {
\OC_App::disable('files_trashbin');
// login as first user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
} else {
OC_App::disable('files_trashbin');
}
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
@@ -139,6 +144,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
@@ -148,7 +155,7 @@ public static function tearDownAfterClass() {
*/
function testShareFile($withTeardown = true) {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
@@ -177,7 +184,7 @@ function testShareFile($withTeardown = true) {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 exists
$this->assertTrue($this->view->file_exists(
@@ -185,7 +192,7 @@ function testShareFile($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -198,7 +205,7 @@ function testShareFile($withTeardown = true) {
if ($withTeardown) {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
@@ -228,7 +235,7 @@ function testReShareFile($withTeardown = true) {
$this->testShareFile(false);
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get the file info
$fileInfo = $this->view->getFileInfo(
@@ -238,7 +245,7 @@ function testReShareFile($withTeardown = true) {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user2 exists
$this->assertTrue($this->view->file_exists(
@@ -246,7 +253,7 @@ function testReShareFile($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -259,13 +266,13 @@ function testReShareFile($withTeardown = true) {
if ($withTeardown) {
// login as user1
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// unshare the file with user2
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key not exists
$this->assertFalse($this->view->file_exists(
@@ -299,7 +306,7 @@ function testReShareFile($withTeardown = true) {
*/
function testShareFolder($withTeardown = true) {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// create folder structure
$this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
@@ -334,7 +341,7 @@ function testShareFolder($withTeardown = true) {
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 exists
$this->assertTrue($this->view->file_exists(
@@ -343,7 +350,7 @@ function testShareFolder($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -357,7 +364,7 @@ function testShareFolder($withTeardown = true) {
if ($withTeardown) {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the folder with user1
\OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
@@ -391,7 +398,7 @@ function testReShareFolder($withTeardown = true) {
$fileInfoFolder1 = $this->testShareFolder(false);
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
@@ -412,7 +419,7 @@ function testReShareFolder($withTeardown = true) {
\OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user3 exists
$this->assertTrue($this->view->file_exists(
@@ -421,7 +428,7 @@ function testReShareFolder($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user3
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -443,7 +450,7 @@ function testReShareFolder($withTeardown = true) {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user3 exists
$this->assertTrue($this->view->file_exists(
@@ -452,7 +459,7 @@ function testReShareFolder($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user3
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -465,7 +472,7 @@ function testReShareFolder($withTeardown = true) {
if ($withTeardown) {
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// unshare the file with user3
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
@@ -477,7 +484,7 @@ function testReShareFolder($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// unshare the folder with user2
\OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
@@ -489,7 +496,7 @@ function testReShareFolder($withTeardown = true) {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the folder1 with user1
\OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
@@ -516,7 +523,7 @@ function testReShareFolder($withTeardown = true) {
function testPublicShareFile() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
@@ -545,7 +552,7 @@ function testPublicShareFile() {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, false, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
$publicShareKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'publicShareKeyId');
@@ -557,7 +564,7 @@ function testPublicShareFile() {
// some hacking to simulate public link
//$GLOBALS['app'] = 'files_sharing';
//$GLOBALS['fileOwner'] = \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1;
- \Test_Encryption_Util::logoutHelper();
+ self::logoutHelper();
// get file contents
$retrievedCryptedFile = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
@@ -568,7 +575,7 @@ function testPublicShareFile() {
// tear down
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
@@ -594,7 +601,7 @@ function testPublicShareFile() {
*/
function testShareFileWithGroup() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
@@ -623,7 +630,7 @@ function testShareFileWithGroup() {
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user2 and user3 exists
$this->assertTrue($this->view->file_exists(
@@ -634,7 +641,7 @@ function testShareFileWithGroup() {
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
$retrievedCryptedFile = $this->view->file_get_contents(
@@ -644,7 +651,7 @@ function testShareFileWithGroup() {
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
@@ -675,13 +682,13 @@ function testShareFileWithGroup() {
function testRecoveryFile() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
@@ -781,7 +788,7 @@ function testRecoveryFile() {
function testRecoveryForUser() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
$result = \OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
$this->assertTrue($result);
@@ -789,7 +796,7 @@ function testRecoveryForUser() {
$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
$util = new \OCA\Encryption\Util(new \OC\Files\View('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
@@ -833,7 +840,7 @@ function testRecoveryForUser() {
. $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// change password
\OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123');
@@ -843,7 +850,7 @@ function testRecoveryForUser() {
\OCA\Encryption\Hooks::setPassphrase($params);
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test');
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test');
// get file contents
$retrievedCryptedFile1 = file_get_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
@@ -895,7 +902,7 @@ function testRecoveryForUser() {
*/
function testFailShareFile() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
@@ -933,7 +940,7 @@ function testFailShareFile() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 not exists
$this->assertFalse($this->view->file_exists(
@@ -978,7 +985,7 @@ function testFailShareFile() {
function testRename() {
// login as admin
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
@@ -1003,7 +1010,7 @@ function testRename() {
// login as user2
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
$this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename));
@@ -1026,7 +1033,7 @@ function testRename() {
$this->assertEquals($this->dataShort, $retrievedRenamedFile);
// cleanup
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
$this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
}
@@ -1038,8 +1045,8 @@ function testMoveFolder() {
$view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
- $filename = '/tmp-' . uniqid();
- $folder = '/folder' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
+ $folder = '/folder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir($folder);
@@ -1054,7 +1061,7 @@ function testMoveFolder() {
$this->assertEquals($this->dataShort, $decrypt);
- $newFolder = '/newfolder/subfolder' . uniqid();
+ $newFolder = '/newfolder/subfolder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir('/newfolder');
// get the file info from previous created file
@@ -1096,8 +1103,8 @@ function usersProvider() {
function testMoveFileToFolder($userId) {
$view = new \OC\Files\View('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
- $filename = '/tmp-' . uniqid();
- $folder = '/folder' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
+ $folder = '/folder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir($folder);
@@ -1112,7 +1119,7 @@ function testMoveFileToFolder($userId) {
$this->assertEquals($this->dataShort, $decrypt);
- $subFolder = $folder . '/subfolder' . uniqid();
+ $subFolder = $folder . '/subfolder' . $this->getUniqueID();
\OC\Files\Filesystem::mkdir($subFolder);
// get the file info from previous created file
@@ -1127,9 +1134,9 @@ function testMoveFileToFolder($userId) {
$this->assertTrue($view->file_exists('files_encryption/share-keys' . $folder . '/' . $filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// move the file into the subfolder as the test user
- \Test_Encryption_Util::loginHelper($userId);
+ self::loginHelper($userId);
\OC\Files\Filesystem::rename($folder . $filename, $subFolder . $filename);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// Get file decrypted contents
$newDecrypt = \OC\Files\Filesystem::file_get_contents($subFolder . $filename);
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index b8c18fbe0490..3bc2a3b29fcb 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -27,7 +27,6 @@
require_once __DIR__ . '/../lib/stream.php';
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
@@ -35,7 +34,7 @@
* Class Test_Encryption_Stream
* this class provide basic stream tests
*/
-class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_STREAM_USER1 = "test-stream-user1";
@@ -49,6 +48,8 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
public $stateFilesTrashbin;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -61,10 +62,12 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true);
+ self::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// set user id
\OC_User::setUserId(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
$this->userId = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1;
@@ -83,7 +86,7 @@ function setUp() {
\OC_App::disable('files_trashbin');
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
@@ -91,6 +94,8 @@ function tearDown() {
else {
OC_App::disable('files_trashbin');
}
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
@@ -104,10 +109,12 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
function testStreamOptions() {
- $filename = '/tmp-' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -125,12 +132,14 @@ function testStreamOptions() {
$this->assertTrue(flock($handle, LOCK_SH));
$this->assertTrue(flock($handle, LOCK_UN));
+ fclose($handle);
+
// tear down
$view->unlink($filename);
}
function testStreamSetBlocking() {
- $filename = '/tmp-' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -141,6 +150,13 @@ function testStreamSetBlocking() {
$handle = $view->fopen($filename, 'r');
+
+ if (\OC_Util::runningOnWindows()) {
+ fclose($handle);
+ $view->unlink($filename);
+ $this->markTestSkipped('[Windows] stream_set_blocking() does not work as expected on Windows.');
+ }
+
// set stream options
$this->assertTrue(stream_set_blocking($handle, 1));
@@ -154,7 +170,7 @@ function testStreamSetBlocking() {
* @medium
*/
function testStreamSetTimeout() {
- $filename = '/tmp-' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -175,7 +191,7 @@ function testStreamSetTimeout() {
}
function testStreamSetWriteBuffer() {
- $filename = '/tmp-' . uniqid();
+ $filename = '/tmp-' . $this->getUniqueID();
$view = new \OC\Files\View('/' . $this->userId . '/files');
// Save short data as encrypted file using stream wrapper
@@ -201,9 +217,9 @@ function testStreamSetWriteBuffer() {
*/
function testStreamFromLocalFile() {
- $filename = '/' . $this->userId . '/files/' . 'tmp-' . uniqid().'.txt';
+ $filename = '/' . $this->userId . '/files/' . 'tmp-' . $this->getUniqueID().'.txt';
- $tmpFilename = "/tmp/" . uniqid() . ".txt";
+ $tmpFilename = "/tmp/" . $this->getUniqueID() . ".txt";
// write an encrypted file
$cryptedFile = $this->view->file_put_contents($filename, $this->dataShort);
@@ -228,6 +244,8 @@ function testStreamFromLocalFile() {
// check if it was successful
$this->assertEquals($this->dataShort, $contentFromTmpFile);
+ fclose($handle);
+
// clean up
unlink($tmpFilename);
$this->view->unlink($filename);
diff --git a/apps/files_encryption/tests/testcase.php b/apps/files_encryption/tests/testcase.php
new file mode 100644
index 000000000000..3106aeda8ea8
--- /dev/null
+++ b/apps/files_encryption/tests/testcase.php
@@ -0,0 +1,53 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Encryption\Tests;
+
+use OCA\Encryption;
+
+/**
+ * Class Test_Encryption_TestCase
+ */
+abstract class TestCase extends \Test\TestCase {
+ /**
+ * @param string $user
+ * @param bool $create
+ * @param bool $password
+ */
+ public static function loginHelper($user, $create = false, $password = false, $loadEncryption = true) {
+ if ($create) {
+ try {
+ \OC_User::createUser($user, $user);
+ } catch (\Exception $e) {
+ // catch username is already being used from previous aborted runs
+ }
+ }
+
+ if ($password === false) {
+ $password = $user;
+ }
+
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::tearDown();
+ \OC_User::setUserId($user);
+ \OC_Util::setupFS($user);
+
+ if ($loadEncryption) {
+ $params['uid'] = $user;
+ $params['password'] = $password;
+ \OCA\Encryption\Hooks::login($params);
+ }
+ }
+
+ public static function logoutHelper() {
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId(false);
+ \OC\Files\Filesystem::tearDown();
+ }
+}
diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php
index 5890292cd7bc..1fd8ff4c940b 100755
--- a/apps/files_encryption/tests/trashbin.php
+++ b/apps/files_encryption/tests/trashbin.php
@@ -28,7 +28,6 @@
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
require_once __DIR__ . '/../../files_trashbin/appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
@@ -36,7 +35,7 @@
* Class Test_Encryption_Trashbin
* this class provide basic trashbin app tests
*/
-class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_TRASHBIN_USER1 = "test-trashbin-user1";
@@ -53,6 +52,8 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase {
public $subsubfolder;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -71,14 +72,16 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1, true);
+ self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER1, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// set user id
- \OC_User::setUserId(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1);
- $this->userId = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1;
- $this->pass = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1;
+ \OC_User::setUserId(self::TEST_ENCRYPTION_TRASHBIN_USER1);
+ $this->userId = self::TEST_ENCRYPTION_TRASHBIN_USER1;
+ $this->pass = self::TEST_ENCRYPTION_TRASHBIN_USER1;
// init filesystem view
$this->view = new \OC\Files\View('/');
@@ -97,7 +100,7 @@ function setUp() {
\OC_App::enable('files_trashbin');
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
@@ -105,11 +108,13 @@ function tearDown() {
else {
OC_App::disable('files_trashbin');
}
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
// cleanup test user
- \OC_User::deleteUser(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_TRASHBIN_USER1);
\OC_Hook::clear();
\OC_FileProxy::clearProxies();
@@ -118,6 +123,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
@@ -127,12 +134,12 @@ public static function tearDownAfterClass() {
function testDeleteFile() {
// generate filename
- $filename = 'tmp-' . uniqid() . '.txt';
+ $filename = 'tmp-' . $this->getUniqueID() . '.txt';
$filename2 = $filename . '.backup'; // a second file with similar name
// save file with content
- $cryptedFile = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort);
- $cryptedFile2 = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename2, $this->dataShort);
+ $cryptedFile = file_put_contents('crypt:///' .self::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort);
+ $cryptedFile2 = file_put_contents('crypt:///' .self::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename2, $this->dataShort);
// test that data was successfully written
$this->assertTrue(is_int($cryptedFile));
@@ -140,59 +147,59 @@ function testDeleteFile() {
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
. '.key'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
. '.key'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete first file
\OC\FIles\Filesystem::unlink($filename);
// check if file not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
. '.key'));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// check that second file still exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2));
// check that key for second file still exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename2
. '.key'));
// check that share key for second file still exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// get files
$trashFiles = $this->view->getDirectoryContent(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
$trashFileSuffix = null;
// find created file with timestamp
foreach ($trashFiles as $file) {
- if (strncmp($file['path'], $filename, strlen($filename))) {
+ if (strpos($file['path'], $filename . '.d') !== false) {
$path_parts = pathinfo($file['name']);
$trashFileSuffix = $path_parts['extension'];
}
@@ -203,13 +210,13 @@ function testDeleteFile() {
// check if key for admin not exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
. '.key.' . $trashFileSuffix));
// check if share key for admin not exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
}
/**
@@ -218,32 +225,27 @@ function testDeleteFile() {
*/
function testRestoreFile() {
// generate filename
- $filename = 'tmp-' . uniqid() . '.txt';
+ $filename = 'tmp-' . $this->getUniqueID() . '.txt';
$filename2 = $filename . '.backup'; // a second file with similar name
// save file with content
- $cryptedFile = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort);
- $cryptedFile2 = file_put_contents('crypt:///' .\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename2, $this->dataShort);
+ $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename, $this->dataShort);
+ $cryptedFile2 = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_TRASHBIN_USER1. '/files/'. $filename2, $this->dataShort);
// delete both files
\OC\Files\Filesystem::unlink($filename);
\OC\Files\Filesystem::unlink($filename2);
- $trashFiles = $this->view->getDirectoryContent(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
+ $trashFiles = $this->view->getDirectoryContent('/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
$trashFileSuffix = null;
$trashFileSuffix2 = null;
// find created file with timestamp
foreach ($trashFiles as $file) {
- if (strncmp($file['path'], $filename, strlen($filename))) {
+ if (strpos($file['path'], $filename . '.d') !== false) {
$path_parts = pathinfo($file['name']);
$trashFileSuffix = $path_parts['extension'];
}
- if (strncmp($file['path'], $filename2, strlen($filename2))) {
- $path_parts = pathinfo($file['name']);
- $trashFileSuffix2 = $path_parts['extension'];
- }
}
// prepare file information
@@ -254,31 +256,31 @@ function testRestoreFile() {
// check if file exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
. $filename . '.key'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// check that second file was NOT restored
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename2));
// check if key for admin exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
. $filename2 . '.key'));
// check if share key for admin exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename2 . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename2 . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
}
/**
@@ -288,7 +290,7 @@ function testRestoreFile() {
function testPermanentDeleteFile() {
// generate filename
- $filename = 'tmp-' . uniqid() . '.txt';
+ $filename = 'tmp-' . $this->getUniqueID() . '.txt';
// save file with content
$cryptedFile = file_put_contents('crypt:///' .$this->userId. '/files/' . $filename, $this->dataShort);
@@ -298,30 +300,30 @@ function testPermanentDeleteFile() {
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
. '.key'));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete file
\OC\Files\Filesystem::unlink($filename);
// check if file not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
. '.key'));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
- . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// find created file with timestamp
$query = \OC_DB::prepare('SELECT `timestamp`,`type` FROM `*PREFIX*files_trash`'
@@ -335,13 +337,13 @@ function testPermanentDeleteFile() {
// check if key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
. '.key.' . $trashFileSuffix));
// check if share key for admin exists
$this->assertTrue($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
// get timestamp from file
$timestamp = str_replace('d', '', $trashFileSuffix);
@@ -351,18 +353,18 @@ function testPermanentDeleteFile() {
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/' . $filename . '.'
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/' . $filename . '.'
. $trashFileSuffix));
// check if key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
. '.key.' . $trashFileSuffix));
// check if share key for admin not exists
$this->assertFalse($this->view->file_exists(
- '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
- . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
+ '/' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . self::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
}
}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 83d2c6b0f92d..d7713259ce2f 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -19,7 +19,7 @@
/**
* Class Test_Encryption_Util
*/
-class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_UTIL_USER1 = "test-util-user1";
const TEST_ENCRYPTION_UTIL_USER2 = "test-util-user2";
@@ -49,6 +49,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
public $stateFilesTrashbin;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -56,9 +58,9 @@ public static function setUpBeforeClass() {
self::setupHooks();
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2, true);
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1, true);
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER2, true);
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
// create groups
\OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
@@ -68,13 +70,14 @@ public static function setUpBeforeClass() {
\OC_Group::addToGroup(self::TEST_ENCRYPTION_UTIL_USER1, self::TEST_ENCRYPTION_UTIL_GROUP1);
}
+ protected function setUp() {
+ parent::setUp();
- function setUp() {
// login user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
- \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
- $this->userId = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
- $this->pass = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1);
+ \OC_User::setUserId(self::TEST_ENCRYPTION_UTIL_USER1);
+ $this->userId = self::TEST_ENCRYPTION_UTIL_USER1;
+ $this->pass = self::TEST_ENCRYPTION_UTIL_USER1;
// set content for encrypting / decrypting in tests
$this->dataUrl = __DIR__ . '/../lib/crypt.php';
@@ -109,7 +112,7 @@ function setUp() {
\OC_App::disable('files_trashbin');
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
@@ -117,13 +120,15 @@ function tearDown() {
else {
OC_App::disable('files_trashbin');
}
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
// cleanup test user
- \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
- \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2);
- \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_UTIL_USER1);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_UTIL_USER2);
+ \OC_User::deleteUser(self::TEST_ENCRYPTION_UTIL_LEGACY_USER);
//cleanup groups
\OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
@@ -136,6 +141,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
public static function setupHooks() {
@@ -172,8 +179,8 @@ function testIsEncryptedPath() {
self::loginHelper($this->userId);
- $unencryptedFile = '/tmpUnencrypted-' . uniqid() . '.txt';
- $encryptedFile = '/tmpEncrypted-' . uniqid() . '.txt';
+ $unencryptedFile = '/tmpUnencrypted-' . $this->getUniqueID() . '.txt';
+ $encryptedFile = '/tmpEncrypted-' . $this->getUniqueID() . '.txt';
// Disable encryption proxy to write a unencrypted file
$proxyStatus = \OC_FileProxy::$enabled;
@@ -280,9 +287,9 @@ function testRecoveryEnabledForUser() {
*/
function testGetUidAndFilename() {
- \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
+ \OC_User::setUserId(self::TEST_ENCRYPTION_UTIL_USER1);
- $filename = '/tmp-' . uniqid() . '.test';
+ $filename = '/tmp-' . $this->getUniqueID() . '.test';
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
@@ -297,7 +304,7 @@ function testGetUidAndFilename() {
list($fileOwnerUid, $file) = $util->getUidAndFilename($filename);
- $this->assertEquals(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, $fileOwnerUid);
+ $this->assertEquals(self::TEST_ENCRYPTION_UTIL_USER1, $fileOwnerUid);
$this->assertEquals($file, $filename);
@@ -308,9 +315,9 @@ function testGetUidAndFilename() {
< * Test that data that is read by the crypto stream wrapper
*/
function testGetFileSize() {
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1);
- $filename = 'tmp-' . uniqid();
+ $filename = 'tmp-' . $this->getUniqueID();
$externalFilename = '/' . $this->userId . '/files/' . $filename;
// Test for 0 byte files
@@ -334,7 +341,7 @@ function testGetFileSize() {
function testEncryptAll() {
- $filename = "/encryptAll" . uniqid() . ".txt";
+ $filename = "/encryptAll" . $this->getUniqueID() . ".txt";
$util = new Encryption\Util($this->view, $this->userId);
// disable encryption to upload a unencrypted file
@@ -365,7 +372,7 @@ function testEncryptAll() {
function testDecryptAll() {
- $filename = "/decryptAll" . uniqid() . ".txt";
+ $filename = "/decryptAll" . $this->getUniqueID() . ".txt";
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
$userdir = $datadir . '/' . $this->userId . '/files/';
@@ -484,8 +491,8 @@ function testBackupAllKeys() {
function testDescryptAllWithBrokenFiles() {
- $file1 = "/decryptAll1" . uniqid() . ".txt";
- $file2 = "/decryptAll2" . uniqid() . ".txt";
+ $file1 = "/decryptAll1" . $this->getUniqueID() . ".txt";
+ $file2 = "/decryptAll2" . $this->getUniqueID() . ".txt";
$util = new Encryption\Util($this->view, $this->userId);
diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php
index cc0cff9aa5ca..c519e4c46d60 100755
--- a/apps/files_encryption/tests/webdav.php
+++ b/apps/files_encryption/tests/webdav.php
@@ -27,7 +27,6 @@
require_once __DIR__ . '/../lib/stream.php';
require_once __DIR__ . '/../lib/util.php';
require_once __DIR__ . '/../appinfo/app.php';
-require_once __DIR__ . '/util.php';
use OCA\Encryption;
@@ -36,7 +35,7 @@
*
* this class provide basic webdav tests for PUT,GET and DELETE
*/
-class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
+class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase {
const TEST_ENCRYPTION_WEBDAV_USER1 = "test-webdav-user1";
@@ -52,6 +51,8 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
private $storage;
public static function setUpBeforeClass() {
+ parent::setUpBeforeClass();
+
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
@@ -67,11 +68,13 @@ public static function setUpBeforeClass() {
\OC_FileProxy::register(new OCA\Encryption\Proxy());
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true);
+ self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true);
}
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
// reset backend
\OC_User::useBackend('database');
@@ -93,16 +96,18 @@ function setUp() {
\OC_App::disable('files_trashbin');
// create test user
- \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
+ self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
} else {
OC_App::disable('files_trashbin');
}
+
+ parent::tearDown();
}
public static function tearDownAfterClass() {
@@ -116,6 +121,8 @@ public static function tearDownAfterClass() {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
/**
@@ -124,7 +131,7 @@ public static function tearDownAfterClass() {
function testWebdavPUT() {
// generate filename
- $filename = '/tmp-' . uniqid() . '.txt';
+ $filename = '/tmp-' . $this->getUniqueID() . '.txt';
// set server vars
$_SERVER['REQUEST_METHOD'] = 'OPTIONS';
diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php
index 1b0fe6fdc6d3..042722206188 100644
--- a/apps/files_sharing/tests/cache.php
+++ b/apps/files_sharing/tests/cache.php
@@ -29,6 +29,18 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
*/
public $user2View;
+ /** @var \OC\Files\Cache\Cache */
+ protected $ownerCache;
+
+ /** @var \OC\Files\Cache\Cache */
+ protected $sharedCache;
+
+ /** @var \OC\Files\Storage\Storage */
+ protected $ownerStorage;
+
+ /** @var \OC\Files\Storage\Storage */
+ protected $sharedStorage;
+
function setUp() {
parent::setUp();
@@ -53,7 +65,7 @@ function setUp() {
$this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
$this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '');
- list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
+ list($this->ownerStorage,) = $this->view->resolvePath('');
$this->ownerCache = $this->ownerStorage->getCache();
$this->ownerStorage->getScanner()->scan('');
@@ -71,7 +83,7 @@ function setUp() {
// retrieve the shared storage
$secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
- list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/shareddir');
+ list($this->sharedStorage,) = $secondView->resolvePath('files/shareddir');
$this->sharedCache = $this->sharedStorage->getCache();
}
@@ -353,7 +365,7 @@ public function testGetPathByIdShareSubFolder() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::mkdir('foo');
\OC\Files\Filesystem::mkdir('foo/bar');
- \OC\Files\Filesystem::touch('foo/bar/test.txt', 'bar');
+ \OC\Files\Filesystem::touch('foo/bar/test.txt');
$folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
$fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\PERMISSION_ALL);
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index f5be7a0cc059..1ebc79086ddb 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -695,13 +695,22 @@ static public function hasUpdated($path, $time) {
* @param bool $stripTrailingSlash
* @return string
*/
- public static function normalizePath($path, $stripTrailingSlash = true) {
+ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
if ($path == '') {
return '/';
}
+
//no windows style slashes
$path = str_replace('\\', '/', $path);
+ // When normalizing an absolute path, we need to ensure that the drive-letter
+ // is still at the beginning on windows
+ $windows_drive_letter = '';
+ if ($isAbsolutePath && \OC_Util::runningOnWindows() && preg_match('#^([a-zA-Z])$#', $path[0]) && $path[1] == ':' && $path[2] == '/') {
+ $windows_drive_letter = substr($path, 0, 2);
+ $path = substr($path, 2);
+ }
+
//add leading slash
if ($path[0] !== '/') {
$path = '/' . $path;
@@ -730,7 +739,7 @@ public static function normalizePath($path, $stripTrailingSlash = true) {
//normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path);
- return $path;
+ return $windows_drive_letter . $path;
}
/**
diff --git a/lib/private/files/storage/mappedlocal.php b/lib/private/files/storage/mappedlocal.php
index ea4deaa66e84..4ff02d295234 100644
--- a/lib/private/files/storage/mappedlocal.php
+++ b/lib/private/files/storage/mappedlocal.php
@@ -24,9 +24,6 @@ public function __construct($arguments) {
}
public function __destruct() {
- if (defined('PHPUNIT_RUN')) {
- $this->mapper->removePath($this->datadir, true, true);
- }
}
public function getId() {
diff --git a/tests/lib/app.php b/tests/lib/app.php
index e538ebec8a0f..e8289f58a26d 100644
--- a/tests/lib/app.php
+++ b/tests/lib/app.php
@@ -460,6 +460,9 @@ private function restoreAppConfig() {
\OC::$server->registerService('AppConfig', function ($c) use ($oldService){
return $oldService;
});
+
+ // Remove the cache of the mocked apps list with a forceRefresh
+ \OC_App::getEnabledApps(true);
}
}
diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php
index d831487b16fa..2b5271edd528 100644
--- a/tests/lib/archive/tar.php
+++ b/tests/lib/archive/tar.php
@@ -8,12 +8,16 @@
require_once 'archive.php';
-if (!OC_Util::runningOnWindows()) {
class Test_Archive_TAR extends Test_Archive {
public function setUp() {
- if (floatval(phpversion())>=5.5) {
+ parent::setUp();
+
+ if (floatval(phpversion()) >= 5.5) {
$this->markTestSkipped('php 5.5 changed unpack function.');
- return;
+ }
+
+ if (OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('[Windows] tar archives are not supported on Windows');
}
}
protected function getExisting() {
@@ -25,4 +29,3 @@ protected function getNew() {
return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
}
}
-}
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index 3767c83fcb1c..8cc45c85405d 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -23,8 +23,12 @@
namespace Test\Cache;
class FileCache extends \Test_Cache {
+ /** @var string */
private $user;
+ /** @var string */
private $datadir;
+ /** @var \OC\Files\Storage\Storage */
+ private $storage;
function skip() {
//$this->skipUnless(OC_User::isLoggedIn());
@@ -42,12 +46,13 @@ public function setUp() {
//}
//set up temporary storage
+ $this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage,array(),'/');
$datadir = str_replace('local::', '', $storage->getId());
- $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
- \OC_Config::setValue('datadirectory', $datadir);
+ $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
+ \OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -67,6 +72,12 @@ public function setUp() {
public function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('datadirectory', $this->datadir);
+ \OC_Config::setValue('cachedirectory', $this->datadir);
+
+ // Restore the original mount point
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->storage, array(), '/');
+
+ parent::tearDown();
}
}
diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php
index 21b7f848ab6d..8a23a805ebee 100644
--- a/tests/lib/cache/usercache.php
+++ b/tests/lib/cache/usercache.php
@@ -23,8 +23,12 @@
namespace Test\Cache;
class UserCache extends \Test_Cache {
+ /** @var string */
private $user;
+ /** @var string */
private $datadir;
+ /** @var \OC\Files\Storage\Storage */
+ private $storage;
public function setUp() {
//clear all proxies and hooks so we can do clean testing
@@ -38,12 +42,13 @@ public function setUp() {
//}
//set up temporary storage
+ $this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage,array(),'/');
$datadir = str_replace('local::', '', $storage->getId());
- $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
- \OC_Config::setValue('datadirectory', $datadir);
+ $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
+ \OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -63,6 +68,12 @@ public function setUp() {
public function tearDown() {
\OC_User::setUserId($this->user);
- \OC_Config::setValue('datadirectory', $this->datadir);
+ \OC_Config::setValue('cachedirectory', $this->datadir);
+
+ // Restore the original mount point
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->storage, array(), '/');
+
+ parent::tearDown();
}
}
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index 96b4207ad430..9e7330db20c0 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -33,7 +33,13 @@ class Updater extends \PHPUnit_Framework_TestCase {
*/
protected $updater;
- public function setUp() {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = Filesystem::getStorage('/');
$this->storage = new Temporary(array());
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/');
@@ -42,6 +48,13 @@ public function setUp() {
$this->cache = $this->storage->getCache();
}
+ protected function tearDown() {
+ Filesystem::clearMounts();
+ Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
+ }
+
public function testNewFile() {
$this->storage->file_put_contents('foo.txt', 'bar');
$this->assertFalse($this->cache->inCache('foo.txt'));
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
index c80c3168ad65..d16a062fcca2 100644
--- a/tests/lib/files/cache/updaterlegacy.php
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -29,6 +29,9 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase {
*/
private $cache;
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
private static $user;
public function setUp() {
@@ -51,7 +54,8 @@ public function setUp() {
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
- \OC\Files\Filesystem::tearDown();
+ $this->originalStorage = Filesystem::getStorage('/');
+ Filesystem::tearDown();
if (!self::$user) {
self::$user = uniqid();
}
@@ -59,7 +63,7 @@ public function setUp() {
\OC_User::createUser(self::$user, 'password');
\OC_User::setUserId(self::$user);
- \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
+ Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
@@ -74,6 +78,7 @@ public function tearDown() {
$result = \OC_User::deleteUser(self::$user);
$this->assertTrue($result);
Filesystem::tearDown();
+ Filesystem::mount($this->originalStorage, array(), '/');
// reset app files_encryption
if ($this->stateFilesEncryption) {
\OC_App::enable('files_encryption');
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 22c11b9a4e01..0b04b9e7058f 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -15,16 +15,27 @@ class Watcher extends \PHPUnit_Framework_TestCase {
*/
private $storages = array();
- public function setUp() {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
}
- public function tearDown() {
+ protected function tearDown() {
foreach ($this->storages as $storage) {
$cache = $storage->getCache();
$ids = $cache->getAll();
$cache->clear();
}
+
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
}
/**
diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php
index af9f66835f09..4b47222dd62c 100644
--- a/tests/lib/files/etagtest.php
+++ b/tests/lib/files/etagtest.php
@@ -11,7 +11,7 @@
use OC\Files\Filesystem;
use OCP\Share;
-class EtagTest extends \PHPUnit_Framework_TestCase {
+class EtagTest extends \Test\TestCase {
private $datadir;
private $tmpDir;
@@ -23,7 +23,12 @@ class EtagTest extends \PHPUnit_Framework_TestCase {
*/
private $userBackend;
- public function setUp() {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
\OC_Hook::clear('OC_Filesystem', 'setup');
\OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
\OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
@@ -37,13 +42,17 @@ public function setUp() {
$this->userBackend = new \OC_User_Dummy();
\OC_User::useBackend($this->userBackend);
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC_Util::tearDownFS();
}
- public function tearDown() {
+ protected function tearDown() {
\OC_Config::setValue('datadirectory', $this->datadir);
\OC_User::setUserId($this->uid);
\OC_Util::setupFS($this->uid);
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
}
public function testNewUser() {
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 930a252bcb24..88e98fbb8c69 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -22,12 +22,15 @@
namespace Test\Files;
-class Filesystem extends \PHPUnit_Framework_TestCase {
+class Filesystem extends \Test\TestCase {
/**
* @var array tmpDirs
*/
private $tmpDirs = array();
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
/**
* @return array
*/
@@ -37,19 +40,23 @@ private function getStorageData() {
return array('datadir' => $dir);
}
- public function tearDown() {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ protected function tearDown() {
foreach ($this->tmpDirs as $dir) {
\OC_Helper::rmdirr($dir);
}
\OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
\OC_User::setUserId('');
}
- public function setUp() {
- \OC_User::setUserId('');
- \OC\Files\Filesystem::clearMounts();
- }
-
public function testMount() {
\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/');
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/'));
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index 319f2f9f5f7e..cde2eb22b7ba 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -20,6 +20,9 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase {
*/
private $root;
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
/**
* @var \OC\Files\Storage\Storage[]
*/
@@ -30,7 +33,10 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase {
*/
private $view;
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::init('', '');
\OC\Files\Filesystem::clearMounts();
$manager = \OC\Files\Filesystem::getMountManager();
@@ -54,11 +60,15 @@ public function setUp() {
$this->root->mount($subStorage, '/substorage/');
}
- public function tearDown() {
+ protected function tearDown() {
foreach ($this->storages as $storage) {
$storage->getCache()->clear();
}
\OC\Files\Filesystem::clearMounts();
+
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
}
public function testBasicFile() {
diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php
index 51315a2a5561..6149213cc722 100644
--- a/tests/lib/files/storage/home.php
+++ b/tests/lib/files/storage/home.php
@@ -73,7 +73,12 @@ public function tearDown() {
* Tests that the root path matches the data dir
*/
public function testRoot() {
- $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder(''));
+ if (\OC_Util::runningOnWindows()) {
+ // Windows removes trailing slashes when returning paths
+ $this->assertEquals(rtrim($this->tmpDir, '/'), $this->instance->getLocalFolder(''));
+ } else {
+ $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder(''));
+ }
}
/**
diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php
index 5e5cc6ac1283..51bd6230cd58 100644
--- a/tests/lib/files/utils/scanner.php
+++ b/tests/lib/files/utils/scanner.php
@@ -38,7 +38,23 @@ public function setPropagator($propagator) {
}
}
-class Scanner extends \PHPUnit_Framework_TestCase {
+
+class Scanner extends \Test\TestCase {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+ }
+
+ protected function tearDown() {
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
+ }
+
public function testReuseExistingRoot() {
$storage = new Temporary(array());
$mount = new Mount($storage, '');
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index 522535946a53..aa50318c85ba 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -22,9 +22,15 @@ class View extends \PHPUnit_Framework_TestCase {
private $storages = array();
private $user;
+ /** @var \OC\Files\Storage\Storage */
private $tempStorage;
- public function setUp() {
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
@@ -33,12 +39,13 @@ public function setUp() {
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$this->tempStorage = null;
}
- public function tearDown() {
+ protected function tearDown() {
\OC_User::setUserId($this->user);
foreach ($this->storages as $storage) {
$cache = $storage->getCache();
@@ -49,6 +56,11 @@ public function tearDown() {
if ($this->tempStorage && !\OC_Util::runningOnWindows()) {
system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir()));
}
+
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
}
/**
@@ -590,7 +602,17 @@ public function testLongPath() {
$longPath = '';
// 4000 is the maximum path length in file_cache.path
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $depth = (4000 / 57);
+
+ $tmpdirLength = strlen(\OC_Helper::tmpFolder());
+ if (\OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('[Windows] ');
+ $depth = ((260 - $tmpdirLength) / 57);
+ } elseif (\OC_Util::runningOnMac()){
+ $depth = ((1024 - $tmpdirLength) / 57);
+ } else {
+ $depth = ((4000 - $tmpdirLength) / 57);
+ }
+
foreach (range(0, $depth - 1) as $i) {
$longPath .= '/' . $folderName;
$result = $rootView->mkdir($longPath);
diff --git a/tests/lib/group.php b/tests/lib/group.php
index 724e723b1871..795de6955131 100644
--- a/tests/lib/group.php
+++ b/tests/lib/group.php
@@ -22,38 +22,39 @@
*
*/
-class Test_Group extends PHPUnit_Framework_TestCase {
- function setUp() {
+class Test_Group extends \Test\TestCase {
+ protected function setUp() {
+ parent::setUp();
OC_Group::clearBackends();
OC_User::clearBackends();
}
- function testSingleBackend() {
+ public function testSingleBackend() {
$userBackend = new \OC_User_Dummy();
\OC_User::getManager()->registerBackend($userBackend);
OC_Group::useBackend(new OC_Group_Dummy());
- $group1 = uniqid();
- $group2 = uniqid();
+ $group1 = $this->getUniqueID();
+ $group2 = $this->getUniqueID();
OC_Group::createGroup($group1);
OC_Group::createGroup($group2);
- $user1 = uniqid();
- $user2 = uniqid();
+ $user1 = $this->getUniqueID();
+ $user2 = $this->getUniqueID();
$userBackend->createUser($user1, '');
$userBackend->createUser($user2, '');
- $this->assertFalse(OC_Group::inGroup($user1, $group1));
- $this->assertFalse(OC_Group::inGroup($user2, $group1));
- $this->assertFalse(OC_Group::inGroup($user1, $group2));
- $this->assertFalse(OC_Group::inGroup($user2, $group2));
+ $this->assertFalse(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is not in group1');
+ $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1');
+ $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2');
+ $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2');
$this->assertTrue(OC_Group::addToGroup($user1, $group1));
- $this->assertTrue(OC_Group::inGroup($user1, $group1));
- $this->assertFalse(OC_Group::inGroup($user2, $group1));
- $this->assertFalse(OC_Group::inGroup($user1, $group2));
- $this->assertFalse(OC_Group::inGroup($user2, $group2));
+ $this->assertTrue(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is in group1');
+ $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1');
+ $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2');
+ $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2');
$this->assertTrue(OC_Group::addToGroup($user1, $group1));
@@ -80,7 +81,7 @@ public function testNoEmptyGIDs() {
public function testNoGroupsTwice() {
OC_Group::useBackend(new OC_Group_Dummy());
- $group = uniqid();
+ $group = $this->getUniqueID();
OC_Group::createGroup($group);
$groupCopy = $group;
@@ -103,7 +104,7 @@ public function testDontDeleteAdminGroup() {
public function testDontAddUserToNonexistentGroup() {
OC_Group::useBackend(new OC_Group_Dummy());
$groupNonExistent = 'notExistent';
- $user = uniqid();
+ $user = $this->getUniqueID();
$this->assertEquals(false, OC_Group::addToGroup($user, $groupNonExistent));
$this->assertEquals(array(), OC_Group::getGroups());
@@ -114,12 +115,12 @@ public function testUsersInGroup() {
$userBackend = new \OC_User_Dummy();
\OC_User::getManager()->registerBackend($userBackend);
- $group1 = uniqid();
- $group2 = uniqid();
- $group3 = uniqid();
- $user1 = uniqid();
- $user2 = uniqid();
- $user3 = uniqid();
+ $group1 = $this->getUniqueID();
+ $group2 = $this->getUniqueID();
+ $group3 = $this->getUniqueID();
+ $user1 = $this->getUniqueID();
+ $user2 = $this->getUniqueID();
+ $user3 = $this->getUniqueID();
OC_Group::createGroup($group1);
OC_Group::createGroup($group2);
OC_Group::createGroup($group3);
@@ -139,8 +140,7 @@ public function testUsersInGroup() {
// FIXME: needs more parameter variation
}
-
- function testMultiBackend() {
+ public function testMultiBackend() {
$userBackend = new \OC_User_Dummy();
\OC_User::getManager()->registerBackend($userBackend);
$backend1 = new OC_Group_Dummy();
@@ -148,8 +148,8 @@ function testMultiBackend() {
OC_Group::useBackend($backend1);
OC_Group::useBackend($backend2);
- $group1 = uniqid();
- $group2 = uniqid();
+ $group1 = $this->getUniqueID();
+ $group2 = $this->getUniqueID();
OC_Group::createGroup($group1);
//groups should be added to the first registered backend
@@ -166,8 +166,8 @@ function testMultiBackend() {
$this->assertTrue(OC_Group::groupExists($group1));
$this->assertTrue(OC_Group::groupExists($group2));
- $user1 = uniqid();
- $user2 = uniqid();
+ $user1 = $this->getUniqueID();
+ $user2 = $this->getUniqueID();
$userBackend->createUser($user1, '');
$userBackend->createUser($user2, '');
diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php
index 95a5cf5f49ca..62c189489d7c 100644
--- a/tests/lib/group/backend.php
+++ b/tests/lib/group/backend.php
@@ -20,7 +20,7 @@
*
*/
-abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
+abstract class Test_Group_Backend extends \Test\TestCase {
/**
* @var OC_Group_Backend $backend
*/
@@ -33,7 +33,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
*/
public function getGroupName($name = null) {
if(is_null($name)) {
- return uniqid('test_');
+ return $this->getUniqueID('test_');
} else {
return $name;
}
@@ -45,7 +45,7 @@ public function getGroupName($name = null) {
* @return string
*/
public function getUserName() {
- return uniqid('test_');
+ return $this->getUniqueID('test_');
}
public function testAddRemove() {
@@ -138,6 +138,4 @@ public function testSearchUsers() {
$result = $this->backend->countUsersInGroup($group, 'bar');
$this->assertSame(2, $result);
}
-
-
}
diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php
index 9b39ac004524..10958a6ccdce 100644
--- a/tests/lib/group/database.php
+++ b/tests/lib/group/database.php
@@ -22,36 +22,27 @@
class Test_Group_Database extends Test_Group_Backend {
private $groups=array();
-
+
/**
* get a new unique group name
* test cases can override this in order to clean up created groups
* @return string
*/
public function getGroupName($name = null) {
- if(is_null($name)) {
- $name=uniqid('test_');
- }
- $this->groups[]=$name;
+ $name = parent::getGroupName($name);
+ $this->groups[] = $name;
return $name;
}
- /**
- * get a new unique user name
- * test cases can override this in order to clean up created user
- * @return string
- */
- public function getUserName() {
- return uniqid('test_');
- }
-
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
$this->backend=new OC_Group_Database();
}
- public function tearDown() {
+ protected function tearDown() {
foreach($this->groups as $group) {
$this->backend->deleteGroup($group);
}
+ parent::tearDown();
}
}
diff --git a/tests/lib/group/dummy.php b/tests/lib/group/dummy.php
index 287d6f1a977e..b4456c8f7e17 100644
--- a/tests/lib/group/dummy.php
+++ b/tests/lib/group/dummy.php
@@ -21,7 +21,8 @@
*/
class Test_Group_Dummy extends Test_Group_Backend {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
$this->backend=new OC_Group_Dummy();
}
}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 6146b29b437d..de625d144cec 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -115,6 +115,10 @@ function testGetFileNameMimeType() {
}
function testGetStringMimeType() {
+ if (\OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows');
+ }
+
$result = OC_Helper::getStringMimeType("/data/data.tar.gz");
$expected = 'text/plain; charset=us-ascii';
$this->assertEquals($result, $expected);
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php
index 4fdd9dd6b9be..9f3bd8824f7b 100644
--- a/tests/lib/helperstorage.php
+++ b/tests/lib/helperstorage.php
@@ -9,14 +9,22 @@
/**
* Test the storage functions of OC_Helper
*/
-class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
+
+class Test_Helper_Storage extends \Test\TestCase {
+ /** @var string */
private $user;
+ /** @var \OC\Files\Storage\Storage */
private $storageMock;
+ /** @var \OC\Files\Storage\Storage */
+ private $storage;
+
+ protected function setUp() {
+ parent::setUp();
- public function setUp() {
- $this->user = 'user_' . uniqid();
+ $this->user = $this->getUniqueID('user_');
\OC_User::createUser($this->user, $this->user);
+ $this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId($this->user);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
@@ -25,7 +33,7 @@ public function setUp() {
$this->storageMock = null;
}
- public function tearDown() {
+ protected function tearDown() {
$this->user = null;
if ($this->storageMock) {
@@ -33,10 +41,13 @@ public function tearDown() {
$this->storageMock = null;
}
\OC\Files\Filesystem::tearDown();
+ \OC\Files\Filesystem::mount($this->storage, array(), '/');
\OC_User::setUserId('');
\OC_User::deleteUser($this->user);
\OC_Preferences::deleteUser($this->user);
+
+ parent::tearDown();
}
/**
diff --git a/tests/lib/image.php b/tests/lib/image.php
index 795bc4641595..a683c3d2c8b6 100644
--- a/tests/lib/image.php
+++ b/tests/lib/image.php
@@ -62,14 +62,18 @@ public function testMimeType() {
$img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
$this->assertEquals('image/png', $img->mimeType());
+ $img = new \OC_Image(null);
+ $this->assertEquals('', $img->mimeType());
+
+ if (\OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('[Windows] Images created with imagecreate() are pngs on windows');
+ }
+
$img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg'));
$this->assertEquals('image/jpeg', $img->mimeType());
$img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif')));
$this->assertEquals('image/gif', $img->mimeType());
-
- $img = new \OC_Image(null);
- $this->assertEquals('', $img->mimeType());
}
public function testWidth() {
diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php
index 58571d641e01..90ecc3dde708 100644
--- a/tests/lib/largefilehelpergetfilesize.php
+++ b/tests/lib/largefilehelpergetfilesize.php
@@ -13,58 +13,77 @@
* Large files are not considered yet.
*/
class LargeFileHelperGetFileSize extends \PHPUnit_Framework_TestCase {
- protected $filename;
- protected $fileSize;
+ /** @var \OC\LargeFileHelper */
protected $helper;
public function setUp() {
parent::setUp();
- $ds = DIRECTORY_SEPARATOR;
- $this->filename = dirname(__DIR__) . "{$ds}data{$ds}strängé filename (duplicate #2).txt";
- $this->fileSize = 446;
- $this->helper = new \OC\LargeFileHelper;
+ $this->helper = new \OC\LargeFileHelper();
}
- public function testGetFileSizeViaCurl() {
+ public function dataFileNameProvider() {
+ $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
+
+ $filePaths = array(array($path . 'lorem.txt', 446));
+ if (!\OC_Util::runningOnWindows()) {
+ $filePaths[] = array($path . 'strängé filename (duplicate #2).txt', 446);
+ }
+
+ return $filePaths;
+ }
+
+ /**
+ * @dataProvider dataFileNameProvider
+ */
+ public function testGetFileSizeViaCurl($filename, $fileSize) {
if (!extension_loaded('curl')) {
$this->markTestSkipped(
'The PHP curl extension is required for this test.'
);
}
$this->assertSame(
- $this->fileSize,
- $this->helper->getFileSizeViaCurl($this->filename)
+ $fileSize,
+ $this->helper->getFileSizeViaCurl($filename)
);
}
- public function testGetFileSizeViaCOM() {
+ /**
+ * @dataProvider dataFileNameProvider
+ */
+ public function testGetFileSizeViaCOM($filename, $fileSize) {
if (!extension_loaded('COM')) {
$this->markTestSkipped(
'The PHP Windows COM extension is required for this test.'
);
}
$this->assertSame(
- $this->fileSize,
- $this->helper->getFileSizeViaCOM($this->filename)
+ $fileSize,
+ $this->helper->getFileSizeViaCOM($filename)
);
}
- public function testGetFileSizeViaExec() {
+ /**
+ * @dataProvider dataFileNameProvider
+ */
+ public function testGetFileSizeViaExec($filename, $fileSize) {
if (!\OC_Helper::is_function_enabled('exec')) {
$this->markTestSkipped(
'The exec() function needs to be enabled for this test.'
);
}
$this->assertSame(
- $this->fileSize,
- $this->helper->getFileSizeViaExec($this->filename)
+ $fileSize,
+ $this->helper->getFileSizeViaExec($filename)
);
}
- public function testGetFileSizeNative() {
+ /**
+ * @dataProvider dataFileNameProvider
+ */
+ public function testGetFileSizeNative($filename, $fileSize) {
$this->assertSame(
- $this->fileSize,
- $this->helper->getFileSizeNative($this->filename)
+ $fileSize,
+ $this->helper->getFileSizeNative($filename)
);
}
}
diff --git a/tests/lib/migrate.php b/tests/lib/migrate.php
index c4442511e1ff..3f87bbc1ac8b 100644
--- a/tests/lib/migrate.php
+++ b/tests/lib/migrate.php
@@ -11,6 +11,28 @@ class Test_Migrate extends PHPUnit_Framework_TestCase {
public $users;
public $tmpfiles = array();
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+ }
+
+ protected function tearDown() {
+ $u = new OC_User();
+ foreach($this->users as $user) {
+ $u->deleteUser($user);
+ }
+ foreach($this->tmpfiles as $file) {
+ \OC_Helper::rmdirr($file);
+ }
+
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+ parent::tearDown();
+ }
+
/**
* Generates a test user and sets up their file system
* @return string the test users id
@@ -73,18 +95,4 @@ public function testUserOtherExport() {
// Validate the export
$this->validateUserExport($user2, $user, json_decode($export)->data);
}
-
- public function tearDown() {
- $u = new OC_User();
- foreach($this->users as $user) {
- $u->deleteUser($user);
- }
- foreach($this->tmpfiles as $file) {
- \OC_Helper::rmdirr($file);
- }
- }
-
-
-
-
}
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index 2febe524cba9..288dd2aa4175 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -8,7 +8,7 @@
namespace Test;
-class Preview extends \PHPUnit_Framework_TestCase {
+class Preview extends \Test\TestCase {
/**
* @var string
@@ -20,14 +20,34 @@ class Preview extends \PHPUnit_Framework_TestCase {
*/
private $rootView;
- public function setUp() {
- $this->user = $this->initFS();
+ /** @var \OC\Files\Storage\Storage */
+ private $originalStorage;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
+
+ // create a new user with his own filesystem view
+ // this gets called by each test in this test class
+ $this->user = $this->getUniqueID();
+ \OC_User::setUserId($this->user);
+ \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/'.$this->user);
$this->rootView->mkdir('/'.$this->user.'/files');
}
+ protected function tearDown() {
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+
+ parent::tearDown();
+ }
+
public function testIsPreviewDeleted() {
$sampleFile = '/'.$this->user.'/files/test.txt';
@@ -184,16 +204,4 @@ public function testScalingUp() {
$this->assertEquals($this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached);
}
*/
-
- private function initFS() {
- // create a new user with his own filesystem view
- // this gets called by each test in this test class
- $user=uniqid();
- \OC_User::setUserId($user);
- \OC\Files\Filesystem::init($user, '/'.$user.'/files');
-
- \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
-
- return $user;
- }
}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index ff2f3c99081b..c3264a8637d1 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -19,7 +19,7 @@
* License along with this library. If not, see .
*/
-class Test_Share extends PHPUnit_Framework_TestCase {
+class Test_Share extends Test\TestCase {
protected $itemType;
protected $userBackend;
@@ -35,14 +35,15 @@ class Test_Share extends PHPUnit_Framework_TestCase {
protected $dateInFuture;
protected $dateInPast;
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
OC_User::clearBackends();
OC_User::useBackend('dummy');
- $this->user1 = uniqid('user1_');
- $this->user2 = uniqid('user2_');
- $this->user3 = uniqid('user3_');
- $this->user4 = uniqid('user4_');
- $this->groupAndUser = uniqid('groupAndUser_');
+ $this->user1 = $this->getUniqueID('user1_');
+ $this->user2 = $this->getUniqueID('user2_');
+ $this->user3 = $this->getUniqueID('user3_');
+ $this->user4 = $this->getUniqueID('user4_');
+ $this->groupAndUser = $this->getUniqueID('groupAndUser_');
OC_User::createUser($this->user1, 'pass');
OC_User::createUser($this->user2, 'pass');
OC_User::createUser($this->user3, 'pass');
@@ -51,8 +52,8 @@ public function setUp() {
OC_User::setUserId($this->user1);
OC_Group::clearBackends();
OC_Group::useBackend(new OC_Group_Dummy);
- $this->group1 = uniqid('group1_');
- $this->group2 = uniqid('group2_');
+ $this->group1 = $this->getUniqueID('group1_');
+ $this->group2 = $this->getUniqueID('group2_');
OC_Group::createGroup($this->group1);
OC_Group::createGroup($this->group2);
OC_Group::createGroup($this->groupAndUser);
@@ -76,10 +77,11 @@ public function setUp() {
$this->dateInFuture = date($dateFormat, $now + 20 * 60);
}
- public function tearDown() {
+ protected function tearDown() {
$query = OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `item_type` = ?');
$query->execute(array('test'));
OC_Appconfig::setValue('core', 'shareapi_allow_resharing', $this->resharing);
+ parent::tearDown();
}
public function testShareInvalidShareType() {
diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php
index 1b61446f4dce..6f92f4870374 100644
--- a/tests/lib/streamwrappers.php
+++ b/tests/lib/streamwrappers.php
@@ -65,7 +65,9 @@ public static function closeCallBack($path) {
}
public function testOC() {
+ $originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
+
$storage = new \OC\Files\Storage\Temporary(array());
$storage->file_put_contents('foo.txt', 'asd');
\OC\Files\Filesystem::mount($storage, array(), '/');
@@ -91,5 +93,8 @@ public function testOC() {
unlink('oc:///foo.txt');
$this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///'));
+
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount($originalStorage, array(), '/');
}
}
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
new file mode 100644
index 000000000000..f257822c9ea3
--- /dev/null
+++ b/tests/lib/testcase.php
@@ -0,0 +1,30 @@
+.
+ *
+ */
+
+namespace Test;
+
+abstract class TestCase extends \PHPUnit_Framework_TestCase {
+ protected function getUniqueID($prefix = '', $length = 13) {
+ // Do not use dots and slashes as we use the value for file names
+ return $prefix . \OC_Util::generateRandomBytes($length);
+ }
+}
diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php
index 0d3914c7ca68..c2040f4e3be4 100644
--- a/tests/lib/user/backend.php
+++ b/tests/lib/user/backend.php
@@ -30,7 +30,7 @@
* For an example see /tests/lib/user/dummy.php
*/
-abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
+abstract class Test_User_Backend extends \Test\TestCase {
/**
* @var OC_User_Backend $backend
*/
@@ -42,7 +42,7 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
* @return string
*/
public function getUser() {
- return uniqid('test_');
+ return $this->getUniqueID('test_');
}
public function testAddRemove() {
@@ -68,29 +68,29 @@ public function testAddRemove() {
$this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
$this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
}
-
+
public function testLogin() {
$name1=$this->getUser();
$name2=$this->getUser();
-
+
$this->assertFalse($this->backend->userExists($name1));
$this->assertFalse($this->backend->userExists($name2));
-
+
$this->backend->createUser($name1, 'pass1');
$this->backend->createUser($name2, 'pass2');
-
+
$this->assertTrue($this->backend->userExists($name1));
$this->assertTrue($this->backend->userExists($name2));
-
+
$this->assertSame($name1, $this->backend->checkPassword($name1, 'pass1'));
$this->assertSame($name2, $this->backend->checkPassword($name2, 'pass2'));
-
+
$this->assertFalse($this->backend->checkPassword($name1, 'pass2'));
$this->assertFalse($this->backend->checkPassword($name2, 'pass1'));
-
+
$this->assertFalse($this->backend->checkPassword($name1, 'dummy'));
$this->assertFalse($this->backend->checkPassword($name2, 'foobar'));
-
+
$this->backend->setPassword($name1, 'newpass1');
$this->assertFalse($this->backend->checkPassword($name1, 'pass1'));
$this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1'));
@@ -112,5 +112,4 @@ public function testSearch() {
$result = $this->backend->getDisplayNames('bar');
$this->assertSame(2, count($result));
}
-
}
diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php
index a8e497720c23..3a6be1ceee53 100644
--- a/tests/lib/user/database.php
+++ b/tests/lib/user/database.php
@@ -21,22 +21,27 @@
*/
class Test_User_Database extends Test_User_Backend {
+ /** @var array */
+ private $users;
+
public function getUser() {
$user = parent::getUser();
$this->users[]=$user;
return $user;
}
-
- public function setUp() {
+
+ protected function setUp() {
+ parent::setUp();
$this->backend=new OC_User_Database();
}
-
- public function tearDown() {
+
+ protected function tearDown() {
if(!isset($this->users)) {
return;
}
foreach($this->users as $user) {
$this->backend->deleteUser($user);
}
+ parent::tearDown();
}
}
diff --git a/tests/lib/user/dummy.php b/tests/lib/user/dummy.php
index e417fd976036..fcc921de4b12 100644
--- a/tests/lib/user/dummy.php
+++ b/tests/lib/user/dummy.php
@@ -21,7 +21,8 @@
*/
class Test_User_Dummy extends Test_User_Backend {
- public function setUp() {
+ protected function setUp() {
+ parent::setUp();
$this->backend=new OC_User_Dummy();
}
}
diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php
index be5596c1900a..73a1d0e95a6d 100644
--- a/tests/lib/utilcheckserver.php
+++ b/tests/lib/utilcheckserver.php
@@ -138,6 +138,10 @@ public function testDataDirWritable() {
* Tests an error is given when the datadir is not writable
*/
public function testDataDirNotWritable() {
+ if (\OC_Util::runningOnWindows()) {
+ $this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.');
+ }
+
chmod($this->datadir, 0300);
$result = \OC_Util::checkServer($this->getConfig(array(
'installed' => true,
diff --git a/tests/testcleanuplistener.php b/tests/testcleanuplistener.php
index fe4fef61ab5e..1ef5a4cfd5d6 100644
--- a/tests/testcleanuplistener.php
+++ b/tests/testcleanuplistener.php
@@ -100,6 +100,12 @@ private function cleanStrayDataFiles() {
'.' => true
);
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
+
+ if (\OC_Util::runningOnWindows()) {
+ $mapper = new \OC\Files\Mapper($datadir);
+ $mapper->removePath($datadir, true, true);
+ }
+
$entries = array();
if ($dh = opendir($datadir)) {
while (($file = readdir($dh)) !== false) {