summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-20 15:22:52 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-20 15:22:52 +0100
commit427d107b9f375f5667a3e8f40191edd46924fdb8 (patch)
treea23de8dcbea7e7d66e842c9e15fc600350c9d49c /tests
parent308aaf89cd916a0c26c219650e09b8612a50fc47 (diff)
parentc86483f3edb931d58477e4003490fb02fee6369f (diff)
downloadnextcloud-server-427d107b9f375f5667a3e8f40191edd46924fdb8.tar.gz
nextcloud-server-427d107b9f375f5667a3e8f40191edd46924fdb8.zip
Merge pull request #20614 from owncloud/use-mocks-when-testing-isSharingDisabledForUser
Use mocks when testing isSharingDisabledForUser
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/util.php52
1 files changed, 22 insertions, 30 deletions
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 9974e799d08..a328b1923e9 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -289,38 +289,30 @@ class Test_Util extends \Test\TestCase {
* @param bool $expected expected result
*/
function testIsSharingDisabledForUser($groups, $membership, $excludedGroups, $expected) {
- $uid = "user1";
- \OC_User::setUserId($uid);
-
- \OC_User::createUser($uid, "passwd");
-
- foreach ($groups as $group) {
- \OC_Group::createGroup($group);
- }
-
- foreach ($membership as $group) {
- \OC_Group::addToGroup($uid, $group);
- }
-
- $appConfig = \OC::$server->getAppConfig();
- $appConfig->setValue('core', 'shareapi_exclude_groups_list', json_encode($excludedGroups));
- $appConfig->setValue('core', 'shareapi_exclude_groups', 'yes');
-
- $result = \OCP\Util::isSharingDisabledForUser();
+ $config = $this->getMockBuilder('OCP\IConfig')->disableOriginalConstructor()->getMock();
+ $groupManager = $this->getMockBuilder('OCP\IGroupManager')->disableOriginalConstructor()->getMock();
+ $user = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock();
+
+ $config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups', 'no')
+ ->will($this->returnValue('yes'));
+ $config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('core', 'shareapi_exclude_groups_list')
+ ->will($this->returnValue(json_encode($excludedGroups)));
+
+ $groupManager
+ ->expects($this->at(0))
+ ->method('getUserGroupIds')
+ ->with($user)
+ ->will($this->returnValue($membership));
+
+ $result = \OC_Util::isSharingDisabledForUser($config, $groupManager, $user);
$this->assertSame($expected, $result);
-
- // cleanup
- \OC_User::deleteUser($uid);
- \OC_User::setUserId('');
-
- foreach ($groups as $group) {
- \OC_Group::deleteGroup($group);
- }
-
- $appConfig->setValue('core', 'shareapi_exclude_groups_list', '');
- $appConfig->setValue('core', 'shareapi_exclude_groups', 'no');
-
}
public function dataProviderForTestIsSharingDisabledForUser() {