1
0

CapabilitiesTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 Vincent Petry <vincent@nextcloud.com>
  4. *
  5. * @author Vincent Petry <vincent@nextcloud.com>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OCA\Provisioning_API\Tests\unit;
  24. use OCA\FederatedFileSharing\FederatedShareProvider;
  25. use OCA\Provisioning_API\Capabilities;
  26. use OCP\App\IAppManager;
  27. use PHPUnit\Framework\MockObject\MockObject;
  28. use Test\TestCase;
  29. /**
  30. * Capabilities test for provisioning API.
  31. *
  32. * Note: group DB needed because of usage of overwriteService()
  33. *
  34. * @package OCA\Provisioning_API\Tests
  35. * @group DB
  36. */
  37. class CapabilitiesTest extends TestCase {
  38. /** @var Capabilities */
  39. protected $capabilities;
  40. /** @var IAppManager|MockObject */
  41. protected $appManager;
  42. public function setUp(): void {
  43. parent::setUp();
  44. $this->appManager = $this->createMock(IAppManager::class);
  45. $this->capabilities = new Capabilities($this->appManager);
  46. $this->appManager->expects($this->once())
  47. ->method('getAppVersion')
  48. ->with('provisioning_api')
  49. ->willReturn('1.12');
  50. }
  51. public function getCapabilitiesProvider() {
  52. return [
  53. [true, false, false, true, false],
  54. [true, true, false, true, false],
  55. [true, true, true, true, true],
  56. [false, false, false, false, false],
  57. [false, true, false, false, false],
  58. [false, true, true, false, true],
  59. ];
  60. }
  61. /**
  62. * @dataProvider getCapabilitiesProvider
  63. */
  64. public function testGetCapabilities($federationAppEnabled, $federatedFileSharingAppEnabled, $lookupServerEnabled, $expectedFederatedScopeEnabled, $expectedPublishedScopeEnabled) {
  65. $this->appManager->expects($this->any())
  66. ->method('isEnabledForUser')
  67. ->will($this->returnValueMap([
  68. ['federation', null, $federationAppEnabled],
  69. ['federatedfilesharing', null, $federatedFileSharingAppEnabled],
  70. ]));
  71. $federatedShareProvider = $this->createMock(FederatedShareProvider::class);
  72. $this->overwriteService(FederatedShareProvider::class, $federatedShareProvider);
  73. $federatedShareProvider->expects($this->any())
  74. ->method('isLookupServerUploadEnabled')
  75. ->willReturn($lookupServerEnabled);
  76. $expected = [
  77. 'provisioning_api' => [
  78. 'version' => '1.12',
  79. 'AccountPropertyScopesVersion' => 2,
  80. 'AccountPropertyScopesFederatedEnabled' => $expectedFederatedScopeEnabled,
  81. 'AccountPropertyScopesPublishedEnabled' => $expectedPublishedScopeEnabled,
  82. ],
  83. ];
  84. $this->assertSame($expected, $this->capabilities->getCapabilities());
  85. }
  86. }