summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/util.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests/util.php')
-rwxr-xr-xapps/files_encryption/tests/util.php55
1 files changed, 31 insertions, 24 deletions
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 210ffcc5410..bbf6efae5b9 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -11,7 +11,7 @@ use OCA\Encryption;
/**
* 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";
@@ -41,6 +41,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');
@@ -48,9 +50,9 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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);
@@ -60,13 +62,14 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
\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';
@@ -101,7 +104,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
\OC_App::disable('files_trashbin');
}
- function tearDown() {
+ protected function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
@@ -109,13 +112,15 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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);
@@ -128,6 +133,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
$view = new \OC\Files\View('/');
$view->rmdir('public-keys');
$view->rmdir('owncloud_private_key');
+
+ parent::tearDownAfterClass();
}
public static function setupHooks() {
@@ -164,8 +171,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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;
@@ -244,9 +251,9 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
*/
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;
@@ -261,7 +268,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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);
@@ -272,9 +279,9 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
* 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
@@ -298,7 +305,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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
@@ -329,7 +336,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
function testDecryptAll() {
- $filename = "/decryptAll" . uniqid() . ".txt";
+ $filename = "/decryptAll" . $this->getUniqueID() . ".txt";
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
$userdir = $datadir . '/' . $this->userId . '/files/';
@@ -448,8 +455,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
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);