Use IAccountManager constants

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-10-15 13:29:53 +02:00
parent 90cdd0a12a
commit b9a87a69cf
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
3 changed files with 67 additions and 68 deletions

View File

@ -23,10 +23,8 @@
namespace Test\Accounts;
use OC\Accounts\Account;
use OC\Accounts\AccountManager;
use OC\Accounts\AccountProperty;
use OCP\Accounts\IAccountManager;
use Test\TestCase;
/**
@ -38,23 +36,23 @@ class AccountPropertyTest extends TestCase {
public function testConstructor() {
$accountProperty = new AccountProperty(
AccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_WEBSITE,
'https://example.com',
AccountManager::VISIBILITY_PUBLIC,
AccountManager::VERIFIED
IAccountManager::VISIBILITY_PUBLIC,
IAccountManager::VERIFIED
);
$this->assertEquals(AccountManager::PROPERTY_WEBSITE, $accountProperty->getName());
$this->assertEquals(IAccountManager::PROPERTY_WEBSITE, $accountProperty->getName());
$this->assertEquals('https://example.com', $accountProperty->getValue());
$this->assertEquals(AccountManager::VISIBILITY_PUBLIC, $accountProperty->getScope());
$this->assertEquals(AccountManager::VERIFIED, $accountProperty->getVerified());
$this->assertEquals(IAccountManager::VISIBILITY_PUBLIC, $accountProperty->getScope());
$this->assertEquals(IAccountManager::VERIFIED, $accountProperty->getVerified());
}
public function testSetValue() {
$accountProperty = new AccountProperty(
AccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_WEBSITE,
'https://example.com',
AccountManager::VISIBILITY_PUBLIC,
AccountManager::VERIFIED
IAccountManager::VISIBILITY_PUBLIC,
IAccountManager::VERIFIED
);
$actualReturn = $accountProperty->setValue('https://example.org');
$this->assertEquals('https://example.org', $accountProperty->getValue());
@ -63,40 +61,40 @@ class AccountPropertyTest extends TestCase {
public function testSetScope() {
$accountProperty = new AccountProperty(
AccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_WEBSITE,
'https://example.com',
AccountManager::VISIBILITY_PUBLIC,
AccountManager::VERIFIED
IAccountManager::VISIBILITY_PUBLIC,
IAccountManager::VERIFIED
);
$actualReturn = $accountProperty->setScope(AccountManager::VISIBILITY_PRIVATE);
$this->assertEquals(AccountManager::VISIBILITY_PRIVATE, $accountProperty->getScope());
$this->assertEquals(AccountManager::VISIBILITY_PRIVATE, $actualReturn->getScope());
$actualReturn = $accountProperty->setScope(IAccountManager::VISIBILITY_PRIVATE);
$this->assertEquals(IAccountManager::VISIBILITY_PRIVATE, $accountProperty->getScope());
$this->assertEquals(IAccountManager::VISIBILITY_PRIVATE, $actualReturn->getScope());
}
public function testSetVerified() {
$accountProperty = new AccountProperty(
AccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_WEBSITE,
'https://example.com',
AccountManager::VISIBILITY_PUBLIC,
AccountManager::VERIFIED
IAccountManager::VISIBILITY_PUBLIC,
IAccountManager::VERIFIED
);
$actualReturn = $accountProperty->setVerified(AccountManager::NOT_VERIFIED);
$this->assertEquals(AccountManager::NOT_VERIFIED, $accountProperty->getVerified());
$this->assertEquals(AccountManager::NOT_VERIFIED, $actualReturn->getVerified());
$actualReturn = $accountProperty->setVerified(IAccountManager::NOT_VERIFIED);
$this->assertEquals(IAccountManager::NOT_VERIFIED, $accountProperty->getVerified());
$this->assertEquals(IAccountManager::NOT_VERIFIED, $actualReturn->getVerified());
}
public function testJsonSerialize() {
$accountProperty = new AccountProperty(
AccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_WEBSITE,
'https://example.com',
AccountManager::VISIBILITY_PUBLIC,
AccountManager::VERIFIED
IAccountManager::VISIBILITY_PUBLIC,
IAccountManager::VERIFIED
);
$this->assertEquals([
'name' => AccountManager::PROPERTY_WEBSITE,
'name' => IAccountManager::PROPERTY_WEBSITE,
'value' => 'https://example.com',
'scope' => AccountManager::VISIBILITY_PUBLIC,
'verified' => AccountManager::VERIFIED
'scope' => IAccountManager::VISIBILITY_PUBLIC,
'verified' => IAccountManager::VERIFIED
], $accountProperty->jsonSerialize());
}

View File

@ -24,8 +24,8 @@
namespace Test\Accounts;
use OC\Accounts\Account;
use OC\Accounts\AccountManager;
use OC\Accounts\AccountProperty;
use OCP\Accounts\IAccountManager;
use OCP\IUser;
use Test\TestCase;
@ -44,21 +44,21 @@ class AccountTest extends TestCase {
public function testSetProperty() {
$user = $this->createMock(IUser::class);
$property = new AccountProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED);
$property = new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED);
$account = new Account($user);
$account->setProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED);
$this->assertEquals($property, $account->getProperty(AccountManager::PROPERTY_WEBSITE));
$account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED);
$this->assertEquals($property, $account->getProperty(IAccountManager::PROPERTY_WEBSITE));
}
public function testGetProperties() {
$user = $this->createMock(IUser::class);
$properties = [
AccountManager::PROPERTY_WEBSITE => new AccountProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED),
AccountManager::PROPERTY_EMAIL => new AccountProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED)
IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED),
IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED)
];
$account = new Account($user);
$account->setProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED);
$account->setProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED);
$this->assertEquals($properties, $account->getProperties());
}
@ -66,45 +66,45 @@ class AccountTest extends TestCase {
public function testGetFilteredProperties() {
$user = $this->createMock(IUser::class);
$properties = [
AccountManager::PROPERTY_WEBSITE => new AccountProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED),
AccountManager::PROPERTY_EMAIL => new AccountProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED),
AccountManager::PROPERTY_PHONE => new AccountProperty(AccountManager::PROPERTY_PHONE, '123456', AccountManager::VISIBILITY_PUBLIC, AccountManager::VERIFIED),
IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED),
IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED),
IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::VERIFIED),
];
$account = new Account($user);
$account->setProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED);
$account->setProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED);
$account->setProperty(AccountManager::PROPERTY_PHONE, '123456', AccountManager::VISIBILITY_PUBLIC, AccountManager::VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::VERIFIED);
$this->assertEquals(
[
AccountManager::PROPERTY_WEBSITE => $properties[AccountManager::PROPERTY_WEBSITE],
AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE],
IAccountManager::PROPERTY_WEBSITE => $properties[IAccountManager::PROPERTY_WEBSITE],
IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE],
],
$account->getFilteredProperties(AccountManager::VISIBILITY_PUBLIC)
$account->getFilteredProperties(IAccountManager::VISIBILITY_PUBLIC)
);
$this->assertEquals(
[
AccountManager::PROPERTY_EMAIL => $properties[AccountManager::PROPERTY_EMAIL],
AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE],
IAccountManager::PROPERTY_EMAIL => $properties[IAccountManager::PROPERTY_EMAIL],
IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE],
],
$account->getFilteredProperties(null, AccountManager::VERIFIED)
$account->getFilteredProperties(null, IAccountManager::VERIFIED)
);
$this->assertEquals(
[AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE]],
$account->getFilteredProperties(AccountManager::VISIBILITY_PUBLIC, AccountManager::VERIFIED)
[IAccountManager::PROPERTY_PHONE => $properties[IAccountManager::PROPERTY_PHONE]],
$account->getFilteredProperties(IAccountManager::VISIBILITY_PUBLIC, IAccountManager::VERIFIED)
);
}
public function testJsonSerialize() {
$user = $this->createMock(IUser::class);
$properties = [
AccountManager::PROPERTY_WEBSITE => new AccountProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED),
AccountManager::PROPERTY_EMAIL => new AccountProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED)
IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED),
IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED)
];
$account = new Account($user);
$account->setProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::NOT_VERIFIED);
$account->setProperty(AccountManager::PROPERTY_EMAIL, 'user@example.com', AccountManager::VISIBILITY_PRIVATE, AccountManager::VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::NOT_VERIFIED);
$account->setProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::VERIFIED);
$this->assertEquals($properties, $account->jsonSerialize());
}

View File

@ -25,6 +25,7 @@ namespace Test\Accounts;
use OC\Accounts\Account;
use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -261,29 +262,29 @@ class AccountsManagerTest extends TestCase {
$user = $this->createMock(IUser::class);
$data = [
AccountManager::PROPERTY_TWITTER =>
IAccountManager::PROPERTY_TWITTER =>
[
'value' => '@twitterhandle',
'scope' => AccountManager::VISIBILITY_PRIVATE,
'verified' => AccountManager::NOT_VERIFIED,
'scope' => IAccountManager::VISIBILITY_PRIVATE,
'verified' => IAccountManager::NOT_VERIFIED,
],
AccountManager::PROPERTY_EMAIL =>
IAccountManager::PROPERTY_EMAIL =>
[
'value' => 'test@example.com',
'scope' => AccountManager::VISIBILITY_PUBLIC,
'verified' => AccountManager::VERIFICATION_IN_PROGRESS,
'scope' => IAccountManager::VISIBILITY_PUBLIC,
'verified' => IAccountManager::VERIFICATION_IN_PROGRESS,
],
AccountManager::PROPERTY_WEBSITE =>
IAccountManager::PROPERTY_WEBSITE =>
[
'value' => 'https://example.com',
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
'verified' => AccountManager::VERIFIED,
'scope' => IAccountManager::VISIBILITY_CONTACTS_ONLY,
'verified' => IAccountManager::VERIFIED,
],
];
$expected = new Account($user);
$expected->setProperty(AccountManager::PROPERTY_TWITTER, '@twitterhandle', AccountManager::VISIBILITY_PRIVATE, AccountManager::NOT_VERIFIED);
$expected->setProperty(AccountManager::PROPERTY_EMAIL, 'test@example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::VERIFICATION_IN_PROGRESS);
$expected->setProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_CONTACTS_ONLY, AccountManager::VERIFIED);
$expected->setProperty(IAccountManager::PROPERTY_TWITTER, '@twitterhandle', IAccountManager::VISIBILITY_PRIVATE, IAccountManager::NOT_VERIFIED);
$expected->setProperty(IAccountManager::PROPERTY_EMAIL, 'test@example.com', IAccountManager::VISIBILITY_PUBLIC, IAccountManager::VERIFICATION_IN_PROGRESS);
$expected->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::VISIBILITY_CONTACTS_ONLY, IAccountManager::VERIFIED);
$accountManager->expects($this->once())
->method('getUser')