diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-19 15:35:58 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-19 15:36:16 +0100 |
commit | 9ec2850c78e673a4aa1c4af97aa5be4414bd438f (patch) | |
tree | 6d127c4443d5fd6a69f7577dfd0dc8c3d01e9f26 /tests | |
parent | 58eaeb267c60ed2aed4b5592a28d16f5453bb773 (diff) | |
download | nextcloud-server-9ec2850c78e673a4aa1c4af97aa5be4414bd438f.tar.gz nextcloud-server-9ec2850c78e673a4aa1c4af97aa5be4414bd438f.zip |
Use mocks when testing isSharingDisabledForUser
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/util.php | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/tests/lib/util.php b/tests/lib/util.php index 9974e799d08..cb575976f3f 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -289,38 +289,44 @@ 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('getUserGroups') + ->with($user) + ->will($this->returnValue($membership)); + +// $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); +// } +// + + $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() { |