Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
  • Loading branch information
schiessle committed Dec 1, 2017
1 parent 9f653aa commit 9742d95
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 28 deletions.
5 changes: 4 additions & 1 deletion apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;

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

return new ShareAPIController(
self::APP_NAME,
Expand All @@ -115,7 +117,8 @@ private function createOCS($userId) {
\OC::$server->getRootFolder(),
\OC::$server->getURLGenerator(),
$userId,
$l
$l,
$config
);
}

Expand Down
13 changes: 12 additions & 1 deletion apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IL10N;
use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -84,6 +85,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;

/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;

protected function setUp() {
$this->shareManager = $this->createMock(IManager::class);
$this->shareManager
Expand All @@ -102,6 +106,7 @@ protected function setUp() {
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
$this->config = $this->createMock(IConfig::class);

$this->ocs = new ShareAPIController(
$this->appName,
Expand All @@ -112,7 +117,8 @@ protected function setUp() {
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
$this->l
$this->l,
$this->config
);
}

Expand All @@ -131,6 +137,7 @@ private function mockFormatShare() {
$this->urlGenerator,
$this->currentUser,
$this->l,
$this->config
])->setMethods(['formatShare'])
->getMock();
}
Expand Down Expand Up @@ -439,6 +446,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$this->urlGenerator,
$this->currentUser,
$this->l,
$this->config
])->setMethods(['canAccessShare'])
->getMock();

Expand Down Expand Up @@ -707,6 +715,7 @@ public function testCreateShareUser() {
$this->urlGenerator,
$this->currentUser,
$this->l,
$this->config
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -804,6 +813,7 @@ public function testCreateShareGroup() {
$this->urlGenerator,
$this->currentUser,
$this->l,
$this->config
])->setMethods(['formatShare'])
->getMock();

Expand Down Expand Up @@ -1119,6 +1129,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$this->urlGenerator,
$this->currentUser,
$this->l,
$this->config
])->setMethods(['formatShare'])
->getMock();

Expand Down
55 changes: 31 additions & 24 deletions lib/private/Settings/Admin/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ public function getForm() {
$excludeGroupsList = !is_null(json_decode($excludedGroups))
? implode('|', json_decode($excludedGroups, true)) : '';

$permList = [
[
'id' => 'cancreate',
'label' => $this->l->t('Create'),
'value' => Constants::PERMISSION_CREATE
],
[
'id' => 'canupdate',
'label' => $this->l->t('Change'),
'value' => Constants::PERMISSION_UPDATE
],
[
'id' => 'candelete',
'label' => $this->l->t('Delete'),
'value' => Constants::PERMISSION_DELETE
],
[
'id' => 'canshare',
'label' => $this->l->t('Share'),
'value' => Constants::PERMISSION_SHARE
],
];

$parameters = [
// Built-In Sharing
'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
Expand All @@ -98,12 +75,42 @@ public function getForm() {
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null),
'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'),
'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL),
'shareApiDefaultPermissionsCheckboxes' => $permList,
'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(),
];

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

/**
* get share permission list for template
*
* @return array
*/
private function getSharePermissionList() {
return [
[
'id' => 'cancreate',
'label' => $this->l->t('Create'),
'value' => Constants::PERMISSION_CREATE
],
[
'id' => 'canupdate',
'label' => $this->l->t('Change'),
'value' => Constants::PERMISSION_UPDATE
],
[
'id' => 'candelete',
'label' => $this->l->t('Delete'),
'value' => Constants::PERMISSION_DELETE
],
[
'id' => 'canshare',
'label' => $this->l->t('Share'),
'value' => Constants::PERMISSION_SHARE
],
];
}

/**
* @return string the section ID, e.g. 'sharing'
*/
Expand Down
20 changes: 18 additions & 2 deletions tests/lib/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OC\Settings\Admin\Sharing;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Constants;
use OCP\IConfig;
use OCP\IL10N;
use Test\TestCase;
Expand Down Expand Up @@ -114,6 +115,11 @@ public function testGetFormWithoutExcludedGroups() {
->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes');
$this->config
->expects($this->at(13))
->method('getAppValue')
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
->willReturn(Constants::PERMISSION_ALL);

$expected = new TemplateResponse(
'settings',
Expand All @@ -133,7 +139,9 @@ public function testGetFormWithoutExcludedGroups() {
'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes'
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
],
''
);
Expand Down Expand Up @@ -207,6 +215,12 @@ public function testGetFormWithExcludedGroups() {
->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes');
$this->config
->expects($this->at(13))
->method('getAppValue')
->with('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL)
->willReturn(Constants::PERMISSION_ALL);


$expected = new TemplateResponse(
'settings',
Expand All @@ -226,7 +240,9 @@ public function testGetFormWithExcludedGroups() {
'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes'
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
],
''
);
Expand Down

0 comments on commit 9742d95

Please sign in to comment.