Skip to content

Commit 9742d95

Browse files
committed
fix unit tests
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
1 parent 9f653aa commit 9742d95

File tree

4 files changed

+65
-28
lines changed

4 files changed

+65
-28
lines changed

apps/files_sharing/tests/ApiTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCP\AppFramework\OCS\OCSException;
3838
use OCP\AppFramework\OCS\OCSForbiddenException;
3939
use OCP\AppFramework\OCS\OCSNotFoundException;
40+
use OCP\IConfig;
4041
use OCP\IL10N;
4142
use OCP\IRequest;
4243

@@ -105,6 +106,7 @@ private function createOCS($userId) {
105106
->will($this->returnCallback(function($text, $parameters = []) {
106107
return vsprintf($text, $parameters);
107108
}));
109+
$config = $this->createMock(IConfig::class);
108110

109111
return new ShareAPIController(
110112
self::APP_NAME,
@@ -115,7 +117,8 @@ private function createOCS($userId) {
115117
\OC::$server->getRootFolder(),
116118
\OC::$server->getURLGenerator(),
117119
$userId,
118-
$l
120+
$l,
121+
$config
119122
);
120123
}
121124

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\Files\File;
3232
use OCP\Files\Folder;
3333
use OCP\Files\Storage;
34+
use OCP\IConfig;
3435
use OCP\IL10N;
3536
use OCA\Files_Sharing\Controller\ShareAPIController;
3637
use OCP\Files\NotFoundException;
@@ -84,6 +85,9 @@ class ShareAPIControllerTest extends TestCase {
8485
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
8586
private $l;
8687

88+
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
89+
private $config;
90+
8791
protected function setUp() {
8892
$this->shareManager = $this->createMock(IManager::class);
8993
$this->shareManager
@@ -102,6 +106,7 @@ protected function setUp() {
102106
->will($this->returnCallback(function($text, $parameters = []) {
103107
return vsprintf($text, $parameters);
104108
}));
109+
$this->config = $this->createMock(IConfig::class);
105110

106111
$this->ocs = new ShareAPIController(
107112
$this->appName,
@@ -112,7 +117,8 @@ protected function setUp() {
112117
$this->rootFolder,
113118
$this->urlGenerator,
114119
$this->currentUser,
115-
$this->l
120+
$this->l,
121+
$this->config
116122
);
117123
}
118124

@@ -131,6 +137,7 @@ private function mockFormatShare() {
131137
$this->urlGenerator,
132138
$this->currentUser,
133139
$this->l,
140+
$this->config
134141
])->setMethods(['formatShare'])
135142
->getMock();
136143
}
@@ -439,6 +446,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
439446
$this->urlGenerator,
440447
$this->currentUser,
441448
$this->l,
449+
$this->config
442450
])->setMethods(['canAccessShare'])
443451
->getMock();
444452

@@ -707,6 +715,7 @@ public function testCreateShareUser() {
707715
$this->urlGenerator,
708716
$this->currentUser,
709717
$this->l,
718+
$this->config
710719
])->setMethods(['formatShare'])
711720
->getMock();
712721

@@ -804,6 +813,7 @@ public function testCreateShareGroup() {
804813
$this->urlGenerator,
805814
$this->currentUser,
806815
$this->l,
816+
$this->config
807817
])->setMethods(['formatShare'])
808818
->getMock();
809819

@@ -1119,6 +1129,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
11191129
$this->urlGenerator,
11201130
$this->currentUser,
11211131
$this->l,
1132+
$this->config
11221133
])->setMethods(['formatShare'])
11231134
->getMock();
11241135

