[Pkg-owncloud-commits] [owncloud] 231/258: Added failing unit tests for mount config hooks
David Prévot
taffit at moszumanska.debian.org
Sat Oct 11 17:22:39 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 3d68d172af6ede67fad7bbed2a61a60663ef226e
Author: Vincent Petry <pvince81 at owncloud.com>
Date: Fri Sep 26 12:51:25 2014 +0200
Added failing unit tests for mount config hooks
---
apps/files_external/lib/config.php | 16 ++--
apps/files_external/tests/mountconfig.php | 134 ++++++++++++++++++++++++++++++
lib/private/files/filesystem.php | 5 ++
3 files changed, 147 insertions(+), 8 deletions(-)
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 68a9e7e..6d46fd7 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -514,11 +514,11 @@ class OC_Mount_Config {
if ($result && $isNew) {
\OC_Hook::emit(
\OC\Files\Filesystem::CLASSNAME,
- 'add_mount_point',
+ \OC\Files\Filesystem::signal_create_mount,
array(
- 'path' => $mountPoint,
- 'type' => $mountType,
- 'applicable' => $applicable
+ \OC\Files\Filesystem::signal_param_path => $mountPoint,
+ \OC\Files\Filesystem::signal_param_mount_type => $mountType,
+ \OC\Files\Filesystem::signal_param_users => $applicable,
)
);
}
@@ -557,11 +557,11 @@ class OC_Mount_Config {
self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
\OC_Hook::emit(
\OC\Files\Filesystem::CLASSNAME,
- 'remove_mount_point',
+ \OC\Files\Filesystem::signal_delete_mount,
array(
- 'path' => $mountPoint,
- 'type' => $mountType,
- 'applicable' => $applicable
+ \OC\Files\Filesystem::signal_param_path => $mountPoint,
+ \OC\Files\Filesystem::signal_param_mount_type => $mountType,
+ \OC\Files\Filesystem::signal_param_users => $applicable,
)
);
return true;
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php
index 7e38a87..db4fbf5 100644
--- a/apps/files_external/tests/mountconfig.php
+++ b/apps/files_external/tests/mountconfig.php
@@ -26,6 +26,42 @@ class Test_Mount_Config_Dummy_Storage {
}
}
+class Test_Mount_Config_Hook_Test {
+ static $signal;
+ static $params;
+
+ public static function setUpHooks() {
+ self::clear();
+ \OCP\Util::connectHook(
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_create_mount,
+ '\Test_Mount_Config_Hook_Test', 'createHookCallback');
+ \OCP\Util::connectHook(
+ \OC\Files\Filesystem::CLASSNAME,
+ \OC\Files\Filesystem::signal_delete_mount,
+ '\Test_Mount_Config_Hook_Test', 'deleteHookCallback');
+ }
+
+ public static function clear() {
+ self::$signal = null;
+ self::$params = null;
+ }
+
+ public static function createHookCallback($params) {
+ self::$signal = \OC\Files\Filesystem::signal_create_mount;
+ self::$params = $params;
+ }
+
+ public static function deleteHookCallback($params) {
+ self::$signal = \OC\Files\Filesystem::signal_create_mount;
+ self::$params = $params;
+ }
+
+ public static function getLastCall() {
+ return array(self::$signal, self::$params);
+ }
+}
+
/**
* Class Test_Mount_Config
*/
@@ -77,9 +113,11 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
);
OC_Mount_Config::$skipTest = true;
+ Test_Mount_Config_Hook_Test::setupHooks();
}
public function tearDown() {
+ Test_Mount_Config_Hook_Test::clear();
OC_Mount_Config::$skipTest = false;
\OC_User::deleteUser(self::TEST_USER2);
@@ -327,6 +365,102 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array_keys($options), array_keys($savedOptions));
}
+ public function testHooks() {
+ $mountPoint = '/test';
+ $mountType = 'user';
+ $applicable = 'all';
+ $isPersonal = false;
+
+ $mountConfig = array(
+ 'host' => 'smbhost',
+ 'user' => 'smbuser',
+ 'password' => 'smbpassword',
+ 'share' => 'smbshare',
+ 'root' => 'smbroot'
+ );
+
+ // write config
+ $this->assertTrue(
+ OC_Mount_Config::addMountPoint(
+ $mountPoint,
+ '\OC\Files\Storage\SMB',
+ $mountConfig,
+ $mountType,
+ $applicable,
+ $isPersonal
+ )
+ );
+
+ list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
+ $this->assertEquals(
+ \OC\Files\Filesystem::signal_create_mount,
+ $hookName
+ );
+ $this->assertEquals(
+ $mountPoint,
+ $params[\OC\Files\Filesystem::signal_param_path]
+ );
+ $this->assertEquals(
+ $mountType,
+ $params[\OC\Files\Filesystem::signal_param_mount_type]
+ );
+ $this->assertEquals(
+ $applicable,
+ $params[\OC\Files\Filesystem::signal_param_mount_users]
+ );
+
+ Test_Mount_Config_Hook_Test::clear();
+
+ // edit
+ $mountConfig['host'] = 'anothersmbhost';
+ $this->assertTrue(
+ OC_Mount_Config::addMountPoint(
+ $mountPoint,
+ '\OC\Files\Storage\SMB',
+ $mountConfig,
+ $mountType,
+ $applicable,
+ $isPersonal
+ )
+ );
+
+ // hook must not be called on edit
+ list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
+ $this->assertEquals(
+ null,
+ $hookName
+ );
+
+ Test_Mount_Config_Hook_Test::clear();
+
+ $this->assertTrue(
+ OC_Mount_Config::removeMountPoint(
+ '/ext',
+ $mountType,
+ $applicable,
+ $isPersonal
+ )
+ );
+
+ list($hookName, $params) = Test_Mount_Config_Hook_Test::getLastCall();
+ $this->assertEquals(
+ \OC\Files\Filesystem::signal_delete_mount,
+ $hookName
+ );
+ $this->assertEquals(
+ $mountPoint,
+ $params[\OC\Files\Filesystem::signal_param_path]
+ );
+ $this->assertEquals(
+ $mountType,
+ $params[\OC\Files\Filesystem::signal_param_mount_type]
+ );
+ $this->assertEquals(
+ $applicable,
+ $params[\OC\Files\Filesystem::signal_param_mount_users]
+ );
+ }
+
/**
* Test password obfuscation
*/
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 02bfa00..f5be7a0 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -160,6 +160,11 @@ class Filesystem {
*/
const signal_param_run = 'run';
+ const signal_create_mount = 'create_mount';
+ const signal_delete_mount = 'delete_mount';
+ const signal_param_mount_type = 'mounttype';
+ const signal_param_users = 'users';
+
/**
* @var \OC\Files\Storage\Loader $loader
*/
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list