123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace Test\Federation;
- use OC\Federation\CloudIdManager;
- use OC\Memcache\ArrayCache;
- use OCP\Contacts\IManager;
- use OCP\EventDispatcher\IEventDispatcher;
- use OCP\ICacheFactory;
- use OCP\IURLGenerator;
- use OCP\IUserManager;
- use Test\TestCase;
- class CloudIdManagerTest extends TestCase {
-
- protected $contactsManager;
-
- private $urlGenerator;
-
- private $userManager;
-
- private $cloudIdManager;
-
- private $cacheFactory;
- protected function setUp(): void {
- parent::setUp();
- $this->contactsManager = $this->createMock(IManager::class);
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->userManager = $this->createMock(IUserManager::class);
- $this->cacheFactory = $this->createMock(ICacheFactory::class);
- $this->cacheFactory->method('createLocal')
- ->willReturn(new ArrayCache(''));
- $this->cloudIdManager = new CloudIdManager(
- $this->contactsManager,
- $this->urlGenerator,
- $this->userManager,
- $this->cacheFactory,
- $this->createMock(IEventDispatcher::class)
- );
- }
- public function cloudIdProvider() {
- return [
- ['test@example.com', 'test', 'example.com', 'test@example.com'],
- ['test@example.com/cloud', 'test', 'example.com/cloud', 'test@example.com/cloud'],
- ['test@example.com/cloud/', 'test', 'example.com/cloud', 'test@example.com/cloud'],
- ['test@example.com/cloud/index.php', 'test', 'example.com/cloud', 'test@example.com/cloud'],
- ['test@example.com@example.com', 'test@example.com', 'example.com', 'test@example.com@example.com'],
- ];
- }
-
- 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() {
- return [
- ['example.com'],
- ['test:foo@example.com'],
- ['test/foo@example.com']
- ];
- }
-
- public function testInvalidCloudId($cloudId) {
- $this->expectException(\InvalidArgumentException::class);
- $this->contactsManager->expects($this->never())
- ->method('search');
- $this->cloudIdManager->resolveCloudId($cloudId);
- }
- public function getCloudIdProvider() {
- return [
- ['test', 'example.com', 'test@example.com'],
- ['test@example.com', 'example.com', 'test@example.com@example.com'],
- ['test@example.com', null, 'test@example.com@example.com'],
- ];
- }
-
- public function testGetCloudId($user, $remote, $id) {
- if ($remote !== null) {
- $this->contactsManager->expects($this->any())
- ->method('search')
- ->with($id, ['CLOUD'])
- ->willReturn([
- [
- 'CLOUD' => [$id],
- 'FN' => 'Ample Ex',
- ]
- ]);
- } else {
- $this->urlGenerator->expects(self::once())
- ->method('getAbsoluteUrl')
- ->willReturn('https://example.com');
- }
- $cloudId = $this->cloudIdManager->getCloudId($user, $remote);
- $this->assertEquals($id, $cloudId->getId());
- }
- }
|