Added failing unit tests for mount config hooks
This commit is contained in:
parent
0610937ac3
commit
6585eaa5df
3 changed files with 147 additions and 8 deletions
|
@ -518,11 +518,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,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -561,11 +561,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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -337,6 +375,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
|
||||
*/
|
||||
|
|
|
@ -158,6 +158,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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue