diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-09-26 12:51:25 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-10-08 14:22:17 +0200 |
commit | 6585eaa5df7a4481638a334926743d496f243d65 (patch) | |
tree | a9c8b9f36d345d8c60d4ee917156b4f09841d47d /apps/files_external/tests | |
parent | 0610937ac3ccd491b2e62133edbf76f1bb151467 (diff) | |
download | nextcloud-server-6585eaa5df7a4481638a334926743d496f243d65.tar.gz nextcloud-server-6585eaa5df7a4481638a334926743d496f243d65.zip |
Added failing unit tests for mount config hooks
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r-- | apps/files_external/tests/mountconfig.php | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php index fc482823843..0fa1e4e46e7 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); @@ -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 */ |