summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2020-11-24 17:23:37 +0100
committerGitHub <noreply@github.com>2020-11-24 17:23:37 +0100
commit5d03b5c5ddbc8df4f8f64c02dba69679bdd0d4bf (patch)
treef66350829227a3f748c7141343faeb96d7e5a8a2 /apps
parent6156a49f6ed258da2e4949f16d331959af537adb (diff)
parent16a78f535a3b607864e0d151de13b0f161520f5c (diff)
downloadnextcloud-server-5d03b5c5ddbc8df4f8f64c02dba69679bdd0d4bf.tar.gz
nextcloud-server-5d03b5c5ddbc8df4f8f64c02dba69679bdd0d4bf.zip
Merge pull request #24162 from nextcloud/fix/noid/fedshares-displaynamez
set the display name of federated sharees from addressbook
Diffstat (limited to 'apps')
-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
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php12
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php12
5 files changed, 94 insertions, 7 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);
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index be8911961df..0a5ea4ca231 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -29,6 +29,7 @@ namespace OCA\Files_Sharing\Tests\External;
use OC\Federation\CloudIdManager;
use OCA\Files_Sharing\Tests\TestCase;
+use OCP\Contacts\IManager;
use OCP\Federation\ICloudIdManager;
/**
@@ -39,6 +40,8 @@ use OCP\Federation\ICloudIdManager;
* @package OCA\Files_Sharing\Tests\External
*/
class CacheTest extends TestCase {
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
/**
* @var \OC\Files\Storage\Storage
@@ -61,7 +64,9 @@ class CacheTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->cloudIdManager = new CloudIdManager();
+ $this->contactsManager = $this->createMock(IManager::class);
+
+ $this->cloudIdManager = new CloudIdManager($this->contactsManager);
$this->remoteUser = $this->getUniqueID('remoteuser');
$this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
@@ -71,6 +76,11 @@ class CacheTest extends TestCase {
->expects($this->any())
->method('getId')
->willReturn('dummystorage::');
+
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$this->cache = new \OCA\Files_Sharing\External\Cache(
$this->storage,
$this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud')
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index c8ae7a64831..22005c8fc6b 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -33,6 +33,7 @@ use OC\Files\Storage\StorageFactory;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
use OCA\Files_Sharing\Tests\TestCase;
+use OCP\Contacts\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
@@ -53,6 +54,9 @@ use Test\Traits\UserTrait;
class ManagerTest extends TestCase {
use UserTrait;
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
+
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject **/
private $manager;
@@ -99,6 +103,12 @@ class ManagerTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
+ $this->contactsManager = $this->createMock(IManager::class);
+ // needed for MountProvider() initialization
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
$this->manager = $this->getMockBuilder(Manager::class)
->setConstructorArgs(
[
@@ -119,7 +129,7 @@ class ManagerTest extends TestCase {
$this->testMountProvider = new MountProvider(\OC::$server->getDatabaseConnection(), function () {
return $this->manager;
- }, new CloudIdManager());
+ }, new CloudIdManager($this->contactsManager));
}
private function setupMounts() {