-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathConfigControllerTest.php
More file actions
119 lines (97 loc) · 2.87 KB
/
Copy pathConfigControllerTest.php
File metadata and controls
119 lines (97 loc) · 2.87 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Forms\Tests\Unit\Controller;
use OCA\Forms\Controller\ConfigController;
use OCA\Forms\Service\ConfigService;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class ConfigControllerTest extends TestCase {
/** @var ConfigController */
private $configController;
/** @var ConfigService */
private $configService;
/** @var IConfig|MockObject */
private $config;
/** @var LoggerInterface|MockObject */
private $logger;
/** @var IRequest|MockObject */
private $request;
public function setUp(): void {
parent::setUp();
$this->configService = $this->createMock(ConfigService::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->request = $this->createMock(IRequest::class);
$this->configController = new ConfigController(
'forms',
$this->configService,
$this->config,
$this->logger,
$this->request
);
}
public function testGetAppConfig() {
$this->configService->expects($this->once())
->method('getAppConfig')
->willReturn([
'allow' => 'someConfig',
'permit' => 'all'
]);
$this->assertEquals(new DataResponse([
'allow' => 'someConfig',
'permit' => 'all'
]), $this->configController->getAppConfig());
}
public function dataUpdateAppConfig() {
return [
'booleanConfig' => [
'configKey' => 'allowPermitAll',
'configValue' => true,
'strConfig' => 'true'
],
'booleanConfig' => [
'configKey' => 'allowShowToAll',
'configValue' => true,
'strConfig' => 'true'
],
'arrayConfig' => [
'configKey' => 'allowPermitAll',
'configValue' => [
'admin',
'group1'
],
'strConfig' => '["admin","group1"]'
]
];
}
/**
* @dataProvider dataUpdateAppConfig
*
* @param string $configKey
* @param mixed $configValue
* @param string $strConfig The configValue as json-string
*/
public function testUpdateAppConfig(string $configKey, $configValue, string $strConfig) {
$this->logger->expects($this->once())
->method('debug');
$this->config->expects($this->once())
->method('setAppValue')
->with('forms', $configKey, $strConfig);
$this->assertEquals(new DataResponse(), $this->configController->updateAppConfig($configKey, $configValue));
}
public function testUpdateAppConfig_unknownKey() {
$this->logger->expects($this->once())
->method('debug');
$this->config->expects($this->never())
->method('setAppValue');
$this->assertEquals(new DataResponse('Unknown appConfig key: someUnknownKey', 400), $this->configController->updateAppConfig('someUnknownKey', 'storeThisValue!'));
}
}