diff options
Diffstat (limited to 'tests/lib/Accounts')
-rw-r--r-- | tests/lib/Accounts/AccountManagerTest.php | 99 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountPropertyTest.php | 12 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Accounts/HooksTest.php | 15 |
4 files changed, 71 insertions, 57 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index fab3aaf5fdd..c625644bd96 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -29,6 +29,7 @@ use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Security\ICrypto; use OCP\Security\VerificationToken\IVerificationToken; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -61,7 +62,7 @@ class AccountManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OCP\Server::get(IDBConnection::class); + $this->connection = Server::get(IDBConnection::class); $this->phoneNumberUtil = new PhoneNumberUtil(); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); @@ -461,10 +462,7 @@ class AccountManagerTest extends TestCase { ->getMock(); } - /** - * @dataProvider dataTrueFalse - * - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTrueFalse')] public function testUpdateUser(array $newData, array $oldData, bool $insertNew, bool $updateExisting): void { $accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser']); /** @var IUser $user */ @@ -488,7 +486,7 @@ class AccountManagerTest extends TestCase { } else { $this->eventDispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback( - function ($event) use ($user, $newData) { + function ($event) use ($user, $newData): void { $this->assertInstanceOf(UserUpdatedEvent::class, $event); $this->assertSame($user, $event->getUser()); $this->assertSame($newData, $event->getData()); @@ -499,7 +497,7 @@ class AccountManagerTest extends TestCase { $this->invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]); } - public function dataTrueFalse(): array { + public static function dataTrueFalse(): array { return [ #$newData | $oldData | $insertNew | $updateExisting [['myProperty' => ['value' => 'newData']], ['myProperty' => ['value' => 'oldData']], false, true], @@ -577,6 +575,13 @@ class AccountManagerTest extends TestCase { ], [ + 'name' => IAccountManager::PROPERTY_BLUESKY, + 'value' => '', + 'scope' => IAccountManager::SCOPE_LOCAL, + 'verified' => IAccountManager::NOT_VERIFIED, + ], + + [ 'name' => IAccountManager::PROPERTY_FEDIVERSE, 'value' => '', 'scope' => IAccountManager::SCOPE_LOCAL, @@ -683,9 +688,7 @@ class AccountManagerTest extends TestCase { ]; } - /** - * @dataProvider dataParsePhoneNumber - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataParsePhoneNumber')] public function testSanitizePhoneNumberOnUpdateAccount(string $phoneInput, string $defaultRegion, ?string $phoneNumber): void { $this->config->method('getSystemValueString') ->willReturn($defaultRegion); @@ -737,9 +740,7 @@ class AccountManagerTest extends TestCase { ]; } - /** - * @dataProvider dataSanitizeOnUpdate - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSanitizeOnUpdate')] public function testSanitizingOnUpdateAccount(string $property, string $input, ?string $output): void { if ($property === IAccountManager::PROPERTY_FEDIVERSE) { @@ -792,20 +793,41 @@ class AccountManagerTest extends TestCase { '@foo@example.com', 'foo@example.com', true, - json_encode(['username' => 'foo']), + json_encode([ + 'subject' => 'acct:foo@example.com', + 'links' => [ + [ + 'rel' => 'self', + 'type' => 'application/activity+json', + 'href' => 'https://example.com/users/foo', + ], + ], + ]), ], 'valid response - no at' => [ 'foo@example.com', 'foo@example.com', true, - json_encode(['username' => 'foo']), + json_encode([ + 'subject' => 'acct:foo@example.com', + 'links' => [ + [ + 'rel' => 'self', + 'type' => 'application/activity+json', + 'href' => 'https://example.com/users/foo', + ], + ], + ]), ], // failures 'invalid response' => [ '@foo@example.com', null, true, - json_encode(['not found']), + json_encode([ + 'subject' => 'acct:foo@example.com', + 'links' => [], + ]), ], 'no response' => [ '@foo@example.com', @@ -817,14 +839,14 @@ class AccountManagerTest extends TestCase { '@foo@example.com', null, true, - json_encode(['username' => 'foo@other.example.com']), + json_encode([ + 'links' => [], + ]), ], ]; } - /** - * @dataProvider dataSanitizeFediverseServer - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSanitizeFediverseServer')] public function testSanitizingFediverseServer(string $input, ?string $output, bool $hasInternet, ?string $serverResponse): void { $this->config->expects(self::once()) ->method('getSystemValueBool') @@ -839,12 +861,12 @@ class AccountManagerTest extends TestCase { ->willReturn($serverResponse); $client->expects(self::once()) ->method('get') - ->with('https://example.com/api/v1/accounts/lookup?acct=foo@example.com') + ->with('https://example.com/.well-known/webfinger?resource=acct:foo@example.com') ->willReturn($response); } else { $client->expects(self::once()) ->method('get') - ->with('https://example.com/api/v1/accounts/lookup?acct=foo@example.com') + ->with('https://example.com/.well-known/webfinger?resource=acct:foo@example.com') ->willThrowException(new \Exception('404')); } @@ -881,9 +903,7 @@ class AccountManagerTest extends TestCase { } } - /** - * @dataProvider searchDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('searchDataProvider')] public function testSearchUsers(string $property, array $values, array $expected): void { $this->populateOrUpdate(); @@ -896,7 +916,7 @@ class AccountManagerTest extends TestCase { } } - public function searchDataProvider(): array { + public static function searchDataProvider(): array { return [ [ #0 Search for an existing name IAccountManager::PROPERTY_DISPLAYNAME, @@ -948,21 +968,20 @@ class AccountManagerTest extends TestCase { ]; } - public function dataCheckEmailVerification(): array { + public static function dataCheckEmailVerification(): array { return [ - [$this->makeUser('steve', 'Steve Smith', 'steve@steve.steve'), null], - [$this->makeUser('emma', 'Emma Morales', 'emma@emma.com'), 'emma@morales.com'], - [$this->makeUser('sarah@web.org', 'Sarah Foster', 'sarah@web.org'), null], - [$this->makeUser('cole@web.org', 'Cole Harrison', 'cole@web.org'), 'cole@example.com'], - [$this->makeUser('8d29e358-cf69-4849-bbf9-28076c0b908b', 'Alice McPherson', 'alice@example.com'), 'alice@mcpherson.com'], - [$this->makeUser('11da2744-3f4d-4c17-8c13-4c057a379237', 'James Loranger', 'james@example.com'), ''], + [['steve', 'Steve Smith', 'steve@steve.steve'], null], + [['emma', 'Emma Morales', 'emma@emma.com'], 'emma@morales.com'], + [['sarah@web.org', 'Sarah Foster', 'sarah@web.org'], null], + [['cole@web.org', 'Cole Harrison', 'cole@web.org'], 'cole@example.com'], + [['8d29e358-cf69-4849-bbf9-28076c0b908b', 'Alice McPherson', 'alice@example.com'], 'alice@mcpherson.com'], + [['11da2744-3f4d-4c17-8c13-4c057a379237', 'James Loranger', 'james@example.com'], ''], ]; } - /** - * @dataProvider dataCheckEmailVerification - */ - public function testCheckEmailVerification(IUser $user, ?string $newEmail): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataCheckEmailVerification')] + public function testCheckEmailVerification(array $userData, ?string $newEmail): void { + $user = $this->makeUser(...$userData); // Once because of getAccount, once because of getUser $this->config->expects($this->exactly(2))->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn([]); $account = $this->accountManager->getAccount($user); @@ -988,7 +1007,7 @@ class AccountManagerTest extends TestCase { $this->invokePrivate($this->accountManager, 'checkEmailVerification', [$account, $oldData]); } - public function dataSetDefaultPropertyScopes(): array { + public static function dataSetDefaultPropertyScopes(): array { return [ [ [], @@ -1025,9 +1044,7 @@ class AccountManagerTest extends TestCase { ]; } - /** - * @dataProvider dataSetDefaultPropertyScopes - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetDefaultPropertyScopes')] public function testSetDefaultPropertyScopes(array $propertyScopes, array $expectedResultScopes): void { $user = $this->makeUser('steve', 'Steve Smith', 'steve@steve.steve'); $this->config->expects($this->once())->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn($propertyScopes); diff --git a/tests/lib/Accounts/AccountPropertyTest.php b/tests/lib/Accounts/AccountPropertyTest.php index 5df66eaa117..b92e45176a3 100644 --- a/tests/lib/Accounts/AccountPropertyTest.php +++ b/tests/lib/Accounts/AccountPropertyTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -56,27 +57,20 @@ class AccountPropertyTest extends TestCase { $this->assertEquals(IAccountManager::SCOPE_LOCAL, $actualReturn->getScope()); } - public function scopesProvider() { + public static function scopesProvider(): array { return [ // current values [IAccountManager::SCOPE_PRIVATE, IAccountManager::SCOPE_PRIVATE], [IAccountManager::SCOPE_LOCAL, IAccountManager::SCOPE_LOCAL], [IAccountManager::SCOPE_FEDERATED, IAccountManager::SCOPE_FEDERATED], [IAccountManager::SCOPE_PUBLISHED, IAccountManager::SCOPE_PUBLISHED], - // legacy values - [IAccountManager::VISIBILITY_PRIVATE, IAccountManager::SCOPE_LOCAL], - [IAccountManager::VISIBILITY_CONTACTS_ONLY, IAccountManager::SCOPE_FEDERATED], - [IAccountManager::VISIBILITY_PUBLIC, IAccountManager::SCOPE_PUBLISHED], - ['', IAccountManager::SCOPE_LOCAL], // invalid values ['unknown', null], ['v2-unknown', null], ]; } - /** - * @dataProvider scopesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('scopesProvider')] public function testSetScopeMapping(string $storedScope, ?string $returnedScope): void { if ($returnedScope === null) { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/lib/Accounts/AccountTest.php b/tests/lib/Accounts/AccountTest.php index 34653bd864a..ddba7c559c0 100644 --- a/tests/lib/Accounts/AccountTest.php +++ b/tests/lib/Accounts/AccountTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -63,6 +64,7 @@ class AccountTest extends TestCase { IAccountManager::PROPERTY_AVATAR => new AccountProperty(IAccountManager::PROPERTY_AVATAR, '', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '+358407991028', IAccountManager::SCOPE_LOCAL, IAccountManager::NOT_VERIFIED, ''), IAccountManager::PROPERTY_TWITTER => new AccountProperty(IAccountManager::PROPERTY_TWITTER, 'therealsteve', IAccountManager::SCOPE_PRIVATE, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_BLUESKY => new AccountProperty(IAccountManager::PROPERTY_BLUESKY, 'therealsteve.bsky.social', IAccountManager::SCOPE_PRIVATE, IAccountManager::NOT_VERIFIED, ''), IAccountManager::PROPERTY_ORGANISATION => new AccountProperty(IAccountManager::PROPERTY_ORGANISATION, 'Steve Incorporated', IAccountManager::SCOPE_FEDERATED, IAccountManager::NOT_VERIFIED, ''), IAccountManager::PROPERTY_ROLE => new AccountProperty(IAccountManager::PROPERTY_ROLE, 'Founder', IAccountManager::SCOPE_FEDERATED, IAccountManager::NOT_VERIFIED, ''), IAccountManager::PROPERTY_HEADLINE => new AccountProperty(IAccountManager::PROPERTY_HEADLINE, 'I am Steve', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), diff --git a/tests/lib/Accounts/HooksTest.php b/tests/lib/Accounts/HooksTest.php index 75772089f43..622fb3c7461 100644 --- a/tests/lib/Accounts/HooksTest.php +++ b/tests/lib/Accounts/HooksTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -43,7 +44,6 @@ class HooksTest extends TestCase { } /** - * @dataProvider dataTestChangeUserHook * * @param $params * @param $data @@ -51,6 +51,7 @@ class HooksTest extends TestCase { * @param $setDisplayName * @param $error */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestChangeUserHook')] public function testChangeUserHook($params, $data, $setEmail, $setDisplayName, $error): void { if ($error) { $this->accountManager->expects($this->never())->method('updateAccount'); @@ -96,14 +97,14 @@ class HooksTest extends TestCase { } } + $params['user'] = $this->createMock(IUser::class); $this->hooks->changeUserHook($params['user'], $params['feature'], $params['value']); } - public function dataTestChangeUserHook() { - $user = $this->createMock(IUser::class); + public static function dataTestChangeUserHook(): array { return [ [ - ['user' => $user, 'feature' => '', 'value' => ''], + ['feature' => '', 'value' => ''], [ IAccountManager::PROPERTY_EMAIL => ['value' => ''], IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] @@ -111,7 +112,7 @@ class HooksTest extends TestCase { false, false, true ], [ - ['user' => $user, 'feature' => 'foo', 'value' => 'bar'], + ['feature' => 'foo', 'value' => 'bar'], [ IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] @@ -119,7 +120,7 @@ class HooksTest extends TestCase { false, false, false ], [ - ['user' => $user, 'feature' => 'eMailAddress', 'value' => 'newMail@example.com'], + ['feature' => 'eMailAddress', 'value' => 'newMail@example.com'], [ IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] @@ -127,7 +128,7 @@ class HooksTest extends TestCase { true, false, false ], [ - ['user' => $user, 'feature' => 'displayName', 'value' => 'newDisplayName'], + ['feature' => 'displayName', 'value' => 'newDisplayName'], [ IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'], IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |