OfflineUserTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\User_LDAP\Tests\User;
  25. use OCA\User_LDAP\Mapping\UserMapping;
  26. use OCA\User_LDAP\User\OfflineUser;
  27. use OCP\IConfig;
  28. use OCP\Share\IManager;
  29. use OCP\Share\IShare;
  30. use Test\TestCase;
  31. class OfflineUserTest extends TestCase {
  32. /** @var OfflineUser */
  33. protected $offlineUser;
  34. /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
  35. protected $mapping;
  36. /** @var string */
  37. protected $uid;
  38. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  39. protected $config;
  40. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  41. protected $shareManager;
  42. public function setUp(): void {
  43. $this->uid = 'deborah';
  44. $this->config = $this->createMock(IConfig::class);
  45. $this->mapping = $this->createMock(UserMapping::class);
  46. $this->shareManager = $this->createMock(IManager::class);
  47. $this->offlineUser = new OfflineUser(
  48. $this->uid,
  49. $this->config,
  50. $this->mapping,
  51. $this->shareManager
  52. );
  53. }
  54. public function shareOwnerProvider(): array {
  55. return [
  56. [[], false],
  57. [[IShare::TYPE_USER], true],
  58. [[IShare::TYPE_GROUP, IShare::TYPE_LINK], true],
  59. [[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true],
  60. [[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true],
  61. ];
  62. }
  63. /**
  64. * @dataProvider shareOwnerProvider
  65. */
  66. public function testHasActiveShares(array $existingShareTypes, bool $expected) {
  67. $shareMock = $this->createMock(IShare::class);
  68. $this->shareManager->expects($this->atLeastOnce())
  69. ->method('getSharesBy')
  70. ->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) {
  71. if (in_array($shareType, $existingShareTypes)) {
  72. return [$shareMock];
  73. }
  74. return [];
  75. });
  76. $this->assertSame($expected, $this->offlineUser->getHasActiveShares());
  77. }
  78. }