OfflineUserTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\User_LDAP\Tests\User;
  8. use OCA\User_LDAP\Mapping\UserMapping;
  9. use OCA\User_LDAP\User\OfflineUser;
  10. use OCP\IConfig;
  11. use OCP\Share\IManager;
  12. use OCP\Share\IShare;
  13. use Test\TestCase;
  14. class OfflineUserTest extends TestCase {
  15. /** @var OfflineUser */
  16. protected $offlineUser;
  17. /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
  18. protected $mapping;
  19. /** @var string */
  20. protected $uid;
  21. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  22. protected $config;
  23. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  24. protected $shareManager;
  25. public function setUp(): void {
  26. $this->uid = 'deborah';
  27. $this->config = $this->createMock(IConfig::class);
  28. $this->mapping = $this->createMock(UserMapping::class);
  29. $this->shareManager = $this->createMock(IManager::class);
  30. $this->offlineUser = new OfflineUser(
  31. $this->uid,
  32. $this->config,
  33. $this->mapping,
  34. $this->shareManager
  35. );
  36. }
  37. public function shareOwnerProvider(): array {
  38. return [
  39. [[], false],
  40. [[IShare::TYPE_USER], true],
  41. [[IShare::TYPE_GROUP, IShare::TYPE_LINK], true],
  42. [[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true],
  43. [[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true],
  44. ];
  45. }
  46. /**
  47. * @dataProvider shareOwnerProvider
  48. */
  49. public function testHasActiveShares(array $existingShareTypes, bool $expected) {
  50. $shareMock = $this->createMock(IShare::class);
  51. $this->shareManager->expects($this->atLeastOnce())
  52. ->method('getSharesBy')
  53. ->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) {
  54. if (in_array($shareType, $existingShareTypes)) {
  55. return [$shareMock];
  56. }
  57. return [];
  58. });
  59. $this->assertSame($expected, $this->offlineUser->getHasActiveShares());
  60. }
  61. }