summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/stream.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/tests/stream.php')
-rw-r--r--apps/files_encryption/tests/stream.php66
1 files changed, 32 insertions, 34 deletions
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index 3765d986e12..3d978767542 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -27,6 +27,7 @@ require_once realpath(dirname(__FILE__) . '/../lib/proxy.php');
require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
@@ -34,8 +35,9 @@ use OCA\Encryption;
* Class Test_Encryption_Stream
* @brief this class provide basic stream tests
*/
-class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_STREAM_USER1 = "test-stream-user1";
public $userId;
public $pass;
@@ -46,15 +48,27 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
public $dataShort;
public $stateFilesTrashbin;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
+ \OC_User::clearBackends();
\OC_User::useBackend('database');
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true);
+ }
+
+ function setUp() {
// set user id
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
+ \OC_User::setUserId(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
+ $this->userId = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1;
+ $this->pass = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1;
// init filesystem view
$this->view = new \OC_FilesystemView('/');
@@ -62,42 +76,26 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
// init short data
$this->dataShort = 'hats';
- // init filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // register encryption file proxy
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
-
- // init filesystem for user
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- // login user
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
}
- function tearDown()
- {
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
+ }
- // clear all proxies
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
}
function testStreamOptions() {
@@ -113,7 +111,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// check if stream is at position zero
- $this->assertEquals(0,ftell($handle));
+ $this->assertEquals(0, ftell($handle));
// set stream options
$this->assertTrue(flock($handle, LOCK_SH));
@@ -136,7 +134,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertTrue(stream_set_blocking($handle,1));
+ $this->assertTrue(stream_set_blocking($handle, 1));
// tear down
$view->unlink($filename);
@@ -155,7 +153,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertFalse(stream_set_timeout($handle,1));
+ $this->assertFalse(stream_set_timeout($handle, 1));
// tear down
$view->unlink($filename);
@@ -174,7 +172,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertEquals(0, stream_set_write_buffer($handle,1024));
+ $this->assertEquals(0, stream_set_write_buffer($handle, 1024));
// tear down
$view->unlink($filename);