0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-04-28 19:13:08 +00:00
nextcloud_server/tests/lib/Federation/CloudIdTest.php
Joas Schilling 6a3c53def3
fix(federation): Don't load the addressbook when resolving a cloud ID
Instead we delay the lookup of the display name until it is actually used

Signed-off-by: Joas Schilling <coding@schilljs.com>
2025-04-09 10:52:03 +02:00

51 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 {
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@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
*/
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());
}
}