diff options
Diffstat (limited to 'apps/settings/tests/Controller/UsersControllerTest.php')
-rw-r--r-- | apps/settings/tests/Controller/UsersControllerTest.php | 122 |
1 files changed, 44 insertions, 78 deletions
diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php index 96823e5ceed..d5fe38ad458 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, @@ -249,12 +237,8 @@ class UsersControllerTest extends \Test\TestCase { /** * @dataProvider dataTestSetUserSettings - * - * @param string $email - * @param bool $validEmail - * @param $expectedStatus */ - public function testSetUserSettings($email, $validEmail, $expectedStatus): void { + 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 +289,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], @@ -515,18 +499,15 @@ class UsersControllerTest extends \Test\TestCase { /** * @dataProvider dataTestSetUserSettingsSubset - * - * @param string $property - * @param string $propertyValue */ - public function testSetUserSettingsSubset($property, $propertyValue): void { + 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()) @@ -554,9 +535,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; @@ -636,7 +617,7 @@ class UsersControllerTest extends \Test\TestCase { ); } - public function dataTestSetUserSettingsSubset() { + public static function dataTestSetUserSettingsSubset(): array { return [ ['avatarScope', IAccountManager::SCOPE_PUBLISHED], ['displayName', 'Display name'], @@ -662,15 +643,8 @@ class UsersControllerTest extends \Test\TestCase { /** * @dataProvider dataTestSaveUserSettings - * - * @param array $data - * @param ?string $oldEmailAddress - * @param ?string $oldDisplayName */ - public function testSaveUserSettings($data, - $oldEmailAddress, - $oldDisplayName, - ): void { + public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void { $controller = $this->getController(); $user = $this->createMock(IUser::class); @@ -722,7 +696,7 @@ class UsersControllerTest extends \Test\TestCase { $this->invokePrivate($controller, 'saveUserSettings', [$account]); } - public function dataTestSaveUserSettings() { + public static function dataTestSaveUserSettings(): array { return [ [ [ @@ -833,7 +807,7 @@ class UsersControllerTest extends \Test\TestCase { } - public function dataTestSaveUserSettingsException() { + public static function dataTestSaveUserSettingsException(): array { return [ [ [ @@ -870,14 +844,9 @@ 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 { + 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 +905,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'], @@ -973,16 +942,13 @@ class UsersControllerTest extends \Test\TestCase { /** * @dataProvider dataTestCanAdminChangeUserPasswords - * - * @param bool $encryptionEnabled - * @param bool $encryptionModuleLoaded - * @param bool $masterKeyEnabled - * @param bool $expected */ - public function testCanAdminChangeUserPasswords($encryptionEnabled, - $encryptionModuleLoaded, - $masterKeyEnabled, - $expected): void { + public function testCanAdminChangeUserPasswords( + bool $encryptionEnabled, + bool $encryptionModuleLoaded, + bool $masterKeyEnabled, + bool $expected, + ): void { $controller = $this->getController(); $this->encryptionManager->expects($this->any()) @@ -1005,7 +971,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], |