summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2020-11-16 17:56:44 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2020-11-24 11:30:11 +0100
commit16a78f535a3b607864e0d151de13b0f161520f5c (patch)
treea9024ddbfa76b51e123177628e17ccb840821880 /apps/federatedfilesharing
parent6d3d6fb81a9b52700f77463fb3fa9084b03132f5 (diff)
downloadnextcloud-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 'apps/federatedfilesharing')
-rw-r--r--apps/federatedfilesharing/tests/AddressHandlerTest.php11
-rw-r--r--apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php6
-rw-r--r--apps/federatedfilesharing/tests/FederatedShareProviderTest.php60
3 files changed, 72 insertions, 5 deletions
diff --git a/apps/federatedfilesharing/tests/AddressHandlerTest.php b/apps/federatedfilesharing/tests/AddressHandlerTest.php
index 6cfe9d60e1d..fb78e83ea68 100644
--- a/apps/federatedfilesharing/tests/AddressHandlerTest.php
+++ b/apps/federatedfilesharing/tests/AddressHandlerTest.php
@@ -29,10 +29,13 @@ namespace OCA\FederatedFileSharing\Tests;
use OC\Federation\CloudIdManager;
use OCA\FederatedFileSharing\AddressHandler;
+use OCP\Contacts\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;
class AddressHandlerTest extends \Test\TestCase {
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
/** @var AddressHandler */
private $addressHandler;
@@ -54,7 +57,9 @@ class AddressHandlerTest extends \Test\TestCase {
$this->il10n = $this->getMockBuilder(IL10N::class)
->getMock();
- $this->cloudIdManager = new CloudIdManager();
+ $this->contactsManager = $this->createMock(IManager::class);
+
+ $this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->addressHandler = new AddressHandler($this->urlGenerator, $this->il10n, $this->cloudIdManager);
}
@@ -98,6 +103,10 @@ class AddressHandlerTest extends \Test\TestCase {
* @param string $expectedUrl
*/
public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) {
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
list($remoteUser, $remoteUrl) = $this->addressHandler->splitUserRemote($remote);
$this->assertSame($expectedUser, $remoteUser);
$this->assertSame($expectedUrl, $remoteUrl);
diff --git a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
index 11dd585f662..412b5b82d64 100644
--- a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
+++ b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php
@@ -34,6 +34,7 @@ use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\Controller\MountPublicLinkController;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http;
+use OCP\Contacts\IManager as IContactsManager;
use OCP\Federation\ICloudIdManager;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
@@ -46,6 +47,8 @@ use OCP\Share\IManager;
use OCP\Share\IShare;
class MountPublicLinkControllerTest extends \Test\TestCase {
+ /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
/** @var MountPublicLinkController */
private $controller;
@@ -102,7 +105,8 @@ class MountPublicLinkControllerTest extends \Test\TestCase {
$this->l10n = $this->getMockBuilder(IL10N::class)->disableOriginalConstructor()->getMock();
$this->userSession = $this->getMockBuilder(IUserSession::class)->disableOriginalConstructor()->getMock();
$this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock();
- $this->cloudIdManager = new CloudIdManager();
+ $this->contactsManager = $this->createMock(IContactsManager::class);
+ $this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->controller = new MountPublicLinkController(
'federatedfilesharing', $this->request,
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index aed08424475..7a2fd5f006f 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -35,6 +35,7 @@ use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\FederatedFileSharing\Notifications;
use OCA\FederatedFileSharing\TokenHandler;
+use OCP\Contacts\IManager as IContactsManager;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager;
use OCP\Files\File;
@@ -46,6 +47,7 @@ use OCP\ILogger;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class FederatedShareProviderTest
@@ -80,6 +82,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
protected $shareManager;
/** @var FederatedShareProvider */
protected $provider;
+ /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
/** @var ICloudIdManager */
private $cloudIdManager;
@@ -108,7 +112,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
//$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock();
- $this->cloudIdManager = new CloudIdManager();
+ $this->contactsManager = $this->createMock(IContactsManager::class);
+ $this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->gsConfig = $this->createMock(\OCP\GlobalScale\IConfig::class);
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
@@ -142,6 +147,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
public function testCreate() {
$share = $this->shareManager->newShare();
+ /** @var File|MockObject $node */
$node = $this->getMockBuilder(File::class)->getMock();
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
@@ -171,10 +177,15 @@ class FederatedShareProviderTest extends \Test\TestCase {
'shareOwner@http://localhost/',
'sharedBy',
'sharedBy@http://localhost/'
- )->willReturn(true);
+ )
+ ->willReturn(true);
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->provider->create($share);
$qb = $this->connection->getQueryBuilder();
@@ -251,6 +262,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
->with('42')
->willReturn([$node]);
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
try {
$share = $this->provider->create($share);
$this->fail();
@@ -308,6 +323,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
->with('42')
->willReturn([$node]);
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
try {
$share = $this->provider->create($share);
$this->fail();
@@ -345,6 +364,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setPermissions(19)
->setNode($node);
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$this->rootFolder->expects($this->never())->method($this->anything());
try {
@@ -404,6 +427,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$this->provider->create($share);
try {
@@ -442,7 +469,6 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
-
$this->addressHandler->expects($this->any())->method('splitUserRemote')
->willReturn(['user', 'server.com']);
@@ -478,6 +504,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->provider->create($share);
$share->setPermissions(1);
@@ -516,6 +546,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->rootFolder->expects($this->never())->method($this->anything());
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
@@ -556,6 +590,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
@@ -599,6 +637,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('shareOwner')
@@ -645,6 +687,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share = $this->shareManager->newShare();
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
@@ -845,6 +891,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->addressHandler->method('generateRemoteURL')
->willReturn('remoteurl.com');
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
@@ -892,6 +942,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
->method('sendRemoteShare')
->willReturn(true);
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$result = $this->provider->getAccessList([$file1], true);
$this->assertEquals(['remote' => []], $result);