fix unit tests

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-12-01 15:50:29 +01:00 committed by Roeland Jago Douma
parent ebb15283a6
commit 3285becdc1
No known key found for this signature in database
GPG Key ID: F941078878347C0C
4 changed files with 65 additions and 28 deletions

View File

@ -37,6 +37,7 @@ use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
@ -105,6 +106,7 @@ class ApiTest extends TestCase {
->will($this->returnCallback(function($text, $parameters = []) { ->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters); return vsprintf($text, $parameters);
})); }));
$config = $this->createMock(IConfig::class);
return new ShareAPIController( return new ShareAPIController(
self::APP_NAME, self::APP_NAME,
@ -115,7 +117,8 @@ class ApiTest extends TestCase {
\OC::$server->getRootFolder(), \OC::$server->getRootFolder(),
\OC::$server->getURLGenerator(), \OC::$server->getURLGenerator(),
$userId, $userId,
$l $l,
$config
); );
} }

View File

@ -31,6 +31,7 @@ use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\Files\Storage; use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCA\Files_Sharing\Controller\ShareAPIController; use OCA\Files_Sharing\Controller\ShareAPIController;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
@ -84,6 +85,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l; private $l;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
protected function setUp() { protected function setUp() {
$this->shareManager = $this->createMock(IManager::class); $this->shareManager = $this->createMock(IManager::class);
$this->shareManager $this->shareManager
@ -102,6 +106,7 @@ class ShareAPIControllerTest extends TestCase {
->will($this->returnCallback(function($text, $parameters = []) { ->will($this->returnCallback(function($text, $parameters = []) {
return vsprintf($text, $parameters); return vsprintf($text, $parameters);
})); }));
$this->config = $this->createMock(IConfig::class);
$this->ocs = new ShareAPIController( $this->ocs = new ShareAPIController(
$this->appName, $this->appName,
@ -112,7 +117,8 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder, $this->rootFolder,
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l $this->l,
$this->config
); );
} }
@ -131,6 +137,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l, $this->l,
$this->config
])->setMethods(['formatShare']) ])->setMethods(['formatShare'])
->getMock(); ->getMock();
} }
@ -439,6 +446,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l, $this->l,
$this->config
])->setMethods(['canAccessShare']) ])->setMethods(['canAccessShare'])
->getMock(); ->getMock();
@ -707,6 +715,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l, $this->l,
$this->config
])->setMethods(['formatShare']) ])->setMethods(['formatShare'])
->getMock(); ->getMock();
@ -804,6 +813,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l, $this->l,
$this->config
])->setMethods(['formatShare']) ])->setMethods(['formatShare'])
->getMock(); ->getMock();
@ -1119,6 +1129,7 @@ class ShareAPIControllerTest extends TestCase {
$this->urlGenerator, $this->urlGenerator,
$this->currentUser, $this->currentUser,
$this->l, $this->l,
$this->config
])->setMethods(['formatShare']) ])->setMethods(['formatShare'])
->getMock(); ->getMock();

View File

@ -57,7 +57,37 @@ class Sharing implements ISettings {
$excludeGroupsList = !is_null(json_decode($excludedGroups)) $excludeGroupsList = !is_null(json_decode($excludedGroups))
? implode('|', json_decode($excludedGroups, true)) : ''; ? implode('|', json_decode($excludedGroups, true)) : '';
$permList = [ $parameters = [
// Built-In Sharing
'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(),
'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
'shareExcludedGroupsList' => $excludeGroupsList,
'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' => $this->getSharePermissionList(),
];
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
}
/**
* get share permission list for template
*
* @return array
*/
private function getSharePermissionList() {
return [
[ [
'id' => 'cancreate', 'id' => 'cancreate',
'label' => $this->l->t('Create'), 'label' => $this->l->t('Create'),
@ -79,29 +109,6 @@ class Sharing implements ISettings {
'value' => Constants::PERMISSION_SHARE 'value' => Constants::PERMISSION_SHARE
], ],
]; ];
$parameters = [
// Built-In Sharing
'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'),
'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'),
'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'),
'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'),
'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'),
'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(),
'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(),
'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'),
'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'),
'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'),
'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes',
'shareExcludedGroupsList' => $excludeGroupsList,
'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,
];
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');
} }
/** /**

View File

@ -25,6 +25,7 @@ namespace Test\Settings\Admin;
use OC\Settings\Admin\Sharing; use OC\Settings\Admin\Sharing;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\Constants;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use Test\TestCase; use Test\TestCase;
@ -114,6 +115,11 @@ class SharingTest extends TestCase {
->method('getAppValue') ->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no') ->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes'); ->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( $expected = new TemplateResponse(
'settings', 'settings',
@ -133,7 +139,9 @@ class SharingTest extends TestCase {
'shareExcludeGroups' => false, 'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '', 'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum', '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') ->method('getAppValue')
->with('core', 'shareapi_enable_link_password_by_default', 'no') ->with('core', 'shareapi_enable_link_password_by_default', 'no')
->willReturn('yes'); ->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( $expected = new TemplateResponse(
'settings', 'settings',
@ -226,7 +240,9 @@ class SharingTest extends TestCase {
'shareExcludeGroups' => true, 'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers', 'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum', 'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes' 'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => $this->invokePrivate($this->admin, 'getSharePermissionList', [])
], ],
'' ''
); );