aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Controller/UsersControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Controller/UsersControllerTest.php')
-rw-r--r--apps/settings/tests/Controller/UsersControllerTest.php167
1 files changed, 71 insertions, 96 deletions
diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php
index 96823e5ceed..1012557bfc4 100644
--- a/apps/settings/tests/Controller/UsersControllerTest.php
+++ b/apps/settings/tests/Controller/UsersControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014-2015 ownCloud, Inc.
@@ -40,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();
@@ -85,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);
@@ -106,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);
@@ -155,7 +141,9 @@ class UsersControllerTest extends \Test\TestCase {
$this->dispatcher,
$this->initialState,
]
- )->onlyMethods($mockedMethods)->getMock();
+ )
+ ->onlyMethods($mockedMethods)
+ ->getMock();
}
}
@@ -177,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,
@@ -214,6 +202,11 @@ 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 fediverse',
@@ -247,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): void {
+ #[\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');
@@ -305,7 +292,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame($expectedStatus, $result->getStatus());
}
- public function dataTestSetUserSettings() {
+ public static function dataTestSetUserSettings(): array {
return [
['', true, Http::STATUS_OK],
['', false, Http::STATUS_OK],
@@ -453,6 +440,8 @@ 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';
@@ -476,6 +465,8 @@ 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;
@@ -504,6 +495,8 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope,
$twitter,
$twitterScope,
+ $bluesky,
+ $blueskyScope,
$fediverse,
$fediverseScope,
$birthdate,
@@ -513,20 +506,15 @@ class UsersControllerTest extends \Test\TestCase {
);
}
- /**
- * @dataProvider dataTestSetUserSettingsSubset
- *
- * @param string $property
- * @param string $propertyValue
- */
- public function testSetUserSettingsSubset($property, $propertyValue): void {
+ #[\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())
@@ -547,6 +535,8 @@ 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;
@@ -554,9 +544,9 @@ class UsersControllerTest extends \Test\TestCase {
$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;
@@ -585,6 +575,10 @@ 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;
@@ -627,6 +621,8 @@ class UsersControllerTest extends \Test\TestCase {
$addressScope,
$twitter,
$twitterScope,
+ $bluesky,
+ $blueskyScope,
$fediverse,
$fediverseScope,
$birthdate,
@@ -636,7 +632,7 @@ class UsersControllerTest extends \Test\TestCase {
);
}
- public function dataTestSetUserSettingsSubset() {
+ public static function dataTestSetUserSettingsSubset(): array {
return [
['avatarScope', IAccountManager::SCOPE_PUBLISHED],
['displayName', 'Display name'],
@@ -651,6 +647,8 @@ 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'],
@@ -660,17 +658,8 @@ class UsersControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataTestSaveUserSettings
- *
- * @param array $data
- * @param ?string $oldEmailAddress
- * @param ?string $oldDisplayName
- */
- public function testSaveUserSettings($data,
- $oldEmailAddress,
- $oldDisplayName,
- ): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettings')]
+ public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void {
$controller = $this->getController();
$user = $this->createMock(IUser::class);
@@ -722,7 +711,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->invokePrivate($controller, 'saveUserSettings', [$account]);
}
- public function dataTestSaveUserSettings() {
+ public static function dataTestSaveUserSettings(): array {
return [
[
[
@@ -784,9 +773,7 @@ class UsersControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataTestSaveUserSettingsException
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettingsException')]
public function testSaveUserSettingsException(
array $data,
string $oldEmailAddress,
@@ -833,7 +820,7 @@ class UsersControllerTest extends \Test\TestCase {
}
- public function dataTestSaveUserSettingsException() {
+ public static function dataTestSaveUserSettingsException(): array {
return [
[
[
@@ -869,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): void {
+ #[\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';
@@ -936,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'],
@@ -971,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): void {
+ #[\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())
@@ -1005,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],