diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-04-10 16:49:26 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-04-25 20:47:17 +0200 |
commit | b8c2a8ae36235780675103286a04f8b6af50b4aa (patch) | |
tree | c75dd2baa0fdaabaf2a2c7aec40781ce3177509a /tests | |
parent | 36cee1f3867bdaf9fd792fe9c03fe4e4ef95ffcc (diff) | |
download | nextcloud-server-b8c2a8ae36235780675103286a04f8b6af50b4aa.tar.gz nextcloud-server-b8c2a8ae36235780675103286a04f8b6af50b4aa.zip |
Don't show contacts an entry for themselves
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php | 57 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ManagerTest.php | 2 |
2 files changed, 49 insertions, 10 deletions
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php index fa7c57bb409..80c26a9078e 100644 --- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php @@ -26,6 +26,7 @@ namespace Tests\Contacts\ContactsMenu; use OC\Contacts\ContactsMenu\ContactsStore; use OCP\Contacts\IManager; +use OCP\IUser; use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; @@ -46,23 +47,27 @@ class ContactsStoreTest extends TestCase { } public function testGetContactsWithoutFilter() { + $user = $this->createMock(IUser::class); $this->contactsManager->expects($this->once()) ->method('search') ->with($this->equalTo(''), $this->equalTo(['FN'])) ->willReturn([ [ - 'id' => 123, + 'UID' => 123, ], [ - 'id' => 567, + 'UID' => 567, 'FN' => 'Darren Roner', 'EMAIL' => [ 'darren@roner.au' ], ], ]); + $user->expects($this->once()) + ->method('getUID') + ->willReturn('user123'); - $entries = $this->contactsStore->getContacts(''); + $entries = $this->contactsStore->getContacts($user, ''); $this->assertCount(2, $entries); $this->assertEquals([ @@ -70,16 +75,43 @@ class ContactsStoreTest extends TestCase { ], $entries[1]->getEMailAddresses()); } + public function testGetContactsHidesOwnEntry() { + $user = $this->createMock(IUser::class); + $this->contactsManager->expects($this->once()) + ->method('search') + ->with($this->equalTo(''), $this->equalTo(['FN'])) + ->willReturn([ + [ + 'UID' => 'user123', + ], + [ + 'UID' => 567, + 'FN' => 'Darren Roner', + 'EMAIL' => [ + 'darren@roner.au' + ], + ], + ]); + $user->expects($this->once()) + ->method('getUID') + ->willReturn('user123'); + + $entries = $this->contactsStore->getContacts($user, ''); + + $this->assertCount(1, $entries); + } + public function testGetContactsWithoutBinaryImage() { + $user = $this->createMock(IUser::class); $this->contactsManager->expects($this->once()) ->method('search') ->with($this->equalTo(''), $this->equalTo(['FN'])) ->willReturn([ [ - 'id' => 123, + 'UID' => 123, ], [ - 'id' => 567, + 'UID' => 567, 'FN' => 'Darren Roner', 'EMAIL' => [ 'darren@roner.au' @@ -87,23 +119,27 @@ class ContactsStoreTest extends TestCase { 'PHOTO' => base64_encode('photophotophoto'), ], ]); + $user->expects($this->once()) + ->method('getUID') + ->willReturn('user123'); - $entries = $this->contactsStore->getContacts(''); + $entries = $this->contactsStore->getContacts($user, ''); $this->assertCount(2, $entries); $this->assertNull($entries[1]->getAvatar()); } public function testGetContactsWithoutAvatarURI() { + $user = $this->createMock(IUser::class); $this->contactsManager->expects($this->once()) ->method('search') ->with($this->equalTo(''), $this->equalTo(['FN'])) ->willReturn([ [ - 'id' => 123, + 'UID' => 123, ], [ - 'id' => 567, + 'UID' => 567, 'FN' => 'Darren Roner', 'EMAIL' => [ 'darren@roner.au' @@ -111,8 +147,11 @@ class ContactsStoreTest extends TestCase { 'PHOTO' => 'VALUE=uri:https://photo', ], ]); + $user->expects($this->once()) + ->method('getUID') + ->willReturn('user123'); - $entries = $this->contactsStore->getContacts(''); + $entries = $this->contactsStore->getContacts($user, ''); $this->assertCount(2, $entries); $this->assertEquals('https://photo', $entries[1]->getAvatar()); diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php index 9b84bd76648..9c92ec54b9f 100644 --- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php +++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php @@ -77,7 +77,7 @@ class ManagerTest extends TestCase { $provider = $this->createMock(IProvider::class); $this->contactsStore->expects($this->once()) ->method('getContacts') - ->with($filter) + ->with($user, $filter) ->willReturn($entries); $this->actionProviderStore->expects($this->once()) ->method('getProviders') |