aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-12-01 15:50:29 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-02-27 12:29:25 +0100
commit3285becdc16a9eb57a507e6ad58100d392f2894a (patch)
tree1c8800777638c6800f2acb8f33beeec0ecaa4dad
parentebb15283a60d1c2ee5fb731feca1c68275d58264 (diff)
downloadnextcloud-server-3285becdc16a9eb57a507e6ad58100d392f2894a.tar.gz
nextcloud-server-3285becdc16a9eb57a507e6ad58100d392f2894a.zip
fix unit tests
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
-rw-r--r--apps/files_sharing/tests/ApiTest.php5
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php13
-rw-r--r--lib/private/Settings/Admin/Sharing.php55
-rw-r--r--tests/lib/Settings/Admin/SharingTest.php20
4 files changed, 65 insertions, 28 deletions
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 6d8e2dd8d84..d7bc169bf4a 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -37,6 +37,7 @@ use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
+use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
@@ -105,6 +106,7 @@ class ApiTest extends TestCase {
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
+ $config = $this->createMock(IConfig::class);
return new ShareAPIController(
self::APP_NAME,
@@ -115,7 +117,8 @@ class ApiTest extends TestCase {
\OC::$server->getRootFolder(),
\OC::$server->getURLGenerator(),
$userId,
- $l
+ $l,
+ $config
);
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index c438dac2521..a475474e3cf 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -31,6 +31,7 @@ use OCP\AppFramework\OCS\OCSNotFoundException;
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;
@@ -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
@@ -102,6 +106,7 @@ class ShareAPIControllerTest extends TestCase {
->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters);
}));
+ $this->config = $this->createMock(IConfig::class);
$this->ocs = new ShareAPIController(
$this->appName,
@@ -112,7 +117,8 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder,
$this->urlGenerator,
$this->currentUser,
- $this->l
+ $this->l,
+ $this->config
);
}
@@ -131,6 +137,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
}
@@ -439,6 +446,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['canAccessShare'])
->getMock();
@@ -707,6 +715,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
@@ -804,6 +813,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
@@ -1119,6 +1129,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator,
$this->currentUser,
$this->l,
+ $this->config
])->setMethods(['formatShare'])
->getMock();
diff --git a/lib/private/Settings/Admin/Sharing.php b/lib/private/Settings/Admin/Sharing.php
index 7b60efdc67b..dfc0b11478b 100644
--- a/lib/private/Settings/Admin/Sharing.php
+++ b/lib/private/Settings/Admin/Sharing.php
@@ -57,29 +57,6 @@ class Sharing implements ISettings {
$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'),
@@ -98,13 +75,43 @@ class Sharing implements ISettings {
'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'
*/
public function getSection() {
diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php
index ee60979b96d..79065fb8d21 100644
--- a/tests/lib/Settings/Admin/SharingTest.php
+++ b/tests/lib/Settings/Admin/SharingTest.php
@@ -25,6 +25,7 @@ namespace Test\Settings\Admin;
use OC\Settings\Admin\Sharing;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Constants;
use OCP\IConfig;
use OCP\IL10N;
use Test\TestCase;
@@ -114,6 +115,11 @@ class SharingTest extends TestCase {
->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',
@@ -133,7 +139,9 @@ class SharingTest extends TestCase {
'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum',
- 'enableLinkPasswordByDefault' => 'yes'
+ 'enableLinkPasswordByDefault' => 'yes',
+ 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
+ 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
],
''
);
@@ -207,6 +215,12 @@ class SharingTest extends TestCase {
->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',
@@ -226,7 +240,9 @@ class SharingTest extends TestCase {
'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum',
- 'enableLinkPasswordByDefault' => 'yes'
+ 'enableLinkPasswordByDefault' => 'yes',
+ 'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
+ 'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
],
''
);