aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/apps.php3
-rw-r--r--tests/core/command/encryption/disabletest.php2
-rw-r--r--tests/core/command/encryption/enabletest.php50
-rw-r--r--tests/lib/appconfig.php225
-rw-r--r--tests/lib/connector/sabre/DummyGetResponsePluginTest.php65
-rw-r--r--tests/lib/connector/sabre/copyetagheaderplugintest.php2
-rw-r--r--tests/lib/connector/sabre/file.php232
-rw-r--r--tests/lib/connector/sabre/quotaplugin.php5
-rw-r--r--tests/lib/encryption/updatetest.php115
-rw-r--r--tests/lib/encryption/utiltest.php1
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php101
-rw-r--r--tests/lib/files/stream/encryption.php36
-rw-r--r--tests/lib/helper.php19
-rw-r--r--tests/lib/hookhelper.php112
-rw-r--r--tests/lib/testcase.php2
-rw-r--r--tests/settings/controller/userscontrollertest.php18
16 files changed, 810 insertions, 178 deletions
diff --git a/tests/apps.php b/tests/apps.php
index 3e27b81df61..f13a996772f 100644
--- a/tests/apps.php
+++ b/tests/apps.php
@@ -7,6 +7,9 @@
*/
function loadDirectory($path) {
+ if (strpos($path, 'integration')) {
+ return;
+ }
if ($dh = opendir($path)) {
while ($name = readdir($dh)) {
if ($name[0] !== '.') {
diff --git a/tests/core/command/encryption/disabletest.php b/tests/core/command/encryption/disabletest.php
index 48a6539b243..26c814a9c4e 100644
--- a/tests/core/command/encryption/disabletest.php
+++ b/tests/core/command/encryption/disabletest.php
@@ -72,7 +72,7 @@ class DisableTest extends TestCase {
$this->consoleOutput->expects($this->once())
->method('writeln')
- ->with($expectedString);
+ ->with($this->stringContains($expectedString));
if ($isUpdating) {
$this->config->expects($this->once())
diff --git a/tests/core/command/encryption/enabletest.php b/tests/core/command/encryption/enabletest.php
index 217329ca291..377d0e2a528 100644
--- a/tests/core/command/encryption/enabletest.php
+++ b/tests/core/command/encryption/enabletest.php
@@ -29,6 +29,8 @@ class EnableTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $manager;
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
protected $consoleInput;
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $consoleOutput;
@@ -42,18 +44,25 @@ class EnableTest extends TestCase {
$config = $this->config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
+ $manager = $this->manager = $this->getMockBuilder('OCP\Encryption\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
/** @var \OCP\IConfig $config */
- $this->command = new Enable($config);
+ /** @var \OCP\Encryption\IManager $manager */
+ $this->command = new Enable($config, $manager);
}
public function dataEnable() {
return [
- ['no', true, 'Encryption enabled'],
- ['yes', false, 'Encryption is already enabled'],
+ ['no', null, [], true, 'Encryption enabled', 'No encryption module is loaded'],
+ ['yes', null, [], false, 'Encryption is already enabled', 'No encryption module is loaded'],
+ ['no', null, ['OC_TEST_MODULE' => []], true, 'Encryption enabled', 'No default module is set'],
+ ['no', 'OC_NO_MODULE', ['OC_TEST_MODULE' => []], true, 'Encryption enabled', 'The current default module does not exist: OC_NO_MODULE'],
+ ['no', 'OC_TEST_MODULE', ['OC_TEST_MODULE' => []], true, 'Encryption enabled', 'Default module: OC_TEST_MODULE'],
];
}
@@ -61,36 +70,49 @@ class EnableTest extends TestCase {
* @dataProvider dataEnable
*
* @param string $oldStatus
+ * @param string $defaultModule
+ * @param array $availableModules
* @param bool $isUpdating
* @param string $expectedString
+ * @param string $expectedDefaultModuleString
*/
- public function testEnable($oldStatus, $isUpdating, $expectedString) {
- $invoceCount = 0;
- $this->config->expects($this->at($invoceCount))
+ public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpdating, $expectedString, $expectedDefaultModuleString) {
+ $invokeCount = 0;
+ $this->config->expects($this->at($invokeCount))
->method('getAppValue')
->with('core', 'encryption_enabled', $this->anything())
->willReturn($oldStatus);
- $invoceCount++;
+ $invokeCount++;
if ($isUpdating) {
$this->config->expects($this->once())
->method('setAppValue')
->with('core', 'encryption_enabled', 'yes');
- $invoceCount++;
+ $invokeCount++;
}
- $this->config->expects($this->at($invoceCount))
- ->method('getAppValue')
- ->with('core', 'default_encryption_module', $this->anything())
- ->willReturnArgument(2);
+ $this->manager->expects($this->atLeastOnce())
+ ->method('getEncryptionModules')
+ ->willReturn($availableModules);
+
+ if (!empty($availableModules)) {
+ $this->config->expects($this->at($invokeCount))
+ ->method('getAppValue')
+ ->with('core', 'default_encryption_module', $this->anything())
+ ->willReturn($defaultModule);
+ }
$this->consoleOutput->expects($this->at(0))
->method('writeln')
- ->with($expectedString);
+ ->with($this->stringContains($expectedString));
$this->consoleOutput->expects($this->at(1))
->method('writeln')
- ->with($this->stringContains('Default module'));
+ ->with('');
+
+ $this->consoleOutput->expects($this->at(2))
+ ->method('writeln')
+ ->with($this->stringContains($expectedDefaultModuleString));
\Test_Helper::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index ead5b859277..adff45706cc 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -8,16 +8,25 @@
*/
class Test_Appconfig extends \Test\TestCase {
- public static function setUpBeforeClass() {
- parent::setUpBeforeClass();
+ /** @var \OCP\IAppConfig */
+ protected $appConfig;
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ /** @var \OCP\IDBConnection */
+ protected $connection;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->connection = \OC::$server->getDatabaseConnection();
+ $this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection()));
+
+ $query = $this->connection->prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
$query->execute(array('testapp'));
$query->execute(array('someapp'));
$query->execute(array('123456'));
$query->execute(array('anotherapp'));
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
+ $query = $this->connection->prepare('INSERT INTO `*PREFIX*appconfig` VALUES (?, ?, ?)');
$query->execute(array('testapp', 'enabled', 'true'));
$query->execute(array('testapp', 'installed_version', '1.2.3'));
@@ -35,17 +44,41 @@ class Test_Appconfig extends \Test\TestCase {
$query->execute(array('anotherapp', 'enabled', 'false'));
}
- public static function tearDownAfterClass() {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ public function tearDown() {
+ $query = $this->connection->prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
$query->execute(array('testapp'));
$query->execute(array('someapp'));
$query->execute(array('123456'));
$query->execute(array('anotherapp'));
- parent::tearDownAfterClass();
+ $this->registerAppConfig(new \OC\AppConfig(\OC::$server->getDatabaseConnection()));
+ parent::tearDown();
+ }
+
+ /**
+ * Register an app config object for testing purposes.
+ *
+ * @param \OCP\IAppConfig $appConfig
+ */
+ protected function registerAppConfig($appConfig) {
+ \OC::$server->registerService('AppConfig', function ($c) use ($appConfig) {
+ return $appConfig;
+ });
}
- public function testGetApps() {
+ public function getAppConfigs() {
+ return [
+ ['\OC_Appconfig'],
+ [new \OC\AppConfig(\OC::$server->getDatabaseConnection())],
+ ];
+ }
+
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testGetApps($callable) {
$query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
$result = $query->execute();
$expected = array();
@@ -53,11 +86,16 @@ class Test_Appconfig extends \Test\TestCase {
$expected[] = $row['appid'];
}
sort($expected);
- $apps = \OC_Appconfig::getApps();
+ $apps = call_user_func([$callable, 'getApps']);
$this->assertEquals($expected, $apps);
}
- public function testGetKeys() {
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testGetKeys($callable) {
$query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
$result = $query->execute(array('testapp'));
$expected = array();
@@ -65,44 +103,103 @@ class Test_Appconfig extends \Test\TestCase {
$expected[] = $row["configkey"];
}
sort($expected);
- $keys = \OC_Appconfig::getKeys('testapp');
+ $keys = call_user_func([$callable, 'getKeys'], 'testapp');
$this->assertEquals($expected, $keys);
}
- public function testGetValue() {
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('testapp', 'installed_version'));
- $expected = $result->fetchRow();
- $value = \OC_Appconfig::getValue('testapp', 'installed_version');
- $this->assertEquals($expected['configvalue'], $value);
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testGetValue($callable) {
+ $value = call_user_func([$callable, 'getValue'], 'testapp', 'installed_version');
+ $this->assertConfigKey('testapp', 'installed_version', $value);
- $value = \OC_Appconfig::getValue('testapp', 'nonexistant');
+ $value = call_user_func([$callable, 'getValue'], 'testapp', 'nonexistant');
$this->assertNull($value);
- $value = \OC_Appconfig::getValue('testapp', 'nonexistant', 'default');
+ $value = call_user_func([$callable, 'getValue'], 'testapp', 'nonexistant', 'default');
$this->assertEquals('default', $value);
}
- public function testHasKey() {
- $value = \OC_Appconfig::hasKey('testapp', 'installed_version');
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testHasKey($callable) {
+ $value = call_user_func([$callable, 'hasKey'], 'testapp', 'installed_version');
$this->assertTrue($value);
- $value = \OC_Appconfig::hasKey('nonexistant', 'nonexistant');
+ $value = call_user_func([$callable, 'hasKey'], 'nonexistant', 'nonexistant');
$this->assertFalse($value);
}
- public function testSetValue() {
- \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7');
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('testapp', 'installed_version'));
- $value = $result->fetchRow();
- $this->assertEquals('1.33.7', $value['configvalue']);
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testSetValue($callable) {
+ call_user_func([$callable, 'setValue'], 'testapp', 'installed_version', '1.33.7');
+ $this->assertConfigKey('testapp', 'installed_version', '1.33.7');
- \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue');
+ call_user_func([$callable, 'setValue'], 'someapp', 'somekey', 'somevalue');
+ $this->assertConfigKey('someapp', 'somekey', 'somevalue');
+ }
+
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testDeleteKey($callable) {
+ call_user_func([$callable, 'deleteKey'], 'testapp', 'deletethis');
$query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('someapp', 'somekey'));
- $value = $result->fetchRow();
- $this->assertEquals('somevalue', $value['configvalue']);
+ $query->execute(array('testapp', 'deletethis'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testDeleteApp($callable) {
+ call_user_func([$callable, 'deleteApp'], 'someapp');
+ $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('someapp'));
+ $result = (bool)$query->fetchRow();
+ $this->assertFalse($result);
+ }
+
+ /**
+ * @dataProvider getAppConfigs
+ *
+ * @param mixed $callable
+ */
+ public function testGetValues($callable) {
+ $this->assertFalse(call_user_func([$callable, 'getValues'], 'testapp', 'enabled'));
+
+ $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array('testapp'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['configkey']] = $row['configvalue'];
+ }
+ $values = call_user_func([$callable, 'getValues'], 'testapp', false);
+ $this->assertEquals($expected, $values);
+
+ $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
+ $query->execute(array('enabled'));
+ $expected = array();
+ while ($row = $query->fetchRow()) {
+ $expected[$row['appid']] = $row['configvalue'];
+ }
+ $values = call_user_func([$callable, 'getValues'], false, 'enabled');
+ $this->assertEquals($expected, $values);
}
public function testSetValueUnchanged() {
@@ -118,7 +215,7 @@ class Test_Appconfig extends \Test\TestCase {
.' WHERE `appid` = ?'), $this->equalTo(array('bar')))
->will($this->returnValue($statementMock));
$connectionMock->expects($this->once())
- ->method('insert')
+ ->method('insertIfNotExist')
->with($this->equalTo('*PREFIX*appconfig'),
$this->equalTo(
array(
@@ -126,7 +223,8 @@ class Test_Appconfig extends \Test\TestCase {
'configkey' => 'foo',
'configvalue' => 'v1',
)
- ));
+ ), $this->equalTo(['appid', 'configkey']))
+ ->willReturn(1);
$connectionMock->expects($this->never())
->method('update');
@@ -149,7 +247,7 @@ class Test_Appconfig extends \Test\TestCase {
.' WHERE `appid` = ?'), $this->equalTo(array('bar')))
->will($this->returnValue($statementMock));
$connectionMock->expects($this->once())
- ->method('insert')
+ ->method('insertIfNotExist')
->with($this->equalTo('*PREFIX*appconfig'),
$this->equalTo(
array(
@@ -157,7 +255,8 @@ class Test_Appconfig extends \Test\TestCase {
'configkey' => 'foo',
'configvalue' => 'v1',
)
- ));
+ ), $this->equalTo(['appid', 'configkey']))
+ ->willReturn(1);
$connectionMock->expects($this->once())
->method('update')
->with($this->equalTo('*PREFIX*appconfig'),
@@ -171,41 +270,29 @@ class Test_Appconfig extends \Test\TestCase {
$appconfig->setValue('bar', 'foo', 'v2');
}
- public function testDeleteKey() {
- \OC_Appconfig::deleteKey('testapp', 'deletethis');
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
- $query->execute(array('testapp', 'deletethis'));
- $result = (bool)$query->fetchRow();
- $this->assertFalse($result);
- }
-
- public function testDeleteApp() {
- \OC_Appconfig::deleteApp('someapp');
- $query = \OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('someapp'));
- $result = (bool)$query->fetchRow();
- $this->assertFalse($result);
- }
+ public function testSettingConfigParallel() {
+ $appConfig1 = new OC\AppConfig(\OC::$server->getDatabaseConnection());
+ $appConfig2 = new OC\AppConfig(\OC::$server->getDatabaseConnection());
+ $appConfig1->getValue('testapp', 'foo', 'v1');
+ $appConfig2->getValue('testapp', 'foo', 'v1');
- public function testGetValues() {
- $this->assertFalse(\OC_Appconfig::getValues('testapp', 'enabled'));
+ $appConfig1->setValue('testapp', 'foo', 'v1');
+ $this->assertConfigKey('testapp', 'foo', 'v1');
- $query = \OC_DB::prepare('SELECT `configkey`, `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
- $query->execute(array('testapp'));
- $expected = array();
- while ($row = $query->fetchRow()) {
- $expected[$row['configkey']] = $row['configvalue'];
- }
- $values = \OC_Appconfig::getValues('testapp', false);
- $this->assertEquals($expected, $values);
+ $appConfig2->setValue('testapp', 'foo', 'v2');
+ $this->assertConfigKey('testapp', 'foo', 'v2');
+ }
- $query = \OC_DB::prepare('SELECT `appid`, `configvalue` FROM `*PREFIX*appconfig` WHERE `configkey` = ?');
- $query->execute(array('enabled'));
- $expected = array();
- while ($row = $query->fetchRow()) {
- $expected[$row['appid']] = $row['configvalue'];
- }
- $values = \OC_Appconfig::getValues(false, 'enabled');
- $this->assertEquals($expected, $values);
+ /**
+ * @param string $app
+ * @param string $key
+ * @param string $expected
+ * @throws \OC\DatabaseException
+ */
+ protected function assertConfigKey($app, $key, $expected) {
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $result = $query->execute([$app, $key]);
+ $actual = $result->fetchRow();
+ $this->assertEquals($expected, $actual['configvalue']);
}
}
diff --git a/tests/lib/connector/sabre/DummyGetResponsePluginTest.php b/tests/lib/connector/sabre/DummyGetResponsePluginTest.php
new file mode 100644
index 00000000000..fa8f0694625
--- /dev/null
+++ b/tests/lib/connector/sabre/DummyGetResponsePluginTest.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace Test\Connector\Sabre;
+
+use OC\Connector\Sabre\DummyGetResponsePlugin;
+use Test\TestCase;
+
+/**
+ * Class DummyGetResponsePluginTest
+ *
+ * @package Test\Connector\Sabre
+ */
+class DummyGetResponsePluginTest extends TestCase {
+ /** @var DummyGetResponsePlugin */
+ private $dummyGetResponsePlugin;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->dummyGetResponsePlugin = new DummyGetResponsePlugin();
+ }
+
+ public function testInitialize() {
+ /** @var \Sabre\DAV\Server $server */
+ $server = $this->getMock('\Sabre\DAV\Server');
+ $server
+ ->expects($this->once())
+ ->method('on')
+ ->with('method:GET', [$this->dummyGetResponsePlugin, 'httpGet'], 200);
+
+ $this->dummyGetResponsePlugin->initialize($server);
+ }
+
+
+ public function testHttpGet() {
+ /** @var \Sabre\HTTP\RequestInterface $request */
+ $request = $this->getMock('\Sabre\HTTP\RequestInterface');
+ /** @var \Sabre\HTTP\ResponseInterface $response */
+ $response = $server = $this->getMock('\Sabre\HTTP\ResponseInterface');
+ $response
+ ->expects($this->once())
+ ->method('setBody');
+
+ $this->assertSame(false, $this->dummyGetResponsePlugin->httpGet($request, $response));
+ }
+}
diff --git a/tests/lib/connector/sabre/copyetagheaderplugintest.php b/tests/lib/connector/sabre/copyetagheaderplugintest.php
index 176f9c8d0ca..6b1b5e96fda 100644
--- a/tests/lib/connector/sabre/copyetagheaderplugintest.php
+++ b/tests/lib/connector/sabre/copyetagheaderplugintest.php
@@ -18,7 +18,7 @@ class CopyEtagPluginTest extends \Test\TestCase {
public function setUp() {
parent::setUp();
$this->server = new \Sabre\DAV\Server();
- $this->plugin = new \OC\Connector\Sabre\CopyEtagHeaderPlugin($this->tree);
+ $this->plugin = new \OC\Connector\Sabre\CopyEtagHeaderPlugin();
$this->plugin->initialize($this->server);
}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index ee9c20fd9cb..6602a2df24f 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -8,8 +8,35 @@
namespace Test\Connector\Sabre;
+use Test\HookHelper;
+use OC\Files\Filesystem;
+
class File extends \Test\TestCase {
+ /**
+ * @var string
+ */
+ private $user;
+
+ public function setUp() {
+ parent::setUp();
+
+ \OC_Hook::clear();
+
+ $this->user = $this->getUniqueID('user_');
+ $userManager = \OC::$server->getUserManager();
+ $userManager->createUser($this->user, 'pass');
+
+ $this->loginAsUser($this->user);
+ }
+
+ public function tearDown() {
+ $userManager = \OC::$server->getUserManager();
+ $userManager->get($this->user)->delete();
+
+ parent::tearDown();
+ }
+
private function getStream($string) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $string);
@@ -23,7 +50,7 @@ class File extends \Test\TestCase {
public function testSimplePutFails() {
// setup
$storage = $this->getMock('\OC\Files\Storage\Local', ['fopen'], [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]);
- $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath', 'resolvePath'), array());
+ $view = $this->getMock('\OC\Files\View', array('getRelativePath', 'resolvePath'), array());
$view->expects($this->any())
->method('resolvePath')
->will($this->returnValue(array($storage, '')));
@@ -45,28 +72,21 @@ class File extends \Test\TestCase {
$file->put('test data');
}
- public function testPutSingleFileShare() {
- // setup
- $stream = fopen('php://temp', 'w+');
- $storage = $this->getMock('\OC\Files\Storage\Local', ['fopen'], [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]);
- $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath', 'resolvePath'), array());
- $view->expects($this->any())
- ->method('resolvePath')
- ->will($this->returnValue(array($storage, '')));
- $view->expects($this->any())
- ->method('getRelativePath')
- ->will($this->returnValue(''));
- $view->expects($this->any())
- ->method('file_put_contents')
- ->with('')
- ->will($this->returnValue(true));
- $storage->expects($this->once())
- ->method('fopen')
- ->will($this->returnValue($stream));
-
- $info = new \OC\Files\FileInfo('/foo.txt', null, null, array(
- 'permissions' => \OCP\Constants::PERMISSION_ALL
- ), null);
+ private function doPut($path, $viewRoot = null) {
+ $view = \OC\Files\Filesystem::getView();
+ if (!is_null($viewRoot)) {
+ $view = new \OC\Files\View($viewRoot);
+ } else {
+ $viewRoot = '/' . $this->user . '/files';
+ }
+
+ $info = new \OC\Files\FileInfo(
+ $viewRoot . '/' . ltrim($path, '/'),
+ null,
+ null,
+ ['permissions' => \OCP\Constants::PERMISSION_ALL],
+ null
+ );
$file = new \OC\Connector\Sabre\File($view, $info);
@@ -74,16 +94,144 @@ class File extends \Test\TestCase {
}
/**
+ * Test putting a single file
+ */
+ public function testPutSingleFile() {
+ $this->doPut('/foo.txt');
+ }
+
+ /**
+ * Test that putting a file triggers create hooks
+ */
+ public function testPutSingleFileTriggersHooks() {
+ HookHelper::setUpHooks();
+
+ $this->doPut('/foo.txt');
+
+ $this->assertCount(4, HookHelper::$hookCalls);
+ $this->assertHookCall(
+ HookHelper::$hookCalls[0],
+ Filesystem::signal_create,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[1],
+ Filesystem::signal_write,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[2],
+ Filesystem::signal_post_create,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[3],
+ Filesystem::signal_post_write,
+ '/foo.txt'
+ );
+ }
+
+ /**
+ * Test that putting a file triggers update hooks
+ */
+ public function testPutOverwriteFileTriggersHooks() {
+ $view = \OC\Files\Filesystem::getView();
+ $view->file_put_contents('/foo.txt', 'some content that will be replaced');
+
+ HookHelper::setUpHooks();
+
+ $this->doPut('/foo.txt');
+
+ $this->assertCount(4, HookHelper::$hookCalls);
+ $this->assertHookCall(
+ HookHelper::$hookCalls[0],
+ Filesystem::signal_update,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[1],
+ Filesystem::signal_write,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[2],
+ Filesystem::signal_post_update,
+ '/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[3],
+ Filesystem::signal_post_write,
+ '/foo.txt'
+ );
+ }
+
+ /**
+ * Test that putting a file triggers hooks with the correct path
+ * if the passed view was chrooted (can happen with public webdav
+ * where the root is the share root)
+ */
+ public function testPutSingleFileTriggersHooksDifferentRoot() {
+ $view = \OC\Files\Filesystem::getView();
+ $view->mkdir('noderoot');
+
+ HookHelper::setUpHooks();
+
+ // happens with public webdav where the view root is the share root
+ $this->doPut('/foo.txt', '/' . $this->user . '/files/noderoot');
+
+ $this->assertCount(4, HookHelper::$hookCalls);
+ $this->assertHookCall(
+ HookHelper::$hookCalls[0],
+ Filesystem::signal_create,
+ '/noderoot/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[1],
+ Filesystem::signal_write,
+ '/noderoot/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[2],
+ Filesystem::signal_post_create,
+ '/noderoot/foo.txt'
+ );
+ $this->assertHookCall(
+ HookHelper::$hookCalls[3],
+ Filesystem::signal_post_write,
+ '/noderoot/foo.txt'
+ );
+ }
+
+ public static function cancellingHook($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_post_create,
+ 'params' => $params
+ );
+ }
+
+ /**
+ * Test put file with cancelled hook
+ *
+ * @expectedException \Sabre\DAV\Exception
+ */
+ public function testPutSingleFileCancelPreHook() {
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create,
+ '\Test\HookHelper',
+ 'cancellingCallback'
+ );
+
+ $this->doPut('/foo.txt');
+ }
+
+ /**
* @expectedException \Sabre\DAV\Exception
*/
public function testSimplePutFailsOnRename() {
// setup
$view = $this->getMock('\OC\Files\View',
- array('file_put_contents', 'rename', 'getRelativePath', 'filesize'));
- $view->expects($this->any())
- ->method('file_put_contents')
- ->withAnyParameters()
- ->will($this->returnValue(true));
+ array('rename', 'getRelativePath', 'filesize'));
$view->expects($this->any())
->method('rename')
->withAnyParameters()
@@ -113,11 +261,7 @@ class File extends \Test\TestCase {
*/
public function testSimplePutInvalidChars() {
// setup
- $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'));
- $view->expects($this->any())
- ->method('file_put_contents')
- ->will($this->returnValue(false));
-
+ $view = $this->getMock('\OC\Files\View', array('getRelativePath'));
$view->expects($this->any())
->method('getRelativePath')
->will($this->returnValue('/*'));
@@ -157,11 +301,7 @@ class File extends \Test\TestCase {
public function testUploadAbort() {
// setup
$view = $this->getMock('\OC\Files\View',
- array('file_put_contents', 'rename', 'getRelativePath', 'filesize'));
- $view->expects($this->any())
- ->method('file_put_contents')
- ->withAnyParameters()
- ->will($this->returnValue(true));
+ array('rename', 'getRelativePath', 'filesize'));
$view->expects($this->any())
->method('rename')
->withAnyParameters()
@@ -248,4 +388,20 @@ class File extends \Test\TestCase {
// action
$file->delete();
}
+
+ /**
+ * Asserts hook call
+ *
+ * @param array $callData hook call data to check
+ * @param string $signal signal name
+ * @param string $hookPath hook path
+ */
+ protected function assertHookCall($callData, $signal, $hookPath) {
+ $this->assertEquals($signal, $callData['signal']);
+ $params = $callData['params'];
+ $this->assertEquals(
+ $hookPath,
+ $params[Filesystem::signal_param_path]
+ );
+ }
}
diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php
index 48f8f319ae4..3d9cd9b5da0 100644
--- a/tests/lib/connector/sabre/quotaplugin.php
+++ b/tests/lib/connector/sabre/quotaplugin.php
@@ -92,7 +92,10 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase {
private function buildFileViewMock($quota) {
// mock filesysten
$view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', false);
- $view->expects($this->any())->method('free_space')->withAnyParameters()->will($this->returnValue($quota));
+ $view->expects($this->any())
+ ->method('free_space')
+ ->with($this->identicalTo(''))
+ ->will($this->returnValue($quota));
return $view;
}
diff --git a/tests/lib/encryption/updatetest.php b/tests/lib/encryption/updatetest.php
index 790d071aa68..b222bc42d7a 100644
--- a/tests/lib/encryption/updatetest.php
+++ b/tests/lib/encryption/updatetest.php
@@ -68,10 +68,6 @@ class UpdateTest extends TestCase {
$this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()->getMock();
- $this->encryptionManager->expects($this->once())
- ->method('getEncryptionModule')
- ->willReturn($this->encryptionModule);
-
$this->uid = 'testUser1';
$this->update = new Update(
@@ -93,6 +89,10 @@ class UpdateTest extends TestCase {
*/
public function testUpdate($path, $isDir, $allFiles, $numberOfFiles) {
+ $this->encryptionManager->expects($this->once())
+ ->method('getEncryptionModule')
+ ->willReturn($this->encryptionModule);
+
$this->view->expects($this->once())
->method('is_dir')
->willReturn($isDir);
@@ -126,4 +126,111 @@ class UpdateTest extends TestCase {
);
}
+ /**
+ * @dataProvider dataTestPostRename
+ *
+ * @param string $source
+ * @param string $target
+ * @param boolean $encryptionEnabled
+ */
+ public function testPostRename($source, $target, $encryptionEnabled) {
+
+ $updateMock = $this->getUpdateMock(['update', 'getOwnerPath']);
+
+ $this->encryptionManager->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($encryptionEnabled);
+
+ if (dirname($source) === dirname($target) || $encryptionEnabled === false) {
+ $updateMock->expects($this->never())->method('getOwnerPath');
+ $updateMock->expects($this->never())->method('update');
+ } else {
+ $updateMock->expects($this->once())
+ ->method('getOwnerPath')
+ ->willReturnCallback(function($path) use ($target) {
+ $this->assertSame(
+ $target,
+ $path,
+ 'update needs to be executed for the target destination');
+ return ['owner', $path];
+
+ });
+ $updateMock->expects($this->once())->method('update');
+ }
+
+ $updateMock->postRename(['oldpath' => $source, 'newpath' => $target]);
+ }
+
+ /**
+ * test data for testPostRename()
+ *
+ * @return array
+ */
+ public function dataTestPostRename() {
+ return array(
+ array('/test.txt', '/testNew.txt', true),
+ array('/test.txt', '/testNew.txt', false),
+ array('/folder/test.txt', '/testNew.txt', true),
+ array('/folder/test.txt', '/testNew.txt', false),
+ array('/folder/test.txt', '/testNew.txt', true),
+ array('/test.txt', '/folder/testNew.txt', false),
+ );
+ }
+
+
+ /**
+ * @dataProvider dataTestPostRestore
+ *
+ * @param boolean $encryptionEnabled
+ */
+ public function testPostRestore($encryptionEnabled) {
+
+ $updateMock = $this->getUpdateMock(['update']);
+
+ $this->encryptionManager->expects($this->once())
+ ->method('isEnabled')
+ ->willReturn($encryptionEnabled);
+
+ if ($encryptionEnabled) {
+ $updateMock->expects($this->once())->method('update');
+
+ } else {
+ $updateMock->expects($this->never())->method('update');
+ }
+
+ $updateMock->postRestore(['filePath' => '/folder/test.txt']);
+ }
+
+ /**
+ * test data for testPostRestore()
+ *
+ * @return array
+ */
+ public function dataTestPostRestore() {
+ return array(
+ array(true),
+ array(false),
+ );
+ }
+
+ /**
+ * create mock of the update method
+ *
+ * @param array$methods methods which should be set
+ * @return \OC\Encryption\Update | \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getUpdateMock($methods) {
+ return $this->getMockBuilder('\OC\Encryption\Update')
+ ->setConstructorArgs(
+ [
+ $this->view,
+ $this->util,
+ $this->mountManager,
+ $this->encryptionManager,
+ $this->fileHelper,
+ $this->uid
+ ]
+ )->setMethods($methods)->getMock();
+ }
+
}
diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php
index 7de57043920..0154fa30f7d 100644
--- a/tests/lib/encryption/utiltest.php
+++ b/tests/lib/encryption/utiltest.php
@@ -135,6 +135,7 @@ class UtilTest extends TestCase {
public function providePathsForTestIsExcluded() {
return array(
+ array('/files_encryption', true),
array('files_encryption/foo.txt', true),
array('test/foo.txt', false),
array('/user1/files_encryption/foo.txt', true),
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index d4492e00928..39af648cb75 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -47,6 +47,22 @@ class Encryption extends \Test\Files\Storage\Storage {
*/
private $cache;
+ /**
+ * @var \OC\Log | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $logger;
+
+ /**
+ * @var \OC\Encryption\File | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $file;
+
+
+ /**
+ * @var \OC\Files\Mount\MountPoint | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $mount;
+
/** @var integer dummy unencrypted size */
private $dummySize = -1;
@@ -77,13 +93,13 @@ class Encryption extends \Test\Files\Storage\Storage {
return ['user1', $path];
});
- $file = $this->getMockBuilder('\OC\Encryption\File')
+ $this->file = $this->getMockBuilder('\OC\Encryption\File')
->disableOriginalConstructor()
->setMethods(['getAccessList'])
->getMock();
- $file->expects($this->any())->method('getAccessList')->willReturn([]);
+ $this->file->expects($this->any())->method('getAccessList')->willReturn([]);
- $logger = $this->getMock('\OC\Log');
+ $this->logger = $this->getMock('\OC\Log');
$this->sourceStorage = new Temporary(array());
@@ -93,11 +109,11 @@ class Encryption extends \Test\Files\Storage\Storage {
$this->update = $this->getMockBuilder('\OC\Encryption\Update')
->disableOriginalConstructor()->getMock();
- $mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ $this->mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
->disableOriginalConstructor()
->setMethods(['getOption'])
->getMock();
- $mount->expects($this->any())->method('getOption')->willReturn(true);
+ $this->mount->expects($this->any())->method('getOption')->willReturn(true);
$this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock();
@@ -112,12 +128,12 @@ class Encryption extends \Test\Files\Storage\Storage {
'storage' => $this->sourceStorage,
'root' => 'foo',
'mountPoint' => '/',
- 'mount' => $mount
+ 'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $logger, $file, null, $this->keyStore, $this->update
+ $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update
]
)
- ->setMethods(['getMetaData', 'getCache'])
+ ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule'])
->getMock();
$this->instance->expects($this->any())
@@ -127,6 +143,10 @@ class Encryption extends \Test\Files\Storage\Storage {
$this->instance->expects($this->any())
->method('getCache')
->willReturn($this->cache);
+
+ $this->instance->expects($this->any())
+ ->method('getEncryptionModule')
+ ->willReturn($mockModule);
}
/**
@@ -135,7 +155,7 @@ class Encryption extends \Test\Files\Storage\Storage {
protected function buildMockModule() {
$this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()
- ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable'])
->getMock();
$this->encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
@@ -147,6 +167,7 @@ class Encryption extends \Test\Files\Storage\Storage {
$this->encryptionModule->expects($this->any())->method('update')->willReturn(true);
$this->encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
$this->encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
+ $this->encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
return $this->encryptionModule;
}
@@ -157,13 +178,11 @@ class Encryption extends \Test\Files\Storage\Storage {
* @param string $target
* @param $encryptionEnabled
* @param boolean $renameKeysReturn
- * @param boolean $shouldUpdate
*/
public function testRename($source,
$target,
$encryptionEnabled,
- $renameKeysReturn,
- $shouldUpdate) {
+ $renameKeysReturn) {
if ($encryptionEnabled) {
$this->keyStore
->expects($this->once())
@@ -177,13 +196,6 @@ class Encryption extends \Test\Files\Storage\Storage {
->method('isFile')->willReturn(true);
$this->encryptionManager->expects($this->once())
->method('isEnabled')->willReturn($encryptionEnabled);
- if ($shouldUpdate) {
- $this->update->expects($this->once())
- ->method('update');
- } else {
- $this->update->expects($this->never())
- ->method('update');
- }
$this->instance->mkdir($source);
$this->instance->mkdir(dirname($target));
@@ -261,4 +273,55 @@ class Encryption extends \Test\Files\Storage\Storage {
->method('isEnabled')->willReturn(true);
$this->assertFalse($this->instance->isLocal());
}
+
+ /**
+ * @dataProvider dataTestRmdir
+ *
+ * @param string $path
+ * @param boolean $rmdirResult
+ * @param boolean $isExcluded
+ * @param boolean $encryptionEnabled
+ */
+ public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled) {
+ $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ ->disableOriginalConstructor()->getMock();
+
+ $util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock();
+
+ $sourceStorage->expects($this->once())->method('rmdir')->willReturn($rmdirResult);
+ $util->expects($this->any())->method('isExcluded')-> willReturn($isExcluded);
+ $this->encryptionManager->expects($this->any())->method('isEnabled')->willReturn($encryptionEnabled);
+
+ $encryptionStorage = new \OC\Files\Storage\Wrapper\Encryption(
+ [
+ 'storage' => $sourceStorage,
+ 'root' => 'foo',
+ 'mountPoint' => '/mountPoint',
+ 'mount' => $this->mount
+ ],
+ $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update
+ );
+
+
+ if ($rmdirResult === true && $isExcluded === false && $encryptionEnabled === true) {
+ $this->keyStore->expects($this->once())->method('deleteAllFileKeys')->with('/mountPoint' . $path);
+ } else {
+ $this->keyStore->expects($this->never())->method('deleteAllFileKeys');
+ }
+
+ $encryptionStorage->rmdir($path);
+ }
+
+ public function dataTestRmdir() {
+ return array(
+ array('/file.txt', true, true, true),
+ array('/file.txt', false, true, true),
+ array('/file.txt', true, false, true),
+ array('/file.txt', false, false, true),
+ array('/file.txt', true, true, false),
+ array('/file.txt', false, true, false),
+ array('/file.txt', true, false, false),
+ array('/file.txt', false, false, false),
+ );
+ }
}
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
index 892491cbc32..c2388c7682a 100644
--- a/tests/lib/files/stream/encryption.php
+++ b/tests/lib/files/stream/encryption.php
@@ -7,6 +7,9 @@ use OCA\Encryption_Dummy\DummyModule;
class Encryption extends \Test\TestCase {
+ /** @var \OCP\Encryption\IEncryptionModule | \PHPUnit_Framework_MockObject_MockObject */
+ private $encryptionModule;
+
/**
* @param string $fileName
* @param string $mode
@@ -21,7 +24,7 @@ class Encryption extends \Test\TestCase {
$fullPath = $fileName;
$header = [];
$uid = '';
- $encryptionModule = $this->buildMockModule();
+ $this->encryptionModule = $this->buildMockModule();
$storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
$encStorage = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
@@ -43,7 +46,7 @@ class Encryption extends \Test\TestCase {
->willReturn(['user1', $internalPath]);
return \OC\Files\Stream\Encryption::wrap($source, $internalPath,
- $fullPath, $header, $uid, $encryptionModule, $storage, $encStorage,
+ $fullPath, $header, $uid, $this->encryptionModule, $storage, $encStorage,
$util, $file, $mode, $size, $unencryptedSize, 8192);
}
@@ -160,15 +163,6 @@ class Encryption extends \Test\TestCase {
$this->assertEquals('foobar', fread($stream, 100));
fclose($stream);
- unlink($fileName);
- }
-
- public function testWriteWriteRead() {
- $fileName = tempnam("/tmp", "FOO");
- $stream = $this->getStream($fileName, 'w+', 0);
- $this->assertEquals(6, fwrite($stream, 'foobar'));
- fclose($stream);
-
$stream = $this->getStream($fileName, 'r+', 6);
$this->assertEquals(3, fwrite($stream, 'bar'));
fclose($stream);
@@ -176,6 +170,8 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 6);
$this->assertEquals('barbar', fread($stream, 100));
fclose($stream);
+
+ unlink($fileName);
}
public function testRewind() {
@@ -191,7 +187,9 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 6);
$this->assertEquals('barbar', fread($stream, 100));
fclose($stream);
- }
+
+ unlink($fileName);
+}
public function testSeek() {
$fileName = tempnam("/tmp", "FOO");
@@ -203,6 +201,12 @@ class Encryption extends \Test\TestCase {
$stream = $this->getStream($fileName, 'r', 9);
$this->assertEquals('foofoobar', fread($stream, 100));
+ $this->assertEquals(-1, fseek($stream, 10));
+ $this->assertEquals(0, fseek($stream, 9));
+ $this->assertEquals(-1, fseek($stream, -10, SEEK_CUR));
+ $this->assertEquals(0, fseek($stream, -9, SEEK_CUR));
+ $this->assertEquals(-1, fseek($stream, -10, SEEK_END));
+ $this->assertEquals(0, fseek($stream, -9, SEEK_END));
fclose($stream);
unlink($fileName);
@@ -220,10 +224,15 @@ class Encryption extends \Test\TestCase {
* @dataProvider dataFilesProvider
*/
public function testWriteReadBigFile($testFile) {
+
$expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile);
// write it
$fileName = tempnam("/tmp", "FOO");
$stream = $this->getStream($fileName, 'w+', 0);
+ // while writing the file from the beginning to the end we should never try
+ // to read parts of the file. This should only happen for write operations
+ // in the middle of a file
+ $this->encryptionModule->expects($this->never())->method('decrypt');
fwrite($stream, $expectedData);
fclose($stream);
@@ -253,13 +262,14 @@ class Encryption extends \Test\TestCase {
protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()
- ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable'])
->getMock();
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
$encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
$encryptionModule->expects($this->any())->method('end')->willReturn('');
+ $encryptionModule->expects($this->any())->method('isReadable')->willReturn(true);
$encryptionModule->expects($this->any())->method('encrypt')->willReturnCallback(function($data) {
// simulate different block size by adding some padding to the data
if (isset($data[6125])) {
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index ed15a677300..b7aa185f4e3 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -53,21 +53,22 @@ class Test_Helper extends \Test\TestCase {
}
/**
- * @dataProvider computerFileSizeProvider
+ * @dataProvider providesComputerFileSize
*/
function testComputerFileSize($expected, $input) {
$result = OC_Helper::computerFileSize($input);
$this->assertEquals($expected, $result);
}
- function computerFileSizeProvider(){
- return array(
- array(0.0, "0 B"),
- array(1024.0, "1 kB"),
- array(1395864371.0, '1.3 GB'),
- array(9961472.0, "9.5 MB"),
- array(500041567437.0, "465.7 GB"),
- );
+ function providesComputerFileSize(){
+ return [
+ [0.0, "0 B"],
+ [1024.0, "1 kB"],
+ [1395864371.0, '1.3 GB'],
+ [9961472.0, "9.5 MB"],
+ [500041567437.0, "465.7 GB"],
+ [false, "12 GB etfrhzui"]
+ ];
}
function testGetMimeType() {
diff --git a/tests/lib/hookhelper.php b/tests/lib/hookhelper.php
new file mode 100644
index 00000000000..93411bd068b
--- /dev/null
+++ b/tests/lib/hookhelper.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test;
+
+use OC\Files\Filesystem;
+
+/**
+ * Helper class to register hooks on
+ */
+class HookHelper {
+ public static $hookCalls;
+
+ public static function setUpHooks() {
+ self::clear();
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_create,
+ '\Test\HookHelper',
+ 'createCallback'
+ );
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_update,
+ '\Test\HookHelper',
+ 'updateCallback'
+ );
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_write,
+ '\Test\HookHelper',
+ 'writeCallback'
+ );
+
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_create,
+ '\Test\HookHelper',
+ 'postCreateCallback'
+ );
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_update,
+ '\Test\HookHelper',
+ 'postUpdateCallback'
+ );
+ \OCP\Util::connectHook(
+ Filesystem::CLASSNAME,
+ Filesystem::signal_post_write,
+ '\Test\HookHelper',
+ 'postWriteCallback'
+ );
+ }
+
+ public static function clear() {
+ self::$hookCalls = [];
+ }
+
+ public static function createCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_create,
+ 'params' => $params
+ );
+ }
+
+ public static function updateCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_update,
+ 'params' => $params
+ );
+ }
+
+ public static function writeCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_write,
+ 'params' => $params
+ );
+ }
+
+ public static function postCreateCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_post_create,
+ 'params' => $params
+ );
+ }
+
+ public static function postUpdateCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_post_update,
+ 'params' => $params
+ );
+ }
+
+ public static function postWriteCallback($params) {
+ self::$hookCalls[] = array(
+ 'signal' => Filesystem::signal_post_write,
+ 'params' => $params
+ );
+ }
+
+ /**
+ * Callback that sets the run paramter to false
+ */
+ public static function cancellingCallback($params) {
+ $params[Filesystem::signal_param_run] = false;
+ }
+}
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index e66dfb13353..76d5662da9d 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -182,6 +182,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
static protected function logout() {
\OC_Util::tearDownFS();
\OC_User::setUserId('');
+ // needed for fully logout
+ \OC::$server->getUserSession()->setUser(null);
}
/**
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index b9d45d786ec..e70b235f603 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -1303,14 +1303,14 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->once())
->method('isEnabledForUser')
->with(
- $this->equalTo('files_encryption')
+ $this->equalTo('encryption')
)
->will($this->returnValue(true));
$this->container['Config']
->expects($this->once())
->method('getAppValue')
->with(
- $this->equalTo('files_encryption'),
+ $this->equalTo('encryption'),
$this->equalTo('recoveryAdminEnabled'),
$this->anything()
)
@@ -1321,8 +1321,8 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUserValue')
->with(
$this->anything(),
- $this->equalTo('files_encryption'),
- $this->equalTo('recovery_enabled'),
+ $this->equalTo('encryption'),
+ $this->equalTo('recoveryEnabled'),
$this->anything()
)
->will($this->returnValue('1'));
@@ -1339,7 +1339,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->container['OCP\\App\\IAppManager']
->method('isEnabledForUser')
->with(
- $this->equalTo('files_encryption')
+ $this->equalTo('encryption')
)
->will($this->returnValue(true));
@@ -1358,14 +1358,14 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->once())
->method('isEnabledForUser')
->with(
- $this->equalTo('files_encryption')
+ $this->equalTo('encryption')
)
->will($this->returnValue(true));
$this->container['Config']
->expects($this->once())
->method('getAppValue')
->with(
- $this->equalTo('files_encryption'),
+ $this->equalTo('encryption'),
$this->equalTo('recoveryAdminEnabled'),
$this->anything()
)
@@ -1376,8 +1376,8 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUserValue')
->with(
$this->anything(),
- $this->equalTo('files_encryption'),
- $this->equalTo('recovery_enabled'),
+ $this->equalTo('encryption'),
+ $this->equalTo('recoveryEnabled'),
$this->anything()
)
->will($this->returnValue('0'));