aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2021-06-08 14:25:18 +0200
committerGitHub <noreply@github.com>2021-06-08 14:25:18 +0200
commit662ab937e0d30947727be1462f8744681fdd2e49 (patch)
tree3b857453adb11fb00d23d68515b85f6f84cfad6c /tests
parentb3cfa1859b14384ae8134e8eb88c171667f77799 (diff)
parentff2382e5a4a5c29e3e1c948a514c151cae71d402 (diff)
downloadnextcloud-server-662ab937e0d30947727be1462f8744681fdd2e49.tar.gz
nextcloud-server-662ab937e0d30947727be1462f8744681fdd2e49.zip
Merge pull request #27189 from nextcloud/feat/26866/account-collection-properties
Extend Accounts with multivalue properties (PropertyCollection)
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Accounts/AccountManagerTest.php187
-rw-r--r--tests/lib/Accounts/AccountPropertyCollectionTest.php209
-rw-r--r--tests/lib/Accounts/AccountTest.php27
3 files changed, 404 insertions, 19 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php
index 9bce92716ac..ea82bd04f3f 100644
--- a/tests/lib/Accounts/AccountManagerTest.php
+++ b/tests/lib/Accounts/AccountManagerTest.php
@@ -26,6 +26,7 @@ use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
@@ -59,13 +60,24 @@ class AccountManagerTest extends TestCase {
/** @var LoggerInterface|MockObject */
private $logger;
+ /** @var AccountManager */
+ private $accountManager;
+
protected function setUp(): void {
parent::setUp();
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = \OC::$server->get(IDBConnection::class);
$this->config = $this->createMock(IConfig::class);
$this->jobList = $this->createMock(IJobList::class);
$this->logger = $this->createMock(LoggerInterface::class);
+
+ $this->accountManager = new AccountManager(
+ $this->connection,
+ $this->config,
+ $this->eventDispatcher,
+ $this->jobList,
+ $this->logger,
+ );
}
protected function tearDown(): void {
@@ -74,6 +86,90 @@ class AccountManagerTest extends TestCase {
$query->delete($this->table)->execute();
}
+ protected function makeUser(string $uid, string $name, string $email = null): IUser {
+ $user = $this->createMock(IUser::class);
+ $user->expects($this->any())
+ ->method('getUid')
+ ->willReturn($uid);
+ $user->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn($name);
+ if ($email !== null) {
+ $user->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn($email);
+ }
+
+ return $user;
+ }
+
+ protected function populateOrUpdate(): void {
+ $users = [
+ [
+ 'user' => $this->makeUser('j.doe', 'Jane Doe', 'jane.doe@acme.com'),
+ 'data' => [
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Jane Doe', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'jane.doe@acme.com', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_ADDRESS => ['value' => 'some street', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://acme.com', 'scope' => IAccountManager::SCOPE_PRIVATE],
+ ],
+ ],
+ [
+ 'user' => $this->makeUser('a.allison', 'Alice Allison', 'a.allison@example.org'),
+ 'data' => [
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Alice Allison', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'a.allison@example.org', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '@a_alice', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_PHONE => ['value' => '+491602312121', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_ADDRESS => ['value' => 'Dundee Road 45', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.org', 'scope' => IAccountManager::SCOPE_LOCAL],
+ ],
+ ],
+ [
+ 'user' => $this->makeUser('b32c5a5b-1084-4380-8856-e5223b16de9f', 'Armel Oliseh', 'oliseh@example.com'),
+ 'data' => [
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Armel Oliseh', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'oliseh@example.com', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_PHONE => ['value' => '+491603121212', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_ADDRESS => ['value' => 'Sunflower Blvd. 77', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.com', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ ],
+ ],
+ [
+ 'user' => $this->makeUser('31b5316a-9b57-4b17-970a-315a4cbe73eb', 'K. Cheng', 'cheng@emca.com'),
+ 'data' => [
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'K. Cheng', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'cheng@emca.com', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_PHONE => ['value' => '+71601212123', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_ADDRESS => ['value' => 'Pinapple Street 22', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://emca.com', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::COLLECTION_EMAIL => [
+ ['value' => 'k.cheng@emca.com', 'scope' => IAccountManager::SCOPE_LOCAL],
+ ['value' => 'kai.cheng@emca.com', 'scope' => IAccountManager::SCOPE_LOCAL],
+ ],
+ ],
+ ],
+ [
+ 'user' => $this->makeUser('goodpal@elpmaxe.org', 'Goodpal, Kim', 'goodpal@elpmaxe.org'),
+ 'data' => [
+ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Goodpal, Kim', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_EMAIL => ['value' => 'goodpal@elpmaxe.org', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ IAccountManager::PROPERTY_TWITTER => ['value' => '', 'scope' => IAccountManager::SCOPE_LOCAL],
+ IAccountManager::PROPERTY_PHONE => ['value' => '+71602121231', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_ADDRESS => ['value' => 'Octopus Ave 17', 'scope' => IAccountManager::SCOPE_FEDERATED],
+ IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://elpmaxe.org', 'scope' => IAccountManager::SCOPE_PUBLISHED],
+ ],
+ ],
+ ];
+ foreach ($users as $userInfo) {
+ $this->accountManager->updateUser($userInfo['user'], $userInfo['data'], false);
+ }
+ }
+
/**
* get a instance of the accountManager
*
@@ -340,9 +436,8 @@ class AccountManagerTest extends TestCase {
$oldData = ['key' => ['value' => 'value']];
$newData = ['newKey' => ['value' => 'newValue']];
- $accountManager = $this->getInstance();
$this->addDummyValuesToTable('uid', $oldData);
- $this->invokePrivate($accountManager, 'updateExistingUser', [$user, $newData]);
+ $this->invokePrivate($this->accountManager, 'updateExistingUser', [$user, $newData]);
$newDataFromTable = $this->getDataFromTable('uid');
$this->assertEquals($newData, $newDataFromTable);
}
@@ -352,18 +447,15 @@ class AccountManagerTest extends TestCase {
$uid = 'uid';
$data = ['key' => ['value' => 'value']];
- $accountManager = $this->getInstance();
$user->expects($this->atLeastOnce())->method('getUID')->willReturn($uid);
$this->assertNull($this->getDataFromTable($uid));
- $this->invokePrivate($accountManager, 'insertNewUser', [$user, $data]);
+ $this->invokePrivate($this->accountManager, 'insertNewUser', [$user, $data]);
$dataFromDb = $this->getDataFromTable($uid);
$this->assertEquals($data, $dataFromDb);
}
public function testAddMissingDefaultValues() {
- $accountManager = $this->getInstance();
-
$input = [
'key1' => ['value' => 'value1', 'verified' => '0'],
'key2' => ['value' => 'value1'],
@@ -374,7 +466,7 @@ class AccountManagerTest extends TestCase {
'key2' => ['value' => 'value1', 'verified' => '0'],
];
- $result = $this->invokePrivate($accountManager, 'addMissingDefaultValues', [$input]);
+ $result = $this->invokePrivate($this->accountManager, 'addMissingDefaultValues', [$input]);
$this->assertSame($expected, $result);
}
@@ -461,13 +553,11 @@ class AccountManagerTest extends TestCase {
$this->config->method('getSystemValueString')
->willReturn($defaultRegion);
- $instance = $this->getInstance();
-
if ($phoneNumber === null) {
$this->expectException(\InvalidArgumentException::class);
- self::invokePrivate($instance, 'parsePhoneNumber', [$phoneInput]);
+ self::invokePrivate($this->accountManager, 'parsePhoneNumber', [$phoneInput]);
} else {
- self::assertEquals($phoneNumber, self::invokePrivate($instance, 'parsePhoneNumber', [$phoneInput]));
+ self::assertEquals($phoneNumber, self::invokePrivate($this->accountManager, 'parsePhoneNumber', [$phoneInput]));
}
}
@@ -487,13 +577,78 @@ class AccountManagerTest extends TestCase {
* @param string|null $websiteOutput
*/
public function testParseWebsite(string $websiteInput, ?string $websiteOutput): void {
- $instance = $this->getInstance();
-
if ($websiteOutput === null) {
$this->expectException(\InvalidArgumentException::class);
- self::invokePrivate($instance, 'parseWebsite', [$websiteInput]);
+ self::invokePrivate($this->accountManager, 'parseWebsite', [$websiteInput]);
} else {
- self::assertEquals($websiteOutput, self::invokePrivate($instance, 'parseWebsite', [$websiteInput]));
+ self::assertEquals($websiteOutput, self::invokePrivate($this->accountManager, 'parseWebsite', [$websiteInput]));
+ }
+ }
+
+ /**
+ * @dataProvider searchDataProvider
+ */
+ public function testSearchUsers(string $property, array $values, array $expected): void {
+ $this->populateOrUpdate();
+
+ $matchedUsers = $this->accountManager->searchUsers($property, $values);
+ foreach ($expected as $expectedEntry) {
+ $this->assertContains($expectedEntry, $matchedUsers);
+ }
+ if (empty($expected)) {
+ $this->assertEmpty($matchedUsers);
}
}
+
+ public function searchDataProvider(): array {
+ return [
+ [ #0 Search for an existing name
+ IAccountManager::PROPERTY_DISPLAYNAME,
+ ['Jane Doe'],
+ ['Jane Doe' => 'j.doe']
+ ],
+ [ #1 Search for part of a name (no result)
+ IAccountManager::PROPERTY_DISPLAYNAME,
+ ['Jane'],
+ []
+ ],
+ [ #2 Search for part of a name (no result, test wildcard)
+ IAccountManager::PROPERTY_DISPLAYNAME,
+ ['Jane%'],
+ []
+ ],
+ [ #3 Search for phone
+ IAccountManager::PROPERTY_PHONE,
+ ['+491603121212'],
+ ['+491603121212' => 'b32c5a5b-1084-4380-8856-e5223b16de9f'],
+ ],
+ [ #4 Search for twitter handles
+ IAccountManager::PROPERTY_TWITTER,
+ ['@sometwitter', '@a_alice', '@unseen'],
+ ['@sometwitter' => 'j.doe', '@a_alice' => 'a.allison'],
+ ],
+ [ #5 Search for email
+ IAccountManager::PROPERTY_EMAIL,
+ ['cheng@emca.com'],
+ ['cheng@emca.com' => '31b5316a-9b57-4b17-970a-315a4cbe73eb'],
+ ],
+ [ #6 Search for email by additional email
+ IAccountManager::PROPERTY_EMAIL,
+ ['kai.cheng@emca.com'],
+ ['kai.cheng@emca.com' => '31b5316a-9b57-4b17-970a-315a4cbe73eb'],
+ ],
+ [ #7 Search for additional email
+ IAccountManager::COLLECTION_EMAIL,
+ ['kai.cheng@emca.com', 'cheng@emca.com'],
+ ['kai.cheng@emca.com' => '31b5316a-9b57-4b17-970a-315a4cbe73eb'],
+ ],
+ [ #8 Search for email by additional email (two valid search values, but the same user)
+ IAccountManager::PROPERTY_EMAIL,
+ ['kai.cheng@emca.com', 'cheng@emca.com'],
+ [
+ 'kai.cheng@emca.com' => '31b5316a-9b57-4b17-970a-315a4cbe73eb',
+ ],
+ ],
+ ];
+ }
}
diff --git a/tests/lib/Accounts/AccountPropertyCollectionTest.php b/tests/lib/Accounts/AccountPropertyCollectionTest.php
new file mode 100644
index 00000000000..d8a6bafd24b
--- /dev/null
+++ b/tests/lib/Accounts/AccountPropertyCollectionTest.php
@@ -0,0 +1,209 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace lib\Accounts;
+
+use InvalidArgumentException;
+use OC\Accounts\AccountPropertyCollection;
+use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\IAccountPropertyCollection;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class AccountPropertyCollectionTest extends TestCase {
+ /** @var IAccountPropertyCollection */
+ protected $collection;
+
+ protected const COLLECTION_NAME = 'my_multivalue_property';
+
+ public function setUp(): void {
+ parent::setUp();
+
+ $this->collection = new AccountPropertyCollection(self::COLLECTION_NAME);
+ }
+
+ /**
+ * @return IAccountProperty|MockObject
+ */
+ protected function makePropertyMock(string $propertyName): MockObject {
+ $mock = $this->createMock(IAccountProperty::class);
+ $mock->expects($this->any())
+ ->method('getName')
+ ->willReturn($propertyName);
+
+ return $mock;
+ }
+
+ public function testSetAndGetProperties() {
+ $propsBefore = $this->collection->getProperties();
+ $this->assertIsArray($propsBefore);
+ $this->assertEmpty($propsBefore);
+
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+
+ $this->collection->setProperties($props);
+ $propsAfter = $this->collection->getProperties();
+ $this->assertIsArray($propsAfter);
+ $this->assertCount(count($props), $propsAfter);
+ }
+
+ public function testSetPropertiesMixedInvalid() {
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock('sneaky_property'),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+
+ $this->expectException(InvalidArgumentException::class);
+ $this->collection->setProperties($props);
+ }
+
+ public function testAddProperty() {
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+ $this->collection->setProperties($props);
+
+ $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME);
+ $this->collection->addProperty($additionalProperty);
+
+ $propsAfter = $this->collection->getProperties();
+ $this->assertCount(count($props) + 1, $propsAfter);
+ $this->assertNotFalse(array_search($additionalProperty, $propsAfter, true));
+ }
+
+ public function testAddPropertyInvalid() {
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+ $this->collection->setProperties($props);
+
+ $additionalProperty = $this->makePropertyMock('sneaky_property');
+ $exceptionThrown = false;
+ try {
+ $this->collection->addProperty($additionalProperty);
+ } catch (\InvalidArgumentException $e) {
+ $exceptionThrown = true;
+ } finally {
+ $propsAfter = $this->collection->getProperties();
+ $this->assertCount(count($props), $propsAfter);
+ $this->assertFalse(array_search($additionalProperty, $propsAfter, true));
+ $this->assertTrue($exceptionThrown);
+ }
+ }
+
+ public function testRemoveProperty() {
+ $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME);
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $additionalProperty,
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+ $this->collection->setProperties($props);
+
+ $propsBefore = $this->collection->getProperties();
+ $this->collection->removeProperty($additionalProperty);
+ $propsAfter = $this->collection->getProperties();
+
+ $this->assertTrue(count($propsBefore) > count($propsAfter));
+ $this->assertCount(count($propsBefore) - 1, $propsAfter);
+ $this->assertFalse(array_search($additionalProperty, $propsAfter, true));
+ }
+
+ public function testRemovePropertyNotFound() {
+ $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME);
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+ $this->collection->setProperties($props);
+
+ $propsBefore = $this->collection->getProperties();
+ $this->collection->removeProperty($additionalProperty);
+ $propsAfter = $this->collection->getProperties();
+
+ // no errors, gently
+ $this->assertCount(count($propsBefore), $propsAfter);
+ }
+
+ public function testRemovePropertyByValue() {
+ $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME);
+ $additionalProperty->expects($this->any())
+ ->method('getValue')
+ ->willReturn('Lorem ipsum');
+
+ $additionalPropertyTwo = clone $additionalProperty;
+
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $additionalProperty,
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $additionalPropertyTwo
+ ];
+ $this->collection->setProperties($props);
+
+ $propsBefore = $this->collection->getProperties();
+ $this->collection->removePropertyByValue('Lorem ipsum');
+ $propsAfter = $this->collection->getProperties();
+
+ $this->assertTrue(count($propsBefore) > count($propsAfter));
+ $this->assertCount(count($propsBefore) - 2, $propsAfter);
+ $this->assertFalse(array_search($additionalProperty, $propsAfter, true));
+ $this->assertFalse(array_search($additionalPropertyTwo, $propsAfter, true));
+ }
+
+ public function testRemovePropertyByValueNotFound() {
+ $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME);
+ $additionalProperty->expects($this->any())
+ ->method('getValue')
+ ->willReturn('Lorem ipsum');
+
+ $props = [
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ $this->makePropertyMock(self::COLLECTION_NAME),
+ ];
+ $this->collection->setProperties($props);
+
+ $propsBefore = $this->collection->getProperties();
+ $this->collection->removePropertyByValue('Lorem ipsum');
+ $propsAfter = $this->collection->getProperties();
+
+ // no errors, gently
+ $this->assertCount(count($propsBefore), $propsAfter);
+ }
+}
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),
);
}