diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-16 17:56:44 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-11-24 11:30:11 +0100 |
commit | 16a78f535a3b607864e0d151de13b0f161520f5c (patch) | |
tree | a9024ddbfa76b51e123177628e17ccb840821880 /tests | |
parent | 6d3d6fb81a9b52700f77463fb3fa9084b03132f5 (diff) | |
download | nextcloud-server-16a78f535a3b607864e0d151de13b0f161520f5c.tar.gz nextcloud-server-16a78f535a3b607864e0d151de13b0f161520f5c.zip |
set the display name of federated sharees from addressbook
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/MailPluginTest.php | 19 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/RemotePluginTest.php | 14 | ||||
-rw-r--r-- | tests/lib/Federation/CloudIdManagerTest.php | 34 |
3 files changed, 58 insertions, 9 deletions
diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index b3a1e2c2756..8feebfab1c5 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -65,7 +65,8 @@ class MailPluginTest extends TestCase { $this->contactsManager = $this->createMock(IManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->userSession = $this->createMock(IUserSession::class); - $this->cloudIdManager = new CloudIdManager(); + $this->cloudIdManager = new CloudIdManager($this->contactsManager); + $this->searchResult = new SearchResult(); } @@ -104,8 +105,12 @@ class MailPluginTest extends TestCase { $this->contactsManager->expects($this->any()) ->method('search') - ->with($searchTerm, ['EMAIL', 'FN']) - ->willReturn($contacts); + ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) { + if ($search === $searchTerm) { + return $contacts; + } + return []; + }); $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult); $result = $this->searchResult->asArray(); @@ -553,8 +558,12 @@ class MailPluginTest extends TestCase { $this->contactsManager->expects($this->any()) ->method('search') - ->with($searchTerm, ['EMAIL', 'FN']) - ->willReturn($contacts); + ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) { + if ($search === $searchTerm) { + return $contacts; + } + return []; + }); $this->userSession->expects($this->any()) ->method('getUser') diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index c03f993508b..1345df13379 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -62,7 +62,7 @@ class RemotePluginTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->config = $this->createMock(IConfig::class); $this->contactsManager = $this->createMock(IManager::class); - $this->cloudIdManager = new CloudIdManager(); + $this->cloudIdManager = new CloudIdManager($this->contactsManager); $this->searchResult = new SearchResult(); } @@ -104,8 +104,12 @@ class RemotePluginTest extends TestCase { $this->contactsManager->expects($this->any()) ->method('search') - ->with($searchTerm, ['CLOUD', 'FN']) - ->willReturn($contacts); + ->willReturnCallback(function ($search, $searchAttributes) use ($searchTerm, $contacts) { + if ($search === $searchTerm) { + return $contacts; + } + return []; + }); $moreResults = $this->plugin->search($searchTerm, 2, 0, $this->searchResult); $result = $this->searchResult->asArray(); @@ -125,6 +129,10 @@ class RemotePluginTest extends TestCase { public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) { $this->instantiatePlugin(); + $this->contactsManager->expects($this->any()) + ->method('search') + ->willReturn([]); + list($remoteUser, $remoteUrl) = $this->plugin->splitUserRemote($remote); $this->assertSame($expectedUser, $remoteUser); $this->assertSame($expectedUrl, $remoteUrl); diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php index 224acadbde4..dd68abf0ecb 100644 --- a/tests/lib/Federation/CloudIdManagerTest.php +++ b/tests/lib/Federation/CloudIdManagerTest.php @@ -22,15 +22,21 @@ namespace Test\Federation; use OC\Federation\CloudIdManager; +use OCP\Contacts\IManager; use Test\TestCase; class CloudIdManagerTest extends TestCase { + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $contactsManager; /** @var CloudIdManager */ private $cloudIdManager; protected function setUp(): void { parent::setUp(); - $this->cloudIdManager = new CloudIdManager(); + + $this->contactsManager = $this->createMock(IManager::class); + + $this->cloudIdManager = new CloudIdManager($this->contactsManager); } public function cloudIdProvider() { @@ -51,11 +57,24 @@ class CloudIdManagerTest extends TestCase { * @param string $remote */ public function testResolveCloudId($cloudId, $user, $remote, $cleanId) { + $displayName = 'Ample Ex'; + + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($cleanId, ['CLOUD']) + ->willReturn([ + [ + 'CLOUD' => [$cleanId], + 'FN' => 'Ample Ex', + ] + ]); + $cloudId = $this->cloudIdManager->resolveCloudId($cloudId); $this->assertEquals($user, $cloudId->getUser()); $this->assertEquals($remote, $cloudId->getRemote()); $this->assertEquals($cleanId, $cloudId->getId()); + $this->assertEquals($displayName . '@' . $remote, $cloudId->getDisplayId()); } public function invalidCloudIdProvider() { @@ -75,6 +94,9 @@ class CloudIdManagerTest extends TestCase { public function testInvalidCloudId($cloudId) { $this->expectException(\InvalidArgumentException::class); + $this->contactsManager->expects($this->never()) + ->method('search'); + $this->cloudIdManager->resolveCloudId($cloudId); } @@ -93,6 +115,16 @@ class CloudIdManagerTest extends TestCase { * @param string $id */ public function testGetCloudId($user, $remote, $id) { + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($id, ['CLOUD']) + ->willReturn([ + [ + 'CLOUD' => [$id], + 'FN' => 'Ample Ex', + ] + ]); + $cloudId = $this->cloudIdManager->getCloudId($user, $remote); $this->assertEquals($id, $cloudId->getId()); |