diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-05-25 21:22:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-25 21:22:37 +0200 |
commit | 1b47886abb85d97fd6825db6c4edef3fbd278881 (patch) | |
tree | c4b8389196b5a9adde015f24e941a542a4ce0cc3 /tests | |
parent | 3d1c78647e2dcc9c3ca2dcad28f39a2b7e5bc589 (diff) | |
parent | 847ed37afcc2b00f8dcf9ffc9f2f0671a3539bd4 (diff) | |
download | nextcloud-server-1b47886abb85d97fd6825db6c4edef3fbd278881.tar.gz nextcloud-server-1b47886abb85d97fd6825db6c4edef3fbd278881.zip |
Merge pull request #27035 from nextcloud/techdebt/26866/userscontroller-accountmanager-api
do not use private AccountManager in UsersController
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Accounts/AccountManagerTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountPropertyTest.php | 35 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountTest.php | 16 |
3 files changed, 40 insertions, 18 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index 1da128ae124..9bce92716ac 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -106,6 +106,7 @@ class AccountManagerTest extends TestCase { /** @var IUser $user */ $user = $this->createMock(IUser::class); + // FIXME: should be an integration test instead of this abomination $accountManager->expects($this->once())->method('getUser')->with($user)->willReturn($oldData); if ($updateExisting) { @@ -147,9 +148,9 @@ class AccountManagerTest extends TestCase { public function dataTrueFalse() { return [ - [['newData'], ['oldData'], false, true], - [['newData'], [], true, false], - [['oldData'], ['oldData'], false, false] + [['myProperty' => ['value' => 'newData']], ['myProperty' => ['value' => 'oldData']], false, true], + [['myProperty' => ['value' => 'newData']], [], true, false], + [['myProperty' => ['value' => 'oldData']], ['myProperty' => ['value' => 'oldData']], false, false] ]; } diff --git a/tests/lib/Accounts/AccountPropertyTest.php b/tests/lib/Accounts/AccountPropertyTest.php index 84059bbc35d..50c3b8f84a4 100644 --- a/tests/lib/Accounts/AccountPropertyTest.php +++ b/tests/lib/Accounts/AccountPropertyTest.php @@ -38,7 +38,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $this->assertEquals(IAccountManager::PROPERTY_WEBSITE, $accountProperty->getName()); $this->assertEquals('https://example.com', $accountProperty->getValue()); @@ -51,7 +52,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setValue('https://example.org'); $this->assertEquals('https://example.org', $accountProperty->getValue()); @@ -63,7 +65,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setScope(IAccountManager::SCOPE_LOCAL); $this->assertEquals(IAccountManager::SCOPE_LOCAL, $accountProperty->getScope()); @@ -98,7 +101,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', $storedScope, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $this->assertEquals($returnedScope, $accountProperty->getScope()); } @@ -108,25 +112,42 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setVerified(IAccountManager::NOT_VERIFIED); $this->assertEquals(IAccountManager::NOT_VERIFIED, $accountProperty->getVerified()); $this->assertEquals(IAccountManager::NOT_VERIFIED, $actualReturn->getVerified()); } + public function testSetVerificationData() { + $accountProperty = new AccountProperty( + IAccountManager::PROPERTY_WEBSITE, + 'https://example.com', + IAccountManager::SCOPE_PUBLISHED, + IAccountManager::VERIFIED, + '' + ); + $token = uniqid(); + $actualReturn = $accountProperty->setVerificationData($token); + $this->assertEquals($token, $accountProperty->getVerificationData()); + $this->assertEquals($token, $actualReturn->getVerificationData()); + } + public function testJsonSerialize() { $accountProperty = new AccountProperty( IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '60a7a633b74af', ); $this->assertEquals([ 'name' => IAccountManager::PROPERTY_WEBSITE, 'value' => 'https://example.com', 'scope' => IAccountManager::SCOPE_PUBLISHED, - 'verified' => IAccountManager::VERIFIED + 'verified' => IAccountManager::VERIFIED, + 'verificationData' => '60a7a633b74af' ], $accountProperty->jsonSerialize()); } } diff --git a/tests/lib/Accounts/AccountTest.php b/tests/lib/Accounts/AccountTest.php index 8afcc44afd1..9c2a5333d20 100644 --- a/tests/lib/Accounts/AccountTest.php +++ b/tests/lib/Accounts/AccountTest.php @@ -43,7 +43,7 @@ class AccountTest extends TestCase { public function testSetProperty() { $user = $this->createMock(IUser::class); - $property = new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); + $property = new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''); $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); $this->assertEquals($property, $account->getProperty(IAccountManager::PROPERTY_WEBSITE)); @@ -52,8 +52,8 @@ class AccountTest extends TestCase { public function testGetProperties() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED) + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, '') ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); @@ -65,9 +65,9 @@ class AccountTest extends TestCase { public function testGetFilteredProperties() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED), - IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED), + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, ''), + IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED, ''), ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); @@ -98,8 +98,8 @@ class AccountTest extends TestCase { public function testJsonSerialize() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED) + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, '') ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); |