diff options
author | Julius Knorr <jus@bitgrid.net> | 2025-04-09 12:33:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-09 12:33:38 +0200 |
commit | 455fb740d085c5649b0892b1185989451f7a14fa (patch) | |
tree | 5b2d723a63815a4f1ffe2f9f7edf7994355291a7 /tests | |
parent | 3808f86c88053b7cd226a6af953cae239142f235 (diff) | |
parent | 6a3c53def3155dcff4aa6bd532e34beab8918035 (diff) | |
download | nextcloud-server-master.tar.gz nextcloud-server-master.zip |
Merge pull request #52066 from nextcloud/perf/noid/dont-load-addressbook-on-resolving-cloudidHEADmaster
fix(federation): Don't load the addressbook when resolving a cloud ID
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Federation/CloudIdManagerTest.php | 15 | ||||
-rw-r--r-- | tests/lib/Federation/CloudIdTest.php | 38 |
2 files changed, 39 insertions, 14 deletions
diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php index 13e6b111864..14daef27142 100644 --- a/tests/lib/Federation/CloudIdManagerTest.php +++ b/tests/lib/Federation/CloudIdManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -10,11 +13,15 @@ use OC\Federation\CloudIdManager; use OC\Memcache\ArrayCache; use OCP\Contacts\IManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Federation\ICloudIdManager; use OCP\ICacheFactory; use OCP\IURLGenerator; use OCP\IUserManager; use Test\TestCase; +/** + * @group DB + */ class CloudIdManagerTest extends TestCase { /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $contactsManager; @@ -36,7 +43,7 @@ class CloudIdManagerTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); - $this->cacheFactory->method('createLocal') + $this->cacheFactory->method('createDistributed') ->willReturn(new ArrayCache('')); $this->cloudIdManager = new CloudIdManager( @@ -46,6 +53,7 @@ class CloudIdManagerTest extends TestCase { $this->cacheFactory, $this->createMock(IEventDispatcher::class) ); + $this->overwriteService(ICloudIdManager::class, $this->cloudIdManager); } public function cloudIdProvider(): array { @@ -70,7 +78,7 @@ class CloudIdManagerTest extends TestCase { ->willReturn([ [ 'CLOUD' => [$cleanId], - 'FN' => 'Ample Ex', + 'FN' => $displayName, ] ]); @@ -92,9 +100,6 @@ class CloudIdManagerTest extends TestCase { /** * @dataProvider invalidCloudIdProvider - * - * @param string $cloudId - * */ public function testInvalidCloudId(string $cloudId): void { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/lib/Federation/CloudIdTest.php b/tests/lib/Federation/CloudIdTest.php index 4087f45622d..ca949d163c7 100644 --- a/tests/lib/Federation/CloudIdTest.php +++ b/tests/lib/Federation/CloudIdTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,25 +10,42 @@ namespace Test\Federation; use OC\Federation\CloudId; +use OC\Federation\CloudIdManager; +use OCP\Federation\ICloudIdManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; +/** + * @group DB + */ class CloudIdTest extends TestCase { - public function dataGetDisplayCloudId() { + protected CloudIdManager&MockObject $cloudIdManager; + + protected function setUp(): void { + parent::setUp(); + + $this->cloudIdManager = $this->createMock(CloudIdManager::class); + $this->overwriteService(ICloudIdManager::class, $this->cloudIdManager); + } + + public function dataGetDisplayCloudId(): array { return [ - ['test@example.com', 'test@example.com'], - ['test@http://example.com', 'test@example.com'], - ['test@https://example.com', 'test@example.com'], + ['test@example.com', 'test', 'example.com', 'test@example.com'], + ['test@http://example.com', 'test', 'http://example.com', 'test@example.com'], + ['test@https://example.com', 'test', 'https://example.com', 'test@example.com'], + ['test@https://example.com', 'test', 'https://example.com', 'Beloved Amy@example.com', 'Beloved Amy'], ]; } /** * @dataProvider dataGetDisplayCloudId - * - * @param string $id - * @param string $display */ - public function testGetDisplayCloudId($id, $display): void { - $cloudId = new CloudId($id, '', ''); + public function testGetDisplayCloudId(string $id, string $user, string $remote, string $display, ?string $addressbookName = null): void { + $this->cloudIdManager->expects($this->once()) + ->method('getDisplayNameFromContact') + ->willReturn($addressbookName); + + $cloudId = new CloudId($id, $user, $remote); $this->assertEquals($display, $cloudId->getDisplayId()); } } |