-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't show contacts an entry for themselves
Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
1 parent
239eb11
commit cc3edca
Showing
5 changed files
with
59 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
use OC\Contacts\ContactsMenu\ContactsStore; | ||
use OCP\Contacts\IManager; | ||
use OCP\IUser; | ||
use PHPUnit_Framework_MockObject_MockObject; | ||
use Test\TestCase; | ||
|
||
|
@@ -46,73 +47,111 @@ protected function setUp() { | |
} | ||
|
||
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' => [ | ||
'[email protected]' | ||
], | ||
], | ||
]); | ||
$user->expects($this->once()) | ||
->method('getUID') | ||
->willReturn('user123'); | ||
|
||
$entries = $this->contactsStore->getContacts(''); | ||
$entries = $this->contactsStore->getContacts($user, ''); | ||
|
||
$this->assertCount(2, $entries); | ||
$this->assertEquals([ | ||
'[email protected]' | ||
], $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' => [ | ||
'[email protected]' | ||
], | ||
], | ||
]); | ||
$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' => [ | ||
'[email protected]' | ||
], | ||
'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' => [ | ||
'[email protected]' | ||
], | ||
'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()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters