Skip to content

Commit

Permalink
Fix sharing settings unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Nov 21, 2023
1 parent f74084c commit eee4c3f
Showing 1 changed file with 102 additions and 71 deletions.
173 changes: 102 additions & 71 deletions apps/settings/tests/Settings/Admin/SharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
use OCA\Settings\Settings\Admin\Sharing;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand All @@ -52,20 +54,35 @@ class SharingTest extends TestCase {
private $shareManager;
/** @var IAppManager|MockObject */
private $appManager;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
/** @var IInitialState|MockObject */
private $initialState;

protected function setUp(): void {
parent::setUp();
/** @var IConfig|MockObject */
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
/** @var IL10N|MockObject */
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();

/** @var IManager|MockObject */
$this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
/** @var IAppManager|MockObject */
$this->appManager = $this->getMockBuilder(IAppManager::class)->getMock();
/** @var IURLGenerator|MockObject */
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
/** @var IInitialState|MockObject */
$this->initialState = $this->getMockBuilder(IInitialState::class)->getMock();

$this->admin = new Sharing(
$this->config,
$this->l10n,
$this->shareManager,
$this->appManager
$this->appManager,
$this->urlGenerator,
$this->initialState,
"settings",
);
}

Expand Down Expand Up @@ -106,45 +123,52 @@ public function testGetFormWithoutExcludedGroups(): void {
->willReturn(false);

$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
$this->initialState
->expect($this->once())
->method('provideInitialState')->w
->with(
'sharingSettings',
[
'sharingAppEnabled' => false,
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
'allowPublicUpload' => 'yes',
'allowResharing' => 'yes',
'allowShareDialogUserEnumeration' => 'yes',
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
'restrictUserEnumerationFullMatchEmail' => 'yes',
'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
'shareDefaultExpireDateSet' => 'no',
'shareExpireAfterNDays' => '7',
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
'allowLinksExcludeGroups' => '',
'passwordExcludedGroups' => '',
'passwordExcludedGroupsFeatureEnabled' => false,
],
);

$expected = new TemplateResponse(
'settings',
'settings/admin/sharing',
[
'sharingAppEnabled' => false,
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
'allowPublicUpload' => 'yes',
'allowResharing' => 'yes',
'allowShareDialogUserEnumeration' => 'yes',
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
'restrictUserEnumerationFullMatchEmail' => 'yes',
'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
'shareDefaultExpireDateSet' => 'no',
'shareExpireAfterNDays' => '7',
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => false,
'shareExcludedGroupsList' => '',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
'allowLinksExcludeGroups' => '',
'passwordExcludedGroups' => '',
'passwordExcludedGroupsFeatureEnabled' => false,
],
[],
''
);

Expand Down Expand Up @@ -188,45 +212,52 @@ public function testGetFormWithExcludedGroups(): void {
->willReturn(false);

$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
$this->initialState
->expect($this->once())
->method('provideInitialState')
->with(
'sharingSettings',
[
'sharingAppEnabled' => true,
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
'allowPublicUpload' => 'yes',
'allowResharing' => 'yes',
'allowShareDialogUserEnumeration' => 'yes',
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
'restrictUserEnumerationFullMatchEmail' => 'yes',
'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
'shareDefaultExpireDateSet' => 'no',
'shareExpireAfterNDays' => '7',
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
'allowLinksExcludeGroups' => '',
'passwordExcludedGroups' => '',
'passwordExcludedGroupsFeatureEnabled' => false,
],
);

$expected = new TemplateResponse(
'settings',
'settings/admin/sharing',
[
'sharingAppEnabled' => true,
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
'allowPublicUpload' => 'yes',
'allowResharing' => 'yes',
'allowShareDialogUserEnumeration' => 'yes',
'restrictUserEnumerationToGroup' => 'no',
'restrictUserEnumerationToPhone' => 'no',
'restrictUserEnumerationFullMatch' => 'yes',
'restrictUserEnumerationFullMatchUserId' => 'yes',
'restrictUserEnumerationFullMatchEmail' => 'yes',
'restrictUserEnumerationFullMatchIgnoreSecondDN' => 'no',
'enforceLinkPassword' => false,
'onlyShareWithGroupMembers' => false,
'shareAPIEnabled' => 'yes',
'shareDefaultExpireDateSet' => 'no',
'shareExpireAfterNDays' => '7',
'shareEnforceExpireDate' => 'no',
'shareExcludeGroups' => true,
'shareExcludedGroupsList' => 'NoSharers|OtherNoSharers',
'publicShareDisclaimerText' => 'Lorem ipsum',
'enableLinkPasswordByDefault' => 'yes',
'shareApiDefaultPermissions' => Constants::PERMISSION_ALL,
'shareApiDefaultPermissionsCheckboxes' => self::invokePrivate($this->admin, 'getSharePermissionList', []),
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
'allowLinksExcludeGroups' => '',
'passwordExcludedGroups' => '',
'passwordExcludedGroupsFeatureEnabled' => false,
],
[],
''
);

Expand Down

0 comments on commit eee4c3f

Please sign in to comment.