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