From 7984b80a764a8c73fb1d4521523b7107fc31a61a Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 21 Nov 2023 14:12:29 +0100 Subject: [PATCH 1/2] Fix sharing settings unit tests Signed-off-by: Louis Chemineau --- .../tests/Settings/Admin/SharingTest.php | 173 +++++++++++------- 1 file changed, 102 insertions(+), 71 deletions(-) diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php index c0b5861f549..2a8a7fed245 100644 --- a/apps/settings/tests/Settings/Admin/SharingTest.php +++ b/apps/settings/tests/Settings/Admin/SharingTest.php @@ -34,9 +34,11 @@ namespace OCA\Settings\Tests\Settings\Admin; 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; @@ -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", ); } @@ -106,45 +123,52 @@ class SharingTest extends TestCase { ->willReturn(false); $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false); + $this->initialState + ->expect($this->once()) + ->method('provideInitialState') + ->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, - ], + [], '' ); @@ -188,45 +212,52 @@ class SharingTest extends TestCase { ->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, - ], + [], '' ); From 281cbbfa97ad9429384118fbb7efac3952a2ddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 21 Nov 2023 17:50:17 +0100 Subject: [PATCH 2/2] Fix tests for apps/settings new section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../tests/Settings/Admin/SharingTest.php | 148 +++++++++--------- 1 file changed, 76 insertions(+), 72 deletions(-) diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php index 2a8a7fed245..b34c4945774 100644 --- a/apps/settings/tests/Settings/Admin/SharingTest.php +++ b/apps/settings/tests/Settings/Admin/SharingTest.php @@ -124,44 +124,46 @@ class SharingTest extends TestCase { $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false); $this->initialState - ->expect($this->once()) + ->expects($this->exactly(3)) ->method('provideInitialState') - ->with( - 'sharingSettings', + ->withConsecutive( + ['sharingAppEnabled', false], + ['sharingDocumentation', ''], [ - '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, + 'sharingSettings', + [ + 'allowGroupSharing' => true, + 'allowLinks' => true, + 'allowPublicUpload' => true, + 'allowResharing' => true, + 'allowShareDialogUserEnumeration' => true, + 'restrictUserEnumerationToGroup' => false, + 'restrictUserEnumerationToPhone' => false, + 'restrictUserEnumerationFullMatch' => true, + 'restrictUserEnumerationFullMatchUserId' => true, + 'restrictUserEnumerationFullMatchEmail' => true, + 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false, + 'enforceLinksPassword' => false, + 'onlyShareWithGroupMembers' => false, + 'enabled' => true, + 'defaultExpireDate' => false, + 'expireAfterNDays' => '7', + 'enforceExpireDate' => false, + 'excludeGroups' => false, + 'excludeGroupsList' => [], + 'publicShareDisclaimerText' => 'Lorem ipsum', + 'enableLinkPasswordByDefault' => true, + 'defaultPermissions' => Constants::PERMISSION_ALL, + 'defaultInternalExpireDate' => false, + 'internalExpireAfterNDays' => '7', + 'enforceInternalExpireDate' => false, + 'defaultRemoteExpireDate' => false, + 'remoteExpireAfterNDays' => '7', + 'enforceRemoteExpireDate' => false, + 'allowLinksExcludeGroups' => [], + 'passwordExcludedGroups' => [], + 'passwordExcludedGroupsFeatureEnabled' => false, + ] ], ); @@ -213,44 +215,46 @@ class SharingTest extends TestCase { $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true); $this->initialState - ->expect($this->once()) + ->expects($this->exactly(3)) ->method('provideInitialState') - ->with( - 'sharingSettings', + ->withConsecutive( + ['sharingAppEnabled', true], + ['sharingDocumentation', ''], [ - '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, + 'sharingSettings', + [ + 'allowGroupSharing' => true, + 'allowLinks' => true, + 'allowPublicUpload' => true, + 'allowResharing' => true, + 'allowShareDialogUserEnumeration' => true, + 'restrictUserEnumerationToGroup' => false, + 'restrictUserEnumerationToPhone' => false, + 'restrictUserEnumerationFullMatch' => true, + 'restrictUserEnumerationFullMatchUserId' => true, + 'restrictUserEnumerationFullMatchEmail' => true, + 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false, + 'enforceLinksPassword' => false, + 'onlyShareWithGroupMembers' => false, + 'enabled' => true, + 'defaultExpireDate' => false, + 'expireAfterNDays' => '7', + 'enforceExpireDate' => false, + 'excludeGroups' => true, + 'excludeGroupsList' => ['NoSharers','OtherNoSharers'], + 'publicShareDisclaimerText' => 'Lorem ipsum', + 'enableLinkPasswordByDefault' => true, + 'defaultPermissions' => Constants::PERMISSION_ALL, + 'defaultInternalExpireDate' => false, + 'internalExpireAfterNDays' => '7', + 'enforceInternalExpireDate' => false, + 'defaultRemoteExpireDate' => false, + 'remoteExpireAfterNDays' => '7', + 'enforceRemoteExpireDate' => false, + 'allowLinksExcludeGroups' => [], + 'passwordExcludedGroups' => [], + 'passwordExcludedGroupsFeatureEnabled' => false, + ] ], );