CapabilitiesTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Provisioning_API\Tests\unit;
  7. use OCA\FederatedFileSharing\FederatedShareProvider;
  8. use OCA\Provisioning_API\Capabilities;
  9. use OCP\App\IAppManager;
  10. use PHPUnit\Framework\MockObject\MockObject;
  11. use Test\TestCase;
  12. /**
  13. * Capabilities test for provisioning API.
  14. *
  15. * Note: group DB needed because of usage of overwriteService()
  16. *
  17. * @package OCA\Provisioning_API\Tests
  18. * @group DB
  19. */
  20. class CapabilitiesTest extends TestCase {
  21. /** @var Capabilities */
  22. protected $capabilities;
  23. /** @var IAppManager|MockObject */
  24. protected $appManager;
  25. public function setUp(): void {
  26. parent::setUp();
  27. $this->appManager = $this->createMock(IAppManager::class);
  28. $this->capabilities = new Capabilities($this->appManager);
  29. $this->appManager->expects($this->once())
  30. ->method('getAppVersion')
  31. ->with('provisioning_api')
  32. ->willReturn('1.12');
  33. }
  34. public function getCapabilitiesProvider() {
  35. return [
  36. [true, false, false, true, false],
  37. [true, true, false, true, false],
  38. [true, true, true, true, true],
  39. [false, false, false, false, false],
  40. [false, true, false, false, false],
  41. [false, true, true, false, true],
  42. ];
  43. }
  44. /**
  45. * @dataProvider getCapabilitiesProvider
  46. */
  47. public function testGetCapabilities($federationAppEnabled, $federatedFileSharingAppEnabled, $lookupServerEnabled, $expectedFederatedScopeEnabled, $expectedPublishedScopeEnabled): void {
  48. $this->appManager->expects($this->any())
  49. ->method('isEnabledForUser')
  50. ->will($this->returnValueMap([
  51. ['federation', null, $federationAppEnabled],
  52. ['federatedfilesharing', null, $federatedFileSharingAppEnabled],
  53. ]));
  54. $federatedShareProvider = $this->createMock(FederatedShareProvider::class);
  55. $this->overwriteService(FederatedShareProvider::class, $federatedShareProvider);
  56. $federatedShareProvider->expects($this->any())
  57. ->method('isLookupServerUploadEnabled')
  58. ->willReturn($lookupServerEnabled);
  59. $expected = [
  60. 'provisioning_api' => [
  61. 'version' => '1.12',
  62. 'AccountPropertyScopesVersion' => 2,
  63. 'AccountPropertyScopesFederatedEnabled' => $expectedFederatedScopeEnabled,
  64. 'AccountPropertyScopesPublishedEnabled' => $expectedPublishedScopeEnabled,
  65. ],
  66. ];
  67. $this->assertSame($expected, $this->capabilities->getCapabilities());
  68. }
  69. }