aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests')
-rw-r--r--apps/settings/tests/Activity/SecurityFilterTest.php47
-rw-r--r--apps/settings/tests/Activity/SecurityProviderTest.php66
-rw-r--r--apps/settings/tests/Activity/SecuritySettingTest.php39
-rw-r--r--apps/settings/tests/AppInfo/ApplicationTest.php46
-rw-r--r--apps/settings/tests/Controller/AdminSettingsControllerTest.php79
-rw-r--r--apps/settings/tests/Controller/AppSettingsControllerTest.php90
-rw-r--r--apps/settings/tests/Controller/AuthSettingsControllerTest.php119
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php118
-rw-r--r--apps/settings/tests/Controller/DelegationControllerTest.php47
-rw-r--r--apps/settings/tests/Controller/MailSettingsControllerTest.php119
-rw-r--r--apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php40
-rw-r--r--apps/settings/tests/Controller/UsersControllerTest.php279
-rw-r--r--apps/settings/tests/Mailer/NewUserMailHelperTest.php243
-rw-r--r--apps/settings/tests/Middleware/SubadminMiddlewareTest.php124
-rw-r--r--apps/settings/tests/Settings/Admin/MailTest.php67
-rw-r--r--apps/settings/tests/Settings/Admin/SecurityTest.php66
-rw-r--r--apps/settings/tests/Settings/Admin/ServerTest.php65
-rw-r--r--apps/settings/tests/Settings/Admin/SharingTest.php262
-rw-r--r--apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php105
-rw-r--r--apps/settings/tests/Settings/Personal/Security/PasswordTest.php36
-rw-r--r--apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php30
-rw-r--r--apps/settings/tests/SetupChecks/CodeIntegrityTest.php134
-rw-r--r--apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php69
-rw-r--r--apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php33
-rw-r--r--apps/settings/tests/SetupChecks/LoggingLevelTest.php76
-rw-r--r--apps/settings/tests/SetupChecks/OcxProvicersTest.php27
-rw-r--r--apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php26
-rw-r--r--apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php26
-rw-r--r--apps/settings/tests/SetupChecks/SecurityHeadersTest.php62
-rw-r--r--apps/settings/tests/SetupChecks/SupportedDatabaseTest.php40
-rw-r--r--apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php73
-rw-r--r--apps/settings/tests/SetupChecks/WellKnownUrlsTest.php44
-rw-r--r--apps/settings/tests/UserMigration/AccountMigratorTest.php86
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex-config.json2
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex.jpgbin1063519 -> 1040846 bytes
-rw-r--r--apps/settings/tests/UserMigration/assets/account-complex.json2
-rw-r--r--apps/settings/tests/UserMigration/assets/account-config.json2
-rw-r--r--apps/settings/tests/UserMigration/assets/account.json2
-rw-r--r--apps/settings/tests/UserMigration/assets/account.pngbin913877 -> 451063 bytes
39 files changed, 1240 insertions, 1551 deletions
diff --git a/apps/settings/tests/Activity/SecurityFilterTest.php b/apps/settings/tests/Activity/SecurityFilterTest.php
index 6903cf5f3c2..b07c1e825b4 100644
--- a/apps/settings/tests/Activity/SecurityFilterTest.php
+++ b/apps/settings/tests/Activity/SecurityFilterTest.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
@@ -30,15 +13,9 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SecurityFilterTest extends TestCase {
-
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
-
- /** @var IL10N|MockObject */
- private $l10n;
-
- /** @var SecurityFilter */
- private $filter;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private SecurityFilter $filter;
protected function setUp(): void {
parent::setUp();
@@ -49,15 +26,15 @@ class SecurityFilterTest extends TestCase {
$this->filter = new SecurityFilter($this->urlGenerator, $this->l10n);
}
- public function testAllowedApps() {
+ public function testAllowedApps(): void {
$this->assertEquals([], $this->filter->allowedApps());
}
- public function testFilterTypes() {
+ public function testFilterTypes(): void {
$this->assertEquals(['security'], $this->filter->filterTypes(['comments', 'security']));
}
- public function testGetIcon() {
+ public function testGetIcon(): void {
$this->urlGenerator->expects($this->once())
->method('imagePath')
->with('core', 'actions/password.svg')
@@ -69,11 +46,11 @@ class SecurityFilterTest extends TestCase {
$this->assertEquals('abs/path/to/icon.svg', $this->filter->getIcon());
}
- public function testGetIdentifier() {
+ public function testGetIdentifier(): void {
$this->assertEquals('security', $this->filter->getIdentifier());
}
- public function testGetName() {
+ public function testGetName(): void {
$this->l10n->expects($this->once())
->method('t')
->with('Security')
@@ -81,7 +58,7 @@ class SecurityFilterTest extends TestCase {
$this->assertEquals('translated', $this->filter->getName());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertEquals(30, $this->filter->getPriority());
}
}
diff --git a/apps/settings/tests/Activity/SecurityProviderTest.php b/apps/settings/tests/Activity/SecurityProviderTest.php
index 4499e470c2b..ed9de362a87 100644
--- a/apps/settings/tests/Activity/SecurityProviderTest.php
+++ b/apps/settings/tests/Activity/SecurityProviderTest.php
@@ -1,31 +1,13 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
-use InvalidArgumentException;
use OCA\Settings\Activity\SecurityProvider;
+use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IL10N;
@@ -35,51 +17,41 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SecurityProviderTest extends TestCase {
-
- /** @var IFactory|MockObject */
- private $l10n;
-
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
-
- /** @var IManager|MockObject */
- private $activityManager;
-
- /** @var SecurityProvider */
- private $provider;
+ private IFactory&MockObject $l10nFactory;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IManager&MockObject $activityManager;
+ private SecurityProvider $provider;
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->createMock(IFactory::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->activityManager = $this->createMock(IManager::class);
- $this->provider = new SecurityProvider($this->l10n, $this->urlGenerator, $this->activityManager);
+ $this->provider = new SecurityProvider($this->l10nFactory, $this->urlGenerator, $this->activityManager);
}
- public function testParseUnrelated() {
+ public function testParseUnrelated(): void {
$lang = 'ru';
$event = $this->createMock(IEvent::class);
$event->expects($this->once())
->method('getType')
->willReturn('comments');
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException(UnknownActivityException::class);
$this->provider->parse($lang, $event);
}
- public function subjectData() {
+ public static function subjectData(): array {
return [
['twofactor_success'],
['twofactor_failed'],
];
}
- /**
- * @dataProvider subjectData
- */
- public function testParse($subject) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')]
+ public function testParse(string $subject): void {
$lang = 'ru';
$event = $this->createMock(IEvent::class);
$l = $this->createMock(IL10N::class);
@@ -87,7 +59,7 @@ class SecurityProviderTest extends TestCase {
$event->expects($this->once())
->method('getType')
->willReturn('security');
- $this->l10n->expects($this->once())
+ $this->l10nFactory->expects($this->once())
->method('get')
->with('settings', $lang)
->willReturn($l);
@@ -115,7 +87,7 @@ class SecurityProviderTest extends TestCase {
$this->provider->parse($lang, $event);
}
- public function testParseInvalidSubject() {
+ public function testParseInvalidSubject(): void {
$lang = 'ru';
$l = $this->createMock(IL10N::class);
$event = $this->createMock(IEvent::class);
@@ -123,7 +95,7 @@ class SecurityProviderTest extends TestCase {
$event->expects($this->once())
->method('getType')
->willReturn('security');
- $this->l10n->expects($this->once())
+ $this->l10nFactory->expects($this->once())
->method('get')
->with('settings', $lang)
->willReturn($l);
@@ -131,7 +103,7 @@ class SecurityProviderTest extends TestCase {
->method('getSubject')
->willReturn('unrelated');
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException(UnknownActivityException::class);
$this->provider->parse($lang, $event);
}
}
diff --git a/apps/settings/tests/Activity/SecuritySettingTest.php b/apps/settings/tests/Activity/SecuritySettingTest.php
index 840f228b0c1..ca11e38caa8 100644
--- a/apps/settings/tests/Activity/SecuritySettingTest.php
+++ b/apps/settings/tests/Activity/SecuritySettingTest.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
@@ -30,8 +13,8 @@ use Test\TestCase;
class SecuritySettingTest extends TestCase {
private $l10n;
- /** @var SecuritySetting */
- private $setting;
+ /** @var */
+ private SecuritySetting $setting;
protected function setUp(): void {
parent::setUp();
@@ -41,19 +24,19 @@ class SecuritySettingTest extends TestCase {
$this->setting = new SecuritySetting($this->l10n);
}
- public function testCanChangeMail() {
+ public function testCanChangeMail(): void {
$this->assertFalse($this->setting->canChangeMail());
}
- public function testCanChangeStream() {
+ public function testCanChangeStream(): void {
$this->assertFalse($this->setting->canChangeStream());
}
- public function testGetIdentifier() {
+ public function testGetIdentifier(): void {
$this->assertEquals('security', $this->setting->getIdentifier());
}
- public function testGetName() {
+ public function testGetName(): void {
$this->l10n->expects($this->once())
->method('t')
->with('Security')
@@ -61,11 +44,11 @@ class SecuritySettingTest extends TestCase {
$this->assertEquals('Sicherheit', $this->setting->getName());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertEquals(30, $this->setting->getPriority());
}
- public function testIsDefaultEnabled() {
+ public function testIsDefaultEnabled(): void {
$this->assertTrue($this->setting->isDefaultEnabledMail());
$this->assertTrue($this->setting->isDefaultEnabledStream());
}
diff --git a/apps/settings/tests/AppInfo/ApplicationTest.php b/apps/settings/tests/AppInfo/ApplicationTest.php
index c9b44bda987..3e895d87b06 100644
--- a/apps/settings/tests/AppInfo/ApplicationTest.php
+++ b/apps/settings/tests/AppInfo/ApplicationTest.php
@@ -1,26 +1,9 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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\AppInfo;
@@ -45,11 +28,8 @@ use Test\TestCase;
* @group DB
*/
class ApplicationTest extends TestCase {
- /** @var Application */
- protected $app;
-
- /** @var IAppContainer */
- protected $container;
+ protected Application $app;
+ protected IAppContainer $container;
protected function setUp(): void {
parent::setUp();
@@ -57,12 +37,12 @@ class ApplicationTest extends TestCase {
$this->container = $this->app->getContainer();
}
- public function testContainerAppName() {
+ public function testContainerAppName(): void {
$this->app = new Application();
- $this->assertEquals('settings', $this->container->getAppName());
+ $this->assertEquals('settings', $this->container->get('appName'));
}
- public function dataContainerQuery() {
+ public static function dataContainerQuery(): array {
return [
[AdminSettingsController::class, Controller::class],
[AppSettingsController::class, Controller::class],
@@ -76,12 +56,8 @@ class ApplicationTest extends TestCase {
];
}
- /**
- * @dataProvider dataContainerQuery
- * @param string $service
- * @param string $expected
- */
- public function testContainerQuery($service, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataContainerQuery')]
+ public function testContainerQuery(string $service, string $expected): void {
$this->assertTrue($this->container->query($service) instanceof $expected);
}
}
diff --git a/apps/settings/tests/Controller/AdminSettingsControllerTest.php b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
index 6a11ceb9fca..fbdc506457b 100644
--- a/apps/settings/tests/Controller/AdminSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AdminSettingsControllerTest.php
@@ -1,28 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jan C. Borchardt <hey@jancborchardt.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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\Controller;
@@ -35,7 +15,9 @@ use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IUser;
+use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Server;
use OCP\Settings\IDeclarativeManager;
use OCP\Settings\IManager;
use PHPUnit\Framework\MockObject\MockObject;
@@ -50,26 +32,17 @@ use Test\TestCase;
*/
class AdminSettingsControllerTest extends TestCase {
- /** @var AdminSettingsController */
- private $adminSettingsController;
- /** @var IRequest|MockObject */
- private $request;
- /** @var INavigationManager|MockObject */
- private $navigationManager;
- /** @var IManager|MockObject */
- private $settingsManager;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IGroupManager|MockObject */
- private $groupManager;
- /** @var ISubAdmin|MockObject */
- private $subAdmin;
- /** @var IDeclarativeManager|MockObject */
- private $declarativeSettingsManager;
- /** @var IInitialState|MockObject */
- private $initialState;
- /** @var string */
- private $adminUid = 'lololo';
+ private IRequest&MockObject $request;
+ private INavigationManager&MockObject $navigationManager;
+ private IManager&MockObject $settingsManager;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+ private ISubAdmin&MockObject $subAdmin;
+ private IDeclarativeManager&MockObject $declarativeSettingsManager;
+ private IInitialState&MockObject $initialState;
+
+ private string $adminUid = 'lololo';
+ private AdminSettingsController $adminSettingsController;
protected function setUp(): void {
parent::setUp();
@@ -95,18 +68,22 @@ class AdminSettingsControllerTest extends TestCase {
$this->initialState,
);
- $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'mylongrandompassword');
+ $user = Server::get(IUserManager::class)->createUser($this->adminUid, 'mylongrandompassword');
\OC_User::setUserId($user->getUID());
- \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
+ Server::get(IGroupManager::class)->createGroup('admin')->addUser($user);
}
protected function tearDown(): void {
- \OC::$server->getUserManager()->get($this->adminUid)->delete();
+ Server::get(IUserManager::class)
+ ->get($this->adminUid)
+ ->delete();
+ \OC_User::setUserId(null);
+ Server::get(IUserSession::class)->setUser(null);
parent::tearDown();
}
- public function testIndex() {
+ public function testIndex(): void {
$user = $this->createMock(IUser::class);
$this->userSession
->method('getUser')
@@ -120,6 +97,12 @@ class AdminSettingsControllerTest extends TestCase {
->method('isSubAdmin')
->with($user)
->willReturn(false);
+
+ $form = new TemplateResponse('settings', 'settings/empty');
+ $setting = $this->createMock(ServerDevNotice::class);
+ $setting->expects(self::any())
+ ->method('getForm')
+ ->willReturn($form);
$this->settingsManager
->expects($this->once())
->method('getAdminSections')
@@ -132,7 +115,7 @@ class AdminSettingsControllerTest extends TestCase {
->expects($this->once())
->method('getAllowedAdminSettings')
->with('test')
- ->willReturn([5 => $this->createMock(ServerDevNotice::class)]);
+ ->willReturn([5 => [$setting]]);
$this->declarativeSettingsManager
->expects($this->any())
->method('getFormIDs')
diff --git a/apps/settings/tests/Controller/AppSettingsControllerTest.php b/apps/settings/tests/Controller/AppSettingsControllerTest.php
index 25f2431ee77..392bb7b561d 100644
--- a/apps/settings/tests/Controller/AppSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AppSettingsControllerTest.php
@@ -1,40 +1,19 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Settings\Tests\Controller;
+use OC\App\AppManager;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\App\AppStore\Fetcher\AppDiscoverFetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\Installer;
use OCA\Settings\Controller\AppSettingsController;
-use OCP\App\IAppManager;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
@@ -59,40 +38,23 @@ use Test\TestCase;
* @group DB
*/
class AppSettingsControllerTest extends TestCase {
- /** @var AppSettingsController */
- private $appSettingsController;
- /** @var IRequest|MockObject */
- private $request;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IConfig|MockObject */
- private $config;
- /** @var INavigationManager|MockObject */
- private $navigationManager;
- /** @var IAppManager|MockObject */
- private $appManager;
- /** @var CategoryFetcher|MockObject */
- private $categoryFetcher;
- /** @var AppFetcher|MockObject */
- private $appFetcher;
- /** @var IFactory|MockObject */
- private $l10nFactory;
- /** @var BundleFetcher|MockObject */
- private $bundleFetcher;
- /** @var Installer|MockObject */
- private $installer;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var LoggerInterface|MockObject */
- private $logger;
- /** @var IInitialState|MockObject */
- private $initialState;
- /** @var IAppDataFactory|MockObject */
- private $appDataFactory;
- /** @var AppDiscoverFetcher|MockObject */
- private $discoverFetcher;
- /** @var IClientService|MockObject */
- private $clientService;
+ private IRequest&MockObject $request;
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private INavigationManager&MockObject $navigationManager;
+ private AppManager&MockObject $appManager;
+ private CategoryFetcher&MockObject $categoryFetcher;
+ private AppFetcher&MockObject $appFetcher;
+ private IFactory&MockObject $l10nFactory;
+ private BundleFetcher&MockObject $bundleFetcher;
+ private Installer&MockObject $installer;
+ private IURLGenerator&MockObject $urlGenerator;
+ private LoggerInterface&MockObject $logger;
+ private IInitialState&MockObject $initialState;
+ private IAppDataFactory&MockObject $appDataFactory;
+ private AppDiscoverFetcher&MockObject $discoverFetcher;
+ private IClientService&MockObject $clientService;
+ private AppSettingsController $appSettingsController;
protected function setUp(): void {
parent::setUp();
@@ -105,7 +67,7 @@ class AppSettingsControllerTest extends TestCase {
->willReturnArgument(0);
$this->config = $this->createMock(IConfig::class);
$this->navigationManager = $this->createMock(INavigationManager::class);
- $this->appManager = $this->createMock(IAppManager::class);
+ $this->appManager = $this->createMock(AppManager::class);
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
$this->appFetcher = $this->createMock(AppFetcher::class);
$this->l10nFactory = $this->createMock(IFactory::class);
@@ -138,7 +100,7 @@ class AppSettingsControllerTest extends TestCase {
);
}
- public function testListCategories() {
+ public function testListCategories(): void {
$this->installer->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
@@ -193,7 +155,7 @@ class AppSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->appSettingsController->listCategories());
}
- public function testViewApps() {
+ public function testViewApps(): void {
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
$this->installer->expects($this->any())
->method('isUpdateAvailable')
@@ -226,7 +188,7 @@ class AppSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->appSettingsController->viewApps());
}
- public function testViewAppsAppstoreNotEnabled() {
+ public function testViewAppsAppstoreNotEnabled(): void {
$this->installer->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
index b744b942e09..d195dbf83d3 100644
--- a/apps/settings/tests/Controller/AuthSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
@@ -1,31 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Fabrizio Steiner <fabrizio.steiner@gmail.com>
- * @author Greta Doci <gretadoci@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sergej Nikolaev <kinolaev@gmail.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Settings\Controller;
@@ -51,24 +29,15 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class AuthSettingsControllerTest extends TestCase {
-
- /** @var AuthSettingsController */
- private $controller;
- /** @var IRequest|MockObject */
- private $request;
- /** @var IProvider|MockObject */
- private $tokenProvider;
- /** @var ISession|MockObject */
- private $session;
- /**@var IUserSession|MockObject */
- private $userSession;
- /** @var ISecureRandom|MockObject */
- private $secureRandom;
- /** @var IManager|MockObject */
- private $activityManager;
- /** @var RemoteWipe|MockObject */
- private $remoteWipe;
- private $uid = 'jane';
+ private IRequest&MockObject $request;
+ private IProvider&MockObject $tokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private ISecureRandom&MockObject $secureRandom;
+ private IManager&MockObject $activityManager;
+ private RemoteWipe&MockObject $remoteWipe;
+ private string $uid = 'jane';
+ private AuthSettingsController $controller;
protected function setUp(): void {
parent::setUp();
@@ -80,7 +49,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->activityManager = $this->createMock(IManager::class);
$this->remoteWipe = $this->createMock(RemoteWipe::class);
- /** @var LoggerInterface|MockObject $logger */
+ /** @var LoggerInterface&MockObject $logger */
$logger = $this->createMock(LoggerInterface::class);
$this->controller = new AuthSettingsController(
@@ -97,7 +66,7 @@ class AuthSettingsControllerTest extends TestCase {
);
}
- public function testCreate() {
+ public function testCreate(): void {
$name = 'Nexus 4';
$sessionToken = $this->createMock(IToken::class);
$deviceToken = $this->createMock(IToken::class);
@@ -146,12 +115,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $response->getData());
}
- public function testCreateSessionNotAvailable() {
+ public function testCreateSessionNotAvailable(): void {
$name = 'personal phone';
$this->session->expects($this->once())
->method('getId')
- ->will($this->throwException(new SessionNotAvailableException()));
+ ->willThrowException(new SessionNotAvailableException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -159,7 +128,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testCreateInvalidToken() {
+ public function testCreateInvalidToken(): void {
$name = 'Company IPhone';
$this->session->expects($this->once())
@@ -168,7 +137,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('sessionid')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -176,7 +145,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testDestroy() {
+ public function testDestroy(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -198,7 +167,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals([], $this->controller->destroy($tokenId));
}
- public function testDestroyExpired() {
+ public function testDestroyExpired(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -222,7 +191,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->destroy($tokenId));
}
- public function testDestroyWrongUser() {
+ public function testDestroyWrongUser(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -237,19 +206,14 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function dataRenameToken(): array {
+ public static function dataRenameToken(): array {
return [
'App password => Other token name' => ['App password', 'Other token name'],
'Other token name => App password' => ['Other token name', 'App password'],
];
}
- /**
- * @dataProvider dataRenameToken
- *
- * @param string $name
- * @param string $newName
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenameToken')]
public function testUpdateRename(string $name, string $newName): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -267,7 +231,7 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => true]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
$token->expects($this->once())
->method('setName')
@@ -277,22 +241,17 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], $newName));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], $newName));
}
- public function dataUpdateFilesystemScope(): array {
+ public static function dataUpdateFilesystemScope(): array {
return [
'Grant filesystem access' => [false, true],
'Revoke filesystem access' => [true, false],
];
}
- /**
- * @dataProvider dataUpdateFilesystemScope
- *
- * @param bool $filesystem
- * @param bool $newFilesystem
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateFilesystemScope')]
public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -310,17 +269,17 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => $filesystem]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => $filesystem]);
$token->expects($this->once())
->method('setScope')
- ->with($this->equalTo(['filesystem' => $newFilesystem]));
+ ->with($this->equalTo([IToken::SCOPE_FILESYSTEM => $newFilesystem]));
$this->tokenProvider->expects($this->once())
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => $newFilesystem], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => $newFilesystem], 'App password'));
}
public function testUpdateNoChange(): void {
@@ -339,7 +298,7 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => true]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
$token->expects($this->never())
->method('setName');
@@ -351,10 +310,10 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateExpired() {
+ public function testUpdateExpired(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -371,10 +330,10 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateTokenWrongUser() {
+ public function testUpdateTokenWrongUser(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -389,12 +348,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->never())
->method('updateToken');
- $response = $this->controller->update($tokenId, ['filesystem' => true], 'App password');
+ $response = $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password');
$this->assertSame([], $response->getData());
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function testUpdateTokenNonExisting() {
+ public function testUpdateTokenNonExisting(): void {
$this->tokenProvider->expects($this->once())
->method('getTokenById')
->with($this->equalTo(42))
@@ -403,7 +362,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->never())
->method('updateToken');
- $response = $this->controller->update(42, ['filesystem' => true], 'App password');
+ $response = $this->controller->update(42, [IToken::SCOPE_FILESYSTEM => true], 'App password');
$this->assertSame([], $response->getData());
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index 0f3771b27f7..a8e89260573 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -1,36 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- *
- * @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 John Molakvoæ <skjnldsv@protonmail.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Weimann <mail@michael-weimann.eu>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author nhirokinet <nhirokinet@nhiroki.net>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sylvia van Os <sylvia@hackerchick.me>
- * @author Timo Förster <tfoerster@webfoersterei.de>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Settings\Tests\Controller;
@@ -56,62 +29,43 @@ use Test\TestCase;
* @package Tests\Settings\Controller
*/
class CheckSetupControllerTest extends TestCase {
- /** @var CheckSetupController | \PHPUnit\Framework\MockObject\MockObject */
- private $checkSetupController;
- /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
- private $request;
- /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
- /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
- private $l10n;
- /** @var LoggerInterface */
- private $logger;
- /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
- private $checker;
- /** @var ISetupCheckManager|MockObject */
- private $setupCheckManager;
+ private IRequest&MockObject $request;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private LoggerInterface&MockObject $logger;
+ private Checker&MockObject $checker;
+ private ISetupCheckManager&MockObject $setupCheckManager;
+ private CheckSetupController $checkSetupController;
protected function setUp(): void {
parent::setUp();
- $this->request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()->getMock();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()->getMock();
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
- ->disableOriginalConstructor()->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
return vsprintf($message, $replace);
});
- $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
- ->disableOriginalConstructor()->getMock();
- $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
+ $this->checker = $this->createMock(Checker::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->setupCheckManager = $this->createMock(ISetupCheckManager::class);
- $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
- ->setConstructorArgs([
- 'settings',
- $this->request,
- $this->config,
- $this->urlGenerator,
- $this->l10n,
- $this->checker,
- $this->logger,
- $this->setupCheckManager,
- ])
- ->setMethods([
- 'getCurlVersion',
- 'isPhpOutdated',
- 'isPHPMailerUsed',
- ])->getMock();
+ $this->checkSetupController = new CheckSetupController(
+ 'settings',
+ $this->request,
+ $this->config,
+ $this->urlGenerator,
+ $this->l10n,
+ $this->checker,
+ $this->logger,
+ $this->setupCheckManager,
+ );
}
- public function testCheck() {
+ public function testCheck(): void {
$this->config->expects($this->any())
->method('getAppValue')
->willReturnMap([
@@ -169,7 +123,7 @@ class CheckSetupControllerTest extends TestCase {
$this->assertEquals($expected, $this->checkSetupController->check());
}
- public function testRescanFailedIntegrityCheck() {
+ public function testRescanFailedIntegrityCheck(): void {
$this->checker
->expects($this->once())
->method('runInstanceVerification');
@@ -183,7 +137,7 @@ class CheckSetupControllerTest extends TestCase {
$this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck());
}
- public function testGetFailedIntegrityCheckDisabled() {
+ public function testGetFailedIntegrityCheckDisabled(): void {
$this->checker
->expects($this->once())
->method('isCodeCheckEnforced')
@@ -194,7 +148,7 @@ class CheckSetupControllerTest extends TestCase {
}
- public function testGetFailedIntegrityCheckFilesWithNoErrorsFound() {
+ public function testGetFailedIntegrityCheckFilesWithNoErrorsFound(): void {
$this->checker
->expects($this->once())
->method('isCodeCheckEnforced')
@@ -214,15 +168,15 @@ class CheckSetupControllerTest extends TestCase {
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
}
- public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
+ public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound(): void {
$this->checker
->expects($this->once())
->method('isCodeCheckEnforced')
->willReturn(true);
$this->checker
- ->expects($this->once())
- ->method('getResults')
- ->willReturn([ 'core' => [ 'EXTRA_FILE' => ['/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'sketch' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'threatblock' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'two_factor_auth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_ldap' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_shibboleth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], ]);
+ ->expects($this->once())
+ ->method('getResults')
+ ->willReturn([ 'core' => [ 'EXTRA_FILE' => ['/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'sketch' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'threatblock' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'two_factor_auth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_ldap' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_shibboleth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], ]);
$expected = new DataDisplayResponse(
'Technical information
diff --git a/apps/settings/tests/Controller/DelegationControllerTest.php b/apps/settings/tests/Controller/DelegationControllerTest.php
index 64157427fa4..c4cbe67466b 100644
--- a/apps/settings/tests/Controller/DelegationControllerTest.php
+++ b/apps/settings/tests/Controller/DelegationControllerTest.php
@@ -1,56 +1,33 @@
<?php
+
/**
- * @copyright Copyright (c) 2021 Nextcloud GmbH
- *
- * @author Carl Schwan <carl@carlschwan.eu>
- *
- * @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 <https://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
-
namespace OCA\Settings\Tests\Controller\Admin;
use OC\Settings\AuthorizedGroup;
use OCA\Settings\Controller\AuthorizedGroupController;
use OCA\Settings\Service\AuthorizedGroupService;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class DelegationControllerTest extends TestCase {
-
- /** @var AuthorizedGroupService */
- private $service;
-
- /** @var IRequest */
- private $request;
-
- /** @var AuthorizedGroupController */
- private $controller;
+ private AuthorizedGroupService&MockObject $service;
+ private IRequest&MockObject $request;
+ private AuthorizedGroupController $controller;
protected function setUp(): void {
parent::setUp();
- $this->request = $this->getMockBuilder(IRequest::class)->getMock();
- $this->service = $this->getMockBuilder(AuthorizedGroupService::class)->disableOriginalConstructor()->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->service = $this->createMock(AuthorizedGroupService::class);
$this->controller = new AuthorizedGroupController(
'settings', $this->request, $this->service
);
}
- public function testSaveSettings() {
+ public function testSaveSettings(): void {
$setting = 'MySecretSetting';
$oldGroups = [];
$oldGroups[] = AuthorizedGroup::fromParams(['groupId' => 'hello', 'class' => $setting]);
@@ -59,7 +36,7 @@ class DelegationControllerTest extends TestCase {
$this->service->expects($this->once())
->method('findExistingGroupsForClass')
->with('MySecretSetting')
- ->will($this->returnValue($oldGroups));
+ ->willReturn($oldGroups);
$this->service->expects($this->once())
->method('delete')
@@ -68,7 +45,7 @@ class DelegationControllerTest extends TestCase {
$this->service->expects($this->once())
->method('create')
->with('world', 'MySecretSetting')
- ->will($this->returnValue(AuthorizedGroup::fromParams(['groupId' => 'world', 'class' => $setting])));
+ ->willReturn(AuthorizedGroup::fromParams(['groupId' => 'world', 'class' => $setting]));
$result = $this->controller->saveSettings([['gid' => 'hello'], ['gid' => 'world']], 'MySecretSetting');
diff --git a/apps/settings/tests/Controller/MailSettingsControllerTest.php b/apps/settings/tests/Controller/MailSettingsControllerTest.php
index 3918d4b5fa9..1bc05ca4718 100644
--- a/apps/settings/tests/Controller/MailSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/MailSettingsControllerTest.php
@@ -1,30 +1,9 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright 2014 Lukas Reschke lukas@nextcloud.com
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @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 Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Controller;
@@ -39,25 +18,18 @@ use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @package Tests\Settings\Controller
*/
class MailSettingsControllerTest extends \Test\TestCase {
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
- /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
- private $mailer;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l;
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var MailSettingsController */
- private $mailController;
+ private IConfig&MockObject $config;
+ private IUserSession&MockObject $userSession;
+ private IMailer&MockObject $mailer;
+ private IL10N&MockObject $l;
+ private IURLGenerator&MockObject $urlGenerator;
+ private MailSettingsController $mailController;
protected function setUp(): void {
parent::setUp();
@@ -67,7 +39,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->mailer = $this->createMock(IMailer::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject $request */
+ /** @var IRequest&MockObject $request */
$request = $this->createMock(IRequest::class);
$this->mailController = new MailSettingsController(
'settings',
@@ -77,37 +49,40 @@ class MailSettingsControllerTest extends \Test\TestCase {
$this->userSession,
$this->urlGenerator,
$this->mailer,
- 'no-reply@nextcloud.com'
);
}
- public function testSetMailSettings() {
+ public function testSetMailSettings(): void {
+ $calls = [
+ [[
+ 'mail_domain' => 'nextcloud.com',
+ 'mail_from_address' => 'demo@nextcloud.com',
+ 'mail_smtpmode' => 'smtp',
+ 'mail_smtpsecure' => 'ssl',
+ 'mail_smtphost' => 'mx.nextcloud.org',
+ 'mail_smtpauth' => 1,
+ 'mail_smtpport' => '25',
+ 'mail_sendmailmode' => 'smtp',
+ ]],
+ [[
+ 'mail_domain' => 'nextcloud.com',
+ 'mail_from_address' => 'demo@nextcloud.com',
+ 'mail_smtpmode' => 'smtp',
+ 'mail_smtpsecure' => 'ssl',
+ 'mail_smtphost' => 'mx.nextcloud.org',
+ 'mail_smtpauth' => null,
+ 'mail_smtpport' => '25',
+ 'mail_smtpname' => null,
+ 'mail_smtppassword' => null,
+ 'mail_sendmailmode' => 'smtp',
+ ]],
+ ];
$this->config->expects($this->exactly(2))
->method('setSystemValues')
- ->withConsecutive(
- [[
- 'mail_domain' => 'nextcloud.com',
- 'mail_from_address' => 'demo@nextcloud.com',
- 'mail_smtpmode' => 'smtp',
- 'mail_smtpsecure' => 'ssl',
- 'mail_smtphost' => 'mx.nextcloud.org',
- 'mail_smtpauth' => 1,
- 'mail_smtpport' => '25',
- 'mail_sendmailmode' => null,
- ]],
- [[
- 'mail_domain' => 'nextcloud.com',
- 'mail_from_address' => 'demo@nextcloud.com',
- 'mail_smtpmode' => 'smtp',
- 'mail_smtpsecure' => 'ssl',
- 'mail_smtphost' => 'mx.nextcloud.org',
- 'mail_smtpauth' => null,
- 'mail_smtpport' => '25',
- 'mail_smtpname' => null,
- 'mail_smtppassword' => null,
- 'mail_sendmailmode' => null,
- ]]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
// With authentication
$response = $this->mailController->setMailSettings(
@@ -116,9 +91,9 @@ class MailSettingsControllerTest extends \Test\TestCase {
'smtp',
'ssl',
'mx.nextcloud.org',
- 1,
+ '1',
'25',
- null
+ 'smtp'
);
$this->assertSame(Http::STATUS_OK, $response->getStatus());
@@ -129,14 +104,14 @@ class MailSettingsControllerTest extends \Test\TestCase {
'smtp',
'ssl',
'mx.nextcloud.org',
- 0,
+ '0',
'25',
- null
+ 'smtp'
);
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}
- public function testStoreCredentials() {
+ public function testStoreCredentials(): void {
$this->config
->expects($this->once())
->method('setSystemValues')
@@ -149,7 +124,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}
- public function testSendTestMail() {
+ public function testSendTestMail(): void {
$user = $this->createMock(User::class);
$user->expects($this->any())
->method('getUID')
diff --git a/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php b/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php
index a19db6a3380..9f8d53d4f9f 100644
--- a/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/TwoFactorSettingsControllerTest.php
@@ -1,25 +1,9 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Controller;
@@ -32,15 +16,9 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class TwoFactorSettingsControllerTest extends TestCase {
-
- /** @var IRequest|MockObject */
- private $request;
-
- /** @var MandatoryTwoFactor|MockObject */
- private $mandatoryTwoFactor;
-
- /** @var TwoFactorSettingsController */
- private $controller;
+ private IRequest&MockObject $request;
+ private MandatoryTwoFactor&MockObject $mandatoryTwoFactor;
+ private TwoFactorSettingsController $controller;
protected function setUp(): void {
parent::setUp();
@@ -55,7 +33,7 @@ class TwoFactorSettingsControllerTest extends TestCase {
);
}
- public function testIndex() {
+ public function testIndex(): void {
$state = new EnforcementState(true);
$this->mandatoryTwoFactor->expects($this->once())
->method('getState')
@@ -67,7 +45,7 @@ class TwoFactorSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $resp);
}
- public function testUpdate() {
+ public function testUpdate(): void {
$state = new EnforcementState(true);
$this->mandatoryTwoFactor->expects($this->once())
->method('setState')
diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php
index d74f97b7013..1012557bfc4 100644
--- a/apps/settings/tests/Controller/UsersControllerTest.php
+++ b/apps/settings/tests/Controller/UsersControllerTest.php
@@ -1,32 +1,10 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright 2014-2015 Lukas Reschke lukas@owncloud.com
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @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: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2014-2015 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Controller;
@@ -64,38 +42,22 @@ use PHPUnit\Framework\MockObject\MockObject;
* @package Tests\Settings\Controller
*/
class UsersControllerTest extends \Test\TestCase {
- /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
- private $groupManager;
- /** @var UserManager|\PHPUnit\Framework\MockObject\MockObject */
- private $userManager;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
- private $mailer;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $l10nFactory;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
- private $appManager;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l;
- /** @var AccountManager|\PHPUnit\Framework\MockObject\MockObject */
- private $accountManager;
- /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
- private $jobList;
- /** @var \OC\Security\IdentityProof\Manager|\PHPUnit\Framework\MockObject\MockObject */
- private $securityManager;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $encryptionManager;
- /** @var KnownUserService|\PHPUnit\Framework\MockObject\MockObject */
- private $knownUserService;
- /** @var IEncryptionModule|\PHPUnit\Framework\MockObject\MockObject */
- private $encryptionModule;
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $dispatcher;
- /** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject*/
- private $initialState;
+ private IGroupManager&MockObject $groupManager;
+ private UserManager&MockObject $userManager;
+ private IUserSession&MockObject $userSession;
+ private IConfig&MockObject $config;
+ private IMailer&MockObject $mailer;
+ private IFactory&MockObject $l10nFactory;
+ private IAppManager&MockObject $appManager;
+ private IL10N&MockObject $l;
+ private AccountManager&MockObject $accountManager;
+ private IJobList&MockObject $jobList;
+ private \OC\Security\IdentityProof\Manager&MockObject $securityManager;
+ private IManager&MockObject $encryptionManager;
+ private KnownUserService&MockObject $knownUserService;
+ private IEncryptionModule&MockObject $encryptionModule;
+ private IEventDispatcher&MockObject $dispatcher;
+ private IInitialState&MockObject $initialState;
protected function setUp(): void {
parent::setUp();
@@ -109,7 +71,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->l10nFactory = $this->createMock(IFactory::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->accountManager = $this->createMock(AccountManager::class);
- $this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock();
+ $this->securityManager = $this->createMock(\OC\Security\IdentityProof\Manager::class);
$this->jobList = $this->createMock(IJobList::class);
$this->encryptionManager = $this->createMock(IManager::class);
$this->knownUserService = $this->createMock(KnownUserService::class);
@@ -130,9 +92,9 @@ class UsersControllerTest extends \Test\TestCase {
/**
* @param bool $isAdmin
- * @return UsersController | \PHPUnit\Framework\MockObject\MockObject
+ * @return UsersController|MockObject
*/
- protected function getController($isAdmin = false, $mockedMethods = []) {
+ protected function getController(bool $isAdmin = false, array $mockedMethods = []) {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn($isAdmin);
@@ -179,7 +141,9 @@ class UsersControllerTest extends \Test\TestCase {
$this->dispatcher,
$this->initialState,
]
- )->onlyMethods($mockedMethods)->getMock();
+ )
+ ->onlyMethods($mockedMethods)
+ ->getMock();
}
}
@@ -201,7 +165,7 @@ class UsersControllerTest extends \Test\TestCase {
return $property;
}
- protected function getDefaultAccountMock(bool $useDefaultValues = true): MockObject {
+ protected function getDefaultAccountMock(): MockObject {
$propertyMocks = [
IAccountManager::PROPERTY_DISPLAYNAME => $this->buildPropertyMock(
IAccountManager::PROPERTY_DISPLAYNAME,
@@ -238,9 +202,24 @@ class UsersControllerTest extends \Test\TestCase {
'Default twitter',
IAccountManager::SCOPE_LOCAL,
),
+ IAccountManager::PROPERTY_BLUESKY => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_BLUESKY,
+ 'Default bluesky',
+ IAccountManager::SCOPE_LOCAL,
+ ),
IAccountManager::PROPERTY_FEDIVERSE => $this->buildPropertyMock(
IAccountManager::PROPERTY_FEDIVERSE,
- 'Default twitter',
+ 'Default fediverse',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_BIRTHDATE => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_BIRTHDATE,
+ 'Default birthdate',
+ IAccountManager::SCOPE_LOCAL,
+ ),
+ IAccountManager::PROPERTY_PRONOUNS => $this->buildPropertyMock(
+ IAccountManager::PROPERTY_PRONOUNS,
+ 'Default pronouns',
IAccountManager::SCOPE_LOCAL,
),
];
@@ -261,14 +240,8 @@ class UsersControllerTest extends \Test\TestCase {
return $account;
}
- /**
- * @dataProvider dataTestSetUserSettings
- *
- * @param string $email
- * @param bool $validEmail
- * @param $expectedStatus
- */
- public function testSetUserSettings($email, $validEmail, $expectedStatus) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettings')]
+ public function testSetUserSettings(string $email, bool $validEmail, int $expectedStatus): void {
$controller = $this->getController(false, ['saveUserSettings']);
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('johndoe');
@@ -294,7 +267,7 @@ class UsersControllerTest extends \Test\TestCase {
$controller->expects($this->never())->method('saveUserSettings');
}
- $result = $controller->setUserSettings(//
+ $result = $controller->setUserSettings(
AccountManager::SCOPE_FEDERATED,
'displayName',
AccountManager::SCOPE_FEDERATED,
@@ -307,13 +280,19 @@ class UsersControllerTest extends \Test\TestCase {
'street and city',
AccountManager::SCOPE_FEDERATED,
'@nextclouders',
- AccountManager::SCOPE_FEDERATED
+ AccountManager::SCOPE_FEDERATED,
+ '@nextclouders',
+ AccountManager::SCOPE_FEDERATED,
+ '2020-01-01',
+ AccountManager::SCOPE_FEDERATED,
+ 'they/them',
+ AccountManager::SCOPE_FEDERATED,
);
$this->assertSame($expectedStatus, $result->getStatus());
}
- public function dataTestSetUserSettings() {
+ public static function dataTestSetUserSettings(): array {
return [
['', true, Http::STATUS_OK],
['', false, Http::STATUS_OK],
@@ -322,7 +301,7 @@ class UsersControllerTest extends \Test\TestCase {
];
}
- public function testSetUserSettingsWhenUserDisplayNameChangeNotAllowed() {
+ public function testSetUserSettingsWhenUserDisplayNameChangeNotAllowed(): void {
$controller = $this->getController(false, ['saveUserSettings']);
$avatarScope = IAccountManager::SCOPE_PUBLISHED;
@@ -340,6 +319,10 @@ class UsersControllerTest extends \Test\TestCase {
$twitterScope = IAccountManager::SCOPE_PUBLISHED;
$fediverse = '@nextclouders@floss.social';
$fediverseScope = IAccountManager::SCOPE_PUBLISHED;
+ $birtdate = '2020-01-01';
+ $birthdateScope = IAccountManager::SCOPE_PUBLISHED;
+ $pronouns = 'she/her';
+ $pronounsScope = IAccountManager::SCOPE_PUBLISHED;
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('johndoe');
@@ -416,11 +399,15 @@ class UsersControllerTest extends \Test\TestCase {
$twitter,
$twitterScope,
$fediverse,
- $fediverseScope
+ $fediverseScope,
+ $birtdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
);
}
- public function testSetUserSettingsWhenFederatedFilesharingNotEnabled() {
+ public function testSetUserSettingsWhenFederatedFilesharingNotEnabled(): void {
$controller = $this->getController(false, ['saveUserSettings']);
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('johndoe');
@@ -453,8 +440,14 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope = IAccountManager::SCOPE_PUBLISHED;
$twitter = '@nextclouders';
$twitterScope = IAccountManager::SCOPE_PUBLISHED;
+ $bluesky = 'nextclouders.net';
+ $blueskyScope = IAccountManager::SCOPE_PUBLISHED;
$fediverse = '@nextclouders@floss.social';
$fediverseScope = IAccountManager::SCOPE_PUBLISHED;
+ $birthdate = '2020-01-01';
+ $birthdateScope = IAccountManager::SCOPE_PUBLISHED;
+ $pronouns = 'she/her';
+ $pronounsScope = IAccountManager::SCOPE_PUBLISHED;
// All settings are changed (in the past phone, website, address and
// twitter were not changed).
@@ -472,8 +465,14 @@ class UsersControllerTest extends \Test\TestCase {
$expectedProperties[IAccountManager::PROPERTY_ADDRESS]['scope'] = $addressScope;
$expectedProperties[IAccountManager::PROPERTY_TWITTER]['value'] = $twitter;
$expectedProperties[IAccountManager::PROPERTY_TWITTER]['scope'] = $twitterScope;
+ $expectedProperties[IAccountManager::PROPERTY_BLUESKY]['value'] = $bluesky;
+ $expectedProperties[IAccountManager::PROPERTY_BLUESKY]['scope'] = $blueskyScope;
$expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['value'] = $fediverse;
$expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['scope'] = $fediverseScope;
+ $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['value'] = $birthdate;
+ $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['scope'] = $birthdateScope;
+ $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['value'] = $pronouns;
+ $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['scope'] = $pronounsScope;
$this->mailer->expects($this->once())->method('validateMailAddress')
->willReturn(true);
@@ -496,25 +495,26 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope,
$twitter,
$twitterScope,
+ $bluesky,
+ $blueskyScope,
$fediverse,
- $fediverseScope
+ $fediverseScope,
+ $birthdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
);
}
- /**
- * @dataProvider dataTestSetUserSettingsSubset
- *
- * @param string $property
- * @param string $propertyValue
- */
- public function testSetUserSettingsSubset($property, $propertyValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettingsSubset')]
+ public function testSetUserSettingsSubset(string $property, string $propertyValue): void {
$controller = $this->getController(false, ['saveUserSettings']);
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('johndoe');
$this->userSession->method('getUser')->willReturn($user);
- /** @var IAccount|MockObject $userAccount */
+ /** @var IAccount&MockObject $userAccount */
$userAccount = $this->getDefaultAccountMock();
$this->accountManager->expects($this->once())
@@ -535,12 +535,18 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope = ($property === 'addressScope') ? $propertyValue : null;
$twitter = ($property === 'twitter') ? $propertyValue : null;
$twitterScope = ($property === 'twitterScope') ? $propertyValue : null;
+ $bluesky = ($property === 'bluesky') ? $propertyValue : null;
+ $blueskyScope = ($property === 'blueskyScope') ? $propertyValue : null;
$fediverse = ($property === 'fediverse') ? $propertyValue : null;
$fediverseScope = ($property === 'fediverseScope') ? $propertyValue : null;
+ $birthdate = ($property === 'birthdate') ? $propertyValue : null;
+ $birthdateScope = ($property === 'birthdateScope') ? $propertyValue : null;
+ $pronouns = ($property === 'pronouns') ? $propertyValue : null;
+ $pronounsScope = ($property === 'pronounsScope') ? $propertyValue : null;
- /** @var IAccountProperty[]|MockObject[] $expectedProperties */
+ /** @var IAccountProperty[]&MockObject[] $expectedProperties */
$expectedProperties = $userAccount->getProperties();
- $isScope = strrpos($property, 'Scope') === strlen($property) - strlen(5);
+ $isScope = strrpos($property, 'Scope') === strlen($property) - strlen('5');
switch ($property) {
case 'avatarScope':
$propertyId = IAccountManager::PROPERTY_AVATAR;
@@ -569,10 +575,22 @@ class UsersControllerTest extends \Test\TestCase {
case 'twitterScope':
$propertyId = IAccountManager::PROPERTY_TWITTER;
break;
+ case 'bluesky':
+ case 'blueskyScope':
+ $propertyId = IAccountManager::PROPERTY_BLUESKY;
+ break;
case 'fediverse':
case 'fediverseScope':
$propertyId = IAccountManager::PROPERTY_FEDIVERSE;
break;
+ case 'birthdate':
+ case 'birthdateScope':
+ $propertyId = IAccountManager::PROPERTY_BIRTHDATE;
+ break;
+ case 'pronouns':
+ case 'pronounsScope':
+ $propertyId = IAccountManager::PROPERTY_PRONOUNS;
+ break;
default:
$propertyId = '404';
}
@@ -582,7 +600,7 @@ class UsersControllerTest extends \Test\TestCase {
if (!empty($email)) {
$this->mailer->expects($this->once())->method('validateMailAddress')
- ->willReturn(true);
+ ->willReturn(true);
}
$controller->expects($this->once())
@@ -603,12 +621,18 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope,
$twitter,
$twitterScope,
+ $bluesky,
+ $blueskyScope,
$fediverse,
- $fediverseScope
+ $fediverseScope,
+ $birthdate,
+ $birthdateScope,
+ $pronouns,
+ $pronounsScope,
);
}
- public function dataTestSetUserSettingsSubset() {
+ public static function dataTestSetUserSettingsSubset(): array {
return [
['avatarScope', IAccountManager::SCOPE_PUBLISHED],
['displayName', 'Display name'],
@@ -623,22 +647,19 @@ class UsersControllerTest extends \Test\TestCase {
['addressScope', IAccountManager::SCOPE_PUBLISHED],
['twitter', '@nextclouders'],
['twitterScope', IAccountManager::SCOPE_PUBLISHED],
+ ['bluesky', 'nextclouders.net'],
+ ['blueskyScope', IAccountManager::SCOPE_PUBLISHED],
['fediverse', '@nextclouders@floss.social'],
['fediverseScope', IAccountManager::SCOPE_PUBLISHED],
+ ['birthdate', '2020-01-01'],
+ ['birthdateScope', IAccountManager::SCOPE_PUBLISHED],
+ ['pronouns', 'he/him'],
+ ['pronounsScope', IAccountManager::SCOPE_PUBLISHED],
];
}
- /**
- * @dataProvider dataTestSaveUserSettings
- *
- * @param array $data
- * @param ?string $oldEmailAddress
- * @param ?string $oldDisplayName
- */
- public function testSaveUserSettings($data,
- $oldEmailAddress,
- $oldDisplayName
- ) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettings')]
+ public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void {
$controller = $this->getController();
$user = $this->createMock(IUser::class);
@@ -690,7 +711,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->invokePrivate($controller, 'saveUserSettings', [$account]);
}
- public function dataTestSaveUserSettings() {
+ public static function dataTestSaveUserSettings(): array {
return [
[
[
@@ -752,16 +773,14 @@ class UsersControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataTestSaveUserSettingsException
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettingsException')]
public function testSaveUserSettingsException(
array $data,
string $oldEmailAddress,
string $oldDisplayName,
- bool $setDisplayNameResult,
- bool $canChangeEmail
- ) {
+ bool $setDisplayNameResult,
+ bool $canChangeEmail,
+ ): void {
$this->expectException(ForbiddenException::class);
$controller = $this->getController();
@@ -801,7 +820,7 @@ class UsersControllerTest extends \Test\TestCase {
}
- public function dataTestSaveUserSettingsException() {
+ public static function dataTestSaveUserSettingsException(): array {
return [
[
[
@@ -837,15 +856,8 @@ class UsersControllerTest extends \Test\TestCase {
];
}
- /**
- * @param string $account
- * @param string $type
- * @param array $dataBefore
- * @param array $expectedData
- *
- * @dataProvider dataTestGetVerificationCode
- */
- public function testGetVerificationCode($account, $type, $dataBefore, $expectedData, $onlyVerificationCode) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetVerificationCode')]
+ public function testGetVerificationCode(string $account, string $type, array $dataBefore, array $expectedData, bool $onlyVerificationCode): void {
$message = 'Use my Federated Cloud ID to share with me: user@nextcloud.com';
$signature = 'theSignature';
@@ -904,7 +916,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame($code, $data['code']);
}
- public function dataTestGetVerificationCode() {
+ public static function dataTestGetVerificationCode(): array {
$accountDataBefore = [
IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED],
IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
@@ -931,7 +943,7 @@ class UsersControllerTest extends \Test\TestCase {
/**
* test get verification code in case no valid user was given
*/
- public function testGetVerificationCodeInvalidUser() {
+ public function testGetVerificationCodeInvalidUser(): void {
$controller = $this->getController();
$this->userSession->expects($this->once())->method('getUser')->willReturn(null);
$result = $controller->getVerificationCode('account', false);
@@ -939,18 +951,13 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
}
- /**
- * @dataProvider dataTestCanAdminChangeUserPasswords
- *
- * @param bool $encryptionEnabled
- * @param bool $encryptionModuleLoaded
- * @param bool $masterKeyEnabled
- * @param bool $expected
- */
- public function testCanAdminChangeUserPasswords($encryptionEnabled,
- $encryptionModuleLoaded,
- $masterKeyEnabled,
- $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCanAdminChangeUserPasswords')]
+ public function testCanAdminChangeUserPasswords(
+ bool $encryptionEnabled,
+ bool $encryptionModuleLoaded,
+ bool $masterKeyEnabled,
+ bool $expected,
+ ): void {
$controller = $this->getController();
$this->encryptionManager->expects($this->any())
@@ -973,7 +980,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame($expected, $result);
}
- public function dataTestCanAdminChangeUserPasswords() {
+ public static function dataTestCanAdminChangeUserPasswords(): array {
return [
// encryptionEnabled, encryptionModuleLoaded, masterKeyEnabled, expectedResult
[true, true, true, true],
diff --git a/apps/settings/tests/Mailer/NewUserMailHelperTest.php b/apps/settings/tests/Mailer/NewUserMailHelperTest.php
index d4ab5c10692..f352a2b733d 100644
--- a/apps/settings/tests/Mailer/NewUserMailHelperTest.php
+++ b/apps/settings/tests/Mailer/NewUserMailHelperTest.php
@@ -1,40 +1,14 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Brad Rubenstein <brad@wbr.tech>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Liam JACK <liamjack@users.noreply.github.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author medcloud <42641918+medcloud@users.noreply.github.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author zulan <git@zulan.net>
- *
- * @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: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Mailer;
use OC\Mail\EMailTemplate;
use OC\Mail\Message;
+use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IConfig;
@@ -47,29 +21,20 @@ use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class NewUserMailHelperTest extends TestCase {
- /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */
- private $defaults;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l10n;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $l10nFactory;
- /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
- private $mailer;
- /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
- private $secureRandom;
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $timeFactory;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var ICrypto|\PHPUnit\Framework\MockObject\MockObject */
- private $crypto;
- /** @var \OCA\Settings\Mailer\NewUserMailHelper */
- private $newUserMailHelper;
+ private Defaults&MockObject $defaults;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $l10n;
+ private IFactory&MockObject $l10nFactory;
+ private IMailer&MockObject $mailer;
+ private ISecureRandom&MockObject $secureRandom;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private ICrypto&MockObject $crypto;
+ private NewUserMailHelper $newUserMailHelper;
protected function setUp(): void {
parent::setUp();
@@ -85,6 +50,8 @@ class NewUserMailHelperTest extends TestCase {
$this->defaults,
$this->urlGenerator,
$this->l10nFactory,
+ null,
+ null,
'test.TestTemplate',
[]
);
@@ -115,7 +82,7 @@ class NewUserMailHelperTest extends TestCase {
return $this->l10n;
});
- $this->newUserMailHelper = new \OCA\Settings\Mailer\NewUserMailHelper(
+ $this->newUserMailHelper = new NewUserMailHelper(
$this->defaults,
$this->urlGenerator,
$this->l10nFactory,
@@ -128,7 +95,7 @@ class NewUserMailHelperTest extends TestCase {
);
}
- public function testGenerateTemplateWithPasswordResetToken() {
+ public function testGenerateTemplateWithPasswordResetToken(): void {
$this->secureRandom
->expects($this->once())
->method('generate')
@@ -138,7 +105,7 @@ class NewUserMailHelperTest extends TestCase {
->expects($this->once())
->method('getTime')
->willReturn(12345);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser&MockObject $user */
$user = $this->createMock(IUser::class);
$user
->expects($this->any())
@@ -171,8 +138,12 @@ class NewUserMailHelperTest extends TestCase {
->method('getName')
->willReturn('TestCloud');
$this->defaults
- ->expects($this->any())
- ->method('getTextColorPrimary')
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
->willReturn('#ffffff');
$expectedHtmlBody = <<<EOF
@@ -200,7 +171,7 @@ class NewUserMailHelperTest extends TestCase {
<table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
- <center data-parsed="" style="background-color:;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
<img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
</center>
</tr>
@@ -285,32 +256,46 @@ class NewUserMailHelperTest extends TestCase {
<tr style="padding:0;text-align:left;vertical-align:top">
<th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
<center data-parsed="" style="min-width:490px;width:100%">
- <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:60px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:;background-color:;color:#fefefe;">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid ;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/resetPassword/MySuperLongSecureRandomToken" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Set your password</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
- </tr>
- </table>
- <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
+ <![endif]-->
</center>
</th>
<th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
@@ -383,7 +368,7 @@ EOF;
$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
}
- public function testGenerateTemplateWithoutPasswordResetToken() {
+ public function testGenerateTemplateWithoutPasswordResetToken(): void {
$this->urlGenerator
->expects($this->any())
->method('getAbsoluteURL')
@@ -392,7 +377,7 @@ EOF;
['myLogo',''],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser&MockObject $user */
$user = $this->createMock(IUser::class);
$user
->expects($this->any())
@@ -407,8 +392,12 @@ EOF;
->method('getName')
->willReturn('TestCloud');
$this->defaults
- ->expects($this->any())
- ->method('getTextColorPrimary')
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
->willReturn('#ffffff');
$expectedHtmlBody = <<<EOF
@@ -436,7 +425,7 @@ EOF;
<table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
- <center data-parsed="" style="background-color:;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
<img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
</center>
</tr>
@@ -521,32 +510,46 @@ EOF;
<tr style="padding:0;text-align:left;vertical-align:top">
<th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
<center data-parsed="" style="min-width:490px;width:100%">
- <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:60px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:;background-color:;color:#fefefe;">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid ;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
- </tr>
- </table>
- <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
+ <![endif]-->
</center>
</th>
<th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
@@ -619,7 +622,7 @@ EOF;
$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
}
- public function testGenerateTemplateWithoutUserId() {
+ public function testGenerateTemplateWithoutUserId(): void {
$this->urlGenerator
->expects($this->any())
->method('getAbsoluteURL')
@@ -628,7 +631,7 @@ EOF;
['myLogo', ''],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser&MockObject $user */
$user = $this->createMock(IUser::class);
$user
->expects($this->any())
@@ -647,8 +650,12 @@ EOF;
->method('getName')
->willReturn('TestCloud');
$this->defaults
- ->expects($this->any())
- ->method('getTextColorPrimary')
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#00679e');
+ $this->defaults
+ ->expects($this->atLeastOnce())
+ ->method('getDefaultTextColorPrimary')
->willReturn('#ffffff');
$expectedHtmlBody = <<<EOF
@@ -676,7 +683,7 @@ EOF;
<table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
<tbody>
<tr style="padding:0;text-align:left;vertical-align:top">
- <center data-parsed="" style="background-color:;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
+ <center data-parsed="" style="background-color:#00679e;min-width:175px;max-height:175px; padding:35px 0px;border-radius:200px">
<img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none;max-height:105px;max-width:105px;width:auto;height:auto">
</center>
</tr>
@@ -746,32 +753,46 @@ EOF;
<tr style="padding:0;text-align:left;vertical-align:top">
<th style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
<center data-parsed="" style="min-width:490px;width:100%">
- <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:60px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:;background-color:;color:#fefefe;">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <!--[if (gte mso 9)|(IE)]>
+ <table>
+ <tr>
+ <td>
+ <![endif]-->
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;border-radius:8px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto;background:#00679e;background-color:#00679e;color:#fefefe;">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid ;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #00679e;border-collapse:collapse!important;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/" style="Margin:0;border:0 solid #00679e;color:#ffffff;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;padding:8px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
- </tr>
- </table>
- <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:0;text-align:center;vertical-align:top;width:auto">
- <tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <td>
+ <![endif]-->
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;background-color: #ccc;margin:0 0 30px 0;max-height:40px;max-width:300px;padding:1px;border-radius:8px;text-align:center;vertical-align:top;width:auto">
<tr style="padding:0;text-align:left;vertical-align:top">
- <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
- <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:normal;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;color:#6C6C6C!important;display:inline-block;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:regular;line-height:normal;margin:0;border-radius: 7px;padding:8px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
</td>
</tr>
</table>
+ <!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
+ <![endif]-->
</center>
</th>
<th class="expander" style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
@@ -842,8 +863,8 @@ EOF;
$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
}
- public function testSendMail() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ public function testSendMail(): void {
+ /** @var IUser&MockObject $user */
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
@@ -853,7 +874,7 @@ EOF;
->expects($this->once())
->method('getDisplayName')
->willReturn('John Doe');
- /** @var IEMailTemplate|\PHPUnit\Framework\MockObject\MockObject $emailTemplate */
+ /** @var IEMailTemplate&MockObject $emailTemplate */
$emailTemplate = $this->createMock(IEMailTemplate::class);
$message = $this->createMock(Message::class);
$message
diff --git a/apps/settings/tests/Middleware/SubadminMiddlewareTest.php b/apps/settings/tests/Middleware/SubadminMiddlewareTest.php
index a1330857e02..37cfb5ccc59 100644
--- a/apps/settings/tests/Middleware/SubadminMiddlewareTest.php
+++ b/apps/settings/tests/Middleware/SubadminMiddlewareTest.php
@@ -1,29 +1,13 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright 2014 Lukas Reschke lukas@owncloud.com
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2014 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
+
namespace OCA\Settings\Tests\Middleware;
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException;
@@ -31,7 +15,11 @@ use OC\AppFramework\Utility\ControllerMethodReflector;
use OCA\Settings\Middleware\SubadminMiddleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Group\ISubAdmin;
use OCP\IL10N;
+use OCP\IUser;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Verifies whether an user has at least subadmin rights.
@@ -40,81 +28,95 @@ use OCP\IL10N;
* @package Tests\Settings\Middleware
*/
class SubadminMiddlewareTest extends \Test\TestCase {
- /** @var SubadminMiddleware */
- private $subadminMiddlewareAsSubAdmin;
- /** @var SubadminMiddleware */
- private $subadminMiddleware;
- /** @var ControllerMethodReflector */
- private $reflector;
- /** @var Controller */
- private $controller;
- /** @var IL10N */
- private $l10n;
+ private SubadminMiddleware $subadminMiddleware;
+ private IUserSession&MockObject $userSession;
+ private ISubAdmin&MockObject $subAdminManager;
+ private ControllerMethodReflector&MockObject $reflector;
+ private Controller&MockObject $controller;
+ private IL10N&MockObject $l10n;
protected function setUp(): void {
parent::setUp();
- $this->reflector = $this->getMockBuilder(ControllerMethodReflector::class)
- ->disableOriginalConstructor()->getMock();
- $this->controller = $this->getMockBuilder(Controller::class)
- ->disableOriginalConstructor()->getMock();
+ $this->reflector = $this->createMock(ControllerMethodReflector::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->subAdminManager = $this->createMock(ISubAdmin::class);
$this->l10n = $this->createMock(IL10N::class);
- $this->subadminMiddlewareAsSubAdmin = new SubadminMiddleware($this->reflector, true, $this->l10n);
- $this->subadminMiddleware = new SubadminMiddleware($this->reflector, false, $this->l10n);
+ $this->subadminMiddleware = new SubadminMiddleware(
+ $this->reflector,
+ $this->userSession,
+ $this->subAdminManager,
+ $this->l10n,
+ );
+
+ $this->controller = $this->createMock(Controller::class);
+
+ $this->userSession
+ ->expects(self::any())
+ ->method('getUser')
+ ->willReturn($this->createMock(IUser::class));
}
- public function testBeforeControllerAsUserWithExemption() {
- $this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\NotAdminException::class);
+ public function testBeforeControllerAsUserWithoutAnnotation(): void {
+ $this->expectException(NotAdminException::class);
$this->reflector
->expects($this->exactly(2))
->method('hasAnnotation')
- ->withConsecutive(
- ['NoSubAdminRequired'],
- ['AuthorizedAdminSetting'],
- )->willReturn(false);
+ ->willReturnMap([
+ ['NoSubAdminRequired', false],
+ ['AuthorizedAdminSetting', false],
+ ]);
+
+ $this->subAdminManager
+ ->expects(self::once())
+ ->method('isSubAdmin')
+ ->willReturn(false);
+
$this->subadminMiddleware->beforeController($this->controller, 'foo');
}
- public function testBeforeControllerAsUserWithoutExemption() {
+ public function testBeforeControllerWithAnnotation(): void {
$this->reflector
->expects($this->once())
->method('hasAnnotation')
->with('NoSubAdminRequired')
->willReturn(true);
+
+ $this->subAdminManager
+ ->expects(self::never())
+ ->method('isSubAdmin');
+
$this->subadminMiddleware->beforeController($this->controller, 'foo');
}
- public function testBeforeControllerAsSubAdminWithoutExemption() {
+ public function testBeforeControllerAsSubAdminWithoutAnnotation(): void {
$this->reflector
->expects($this->exactly(2))
->method('hasAnnotation')
- ->withConsecutive(
- ['NoSubAdminRequired'],
- ['AuthorizedAdminSetting'],
- )->willReturn(false);
- $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo');
- }
+ ->willReturnMap([
+ ['NoSubAdminRequired', false],
+ ['AuthorizedAdminSetting', false],
+ ]);
- public function testBeforeControllerAsSubAdminWithExemption() {
- $this->reflector
- ->expects($this->once())
- ->method('hasAnnotation')
- ->with('NoSubAdminRequired')
+ $this->subAdminManager
+ ->expects(self::once())
+ ->method('isSubAdmin')
->willReturn(true);
- $this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo');
+
+ $this->subadminMiddleware->beforeController($this->controller, 'foo');
}
- public function testAfterNotAdminException() {
+ public function testAfterNotAdminException(): void {
$expectedResponse = new TemplateResponse('core', '403', [], 'guest');
$expectedResponse->setStatus(403);
$this->assertEquals($expectedResponse, $this->subadminMiddleware->afterException($this->controller, 'foo', new NotAdminException('')));
}
- public function testAfterRegularException() {
+ public function testAfterRegularException(): void {
$this->expectException(\Exception::class);
$expectedResponse = new TemplateResponse('core', '403', [], 'guest');
diff --git a/apps/settings/tests/Settings/Admin/MailTest.php b/apps/settings/tests/Settings/Admin/MailTest.php
index c3b08a9d509..992c7d43dba 100644
--- a/apps/settings/tests/Settings/Admin/MailTest.php
+++ b/apps/settings/tests/Settings/Admin/MailTest.php
@@ -1,51 +1,29 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
use OCA\Settings\Settings\Admin\Mail;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class MailTest extends TestCase {
- /** @var Mail */
- private $admin;
- /** @var IConfig */
- private $config;
- /** @var IL10N */
- private $l10n;
+
+ private Mail $admin;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->admin = new Mail(
$this->config,
@@ -53,7 +31,22 @@ class MailTest extends TestCase {
);
}
- public function testGetForm() {
+ public static function dataGetForm(): array {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForm')]
+ public function testGetForm(bool $sendmail) {
+ $finder = $this->createMock(IBinaryFinder::class);
+ $finder->expects(self::once())
+ ->method('findBinaryPath')
+ ->with('sendmail')
+ ->willReturn($sendmail ? '/usr/bin/sendmail': false);
+ $this->overwriteService(IBinaryFinder::class, $finder);
+
$this->config
->expects($this->any())
->method('getSystemValue')
@@ -74,7 +67,7 @@ class MailTest extends TestCase {
'settings',
'settings/admin/additional-mail',
[
- 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
+ 'sendmail_is_available' => $sendmail,
'mail_domain' => 'mx.nextcloud.com',
'mail_from_address' => 'no-reply@nextcloud.com',
'mail_smtpmode' => 'smtp',
@@ -92,11 +85,11 @@ class MailTest extends TestCase {
$this->assertEquals($expected, $this->admin->getForm());
}
- public function testGetSection() {
+ public function testGetSection(): void {
$this->assertSame('server', $this->admin->getSection());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertSame(10, $this->admin->getPriority());
}
}
diff --git a/apps/settings/tests/Settings/Admin/SecurityTest.php b/apps/settings/tests/Settings/Admin/SecurityTest.php
index 1e261399d19..89a6d8c0d88 100644
--- a/apps/settings/tests/Settings/Admin/SecurityTest.php
+++ b/apps/settings/tests/Settings/Admin/SecurityTest.php
@@ -1,29 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
@@ -38,21 +17,16 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SecurityTest extends TestCase {
- /** @var Security */
- private $admin;
- /** @var Manager */
- private $manager;
- /** @var IUserManager */
- private $userManager;
- /** @var MandatoryTwoFactor|MockObject */
- private $mandatoryTwoFactor;
- /** @var IInitialState|MockObject */
- private $initialState;
+ private Manager $manager;
+ private IUserManager $userManager;
+ private MandatoryTwoFactor&MockObject $mandatoryTwoFactor;
+ private IInitialState&MockObject $initialState;
+ private Security $admin;
protected function setUp(): void {
parent::setUp();
- $this->manager = $this->getMockBuilder(Manager::class)->disableOriginalConstructor()->getMock();
- $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
+ $this->manager = $this->createMock(Manager::class);
+ $this->userManager = $this->createMock(IUserManager::class);
$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
$this->initialState = $this->createMock(IInitialState::class);
@@ -65,21 +39,15 @@ class SecurityTest extends TestCase {
);
}
- /**
- * @return array
- */
- public function encryptionSettingsProvider() {
+ public static function encryptionSettingsProvider(): array {
return [
[true],
[false],
];
}
- /**
- * @dataProvider encryptionSettingsProvider
- * @param bool $enabled
- */
- public function testGetFormWithOnlyOneBackend($enabled) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
+ public function testGetFormWithOnlyOneBackend(bool $enabled): void {
$this->manager
->expects($this->once())
->method('isEnabled')
@@ -106,10 +74,10 @@ class SecurityTest extends TestCase {
}
/**
- * @dataProvider encryptionSettingsProvider
* @param bool $enabled
*/
- public function testGetFormWithMultipleBackends($enabled) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')]
+ public function testGetFormWithMultipleBackends($enabled): void {
$this->manager
->expects($this->once())
->method('isEnabled')
@@ -135,11 +103,11 @@ class SecurityTest extends TestCase {
$this->assertEquals($expected, $this->admin->getForm());
}
- public function testGetSection() {
+ public function testGetSection(): void {
$this->assertSame('security', $this->admin->getSection());
}
- public function testGetPriority() {
+ public function testGetPriority(): void {
$this->assertSame(10, $this->admin->getPriority());
}
}
diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php
index 99392612de9..e2ca4cff3c6 100644
--- a/apps/settings/tests/Settings/Admin/ServerTest.php
+++ b/apps/settings/tests/Settings/Admin/ServerTest.php
@@ -3,31 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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;
@@ -48,28 +25,19 @@ use Test\TestCase;
* @group DB
*/
class ServerTest extends TestCase {
- /** @var Server */
- private $admin;
- /** @var IDBConnection */
- private $connection;
- /** @var IInitialState */
- private $initialStateService;
- /** @var ProfileManager */
- private $profileManager;
- /** @var ITimeFactory|MockObject */
- private $timeFactory;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IAppConfig|MockObject */
- private $appConfig;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IUrlGenerator|MockObject */
- private $urlGenerator;
+ private IDBConnection $connection;
+ private Server&MockObject $admin;
+ private IInitialState&MockObject $initialStateService;
+ private ProfileManager&MockObject $profileManager;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private IAppConfig&MockObject $appConfig;
+ private IL10N&MockObject $l10n;
+ private IUrlGenerator&MockObject $urlGenerator;
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = \OCP\Server::get(IDBConnection::class);
$this->initialStateService = $this->createMock(IInitialState::class);
$this->profileManager = $this->createMock(ProfileManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
@@ -101,10 +69,17 @@ class ServerTest extends TestCase {
->expects($this->any())
->method('getAppValue')
->willReturnMap([
- ['core', 'backgroundjobs_mode', 'ajax', 'ajax'],
['core', 'lastcron', '0', '0'],
['core', 'cronErrors', ''],
]);
+ $this->appConfig
+ ->expects($this->any())
+ ->method('getValueString')
+ ->willReturnCallback(fn ($a, $b, $default) => $default);
+ $this->appConfig
+ ->expects($this->any())
+ ->method('getValueBool')
+ ->willReturnCallback(fn ($a, $b, $default) => $default);
$this->profileManager
->expects($this->exactly(2))
->method('isProfileEnabled')
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 {
diff --git a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
index 5ccec936555..0a0ff4d84af 100644
--- a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
+++ b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Settings\Personal\Security;
@@ -30,30 +13,19 @@ use OC\Authentication\Token\PublicKeyToken;
use OCA\Settings\Settings\Personal\Security\Authtokens;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
+use OCP\Authentication\Token\IToken;
use OCP\ISession;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AuthtokensTest extends TestCase {
-
- /** @var IAuthTokenProvider|MockObject */
- private $authTokenProvider;
-
- /** @var ISession|MockObject */
- private $session;
-
- /** @var IUserSession|MockObject */
- private $userSession;
-
- /** @var IInitialState|MockObject */
- private $initialState;
-
- /** @var string */
- private $uid;
-
- /** @var Authtokens */
- private $section;
+ private IAuthTokenProvider&MockObject $authTokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private IInitialState&MockObject $initialState;
+ private string $uid;
+ private Authtokens $section;
protected function setUp(): void {
parent::setUp();
@@ -73,7 +45,7 @@ class AuthtokensTest extends TestCase {
);
}
- public function testGetForm() {
+ public function testGetForm(): void {
$token1 = new PublicKeyToken();
$token1->setId(100);
$token2 = new PublicKeyToken();
@@ -96,34 +68,39 @@ class AuthtokensTest extends TestCase {
->method('getToken')
->with('session123')
->willReturn($sessionToken);
+
+ $calls = [
+ [
+ 'app_tokens', [
+ [
+ 'id' => 100,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => false,
+ 'current' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => false,
+ ],
+ [
+ 'id' => 200,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => true,
+ 'scope' => [IToken::SCOPE_FILESYSTEM => true],
+ 'canRename' => true,
+ ],
+ ]
+ ],
+ ['can_create_app_token', true],
+ ];
$this->initialState->expects($this->exactly(2))
->method('provideInitialState')
- ->withConsecutive(
- [
- 'app_tokens', [
- [
- 'id' => 100,
- 'name' => null,
- 'lastActivity' => 0,
- 'type' => 0,
- 'canDelete' => false,
- 'current' => true,
- 'scope' => ['filesystem' => true],
- 'canRename' => false,
- ],
- [
- 'id' => 200,
- 'name' => null,
- 'lastActivity' => 0,
- 'type' => 0,
- 'canDelete' => true,
- 'scope' => ['filesystem' => true],
- 'canRename' => true,
- ],
- ]
- ],
- ['can_create_app_token', true],
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$form = $this->section->getForm();
diff --git a/apps/settings/tests/Settings/Personal/Security/PasswordTest.php b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
index 2db1effd660..34a4b8e296f 100644
--- a/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
+++ b/apps/settings/tests/Settings/Personal/Security/PasswordTest.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Tests\Settings\Personal\Security;
@@ -34,15 +16,9 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PasswordTest extends TestCase {
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var string */
- private $uid;
-
- /** @var Password */
- private $section;
+ private IUserManager&MockObject $userManager;
+ private string $uid;
+ private Password $section;
protected function setUp(): void {
parent::setUp();
@@ -56,7 +32,7 @@ class PasswordTest extends TestCase {
);
}
- public function testGetForm() {
+ public function testGetForm(): void {
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
diff --git a/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php
index 9216be3ace5..423f932dcf5 100644
--- a/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php
+++ b/apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Côme Chilliet <come.chilliet@nextcloud.com>
- *
- * @author Côme Chilliet <come.chilliet@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: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\AppDirsWithDifferentOwner;
use OCP\IL10N;
@@ -43,8 +26,7 @@ class AppDirsWithDifferentOwnerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
@@ -63,7 +45,7 @@ class AppDirsWithDifferentOwnerTest extends TestCase {
*
* @return void
*/
- public function testAppDirectoryOwnersOk() {
+ public function testAppDirectoryOwnersOk(): void {
$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
mkdir($tempDir);
mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
@@ -90,7 +72,7 @@ class AppDirsWithDifferentOwnerTest extends TestCase {
*
* @return void
*/
- public function testAppDirectoryOwnersNotWritable() {
+ public function testAppDirectoryOwnersNotWritable(): void {
$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
\OC::$APPSROOTS = [
[
diff --git a/apps/settings/tests/SetupChecks/CodeIntegrityTest.php b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
new file mode 100644
index 00000000000..4dd54a644f5
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
@@ -0,0 +1,134 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OC\IntegrityCheck\Checker;
+use OCA\Settings\SetupChecks\CodeIntegrity;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class CodeIntegrityTest extends TestCase {
+
+ private IL10N&MockObject $l10n;
+ private IURLGenerator&MockObject $urlGenerator;
+ private Checker&MockObject $checker;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->checker = $this->createMock(Checker::class);
+ }
+
+ public function testSkipOnDisabled(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::INFO, $check->run()->getSeverity());
+ }
+
+ public function testSuccessOnEmptyResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn([]);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsReRunWithoutResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(null);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // This is important and must be called
+ $this->checker->expects($this->once())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsNotReReInAdvance(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // There are results thus this must never be called
+ $this->checker->expects($this->never())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testErrorOnMissingIntegrity(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::ERROR, $check->run()->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php
index 8eec24a51c4..c20c78c6e16 100644
--- a/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php
+++ b/apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * 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: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\DataDirectoryProtected;
use OCP\Http\Client\IClientService;
@@ -37,19 +20,17 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class DataDirectoryProtectedTest extends TestCase {
- private IL10N|MockObject $l10n;
- private IConfig|MockObject $config;
- private IURLGenerator|MockObject $urlGenerator;
- private IClientService|MockObject $clientService;
- private LoggerInterface|MockObject $logger;
- private DataDirectoryProtected|MockObject $setupcheck;
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private DataDirectoryProtected&MockObject $setupcheck;
protected function setUp(): void {
parent::setUp();
- /** @var IL10N|MockObject */
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
@@ -62,7 +43,7 @@ class DataDirectoryProtectedTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->setupcheck = $this->getMockBuilder(DataDirectoryProtected::class)
- ->onlyMethods(['runHEAD'])
+ ->onlyMethods(['runRequest'])
->setConstructorArgs([
$this->l10n,
$this->config,
@@ -73,36 +54,36 @@ class DataDirectoryProtectedTest extends TestCase {
->getMock();
}
- /**
- * @dataProvider dataTestStatusCode
- */
- public function testStatusCode(array $status, string $expected): void {
- $responses = array_map(function ($state) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStatusCode')]
+ public function testStatusCode(array $status, string $expected, bool $hasBody): void {
+ $responses = array_map(function ($state) use ($hasBody) {
$response = $this->createMock(IResponse::class);
$response->expects($this->any())->method('getStatusCode')->willReturn($state);
+ $response->expects(($this->atMost(1)))->method('getBody')->willReturn($hasBody ? '# Nextcloud data directory' : 'something else');
return $response;
}, $status);
$this->setupcheck
->expects($this->once())
- ->method('runHEAD')
+ ->method('runRequest')
->will($this->generate($responses));
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getSystemValueString')
->willReturn('');
$result = $this->setupcheck->run();
$this->assertEquals($expected, $result->getSeverity());
}
- public function dataTestStatusCode(): array {
+ public static function dataTestStatusCode(): array {
return [
- 'success: forbidden access' => [[403], SetupResult::SUCCESS],
- 'error: can access' => [[200], SetupResult::ERROR],
- 'error: one forbidden one can access' => [[403, 200], SetupResult::ERROR],
- 'warning: connection issue' => [[], SetupResult::WARNING],
+ 'success: forbidden access' => [[403], SetupResult::SUCCESS, true],
+ 'success: forbidden access with redirect' => [[200], SetupResult::SUCCESS, false],
+ 'error: can access' => [[200], SetupResult::ERROR, true],
+ 'error: one forbidden one can access' => [[403, 200], SetupResult::ERROR, true],
+ 'warning: connection issue' => [[], SetupResult::WARNING, true],
];
}
@@ -112,12 +93,12 @@ class DataDirectoryProtectedTest extends TestCase {
$this->setupcheck
->expects($this->once())
- ->method('runHEAD')
+ ->method('runRequest')
->will($this->generate([]));
$this->config
->expects($this->once())
- ->method('getSystemValue')
+ ->method('getSystemValueString')
->willReturn('');
$result = $this->setupcheck->run();
diff --git a/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php b/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php
index bacc557490b..9b4878b45cc 100644
--- a/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php
+++ b/apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php
@@ -3,28 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Côme Chilliet <come.chilliet@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: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\ForwardedForHeaders;
use OCP\IConfig;
@@ -44,8 +26,7 @@ class ForwardedForHeadersTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
@@ -62,9 +43,7 @@ class ForwardedForHeadersTest extends TestCase {
);
}
- /**
- * @dataProvider dataForwardedForHeadersWorking
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataForwardedForHeadersWorking')]
public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, string $result): void {
$this->config->expects($this->once())
->method('getSystemValue')
@@ -86,7 +65,7 @@ class ForwardedForHeadersTest extends TestCase {
);
}
- public function dataForwardedForHeadersWorking(): array {
+ public static function dataForwardedForHeadersWorking(): array {
return [
// description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
diff --git a/apps/settings/tests/SetupChecks/LoggingLevelTest.php b/apps/settings/tests/SetupChecks/LoggingLevelTest.php
new file mode 100644
index 00000000000..67224e11e3a
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/LoggingLevelTest.php
@@ -0,0 +1,76 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests\SetupChecks;
+
+use OCA\Settings\SetupChecks\LoggingLevel;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\ILogger;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LogLevel;
+use Test\TestCase;
+
+class LoggingLevelTest extends TestCase {
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->config = $this->createMock(IConfig::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ }
+
+ public static function dataRun(): array {
+ return [
+ [ILogger::INFO, SetupResult::SUCCESS],
+ [ILogger::WARN, SetupResult::SUCCESS],
+ [ILogger::ERROR, SetupResult::SUCCESS],
+ [ILogger::FATAL, SetupResult::SUCCESS],
+
+ // Debug is valid but will result in an warning
+ [ILogger::DEBUG, SetupResult::WARNING],
+
+ // negative - invalid range
+ [-1, SetupResult::ERROR],
+ // string value instead of number
+ ['1', SetupResult::ERROR],
+ // random string value
+ ['error', SetupResult::ERROR],
+ // PSR logger value
+ [LogLevel::ALERT, SetupResult::ERROR],
+ // out of range
+ [ILogger::FATAL + 1, SetupResult::ERROR],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRun')]
+ public function testRun(string|int $value, string $expected): void {
+ $this->urlGenerator->method('linkToDocs')->willReturn('admin-logging');
+
+ $this->config->expects(self::once())
+ ->method('getSystemValue')
+ ->with('loglevel', ILogger::WARN)
+ ->willReturn($value);
+
+ $check = new LoggingLevel($this->l10n, $this->config, $this->urlGenerator);
+
+ $result = $check->run();
+ $this->assertEquals($expected, $result->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/OcxProvicersTest.php b/apps/settings/tests/SetupChecks/OcxProvicersTest.php
index 2cc6ac6de07..8e5a2c1b88b 100644
--- a/apps/settings/tests/SetupChecks/OcxProvicersTest.php
+++ b/apps/settings/tests/SetupChecks/OcxProvicersTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * 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: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\OcxProviders;
use OCP\Http\Client\IClientService;
@@ -47,9 +30,7 @@ class OcxProvicersTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- /** @var IL10N|MockObject */
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
diff --git a/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
index f8e34a77423..3722346219a 100644
--- a/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
+++ b/apps/settings/tests/SetupChecks/PhpDefaultCharsetTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- *
- * @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: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCP\IL10N;
@@ -38,8 +21,7 @@ class PhpDefaultCharsetTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
diff --git a/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php b/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
index a835708243d..de509347044 100644
--- a/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
+++ b/apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- *
- * @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: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\PhpOutputBuffering;
use OCP\IL10N;
@@ -38,8 +21,7 @@ class PhpOutputBufferingTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
diff --git a/apps/settings/tests/SetupChecks/SecurityHeadersTest.php b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php
index fb8eb757460..1f75907d427 100644
--- a/apps/settings/tests/SetupChecks/SecurityHeadersTest.php
+++ b/apps/settings/tests/SetupChecks/SecurityHeadersTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Côme Chilliet <come.chilliet@nextcloud.com>
- *
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- *
- * @license AGPL-3.0-or-later
- *
- * 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: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\SecurityHeaders;
use OCP\Http\Client\IClientService;
@@ -37,19 +20,17 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class SecurityHeadersTest extends TestCase {
- private IL10N|MockObject $l10n;
- private IConfig|MockObject $config;
- private IURLGenerator|MockObject $urlGenerator;
- private IClientService|MockObject $clientService;
- private LoggerInterface|MockObject $logger;
- private SecurityHeaders|MockObject $setupcheck;
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private SecurityHeaders&MockObject $setupcheck;
protected function setUp(): void {
parent::setUp();
- /** @var IL10N|MockObject */
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
@@ -103,17 +84,16 @@ class SecurityHeadersTest extends TestCase {
$result = $this->setupcheck->run();
$this->assertEquals(
- "Some headers are not set correctly on your instance\n- The `X-Content-Type-Options` HTTP header is not set to `nosniff`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n",
+ "Some headers are not set correctly on your instance\n- The `X-Content-Type-Options` HTTP header is not set to `nosniff`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n",
$result->getDescription()
);
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
}
- public function dataSuccess(): array {
+ public static function dataSuccess(): array {
return [
// description => modifiedHeaders
'basic' => [[]],
- 'extra-xss-protection' => [['X-XSS-Protection' => '1; mode=block; report=https://example.com']],
'no-space-in-x-robots' => [['X-Robots-Tag' => 'noindex,nofollow']],
'strict-origin-when-cross-origin' => [['Referrer-Policy' => 'strict-origin-when-cross-origin']],
'referrer-no-referrer-when-downgrade' => [['Referrer-Policy' => 'no-referrer-when-downgrade']],
@@ -126,13 +106,10 @@ class SecurityHeadersTest extends TestCase {
];
}
- /**
- * @dataProvider dataSuccess
- */
- public function testSuccess($headers): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSuccess')]
+ public function testSuccess(array $headers): void {
$headers = array_merge(
[
- 'X-XSS-Protection' => '1; mode=block',
'X-Content-Type-Options' => 'nosniff',
'X-Robots-Tag' => 'noindex, nofollow',
'X-Frame-Options' => 'SAMEORIGIN',
@@ -155,12 +132,10 @@ class SecurityHeadersTest extends TestCase {
$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
}
- public function dataFailure(): array {
+ public static function dataFailure(): array {
return [
// description => modifiedHeaders
'x-robots-none' => [['X-Robots-Tag' => 'none'], "- The `X-Robots-Tag` HTTP header is not set to `noindex,nofollow`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
- 'xss-protection-1' => [['X-XSS-Protection' => '1'], "- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
- 'xss-protection-0' => [['X-XSS-Protection' => '0'], "- The `X-XSS-Protection` HTTP header does not contain `1; mode=block`. This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.\n"],
'referrer-origin' => [['Referrer-Policy' => 'origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
'referrer-origin-when-cross-origin' => [['Referrer-Policy' => 'origin-when-cross-origin'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
'referrer-unsafe-url' => [['Referrer-Policy' => 'unsafe-url'], "- The `Referrer-Policy` HTTP header is not set to `no-referrer`, `no-referrer-when-downgrade`, `strict-origin`, `strict-origin-when-cross-origin` or `same-origin`. This can leak referer information. See the {w3c-recommendation}.\n"],
@@ -170,13 +145,10 @@ class SecurityHeadersTest extends TestCase {
];
}
- /**
- * @dataProvider dataFailure
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataFailure')]
public function testFailure(array $headers, string $msg): void {
$headers = array_merge(
[
- 'X-XSS-Protection' => '1; mode=block',
'X-Content-Type-Options' => 'nosniff',
'X-Robots-Tag' => 'noindex, nofollow',
'X-Frame-Options' => 'SAMEORIGIN',
@@ -193,7 +165,7 @@ class SecurityHeadersTest extends TestCase {
$result = $this->setupcheck->run();
$this->assertEquals(
- 'Some headers are not set correctly on your instance'."\n$msg",
+ 'Some headers are not set correctly on your instance' . "\n$msg",
$result->getDescription()
);
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
diff --git a/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
index aede25475c5..6c75df47aa0 100644
--- a/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
+++ b/apps/settings/tests/SetupChecks/SupportedDatabaseTest.php
@@ -3,33 +3,16 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @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: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
-use Doctrine\DBAL\Platforms\SqlitePlatform;
use OCA\Settings\SetupChecks\SupportedDatabase;
use OCP\IDBConnection;
use OCP\IL10N;
-use OCP\IUrlGenerator;
+use OCP\IURLGenerator;
+use OCP\Server;
use OCP\SetupCheck\SetupResult;
use Test\TestCase;
@@ -46,24 +29,23 @@ class SupportedDatabaseTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
- $this->urlGenerator = $this->getMockBuilder(IUrlGenerator::class)->getMock();
- $this->connection = \OCP\Server::get(IDBConnection::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->connection = Server::get(IDBConnection::class);
$this->check = new SupportedDatabase(
$this->l10n,
$this->urlGenerator,
- \OCP\Server::get(IDBConnection::class)
+ Server::get(IDBConnection::class)
);
}
public function testPass(): void {
- $platform = $this->connection->getDatabasePlatform();
- if ($platform instanceof SqlitePlatform) {
+ if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
/** SQlite always gets a warning */
$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
} else {
- $this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
+ $this->assertContains($this->check->run()->getSeverity(), [SetupResult::SUCCESS, SetupResult::INFO]);
}
}
}
diff --git a/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
new file mode 100644
index 00000000000..6375d9f6e7f
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
+use OCP\TaskProcessing\IManager;
+use OCP\TaskProcessing\Task;
+use Test\TestCase;
+
+class TaskProcessingPickupSpeedTest extends TestCase {
+ private IL10N $l10n;
+ private ITimeFactory $timeFactory;
+ private IManager $taskProcessingManager;
+
+ private TaskProcessingPickupSpeed $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
+ $this->taskProcessingManager = $this->getMockBuilder(IManager::class)->getMock();
+
+ $this->check = new TaskProcessingPickupSpeed(
+ $this->l10n,
+ $this->taskProcessingManager,
+ $this->timeFactory,
+ );
+ }
+
+ public function testPass(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 15) {
+ $task->setScheduledAt(60 * 5); // 15% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
+ }
+
+ public function testFail(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 30) {
+ $task->setScheduledAt(60 * 5); // 30% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
+ }
+}
diff --git a/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
index 7d685db039c..d55835d66fc 100644
--- a/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
+++ b/apps/settings/tests/SetupChecks/WellKnownUrlsTest.php
@@ -3,27 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * 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: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Settings\Tests;
+namespace OCA\Settings\Tests\SetupChecks;
use OCA\Settings\SetupChecks\WellKnownUrls;
use OCP\Http\Client\IClientService;
@@ -37,19 +20,18 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class WellKnownUrlsTest extends TestCase {
- private IL10N|MockObject $l10n;
- private IConfig|MockObject $config;
- private IURLGenerator|MockObject $urlGenerator;
- private IClientService|MockObject $clientService;
- private LoggerInterface|MockObject $logger;
- private WellKnownUrls|MockObject $setupcheck;
+ private IL10N&MockObject $l10n;
+ private IConfig&MockObject $config;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IClientService&MockObject $clientService;
+ private LoggerInterface&MockObject $logger;
+ private WellKnownUrls&MockObject $setupcheck;
protected function setUp(): void {
parent::setUp();
- /** @var IL10N|MockObject */
- $this->l10n = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()->getMock();
+ /** @var IL10N&MockObject */
+ $this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnCallback(function ($message, array $replace) {
@@ -114,8 +96,8 @@ class WellKnownUrlsTest extends TestCase {
/**
* Test responses
- * @dataProvider dataTestResponses
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestResponses')]
public function testResponses($responses, string $expectedSeverity): void {
$this->config
->expects($this->once())
@@ -133,7 +115,7 @@ class WellKnownUrlsTest extends TestCase {
}
public function dataTestResponses(): array {
- $createResponse = function (int $statuscode, array $header = []): IResponse|MockObject {
+ $createResponse = function (int $statuscode, array $header = []): IResponse&MockObject {
$response = $this->createMock(IResponse::class);
$response->expects($this->any())
->method('getStatusCode')
diff --git a/apps/settings/tests/UserMigration/AccountMigratorTest.php b/apps/settings/tests/UserMigration/AccountMigratorTest.php
index eebc3bc5910..b8f8301f777 100644
--- a/apps/settings/tests/UserMigration/AccountMigratorTest.php
+++ b/apps/settings/tests/UserMigration/AccountMigratorTest.php
@@ -1,29 +1,10 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright 2022 Christopher Ng <chrng8@gmail.com>
- *
- * @author Christopher Ng <chrng8@gmail.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: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OCA\Settings\Tests\UserMigration;
use OCA\Settings\AppInfo\Application;
@@ -31,7 +12,9 @@ use OCA\Settings\UserMigration\AccountMigrator;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\App;
use OCP\IAvatarManager;
+use OCP\IConfig;
use OCP\IUserManager;
+use OCP\Server;
use OCP\UserMigration\IExportDestination;
use OCP\UserMigration\IImportSource;
use PHPUnit\Framework\Constraint\JsonMatches;
@@ -44,21 +27,12 @@ use Test\TestCase;
* @group DB
*/
class AccountMigratorTest extends TestCase {
-
private IUserManager $userManager;
-
private IAvatarManager $avatarManager;
-
private AccountMigrator $migrator;
-
- /** @var IImportSource|MockObject */
- private $importSource;
-
- /** @var IExportDestination|MockObject */
- private $exportDestination;
-
- /** @var OutputInterface|MockObject */
- private $output;
+ private IImportSource&MockObject $importSource;
+ private IExportDestination&MockObject $exportDestination;
+ private OutputInterface&MockObject $output;
private const ASSETS_DIR = __DIR__ . '/assets/';
@@ -69,8 +43,11 @@ class AccountMigratorTest extends TestCase {
private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
protected function setUp(): void {
+ parent::setUp();
+
$app = new App(Application::APP_ID);
$container = $app->getContainer();
+ $container->get(IConfig::class)->setSystemValue('has_internet_connection', false);
$this->userManager = $container->get(IUserManager::class);
$this->avatarManager = $container->get(IAvatarManager::class);
@@ -81,9 +58,14 @@ class AccountMigratorTest extends TestCase {
$this->output = $this->createMock(OutputInterface::class);
}
- public function dataImportExportAccount(): array {
+ protected function tearDown(): void {
+ Server::get(IConfig::class)->setSystemValue('has_internet_connection', true);
+ parent::tearDown();
+ }
+
+ public static function dataImportExportAccount(): array {
return array_map(
- function (string $filename) {
+ static function (string $filename): array {
$dataPath = static::ASSETS_DIR . $filename;
// For each account json file there is an avatar image and a config json file with the same basename
$basename = pathinfo($filename, PATHINFO_FILENAME);
@@ -103,9 +85,7 @@ class AccountMigratorTest extends TestCase {
);
}
- /**
- * @dataProvider dataImportExportAccount
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataImportExportAccount')]
public function testImportExportAccount(string $userId, array $importData, string $avatarPath, array $importConfig): void {
$user = $this->userManager->createUser($userId, 'topsecretpassword');
$avatarExt = pathinfo($avatarPath, PATHINFO_EXTENSION);
@@ -120,17 +100,18 @@ class AccountMigratorTest extends TestCase {
->with($this->migrator->getId())
->willReturn(1);
+ $calls = [
+ [static::REGEX_ACCOUNT_FILE, json_encode($importData)],
+ [static::REGEX_CONFIG_FILE, json_encode($importConfig)],
+ ];
$this->importSource
->expects($this->exactly(2))
->method('getFileContents')
- ->withConsecutive(
- [$this->matchesRegularExpression(static::REGEX_ACCOUNT_FILE)],
- [$this->matchesRegularExpression(static::REGEX_CONFIG_FILE)],
- )
- ->willReturnOnConsecutiveCalls(
- json_encode($importData),
- json_encode($importConfig),
- );
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertMatchesRegularExpression($expected[0], $path);
+ return $expected[1];
+ });
$this->importSource
->expects($this->once())
@@ -161,13 +142,18 @@ class AccountMigratorTest extends TestCase {
);
}
+ $calls = [
+ [static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))],
+ [static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))],
+ ];
$this->exportDestination
->expects($this->exactly(2))
->method('addFileContents')
- ->withConsecutive(
- [$this->matchesRegularExpression(static::REGEX_ACCOUNT_FILE), new JsonMatches(json_encode($exportData))],
- [$this->matchesRegularExpression(static::REGEX_CONFIG_FILE), new JsonMatches(json_encode($exportConfig))],
- );
+ ->willReturnCallback(function ($path) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertMatchesRegularExpression($expected[0], $path);
+ return $expected[1];
+ });
$this->exportDestination
->expects($this->once())
diff --git a/apps/settings/tests/UserMigration/assets/account-complex-config.json b/apps/settings/tests/UserMigration/assets/account-complex-config.json
index 57c037a9d0d..fecf819057c 100644
--- a/apps/settings/tests/UserMigration/assets/account-complex-config.json
+++ b/apps/settings/tests/UserMigration/assets/account-complex-config.json
@@ -1 +1 @@
-{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show_users_only"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show_users_only"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"hide"},"phone":{"visibility":"hide"},"twitter":{"visibility":"show_users_only"},"website":{"visibility":"show_users_only"},"talk":{"visibility":"show"}} \ No newline at end of file
+{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show_users_only"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show_users_only"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"hide"},"phone":{"visibility":"hide"},"twitter":{"visibility":"show_users_only"},"website":{"visibility":"show_users_only"},"talk":{"visibility":"show"},"birthdate":{"visibility":"show_users_only"},"pronouns":{"visibility":"show"}} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account-complex.jpg b/apps/settings/tests/UserMigration/assets/account-complex.jpg
index bece3675c11..94508343322 100644
--- a/apps/settings/tests/UserMigration/assets/account-complex.jpg
+++ b/apps/settings/tests/UserMigration/assets/account-complex.jpg
Binary files differ
diff --git a/apps/settings/tests/UserMigration/assets/account-complex.json b/apps/settings/tests/UserMigration/assets/account-complex.json
index f16a74174e7..cb4668cf18c 100644
--- a/apps/settings/tests/UserMigration/assets/account-complex.json
+++ b/apps/settings/tests/UserMigration/assets/account-complex.json
@@ -1 +1 @@
-{"displayname":{"name":"displayname","value":"Steve Smith","scope":"v2-local","verified":"0","verificationData":""},"address":{"name":"address","value":"123 Water St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"https:\/\/example.org","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"steve@example.org","scope":"v2-federated","verified":"0","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-local","verified":"0","verificationData":""},"phone":{"name":"phone","value":"+12178515387","scope":"v2-private","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"steve","scope":"v2-federated","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"@steve@floss.social","scope":"v2-federated","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"Mytery Machine","scope":"v2-private","verified":"0","verificationData":""},"role":{"name":"role","value":"Manager","scope":"v2-private","verified":"0","verificationData":""},"headline":{"name":"headline","value":"I am Steve","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porttitor ullamcorper dictum. Sed fermentum ut ligula scelerisque semper. Aliquam interdum convallis tellus eu dapibus. Integer in justo sollicitudin, hendrerit ligula sit amet, blandit sem.\n\nSuspendisse consectetur ultrices accumsan. Quisque sagittis bibendum lectus ut placerat. Mauris tincidunt ornare neque, et pulvinar tortor porttitor eu.","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"additional_mail":[{"name":"additional_mail","value":"steve@example.com","scope":"v2-published","verified":"0","verificationData":""},{"name":"additional_mail","value":"steve@earth.world","scope":"v2-local","verified":"0","verificationData":""}]} \ No newline at end of file
+{"displayname":{"name":"displayname","value":"Steve Smith","scope":"v2-local","verified":"0","verificationData":""},"address":{"name":"address","value":"123 Water St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"https://example.org","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"steve@example.org","scope":"v2-federated","verified":"1","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-local","verified":"0","verificationData":""},"phone":{"name":"phone","value":"+12178515387","scope":"v2-private","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"steve","scope":"v2-federated","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"steve@floss.social","scope":"v2-federated","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"Mytery Machine","scope":"v2-private","verified":"0","verificationData":""},"role":{"name":"role","value":"Manager","scope":"v2-private","verified":"0","verificationData":""},"headline":{"name":"headline","value":"I am Steve","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porttitor ullamcorper dictum. Sed fermentum ut ligula scelerisque semper. Aliquam interdum convallis tellus eu dapibus. Integer in justo sollicitudin, hendrerit ligula sit amet, blandit sem.\n\nSuspendisse consectetur ultrices accumsan. Quisque sagittis bibendum lectus ut placerat. Mauris tincidunt ornare neque, et pulvinar tortor porttitor eu.","scope":"v2-local","verified":"0","verificationData":""},"birthdate":{"name":"birthdate","value":"","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"pronouns":{"name":"pronouns","value":"they/them","scope":"v2-local","verified":"0","verificationData":""},"additional_mail":[{"name":"additional_mail","value":"steve@example.com","scope":"v2-published","verified":"0","verificationData":""},{"name":"additional_mail","value":"steve@earth.world","scope":"v2-local","verified":"0","verificationData":""}]} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account-config.json b/apps/settings/tests/UserMigration/assets/account-config.json
index 442857ced34..a1250fab8e9 100644
--- a/apps/settings/tests/UserMigration/assets/account-config.json
+++ b/apps/settings/tests/UserMigration/assets/account-config.json
@@ -1 +1 @@
-{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"show_users_only"},"phone":{"visibility":"show_users_only"},"twitter":{"visibility":"show"},"website":{"visibility":"show"}} \ No newline at end of file
+{"address":{"visibility":"show_users_only"},"avatar":{"visibility":"show"},"biography":{"visibility":"show"},"displayname":{"visibility":"show"},"fediverse":{"visibility":"show"},"headline":{"visibility":"show"},"organisation":{"visibility":"show"},"role":{"visibility":"show"},"email":{"visibility":"show_users_only"},"phone":{"visibility":"show_users_only"},"twitter":{"visibility":"show"},"website":{"visibility":"show"},"birthdate":{"visibility":"show"},"pronouns":{"visibility":"show"}} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account.json b/apps/settings/tests/UserMigration/assets/account.json
index 0dd5185a6ab..6bdc3c72d47 100644
--- a/apps/settings/tests/UserMigration/assets/account.json
+++ b/apps/settings/tests/UserMigration/assets/account.json
@@ -1 +1 @@
-{"displayname":{"name":"displayname","value":"Emma Jones","scope":"v2-federated","verified":"0","verificationData":""},"address":{"name":"address","value":"920 Grass St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"","scope":"v2-federated","verified":"0","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-federated","verified":"0","verificationData":""},"phone":{"name":"phone","value":"","scope":"v2-local","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"","scope":"v2-local","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"","scope":"v2-local","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"","scope":"v2-local","verified":"0","verificationData":""},"role":{"name":"role","value":"","scope":"v2-local","verified":"0","verificationData":""},"headline":{"name":"headline","value":"","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"additional_mail":[]} \ No newline at end of file
+{"displayname":{"name":"displayname","value":"Emma Jones","scope":"v2-federated","verified":"0","verificationData":""},"address":{"name":"address","value":"920 Grass St","scope":"v2-local","verified":"0","verificationData":""},"website":{"name":"website","value":"","scope":"v2-local","verified":"0","verificationData":""},"email":{"name":"email","value":"","scope":"v2-federated","verified":"1","verificationData":""},"avatar":{"name":"avatar","value":"","scope":"v2-federated","verified":"0","verificationData":""},"phone":{"name":"phone","value":"","scope":"v2-local","verified":"0","verificationData":""},"twitter":{"name":"twitter","value":"","scope":"v2-local","verified":"0","verificationData":""},"fediverse":{"name":"fediverse","value":"","scope":"v2-local","verified":"0","verificationData":""},"organisation":{"name":"organisation","value":"","scope":"v2-local","verified":"0","verificationData":""},"role":{"name":"role","value":"","scope":"v2-local","verified":"0","verificationData":""},"headline":{"name":"headline","value":"","scope":"v2-local","verified":"0","verificationData":""},"biography":{"name":"biography","value":"","scope":"v2-local","verified":"0","verificationData":""},"birthdate":{"name":"birthdate","value":"","scope":"v2-local","verified":"0","verificationData":""},"profile_enabled":{"name":"profile_enabled","value":"1","scope":"v2-local","verified":"0","verificationData":""},"pronouns":{"name":"pronouns","value":"","scope":"v2-federated","verified":"0","verificationData":""},"additional_mail":[]} \ No newline at end of file
diff --git a/apps/settings/tests/UserMigration/assets/account.png b/apps/settings/tests/UserMigration/assets/account.png
index 12226f14334..41c4924e569 100644
--- a/apps/settings/tests/UserMigration/assets/account.png
+++ b/apps/settings/tests/UserMigration/assets/account.png
Binary files differ