diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-10-12 09:30:44 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-10-15 13:30:31 +0200 |
commit | 9381e681a9a5ae0e84aeef6f85d713e2601cbadf (patch) | |
tree | 4647b61106b6d3bbe523e8136fbebce3af207cc1 /tests/lib/Accounts | |
parent | d05080f56aca2614024cfaa2ee1161b55746856b (diff) | |
download | nextcloud-server-9381e681a9a5ae0e84aeef6f85d713e2601cbadf.tar.gz nextcloud-server-9381e681a9a5ae0e84aeef6f85d713e2601cbadf.zip |
Add tests for new account api classes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'tests/lib/Accounts')
-rw-r--r-- | tests/lib/Accounts/AccountPropertyTest.php | 104 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountTest.php | 112 | ||||
-rw-r--r-- | tests/lib/Accounts/AccountsManagerTest.php | 37 |
3 files changed, 253 insertions, 0 deletions
diff --git a/tests/lib/Accounts/AccountPropertyTest.php b/tests/lib/Accounts/AccountPropertyTest.php new file mode 100644 index 00000000000..5d71287fedb --- /dev/null +++ b/tests/lib/Accounts/AccountPropertyTest.php @@ -0,0 +1,104 @@ +<?php +/** + * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Accounts; + +use OC\Accounts\Account; +use OC\Accounts\AccountManager; +use OC\Accounts\AccountProperty; + +use Test\TestCase; + +/** + * Class AccountPropertyTest + * + * @package Test\Accounts + */ +class AccountPropertyTest extends TestCase { + + public function testConstructor() { + $accountProperty = new AccountProperty( + AccountManager::PROPERTY_WEBSITE, + 'https://example.com', + AccountManager::VISIBILITY_PUBLIC, + AccountManager::VERIFIED + ); + $this->assertEquals(AccountManager::PROPERTY_WEBSITE, $accountProperty->getName()); + $this->assertEquals('https://example.com', $accountProperty->getValue()); + $this->assertEquals(AccountManager::VISIBILITY_PUBLIC, $accountProperty->getScope()); + $this->assertEquals(AccountManager::VERIFIED, $accountProperty->getVerified()); + } + + public function testSetValue() { + $accountProperty = new AccountProperty( + AccountManager::PROPERTY_WEBSITE, + 'https://example.com', + AccountManager::VISIBILITY_PUBLIC, + AccountManager::VERIFIED + ); + $actualReturn = $accountProperty->setValue('https://example.org'); + $this->assertEquals('https://example.org', $accountProperty->getValue()); + $this->assertEquals('https://example.org', $actualReturn->getValue()); + } + + public function testSetScope() { + $accountProperty = new AccountProperty( + AccountManager::PROPERTY_WEBSITE, + 'https://example.com', + AccountManager::VISIBILITY_PUBLIC, + AccountManager::VERIFIED + ); + $actualReturn = $accountProperty->setScope(AccountManager::VISIBILITY_PRIVATE); + $this->assertEquals(AccountManager::VISIBILITY_PRIVATE, $accountProperty->getScope()); + $this->assertEquals(AccountManager::VISIBILITY_PRIVATE, $actualReturn->getScope()); + } + + public function testSetVerified() { + $accountProperty = new AccountProperty( + AccountManager::PROPERTY_WEBSITE, + 'https://example.com', + AccountManager::VISIBILITY_PUBLIC, + AccountManager::VERIFIED + ); + $actualReturn = $accountProperty->setVerified(AccountManager::NOT_VERIFIED); + $this->assertEquals(AccountManager::NOT_VERIFIED, $accountProperty->getVerified()); + $this->assertEquals(AccountManager::NOT_VERIFIED, $actualReturn->getVerified()); + } + + public function testJsonSerialize() { + $accountProperty = new AccountProperty( + AccountManager::PROPERTY_WEBSITE, + 'https://example.com', + AccountManager::VISIBILITY_PUBLIC, + AccountManager::VERIFIED + ); + $this->assertEquals([ + 'name' => AccountManager::PROPERTY_WEBSITE, + 'value' => 'https://example.com', + 'scope' => AccountManager::VISIBILITY_PUBLIC, + 'verified' => AccountManager::VERIFIED + ], $accountProperty->jsonSerialize()); + } + + +} diff --git a/tests/lib/Accounts/AccountTest.php b/tests/lib/Accounts/AccountTest.php new file mode 100644 index 00000000000..3fc73f75af6 --- /dev/null +++ b/tests/lib/Accounts/AccountTest.php @@ -0,0 +1,112 @@ +<?php +/** + * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Accounts; + +use OC\Accounts\Account; +use OC\Accounts\AccountManager; +use OC\Accounts\AccountProperty; +use OCP\IUser; +use Test\TestCase; + +/** + * Class AccountTest + * + * @package Test\Accounts + */ +class AccountTest extends TestCase { + + public function testConstructor() { + $user = $this->createMock(IUser::class); + $account = new Account($user); + $this->assertEquals($user, $account->getUser()); + } + + public function testSetProperty() { + $user = $this->createMock(IUser::class); + $property = new AccountProperty(AccountManager::PROPERTY_WEBSITE, 'https://example.com', AccountManager::VISIBILITY_PUBLIC, AccountManager::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)); + } + + 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) + ]; + $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); + + $this->assertEquals($properties, $account->getProperties()); + } + + 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), + ]; + $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); + + + $this->assertEquals( + [ + AccountManager::PROPERTY_WEBSITE => $properties[AccountManager::PROPERTY_WEBSITE], + AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE], + ], + $account->getFilteredProperties(AccountManager::VISIBILITY_PUBLIC) + ); + $this->assertEquals( + [ + AccountManager::PROPERTY_EMAIL => $properties[AccountManager::PROPERTY_EMAIL], + AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE], + ], + $account->getFilteredProperties(null, AccountManager::VERIFIED) + ); + $this->assertEquals( + [AccountManager::PROPERTY_PHONE => $properties[AccountManager::PROPERTY_PHONE]], + $account->getFilteredProperties(AccountManager::VISIBILITY_PUBLIC, AccountManager::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) + ]; + $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); + + $this->assertEquals($properties, $account->jsonSerialize()); + } + +} diff --git a/tests/lib/Accounts/AccountsManagerTest.php b/tests/lib/Accounts/AccountsManagerTest.php index c4add0244bd..dee8ba5d810 100644 --- a/tests/lib/Accounts/AccountsManagerTest.php +++ b/tests/lib/Accounts/AccountsManagerTest.php @@ -23,6 +23,7 @@ namespace Test\Accounts; +use OC\Accounts\Account; use OC\Accounts\AccountManager; use OCP\BackgroundJob\IJobList; use OCP\IUser; @@ -254,4 +255,40 @@ class AccountsManagerTest extends TestCase { } } + public function testGetAccount() { + $accountManager = $this->getInstance(['getUser']); + /** @var IUser $user */ + $user = $this->createMock(IUser::class); + + $data = [ + AccountManager::PROPERTY_TWITTER => + [ + 'value' => '@twitterhandle', + 'scope' => AccountManager::VISIBILITY_PRIVATE, + 'verified' => AccountManager::NOT_VERIFIED, + ], + AccountManager::PROPERTY_EMAIL => + [ + 'value' => 'test@example.com', + 'scope' => AccountManager::VISIBILITY_PUBLIC, + 'verified' => AccountManager::VERIFICATION_IN_PROGRESS, + ], + AccountManager::PROPERTY_WEBSITE => + [ + 'value' => 'https://example.com', + 'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY, + 'verified' => AccountManager::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); + + $accountManager->expects($this->once()) + ->method('getUser') + ->willReturn($data); + $this->assertEquals($expected, $accountManager->getAccount($user)); + } + } |