diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-08-05 15:55:28 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-08-12 17:54:54 +0200 |
commit | 9f9c18bd7492e396c7921b42e34245b25dd6b116 (patch) | |
tree | 28dbd4a1168a2834a3bceb8a4178a61051054714 /apps | |
parent | 6af1a2d9143fb1b4a6e139c96807d4a4f1a0021a (diff) | |
download | nextcloud-server-9f9c18bd7492e396c7921b42e34245b25dd6b116.tar.gz nextcloud-server-9f9c18bd7492e396c7921b42e34245b25dd6b116.zip |
add unit tests
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/files_encryption/tests/util.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 079dafd09ff..0e237014b8d 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -22,6 +22,9 @@ use OCA\Encryption; class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { const TEST_ENCRYPTION_UTIL_USER1 = "test-util-user1"; + const TEST_ENCRYPTION_UTIL_USER2 = "test-util-user2"; + const TEST_ENCRYPTION_UTIL_GROUP1 = "test-util-group1"; + const TEST_ENCRYPTION_UTIL_GROUP2 = "test-util-group2"; const TEST_ENCRYPTION_UTIL_LEGACY_USER = "test-legacy-user"; public $userId; @@ -59,7 +62,15 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { // create test user \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, true); + \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2, true); \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER, true); + + // create groups + \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP1); + \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP2); + + // add user 1 to group1 + \OC_Group::addToGroup(self::TEST_ENCRYPTION_UTIL_USER1, self::TEST_ENCRYPTION_UTIL_GROUP1); } @@ -116,7 +127,11 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); + \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2); \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER); + //cleanup groups + \OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP1); + \OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP2); } /** @@ -538,6 +553,29 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { } /** + * @dataProvider dataProviderFortestIsMountPointApplicableToUser + */ + function testIsMountPointApplicableToUser($mount, $expectedResult) { + self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1); + $dummyClass = new DummyUtilClass($this->view, self::TEST_ENCRYPTION_UTIL_USER1); + $result = $dummyClass->testIsMountPointApplicableToUser($mount); + + $this->assertSame($expectedResult, $result); + } + + function dataProviderFortestIsMountPointApplicableToUser() { + return array( + array(array('applicable' => array('groups' => array(), 'users' => array(self::TEST_ENCRYPTION_UTIL_USER1))), true), + array(array('applicable' => array('groups' => array(), 'users' => array(self::TEST_ENCRYPTION_UTIL_USER2))), false), + array(array('applicable' => array('groups' => array(self::TEST_ENCRYPTION_UTIL_GROUP1), 'users' => array())), true), + array(array('applicable' => array('groups' => array(self::TEST_ENCRYPTION_UTIL_GROUP1), 'users' => array(self::TEST_ENCRYPTION_UTIL_USER2))), true), + array(array('applicable' => array('groups' => array(self::TEST_ENCRYPTION_UTIL_GROUP2), 'users' => array(self::TEST_ENCRYPTION_UTIL_USER2))), false), + array(array('applicable' => array('groups' => array(self::TEST_ENCRYPTION_UTIL_GROUP2), 'users' => array(self::TEST_ENCRYPTION_UTIL_USER2, 'all'))), true), + array(array('applicable' => array('groups' => array(self::TEST_ENCRYPTION_UTIL_GROUP2), 'users' => array('all'))), true), + ); + } + + /** * @param string $user * @param bool $create * @param bool $password @@ -587,3 +625,12 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { } } + +/** + * dummy class extends \OCA\Encryption\Util to access protected methods for testing + */ +class DummyUtilClass extends \OCA\Encryption\Util { + public function testIsMountPointApplicableToUser($mount) { + return $this->isMountPointApplicableToUser($mount); + } +} |