lib/private/Settings/Admin/Sharing.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,6 @@ public function getForm() {
5757
$excludeGroupsList = !is_null(json_decode($excludedGroups))
5858
? implode('|', json_decode($excludedGroups, true)) : '';
5959

60-
$permList = [
61-
[
62-
'id' => 'cancreate',
63-
'label' => $this->l->t('Create'),
64-
'value' => Constants::PERMISSION_CREATE
65-
],
66-
[
67-
'id' => 'canupdate',
68-
'label' => $this->l->t('Change'),
69-
'value' => Constants::PERMISSION_UPDATE
70-
],
71-
[
72-
'id' => 'candelete',
73-
'label' => $this->l->t('Delete'),
74-
'value' => Constants::PERMISSION_DELETE
75-
],
76-
[
77-
'id' => 'canshare',
78-
'label' => $this->l->t('Share'),
79-
'value' => Constants::PERMISSION_SHARE
80-
],
81-
];
82-
8360
$parameters = [
8461
// Built-In Sharing
8562
'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
@@ -98,12 +75,42 @@ public function getForm() {
9875
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
9976
'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
10077
'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
101-
'shareApiDefaultPermissionsCheckboxes' => $permList,
78+
'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
10279
];
10380

10481
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
10582
}
10683

84+
/**
85+
* get share permission list for template
86+
*
87+
* @return array
88+
*/
89+
private function getSharePermissionList() {
90+
return [
91+
[
92+
'id' => 'cancreate',
93+
'label' => $this->l->t('Create'),
94+
'value' => Constants::PERMISSION_CREATE
95+
],
96+
[
97+
'id' => 'canupdate',
98+
'label' => $this->l->t('Change'),
99+
'value' => Constants::PERMISSION_UPDATE
100+
],
101+
[
102+
'id' => 'candelete',
103+
'label' => $this->l->t('Delete'),
104+
'value' => Constants::PERMISSION_DELETE
105+
],
106+
[
107+
'id' => 'canshare',
108+
'label' => $this->l->t('Share'),
109+
'value' => Constants::PERMISSION_SHARE
110+
],
111+
];
112+
}
113+
107114
/**
108115
* @return string the section ID, e.g. 'sharing'
109116
*/

tests/lib/Settings/Admin/SharingTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use OC\Settings\Admin\Sharing;
2727
use OCP\AppFramework\Http\TemplateResponse;
28+
use OCP\Constants;
2829
use OCP\IConfig;
2930
use OCP\IL10N;
3031
use Test\TestCase;
@@ -114,6 +115,11 @@ public function testGetFormWithoutExcludedGroups() {
114115
->method('getAppValue')
115116
->with('core', 'shareapi_enable_link_password_by_default', 'no')
116117
->willReturn('yes');
118+
$this->config
119+
->expects($this->at(13))
120+
->method('getAppValue')
121+
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
122+
->willReturn(Constants::PERMISSION_ALL);
117123

118124
$expected = new TemplateResponse(
119125
'settings',
@@ -133,7 +139,9 @@ public function testGetFormWithoutExcludedGroups() {
133139
'shareExcludeGroups' => false,
134140
'shareExcludedGroupsList' => '',
135141
'publicShareDisclaimerText' => 'Lorem ipsum',
136-
'enableLinkPasswordByDefault' => 'yes'
142+
'enableLinkPasswordByDefault' => 'yes',
143+
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
144+
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
137145
],
138146
''
139147
);
@@ -207,6 +215,12 @@ public function testGetFormWithExcludedGroups() {
207215
->method('getAppValue')
208216
->with('core', 'shareapi_enable_link_password_by_default', 'no')
209217
->willReturn('yes');
218+
$this->config
219+
->expects($this->at(13))
220+
->method('getAppValue')
221+
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
222+
->willReturn(Constants::PERMISSION_ALL);
223+
210224

211225
$expected = new TemplateResponse(
212226
'settings',
@@ -226,7 +240,9 @@ public function testGetFormWithExcludedGroups() {
226240
'shareExcludeGroups' => true,
227241
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
228242
'publicShareDisclaimerText' => 'Lorem ipsum',
229-
'enableLinkPasswordByDefault' => 'yes'
243+
'enableLinkPasswordByDefault' => 'yes',
244+
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
245+
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
230246
],
231247
''
232248
);

0 commit comments

Comments
 (0)