diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-08-05 15:55:28 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-08-12 21:15:39 +0200 |
commit | 53c5a84eac33fdc1deb0bf5607c1984a258771b0 (patch) | |
tree | 9bf3c224acbaacdfa1d58647dee9c524e1ad37a7 /apps | |
parent | da1feafc7859b334959bb6cf1676d866b52c6ca7 (diff) | |
download | nextcloud-server-53c5a84eac33fdc1deb0bf5607c1984a258771b0.tar.gz nextcloud-server-53c5a84eac33fdc1deb0bf5607c1984a258771b0.zip |
add unit tests
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/files_encryption/tests/util.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index d9fc819f981..cbc4df92474 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); } /** @@ -458,6 +473,31 @@ 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 @@ -507,3 +547,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); + } +} |