diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-03 19:53:18 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-03 20:49:49 +0200 |
commit | 44827e37c0a2e9f69feae6a741a223bf19e49685 (patch) | |
tree | e9992e8ae8d85c5a0ad344207bc9d80fa0bd5539 /tests | |
parent | 0bade2747902b22002203c31e7e13f36256f42bc (diff) | |
download | nextcloud-server-44827e37c0a2e9f69feae6a741a223bf19e49685.tar.gz nextcloud-server-44827e37c0a2e9f69feae6a741a223bf19e49685.zip |
allow interacting with IAccountPropertyCollections
- in fact the API could be done in a nicer way and it might be possible to
work without IAccountPropertyCollection, but only with the
IAccountProperties.
- To keep it simple at first and not overengineer the blunt attempt is
followed
- If necessary helpful in the further cause of development adjustements or
extensions can be done quickly with this base
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Accounts/AccountTest.php | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/lib/Accounts/AccountTest.php b/tests/lib/Accounts/AccountTest.php index 9c2a5333d20..0e0c42804e4 100644 --- a/tests/lib/Accounts/AccountTest.php +++ b/tests/lib/Accounts/AccountTest.php @@ -25,6 +25,7 @@ namespace Test\Accounts; use OC\Accounts\Account; use OC\Accounts\AccountProperty; +use OC\Accounts\AccountPropertyCollection; use OCP\Accounts\IAccountManager; use OCP\IUser; use Test\TestCase; @@ -49,7 +50,7 @@ class AccountTest extends TestCase { $this->assertEquals($property, $account->getProperty(IAccountManager::PROPERTY_WEBSITE)); } - public function testGetProperties() { + public function testGetAndGetAllProperties() { $user = $this->createMock(IUser::class); $properties = [ IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), @@ -59,7 +60,14 @@ class AccountTest extends TestCase { $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); $account->setProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED); + $col = new AccountPropertyCollection(IAccountManager::COLLECTION_EMAIL); + $additionalProperty = new AccountProperty($col->getName(), 'second@example.org', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''); + $col->addProperty($additionalProperty); + $account->setPropertyCollection($col); + $this->assertEquals($properties, $account->getProperties()); + $properties[] = $additionalProperty; + $this->assertEquals(array_values($properties), \iterator_to_array($account->getAllProperties())); } public function testGetFilteredProperties() { @@ -74,11 +82,20 @@ class AccountTest extends TestCase { $account->setProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED); $account->setProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED); + $col = new AccountPropertyCollection(IAccountManager::COLLECTION_EMAIL); + $additionalProperty1 = new AccountProperty($col->getName(), 'second@example.org', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''); + $additionalProperty2 = new AccountProperty($col->getName(), 'third@example.org', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED, ''); + $col->addProperty($additionalProperty1); + $col->addProperty($additionalProperty2); + $account->setPropertyCollection($col); + $this->assertEquals( [ IAccountManager::PROPERTY_WEBSITE => $properties[IAccountManager::PROPERTY_WEBSITE], IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE], + IAccountManager::COLLECTION_EMAIL . '#0' => $additionalProperty1, + IAccountManager::COLLECTION_EMAIL . '#1' => $additionalProperty2, ], $account->getFilteredProperties(IAccountManager::SCOPE_PUBLISHED) ); @@ -86,12 +103,16 @@ class AccountTest extends TestCase { [ IAccountManager::PROPERTY_EMAIL => $properties[IAccountManager::PROPERTY_EMAIL], IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE], + IAccountManager::COLLECTION_EMAIL . '#0' => $additionalProperty2, ], $account->getFilteredProperties(null, IAccountManager::VERIFIED) ); $this->assertEquals( - [IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE]], - $account->getFilteredProperties(IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED) + [ + IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE], + IAccountManager::COLLECTION_EMAIL . '#0' => $additionalProperty2, + ], + $account->getFilteredProperties(IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED), ); } |