aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Settings/Admin/SharingTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Settings/Admin/SharingTest.php')
-rw-r--r--apps/settings/tests/Settings/Admin/SharingTest.php262
1 files changed, 122 insertions, 140 deletions
diff --git a/apps/settings/tests/Settings/Admin/SharingTest.php b/apps/settings/tests/Settings/Admin/SharingTest.php
index ae98ce6635b..f37ade2171f 100644
--- a/apps/settings/tests/Settings/Admin/SharingTest.php
+++ b/apps/settings/tests/Settings/Admin/SharingTest.php
@@ -1,33 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Settings\Admin;
@@ -36,6 +11,7 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Constants;
+use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -44,49 +20,47 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SharingTest extends TestCase {
- /** @var Sharing */
- private $admin;
- /** @var IConfig */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IManager|MockObject */
- private $shareManager;
- /** @var IAppManager|MockObject */
- private $appManager;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var IInitialState|MockObject */
- private $initialState;
+ private Sharing $admin;
+
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IManager&MockObject $shareManager;
+ private IAppManager&MockObject $appManager;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IInitialState&MockObject $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();
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
- /** @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->shareManager = $this->createMock(IManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->initialState = $this->createMock(IInitialState::class);
$this->admin = new Sharing(
$this->config,
+ $this->appConfig,
$this->l10n,
$this->shareManager,
$this->appManager,
$this->urlGenerator,
$this->initialState,
- "settings",
+ 'settings',
);
}
public function testGetFormWithoutExcludedGroups(): void {
+ $this->appConfig
+ ->method('getValueBool')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_federation_on_public_shares', true],
+ ['core', 'shareapi_enable_link_password_by_default', true],
+ ]);
+
$this->config
->method('getAppValue')
->willReturnMap([
@@ -108,8 +82,7 @@ class SharingTest extends TestCase {
['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
['core', 'shareapi_exclude_groups', 'no', 'no'],
- ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
- ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
+ ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
@@ -124,50 +97,54 @@ class SharingTest extends TestCase {
->willReturn(false);
$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
+
+ $initialStateCalls = [];
$this->initialState
->expects($this->exactly(3))
->method('provideInitialState')
- ->withConsecutive(
- ['sharingAppEnabled', false],
- ['sharingDocumentation', ''],
- [
- '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' => 'no',
- '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,
- 'onlyShareWithGroupMembersExcludeGroupList' => [],
- ]
- ],
- );
+ ->willReturnCallback(function (string $key) use (&$initialStateCalls): void {
+ $initialStateCalls[$key] = func_get_args();
+ });
+
+ $expectedInitialStateCalls = [
+ 'sharingAppEnabled' => false,
+ 'sharingDocumentation' => '',
+ 'sharingSettings' => [
+ 'allowGroupSharing' => true,
+ 'allowLinks' => true,
+ 'allowPublicUpload' => true,
+ 'allowResharing' => true,
+ 'allowShareDialogUserEnumeration' => true,
+ 'allowFederationOnPublicShares' => 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' => 'no',
+ 'excludeGroupsList' => [],
+ 'publicShareDisclaimerText' => 'Lorem ipsum',
+ 'enableLinkPasswordByDefault' => true,
+ 'defaultPermissions' => Constants::PERMISSION_ALL,
+ 'defaultInternalExpireDate' => false,
+ 'internalExpireAfterNDays' => '7',
+ 'enforceInternalExpireDate' => false,
+ 'defaultRemoteExpireDate' => false,
+ 'remoteExpireAfterNDays' => '7',
+ 'enforceRemoteExpireDate' => false,
+ 'allowLinksExcludeGroups' => [],
+ 'onlyShareWithGroupMembersExcludeGroupList' => [],
+ 'enforceLinksPasswordExcludedGroups' => [],
+ 'enforceLinksPasswordExcludedGroupsEnabled' => false,
+ ]
+ ];
$expected = new TemplateResponse(
'settings',
@@ -177,6 +154,7 @@ class SharingTest extends TestCase {
);
$this->assertEquals($expected, $this->admin->getForm());
+ $this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
}
public function testGetFormWithExcludedGroups(): void {
@@ -201,7 +179,7 @@ class SharingTest extends TestCase {
['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
['core', 'shareapi_exclude_groups', 'no', 'yes'],
- ['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'],
+ ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
@@ -217,50 +195,53 @@ class SharingTest extends TestCase {
->willReturn(false);
$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
+
+ $initialStateCalls = [];
$this->initialState
->expects($this->exactly(3))
->method('provideInitialState')
- ->withConsecutive(
- ['sharingAppEnabled', true],
- ['sharingDocumentation', ''],
- [
- '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' => 'yes',
- '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,
- 'onlyShareWithGroupMembersExcludeGroupList' => [],
- ]
- ],
- );
+ ->willReturnCallback(function (string $key) use (&$initialStateCalls): void {
+ $initialStateCalls[$key] = func_get_args();
+ });
+
+ $expectedInitialStateCalls = [
+ 'sharingAppEnabled' => true,
+ 'sharingDocumentation' => '',
+ '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' => 'yes',
+ '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' => [],
+ 'onlyShareWithGroupMembersExcludeGroupList' => [],
+ 'enforceLinksPasswordExcludedGroups' => [],
+ 'enforceLinksPasswordExcludedGroupsEnabled' => false,
+ ],
+ ];
$expected = new TemplateResponse(
'settings',
@@ -270,6 +251,7 @@ class SharingTest extends TestCase {
);
$this->assertEquals($expected, $this->admin->getForm());
+ $this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
}
public function testGetSection(): void {