@@ -16,304 +16,304 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class ListConfigsTest extends TestCase { |
19 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - protected $appConfig; |
|
21 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - protected $systemConfig; |
|
19 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + protected $appConfig; |
|
21 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + protected $systemConfig; |
|
23 | 23 | |
24 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - protected $consoleInput; |
|
26 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
27 | - protected $consoleOutput; |
|
24 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + protected $consoleInput; |
|
26 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
27 | + protected $consoleOutput; |
|
28 | 28 | |
29 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
30 | - protected $command; |
|
29 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
30 | + protected $command; |
|
31 | 31 | |
32 | - protected function setUp(): void { |
|
33 | - parent::setUp(); |
|
32 | + protected function setUp(): void { |
|
33 | + parent::setUp(); |
|
34 | 34 | |
35 | - $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
36 | - ->disableOriginalConstructor() |
|
37 | - ->getMock(); |
|
38 | - $appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class) |
|
39 | - ->disableOriginalConstructor() |
|
40 | - ->getMock(); |
|
41 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
42 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
35 | + $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
36 | + ->disableOriginalConstructor() |
|
37 | + ->getMock(); |
|
38 | + $appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class) |
|
39 | + ->disableOriginalConstructor() |
|
40 | + ->getMock(); |
|
41 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
42 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
43 | 43 | |
44 | - /** @var \OC\SystemConfig $systemConfig */ |
|
45 | - /** @var \OCP\IAppConfig $appConfig */ |
|
46 | - $this->command = new ListConfigs($systemConfig, $appConfig); |
|
47 | - } |
|
44 | + /** @var \OC\SystemConfig $systemConfig */ |
|
45 | + /** @var \OCP\IAppConfig $appConfig */ |
|
46 | + $this->command = new ListConfigs($systemConfig, $appConfig); |
|
47 | + } |
|
48 | 48 | |
49 | - public static function listData(): array { |
|
50 | - return [ |
|
51 | - [ |
|
52 | - 'all', |
|
53 | - // config.php |
|
54 | - [ |
|
55 | - 'secret', |
|
56 | - 'overwrite.cli.url', |
|
57 | - ], |
|
58 | - [ |
|
59 | - ['secret', 'N;', IConfig::SENSITIVE_VALUE], |
|
60 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
61 | - ], |
|
62 | - // app config |
|
63 | - [ |
|
64 | - ['files', false, [ |
|
65 | - 'enabled' => 'yes', |
|
66 | - ]], |
|
67 | - ['core', false, [ |
|
68 | - 'global_cache_gc_lastrun' => '1430388388', |
|
69 | - ]], |
|
70 | - ], |
|
71 | - false, |
|
72 | - json_encode([ |
|
73 | - 'system' => [ |
|
74 | - 'secret' => IConfig::SENSITIVE_VALUE, |
|
75 | - 'overwrite.cli.url' => 'http://localhost', |
|
76 | - ], |
|
77 | - 'apps' => [ |
|
78 | - 'core' => [ |
|
79 | - 'global_cache_gc_lastrun' => '1430388388', |
|
80 | - ], |
|
81 | - 'files' => [ |
|
82 | - 'enabled' => 'yes', |
|
83 | - ], |
|
84 | - ], |
|
85 | - ]), |
|
86 | - ], |
|
87 | - [ |
|
88 | - 'all', |
|
89 | - // config.php |
|
90 | - [ |
|
91 | - 'secret', |
|
92 | - 'overwrite.cli.url', |
|
93 | - ], |
|
94 | - [ |
|
95 | - ['secret', 'N;', 'my secret'], |
|
96 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
97 | - ], |
|
98 | - // app config |
|
99 | - [ |
|
100 | - ['files', false, [ |
|
101 | - 'enabled' => 'yes', |
|
102 | - ]], |
|
103 | - ['core', false, [ |
|
104 | - 'global_cache_gc_lastrun' => '1430388388', |
|
105 | - ]], |
|
106 | - ], |
|
107 | - true, |
|
108 | - json_encode([ |
|
109 | - 'system' => [ |
|
110 | - 'secret' => 'my secret', |
|
111 | - 'overwrite.cli.url' => 'http://localhost', |
|
112 | - ], |
|
113 | - 'apps' => [ |
|
114 | - 'core' => [ |
|
115 | - 'global_cache_gc_lastrun' => '1430388388', |
|
116 | - ], |
|
117 | - 'files' => [ |
|
118 | - 'enabled' => 'yes', |
|
119 | - ], |
|
120 | - ], |
|
121 | - ]), |
|
122 | - ], |
|
123 | - [ |
|
124 | - 'system', |
|
125 | - // config.php |
|
126 | - [ |
|
127 | - 'secret', |
|
128 | - 'objectstore', |
|
129 | - 'overwrite.cli.url', |
|
130 | - ], |
|
131 | - [ |
|
132 | - ['secret', 'N;', IConfig::SENSITIVE_VALUE], |
|
133 | - ['objectstore', 'N;', [ |
|
134 | - 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
135 | - 'arguments' => [ |
|
136 | - 'username' => 'facebook100000123456789', |
|
137 | - 'password' => IConfig::SENSITIVE_VALUE, |
|
138 | - ], |
|
139 | - ]], |
|
140 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
141 | - ], |
|
142 | - // app config |
|
143 | - [ |
|
144 | - ['files', false, [ |
|
145 | - 'enabled' => 'yes', |
|
146 | - ]], |
|
147 | - ['core', false, [ |
|
148 | - 'global_cache_gc_lastrun' => '1430388388', |
|
149 | - ]], |
|
150 | - ], |
|
151 | - false, |
|
152 | - json_encode([ |
|
153 | - 'system' => [ |
|
154 | - 'secret' => IConfig::SENSITIVE_VALUE, |
|
155 | - 'objectstore' => [ |
|
156 | - 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
157 | - 'arguments' => [ |
|
158 | - 'username' => 'facebook100000123456789', |
|
159 | - 'password' => IConfig::SENSITIVE_VALUE, |
|
160 | - ], |
|
161 | - ], |
|
162 | - 'overwrite.cli.url' => 'http://localhost', |
|
163 | - ], |
|
164 | - ]), |
|
165 | - ], |
|
166 | - [ |
|
167 | - 'system', |
|
168 | - // config.php |
|
169 | - [ |
|
170 | - 'secret', |
|
171 | - 'overwrite.cli.url', |
|
172 | - ], |
|
173 | - [ |
|
174 | - ['secret', 'N;', 'my secret'], |
|
175 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
176 | - ], |
|
177 | - // app config |
|
178 | - [ |
|
179 | - ['files', false, [ |
|
180 | - 'enabled' => 'yes', |
|
181 | - ]], |
|
182 | - ['core', false, [ |
|
183 | - 'global_cache_gc_lastrun' => '1430388388', |
|
184 | - ]], |
|
185 | - ], |
|
186 | - true, |
|
187 | - json_encode([ |
|
188 | - 'system' => [ |
|
189 | - 'secret' => 'my secret', |
|
190 | - 'overwrite.cli.url' => 'http://localhost', |
|
191 | - ], |
|
192 | - ]), |
|
193 | - ], |
|
194 | - [ |
|
195 | - 'files', |
|
196 | - // config.php |
|
197 | - [ |
|
198 | - 'secret', |
|
199 | - 'overwrite.cli.url', |
|
200 | - ], |
|
201 | - [ |
|
202 | - ['secret', 'N;', 'my secret'], |
|
203 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
204 | - ], |
|
205 | - // app config |
|
206 | - [ |
|
207 | - ['files', false, [ |
|
208 | - 'enabled' => 'yes', |
|
209 | - ]], |
|
210 | - ['core', false, [ |
|
211 | - 'global_cache_gc_lastrun' => '1430388388', |
|
212 | - ]], |
|
213 | - ], |
|
214 | - false, |
|
215 | - json_encode([ |
|
216 | - 'apps' => [ |
|
217 | - 'files' => [ |
|
218 | - 'enabled' => 'yes', |
|
219 | - ], |
|
220 | - ], |
|
221 | - ]), |
|
222 | - ], |
|
223 | - [ |
|
224 | - 'files', |
|
225 | - // config.php |
|
226 | - [ |
|
227 | - 'secret', |
|
228 | - 'overwrite.cli.url', |
|
229 | - ], |
|
230 | - [ |
|
231 | - ['secret', 'N;', 'my secret'], |
|
232 | - ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
233 | - ], |
|
234 | - // app config |
|
235 | - [ |
|
236 | - ['files', false, [ |
|
237 | - 'enabled' => 'yes', |
|
238 | - ]], |
|
239 | - ['core', false, [ |
|
240 | - 'global_cache_gc_lastrun' => '1430388388', |
|
241 | - ]], |
|
242 | - ], |
|
243 | - true, |
|
244 | - json_encode([ |
|
245 | - 'apps' => [ |
|
246 | - 'files' => [ |
|
247 | - 'enabled' => 'yes', |
|
248 | - ], |
|
249 | - ], |
|
250 | - ]), |
|
251 | - ], |
|
252 | - ]; |
|
253 | - } |
|
49 | + public static function listData(): array { |
|
50 | + return [ |
|
51 | + [ |
|
52 | + 'all', |
|
53 | + // config.php |
|
54 | + [ |
|
55 | + 'secret', |
|
56 | + 'overwrite.cli.url', |
|
57 | + ], |
|
58 | + [ |
|
59 | + ['secret', 'N;', IConfig::SENSITIVE_VALUE], |
|
60 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
61 | + ], |
|
62 | + // app config |
|
63 | + [ |
|
64 | + ['files', false, [ |
|
65 | + 'enabled' => 'yes', |
|
66 | + ]], |
|
67 | + ['core', false, [ |
|
68 | + 'global_cache_gc_lastrun' => '1430388388', |
|
69 | + ]], |
|
70 | + ], |
|
71 | + false, |
|
72 | + json_encode([ |
|
73 | + 'system' => [ |
|
74 | + 'secret' => IConfig::SENSITIVE_VALUE, |
|
75 | + 'overwrite.cli.url' => 'http://localhost', |
|
76 | + ], |
|
77 | + 'apps' => [ |
|
78 | + 'core' => [ |
|
79 | + 'global_cache_gc_lastrun' => '1430388388', |
|
80 | + ], |
|
81 | + 'files' => [ |
|
82 | + 'enabled' => 'yes', |
|
83 | + ], |
|
84 | + ], |
|
85 | + ]), |
|
86 | + ], |
|
87 | + [ |
|
88 | + 'all', |
|
89 | + // config.php |
|
90 | + [ |
|
91 | + 'secret', |
|
92 | + 'overwrite.cli.url', |
|
93 | + ], |
|
94 | + [ |
|
95 | + ['secret', 'N;', 'my secret'], |
|
96 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
97 | + ], |
|
98 | + // app config |
|
99 | + [ |
|
100 | + ['files', false, [ |
|
101 | + 'enabled' => 'yes', |
|
102 | + ]], |
|
103 | + ['core', false, [ |
|
104 | + 'global_cache_gc_lastrun' => '1430388388', |
|
105 | + ]], |
|
106 | + ], |
|
107 | + true, |
|
108 | + json_encode([ |
|
109 | + 'system' => [ |
|
110 | + 'secret' => 'my secret', |
|
111 | + 'overwrite.cli.url' => 'http://localhost', |
|
112 | + ], |
|
113 | + 'apps' => [ |
|
114 | + 'core' => [ |
|
115 | + 'global_cache_gc_lastrun' => '1430388388', |
|
116 | + ], |
|
117 | + 'files' => [ |
|
118 | + 'enabled' => 'yes', |
|
119 | + ], |
|
120 | + ], |
|
121 | + ]), |
|
122 | + ], |
|
123 | + [ |
|
124 | + 'system', |
|
125 | + // config.php |
|
126 | + [ |
|
127 | + 'secret', |
|
128 | + 'objectstore', |
|
129 | + 'overwrite.cli.url', |
|
130 | + ], |
|
131 | + [ |
|
132 | + ['secret', 'N;', IConfig::SENSITIVE_VALUE], |
|
133 | + ['objectstore', 'N;', [ |
|
134 | + 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
135 | + 'arguments' => [ |
|
136 | + 'username' => 'facebook100000123456789', |
|
137 | + 'password' => IConfig::SENSITIVE_VALUE, |
|
138 | + ], |
|
139 | + ]], |
|
140 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
141 | + ], |
|
142 | + // app config |
|
143 | + [ |
|
144 | + ['files', false, [ |
|
145 | + 'enabled' => 'yes', |
|
146 | + ]], |
|
147 | + ['core', false, [ |
|
148 | + 'global_cache_gc_lastrun' => '1430388388', |
|
149 | + ]], |
|
150 | + ], |
|
151 | + false, |
|
152 | + json_encode([ |
|
153 | + 'system' => [ |
|
154 | + 'secret' => IConfig::SENSITIVE_VALUE, |
|
155 | + 'objectstore' => [ |
|
156 | + 'class' => 'OC\\Files\\ObjectStore\\Swift', |
|
157 | + 'arguments' => [ |
|
158 | + 'username' => 'facebook100000123456789', |
|
159 | + 'password' => IConfig::SENSITIVE_VALUE, |
|
160 | + ], |
|
161 | + ], |
|
162 | + 'overwrite.cli.url' => 'http://localhost', |
|
163 | + ], |
|
164 | + ]), |
|
165 | + ], |
|
166 | + [ |
|
167 | + 'system', |
|
168 | + // config.php |
|
169 | + [ |
|
170 | + 'secret', |
|
171 | + 'overwrite.cli.url', |
|
172 | + ], |
|
173 | + [ |
|
174 | + ['secret', 'N;', 'my secret'], |
|
175 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
176 | + ], |
|
177 | + // app config |
|
178 | + [ |
|
179 | + ['files', false, [ |
|
180 | + 'enabled' => 'yes', |
|
181 | + ]], |
|
182 | + ['core', false, [ |
|
183 | + 'global_cache_gc_lastrun' => '1430388388', |
|
184 | + ]], |
|
185 | + ], |
|
186 | + true, |
|
187 | + json_encode([ |
|
188 | + 'system' => [ |
|
189 | + 'secret' => 'my secret', |
|
190 | + 'overwrite.cli.url' => 'http://localhost', |
|
191 | + ], |
|
192 | + ]), |
|
193 | + ], |
|
194 | + [ |
|
195 | + 'files', |
|
196 | + // config.php |
|
197 | + [ |
|
198 | + 'secret', |
|
199 | + 'overwrite.cli.url', |
|
200 | + ], |
|
201 | + [ |
|
202 | + ['secret', 'N;', 'my secret'], |
|
203 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
204 | + ], |
|
205 | + // app config |
|
206 | + [ |
|
207 | + ['files', false, [ |
|
208 | + 'enabled' => 'yes', |
|
209 | + ]], |
|
210 | + ['core', false, [ |
|
211 | + 'global_cache_gc_lastrun' => '1430388388', |
|
212 | + ]], |
|
213 | + ], |
|
214 | + false, |
|
215 | + json_encode([ |
|
216 | + 'apps' => [ |
|
217 | + 'files' => [ |
|
218 | + 'enabled' => 'yes', |
|
219 | + ], |
|
220 | + ], |
|
221 | + ]), |
|
222 | + ], |
|
223 | + [ |
|
224 | + 'files', |
|
225 | + // config.php |
|
226 | + [ |
|
227 | + 'secret', |
|
228 | + 'overwrite.cli.url', |
|
229 | + ], |
|
230 | + [ |
|
231 | + ['secret', 'N;', 'my secret'], |
|
232 | + ['overwrite.cli.url', 'N;', 'http://localhost'], |
|
233 | + ], |
|
234 | + // app config |
|
235 | + [ |
|
236 | + ['files', false, [ |
|
237 | + 'enabled' => 'yes', |
|
238 | + ]], |
|
239 | + ['core', false, [ |
|
240 | + 'global_cache_gc_lastrun' => '1430388388', |
|
241 | + ]], |
|
242 | + ], |
|
243 | + true, |
|
244 | + json_encode([ |
|
245 | + 'apps' => [ |
|
246 | + 'files' => [ |
|
247 | + 'enabled' => 'yes', |
|
248 | + ], |
|
249 | + ], |
|
250 | + ]), |
|
251 | + ], |
|
252 | + ]; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @dataProvider listData |
|
257 | - * |
|
258 | - * @param string $app |
|
259 | - * @param array $systemConfigs |
|
260 | - * @param array $systemConfigMap |
|
261 | - * @param array $appConfig |
|
262 | - * @param bool $private |
|
263 | - * @param string $expected |
|
264 | - */ |
|
265 | - public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected): void { |
|
266 | - $this->systemConfig->expects($this->any()) |
|
267 | - ->method('getKeys') |
|
268 | - ->willReturn($systemConfigs); |
|
269 | - if ($private) { |
|
270 | - $this->systemConfig->expects($this->any()) |
|
271 | - ->method('getValue') |
|
272 | - ->willReturnMap($systemConfigMap); |
|
273 | - $this->appConfig->expects($this->any()) |
|
274 | - ->method('getValues') |
|
275 | - ->willReturnMap($appConfig); |
|
276 | - } else { |
|
277 | - $this->systemConfig->expects($this->any()) |
|
278 | - ->method('getFilteredValue') |
|
279 | - ->willReturnMap($systemConfigMap); |
|
280 | - $this->appConfig->expects($this->any()) |
|
281 | - ->method('getFilteredValues') |
|
282 | - ->willReturnMap($appConfig); |
|
283 | - } |
|
255 | + /** |
|
256 | + * @dataProvider listData |
|
257 | + * |
|
258 | + * @param string $app |
|
259 | + * @param array $systemConfigs |
|
260 | + * @param array $systemConfigMap |
|
261 | + * @param array $appConfig |
|
262 | + * @param bool $private |
|
263 | + * @param string $expected |
|
264 | + */ |
|
265 | + public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected): void { |
|
266 | + $this->systemConfig->expects($this->any()) |
|
267 | + ->method('getKeys') |
|
268 | + ->willReturn($systemConfigs); |
|
269 | + if ($private) { |
|
270 | + $this->systemConfig->expects($this->any()) |
|
271 | + ->method('getValue') |
|
272 | + ->willReturnMap($systemConfigMap); |
|
273 | + $this->appConfig->expects($this->any()) |
|
274 | + ->method('getValues') |
|
275 | + ->willReturnMap($appConfig); |
|
276 | + } else { |
|
277 | + $this->systemConfig->expects($this->any()) |
|
278 | + ->method('getFilteredValue') |
|
279 | + ->willReturnMap($systemConfigMap); |
|
280 | + $this->appConfig->expects($this->any()) |
|
281 | + ->method('getFilteredValues') |
|
282 | + ->willReturnMap($appConfig); |
|
283 | + } |
|
284 | 284 | |
285 | - $this->appConfig->expects($this->any()) |
|
286 | - ->method('getApps') |
|
287 | - ->willReturn(['core', 'files']); |
|
288 | - $this->appConfig->expects($this->any()) |
|
289 | - ->method('getValues') |
|
290 | - ->willReturnMap($appConfig); |
|
285 | + $this->appConfig->expects($this->any()) |
|
286 | + ->method('getApps') |
|
287 | + ->willReturn(['core', 'files']); |
|
288 | + $this->appConfig->expects($this->any()) |
|
289 | + ->method('getValues') |
|
290 | + ->willReturnMap($appConfig); |
|
291 | 291 | |
292 | - $this->consoleInput->expects($this->once()) |
|
293 | - ->method('getArgument') |
|
294 | - ->with('app') |
|
295 | - ->willReturn($app); |
|
292 | + $this->consoleInput->expects($this->once()) |
|
293 | + ->method('getArgument') |
|
294 | + ->with('app') |
|
295 | + ->willReturn($app); |
|
296 | 296 | |
297 | - $this->consoleInput->expects($this->any()) |
|
298 | - ->method('getOption') |
|
299 | - ->willReturnMap([ |
|
300 | - ['output', 'json'], |
|
301 | - ['private', $private], |
|
302 | - ]); |
|
297 | + $this->consoleInput->expects($this->any()) |
|
298 | + ->method('getOption') |
|
299 | + ->willReturnMap([ |
|
300 | + ['output', 'json'], |
|
301 | + ['private', $private], |
|
302 | + ]); |
|
303 | 303 | |
304 | - global $output; |
|
304 | + global $output; |
|
305 | 305 | |
306 | - $output = ''; |
|
307 | - $this->consoleOutput->expects($this->any()) |
|
308 | - ->method('writeln') |
|
309 | - ->willReturnCallback(function ($value) { |
|
310 | - global $output; |
|
311 | - $output .= $value . "\n"; |
|
312 | - return $output; |
|
313 | - }); |
|
306 | + $output = ''; |
|
307 | + $this->consoleOutput->expects($this->any()) |
|
308 | + ->method('writeln') |
|
309 | + ->willReturnCallback(function ($value) { |
|
310 | + global $output; |
|
311 | + $output .= $value . "\n"; |
|
312 | + return $output; |
|
313 | + }); |
|
314 | 314 | |
315 | - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
315 | + $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
316 | 316 | |
317 | - $this->assertEquals($expected, trim($output, "\n")); |
|
318 | - } |
|
317 | + $this->assertEquals($expected, trim($output, "\n")); |
|
318 | + } |
|
319 | 319 | } |
@@ -21,134 +21,134 @@ |
||
21 | 21 | use Test\TestCase; |
22 | 22 | |
23 | 23 | class RepairTest extends TestCase { |
24 | - /** @var IConfig|MockObject */ |
|
25 | - private $config; |
|
26 | - /** @var IRootFolder|MockObject */ |
|
27 | - private $rootFolder; |
|
28 | - /** @var LoggerInterface|MockObject */ |
|
29 | - private $logger; |
|
30 | - /** @var IniGetWrapper|MockObject */ |
|
31 | - private $iniGetWrapper; |
|
32 | - /** @var InputInterface|MockObject */ |
|
33 | - private $input; |
|
34 | - /** @var OutputInterface|MockObject */ |
|
35 | - private $output; |
|
36 | - /** @var string */ |
|
37 | - private $outputLines = ''; |
|
38 | - /** @var Repair */ |
|
39 | - private $repair; |
|
24 | + /** @var IConfig|MockObject */ |
|
25 | + private $config; |
|
26 | + /** @var IRootFolder|MockObject */ |
|
27 | + private $rootFolder; |
|
28 | + /** @var LoggerInterface|MockObject */ |
|
29 | + private $logger; |
|
30 | + /** @var IniGetWrapper|MockObject */ |
|
31 | + private $iniGetWrapper; |
|
32 | + /** @var InputInterface|MockObject */ |
|
33 | + private $input; |
|
34 | + /** @var OutputInterface|MockObject */ |
|
35 | + private $output; |
|
36 | + /** @var string */ |
|
37 | + private $outputLines = ''; |
|
38 | + /** @var Repair */ |
|
39 | + private $repair; |
|
40 | 40 | |
41 | - protected function setUp(): void { |
|
42 | - parent::setUp(); |
|
43 | - $this->config = $this->getMockBuilder(IConfig::class) |
|
44 | - ->getMock(); |
|
45 | - $this->rootFolder = $this->getMockBuilder(IRootFolder::class) |
|
46 | - ->getMock(); |
|
47 | - $this->logger = $this->getMockBuilder(LoggerInterface::class) |
|
48 | - ->getMock(); |
|
49 | - $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class) |
|
50 | - ->getMock(); |
|
51 | - $this->repair = new Repair( |
|
52 | - $this->config, |
|
53 | - $this->rootFolder, |
|
54 | - $this->logger, |
|
55 | - $this->iniGetWrapper, |
|
56 | - $this->createMock(ILockingProvider::class) |
|
57 | - ); |
|
58 | - $this->input = $this->createMock(InputInterface::class); |
|
59 | - $this->input->expects($this->any()) |
|
60 | - ->method('getOption') |
|
61 | - ->willReturnCallback(function ($parameter) { |
|
62 | - if ($parameter === 'batch') { |
|
63 | - return true; |
|
64 | - } |
|
65 | - return null; |
|
66 | - }); |
|
67 | - $this->output = $this->getMockBuilder(ConsoleOutput::class) |
|
68 | - ->onlyMethods(['section', 'writeln', 'getFormatter']) |
|
69 | - ->getMock(); |
|
70 | - $self = $this; |
|
41 | + protected function setUp(): void { |
|
42 | + parent::setUp(); |
|
43 | + $this->config = $this->getMockBuilder(IConfig::class) |
|
44 | + ->getMock(); |
|
45 | + $this->rootFolder = $this->getMockBuilder(IRootFolder::class) |
|
46 | + ->getMock(); |
|
47 | + $this->logger = $this->getMockBuilder(LoggerInterface::class) |
|
48 | + ->getMock(); |
|
49 | + $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class) |
|
50 | + ->getMock(); |
|
51 | + $this->repair = new Repair( |
|
52 | + $this->config, |
|
53 | + $this->rootFolder, |
|
54 | + $this->logger, |
|
55 | + $this->iniGetWrapper, |
|
56 | + $this->createMock(ILockingProvider::class) |
|
57 | + ); |
|
58 | + $this->input = $this->createMock(InputInterface::class); |
|
59 | + $this->input->expects($this->any()) |
|
60 | + ->method('getOption') |
|
61 | + ->willReturnCallback(function ($parameter) { |
|
62 | + if ($parameter === 'batch') { |
|
63 | + return true; |
|
64 | + } |
|
65 | + return null; |
|
66 | + }); |
|
67 | + $this->output = $this->getMockBuilder(ConsoleOutput::class) |
|
68 | + ->onlyMethods(['section', 'writeln', 'getFormatter']) |
|
69 | + ->getMock(); |
|
70 | + $self = $this; |
|
71 | 71 | |
72 | - /* We need format method to return a string */ |
|
73 | - $outputFormatter = $this->createMock(OutputFormatterInterface::class); |
|
74 | - $outputFormatter->method('isDecorated')->willReturn(false); |
|
75 | - $outputFormatter->method('format')->willReturnArgument(0); |
|
72 | + /* We need format method to return a string */ |
|
73 | + $outputFormatter = $this->createMock(OutputFormatterInterface::class); |
|
74 | + $outputFormatter->method('isDecorated')->willReturn(false); |
|
75 | + $outputFormatter->method('format')->willReturnArgument(0); |
|
76 | 76 | |
77 | - $this->output->expects($this->any()) |
|
78 | - ->method('getFormatter') |
|
79 | - ->willReturn($outputFormatter); |
|
80 | - $this->output->expects($this->any()) |
|
81 | - ->method('writeln') |
|
82 | - ->willReturnCallback(function ($line) use ($self) { |
|
83 | - $self->outputLines .= $line . "\n"; |
|
84 | - }); |
|
85 | - } |
|
77 | + $this->output->expects($this->any()) |
|
78 | + ->method('getFormatter') |
|
79 | + ->willReturn($outputFormatter); |
|
80 | + $this->output->expects($this->any()) |
|
81 | + ->method('writeln') |
|
82 | + ->willReturnCallback(function ($line) use ($self) { |
|
83 | + $self->outputLines .= $line . "\n"; |
|
84 | + }); |
|
85 | + } |
|
86 | 86 | |
87 | - public static function dataEmptyTest(): array { |
|
88 | - /** directoryNames, expectedOutput */ |
|
89 | - return [ |
|
90 | - [ |
|
91 | - [], |
|
92 | - 'All previews are already migrated.' |
|
93 | - ], |
|
94 | - [ |
|
95 | - [['name' => 'a'], ['name' => 'b'], ['name' => 'c']], |
|
96 | - 'All previews are already migrated.' |
|
97 | - ], |
|
98 | - [ |
|
99 | - [['name' => '0', 'content' => ['folder', 'folder']], ['name' => 'b'], ['name' => 'c']], |
|
100 | - 'All previews are already migrated.' |
|
101 | - ], |
|
102 | - [ |
|
103 | - [['name' => '0', 'content' => ['file', 'folder', 'folder']], ['name' => 'b'], ['name' => 'c']], |
|
104 | - 'A total of 1 preview files need to be migrated.' |
|
105 | - ], |
|
106 | - [ |
|
107 | - [['name' => '23'], ['name' => 'b'], ['name' => 'c']], |
|
108 | - 'A total of 1 preview files need to be migrated.' |
|
109 | - ], |
|
110 | - ]; |
|
111 | - } |
|
87 | + public static function dataEmptyTest(): array { |
|
88 | + /** directoryNames, expectedOutput */ |
|
89 | + return [ |
|
90 | + [ |
|
91 | + [], |
|
92 | + 'All previews are already migrated.' |
|
93 | + ], |
|
94 | + [ |
|
95 | + [['name' => 'a'], ['name' => 'b'], ['name' => 'c']], |
|
96 | + 'All previews are already migrated.' |
|
97 | + ], |
|
98 | + [ |
|
99 | + [['name' => '0', 'content' => ['folder', 'folder']], ['name' => 'b'], ['name' => 'c']], |
|
100 | + 'All previews are already migrated.' |
|
101 | + ], |
|
102 | + [ |
|
103 | + [['name' => '0', 'content' => ['file', 'folder', 'folder']], ['name' => 'b'], ['name' => 'c']], |
|
104 | + 'A total of 1 preview files need to be migrated.' |
|
105 | + ], |
|
106 | + [ |
|
107 | + [['name' => '23'], ['name' => 'b'], ['name' => 'c']], |
|
108 | + 'A total of 1 preview files need to be migrated.' |
|
109 | + ], |
|
110 | + ]; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @dataProvider dataEmptyTest |
|
115 | - */ |
|
116 | - public function testEmptyExecute($directoryNames, $expectedOutput): void { |
|
117 | - $previewFolder = $this->getMockBuilder(Folder::class) |
|
118 | - ->getMock(); |
|
119 | - $directories = array_map(function ($element) { |
|
120 | - $dir = $this->getMockBuilder(Folder::class) |
|
121 | - ->getMock(); |
|
122 | - $dir->expects($this->any()) |
|
123 | - ->method('getName') |
|
124 | - ->willReturn($element['name']); |
|
125 | - if (isset($element['content'])) { |
|
126 | - $list = []; |
|
127 | - foreach ($element['content'] as $item) { |
|
128 | - if ($item === 'file') { |
|
129 | - $list[] = $this->getMockBuilder(Node::class) |
|
130 | - ->getMock(); |
|
131 | - } elseif ($item === 'folder') { |
|
132 | - $list[] = $this->getMockBuilder(Folder::class) |
|
133 | - ->getMock(); |
|
134 | - } |
|
135 | - } |
|
136 | - $dir->expects($this->once()) |
|
137 | - ->method('getDirectoryListing') |
|
138 | - ->willReturn($list); |
|
139 | - } |
|
140 | - return $dir; |
|
141 | - }, $directoryNames); |
|
142 | - $previewFolder->expects($this->once()) |
|
143 | - ->method('getDirectoryListing') |
|
144 | - ->willReturn($directories); |
|
145 | - $this->rootFolder->expects($this->once()) |
|
146 | - ->method('get') |
|
147 | - ->with('appdata_/preview') |
|
148 | - ->willReturn($previewFolder); |
|
113 | + /** |
|
114 | + * @dataProvider dataEmptyTest |
|
115 | + */ |
|
116 | + public function testEmptyExecute($directoryNames, $expectedOutput): void { |
|
117 | + $previewFolder = $this->getMockBuilder(Folder::class) |
|
118 | + ->getMock(); |
|
119 | + $directories = array_map(function ($element) { |
|
120 | + $dir = $this->getMockBuilder(Folder::class) |
|
121 | + ->getMock(); |
|
122 | + $dir->expects($this->any()) |
|
123 | + ->method('getName') |
|
124 | + ->willReturn($element['name']); |
|
125 | + if (isset($element['content'])) { |
|
126 | + $list = []; |
|
127 | + foreach ($element['content'] as $item) { |
|
128 | + if ($item === 'file') { |
|
129 | + $list[] = $this->getMockBuilder(Node::class) |
|
130 | + ->getMock(); |
|
131 | + } elseif ($item === 'folder') { |
|
132 | + $list[] = $this->getMockBuilder(Folder::class) |
|
133 | + ->getMock(); |
|
134 | + } |
|
135 | + } |
|
136 | + $dir->expects($this->once()) |
|
137 | + ->method('getDirectoryListing') |
|
138 | + ->willReturn($list); |
|
139 | + } |
|
140 | + return $dir; |
|
141 | + }, $directoryNames); |
|
142 | + $previewFolder->expects($this->once()) |
|
143 | + ->method('getDirectoryListing') |
|
144 | + ->willReturn($directories); |
|
145 | + $this->rootFolder->expects($this->once()) |
|
146 | + ->method('get') |
|
147 | + ->with('appdata_/preview') |
|
148 | + ->willReturn($previewFolder); |
|
149 | 149 | |
150 | - $this->repair->run($this->input, $this->output); |
|
150 | + $this->repair->run($this->input, $this->output); |
|
151 | 151 | |
152 | - $this->assertStringContainsString($expectedOutput, $this->outputLines); |
|
153 | - } |
|
152 | + $this->assertStringContainsString($expectedOutput, $this->outputLines); |
|
153 | + } |
|
154 | 154 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $this->input = $this->createMock(InputInterface::class); |
59 | 59 | $this->input->expects($this->any()) |
60 | 60 | ->method('getOption') |
61 | - ->willReturnCallback(function ($parameter) { |
|
61 | + ->willReturnCallback(function($parameter) { |
|
62 | 62 | if ($parameter === 'batch') { |
63 | 63 | return true; |
64 | 64 | } |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | ->willReturn($outputFormatter); |
80 | 80 | $this->output->expects($this->any()) |
81 | 81 | ->method('writeln') |
82 | - ->willReturnCallback(function ($line) use ($self) { |
|
83 | - $self->outputLines .= $line . "\n"; |
|
82 | + ->willReturnCallback(function($line) use ($self) { |
|
83 | + $self->outputLines .= $line."\n"; |
|
84 | 84 | }); |
85 | 85 | } |
86 | 86 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public function testEmptyExecute($directoryNames, $expectedOutput): void { |
117 | 117 | $previewFolder = $this->getMockBuilder(Folder::class) |
118 | 118 | ->getMock(); |
119 | - $directories = array_map(function ($element) { |
|
119 | + $directories = array_map(function($element) { |
|
120 | 120 | $dir = $this->getMockBuilder(Folder::class) |
121 | 121 | ->getMock(); |
122 | 122 | $dir->expects($this->any()) |
@@ -15,171 +15,171 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class EditTest extends TestCase { |
18 | - /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | - private $systemTagManager; |
|
20 | - |
|
21 | - /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - private $command; |
|
23 | - |
|
24 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - private $input; |
|
26 | - |
|
27 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - private $output; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
34 | - $this->command = $this->getMockBuilder(Edit::class) |
|
35 | - ->setConstructorArgs([$this->systemTagManager]) |
|
36 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | - ->getMock(); |
|
38 | - |
|
39 | - $this->input = $this->createMock(InputInterface::class); |
|
40 | - $this->output = $this->createMock(OutputInterface::class); |
|
41 | - } |
|
42 | - |
|
43 | - public function testExecute(): void { |
|
44 | - $tagId = '5'; |
|
45 | - $tagName = 'unwichtige Dateien'; |
|
46 | - $newTagName = 'moderat wichtige Dateien'; |
|
47 | - $newTagAccess = 'restricted'; |
|
48 | - $newTagUserVisible = true; |
|
49 | - $newTagUserAssignable = false; |
|
50 | - |
|
51 | - $tag = $this->createMock(ISystemTag::class); |
|
52 | - $tag->method('getId')->willReturn($tagId); |
|
53 | - $tag->method('getName')->willReturn($tagName); |
|
54 | - $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
55 | - |
|
56 | - $this->systemTagManager->method('getTagsByIds') |
|
57 | - ->with($tagId) |
|
58 | - ->willReturn([$tag]); |
|
59 | - |
|
60 | - $this->input->method('getArgument') |
|
61 | - ->willReturnCallback(function ($arg) use ($tagId) { |
|
62 | - if ($arg === 'id') { |
|
63 | - return $tagId; |
|
64 | - } |
|
65 | - throw new \Exception(); |
|
66 | - }); |
|
67 | - |
|
68 | - $this->input->method('getOption') |
|
69 | - ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { |
|
70 | - if ($arg === 'name') { |
|
71 | - return $newTagName; |
|
72 | - } elseif ($arg === 'access') { |
|
73 | - return $newTagAccess; |
|
74 | - } |
|
75 | - throw new \Exception(); |
|
76 | - }); |
|
77 | - |
|
78 | - $this->systemTagManager->expects($this->once()) |
|
79 | - ->method('updateTag') |
|
80 | - ->with( |
|
81 | - $tagId, |
|
82 | - $newTagName, |
|
83 | - $newTagUserVisible, |
|
84 | - $newTagUserAssignable, |
|
85 | - '' |
|
86 | - ); |
|
87 | - |
|
88 | - $this->output->expects($this->once()) |
|
89 | - ->method('writeln') |
|
90 | - ->with( |
|
91 | - '<info>Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")</info>' |
|
92 | - ); |
|
93 | - |
|
94 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
95 | - } |
|
96 | - |
|
97 | - public function testAlreadyExists(): void { |
|
98 | - $tagId = '5'; |
|
99 | - $tagName = 'unwichtige Dateien'; |
|
100 | - $tagUserVisible = false; |
|
101 | - $tagUserAssignable = false; |
|
102 | - $newTagName = 'moderat wichtige Dateien'; |
|
103 | - $newTagAccess = 'restricted'; |
|
104 | - $newTagUserVisible = true; |
|
105 | - $newTagUserAssignable = false; |
|
106 | - |
|
107 | - $tag = $this->createMock(ISystemTag::class); |
|
108 | - $tag->method('getId')->willReturn($tagId); |
|
109 | - $tag->method('getName')->willReturn($tagName); |
|
110 | - $tag->method('isUserVisible')->willReturn($tagUserVisible); |
|
111 | - $tag->method('isUserAssignable')->willReturn($tagUserAssignable); |
|
112 | - $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
113 | - |
|
114 | - $this->systemTagManager->method('getTagsByIds') |
|
115 | - ->with($tagId) |
|
116 | - ->willReturn([$tag]); |
|
117 | - |
|
118 | - $this->input->method('getArgument') |
|
119 | - ->willReturnCallback(function ($arg) use ($tagId) { |
|
120 | - if ($arg === 'id') { |
|
121 | - return $tagId; |
|
122 | - } |
|
123 | - throw new \Exception(); |
|
124 | - }); |
|
125 | - |
|
126 | - $this->input->method('getOption') |
|
127 | - ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { |
|
128 | - if ($arg === 'name') { |
|
129 | - return $newTagName; |
|
130 | - } elseif ($arg === 'access') { |
|
131 | - return $newTagAccess; |
|
132 | - } |
|
133 | - throw new \Exception(); |
|
134 | - }); |
|
135 | - |
|
136 | - $this->systemTagManager->method('updateTag') |
|
137 | - ->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable) { |
|
138 | - throw new TagAlreadyExistsException( |
|
139 | - 'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists' |
|
140 | - ); |
|
141 | - }); |
|
142 | - |
|
143 | - $this->systemTagManager->expects($this->once()) |
|
144 | - ->method('updateTag') |
|
145 | - ->with( |
|
146 | - $tagId, |
|
147 | - $newTagName, |
|
148 | - $newTagUserVisible, |
|
149 | - $newTagUserAssignable, |
|
150 | - '' |
|
151 | - ); |
|
152 | - |
|
153 | - $this->output->expects($this->once()) |
|
154 | - ->method('writeln') |
|
155 | - ->with( |
|
156 | - '<error>Tag ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ') already exists</error>' |
|
157 | - ); |
|
158 | - |
|
159 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
160 | - } |
|
161 | - |
|
162 | - public function testNotFound(): void { |
|
163 | - $tagId = '404'; |
|
164 | - |
|
165 | - $this->input->method('getArgument') |
|
166 | - ->willReturnCallback(function ($arg) use ($tagId) { |
|
167 | - if ($arg === 'id') { |
|
168 | - return $tagId; |
|
169 | - } |
|
170 | - throw new \Exception(); |
|
171 | - }); |
|
172 | - |
|
173 | - $this->systemTagManager->method('getTagsByIds') |
|
174 | - ->with($tagId) |
|
175 | - ->willReturn([]); |
|
176 | - |
|
177 | - $this->output->expects($this->once()) |
|
178 | - ->method('writeln') |
|
179 | - ->with( |
|
180 | - '<error>Tag not found</error>' |
|
181 | - ); |
|
182 | - |
|
183 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
184 | - } |
|
18 | + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | + private $systemTagManager; |
|
20 | + |
|
21 | + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + private $command; |
|
23 | + |
|
24 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + private $input; |
|
26 | + |
|
27 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + private $output; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
34 | + $this->command = $this->getMockBuilder(Edit::class) |
|
35 | + ->setConstructorArgs([$this->systemTagManager]) |
|
36 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | + ->getMock(); |
|
38 | + |
|
39 | + $this->input = $this->createMock(InputInterface::class); |
|
40 | + $this->output = $this->createMock(OutputInterface::class); |
|
41 | + } |
|
42 | + |
|
43 | + public function testExecute(): void { |
|
44 | + $tagId = '5'; |
|
45 | + $tagName = 'unwichtige Dateien'; |
|
46 | + $newTagName = 'moderat wichtige Dateien'; |
|
47 | + $newTagAccess = 'restricted'; |
|
48 | + $newTagUserVisible = true; |
|
49 | + $newTagUserAssignable = false; |
|
50 | + |
|
51 | + $tag = $this->createMock(ISystemTag::class); |
|
52 | + $tag->method('getId')->willReturn($tagId); |
|
53 | + $tag->method('getName')->willReturn($tagName); |
|
54 | + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
55 | + |
|
56 | + $this->systemTagManager->method('getTagsByIds') |
|
57 | + ->with($tagId) |
|
58 | + ->willReturn([$tag]); |
|
59 | + |
|
60 | + $this->input->method('getArgument') |
|
61 | + ->willReturnCallback(function ($arg) use ($tagId) { |
|
62 | + if ($arg === 'id') { |
|
63 | + return $tagId; |
|
64 | + } |
|
65 | + throw new \Exception(); |
|
66 | + }); |
|
67 | + |
|
68 | + $this->input->method('getOption') |
|
69 | + ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { |
|
70 | + if ($arg === 'name') { |
|
71 | + return $newTagName; |
|
72 | + } elseif ($arg === 'access') { |
|
73 | + return $newTagAccess; |
|
74 | + } |
|
75 | + throw new \Exception(); |
|
76 | + }); |
|
77 | + |
|
78 | + $this->systemTagManager->expects($this->once()) |
|
79 | + ->method('updateTag') |
|
80 | + ->with( |
|
81 | + $tagId, |
|
82 | + $newTagName, |
|
83 | + $newTagUserVisible, |
|
84 | + $newTagUserAssignable, |
|
85 | + '' |
|
86 | + ); |
|
87 | + |
|
88 | + $this->output->expects($this->once()) |
|
89 | + ->method('writeln') |
|
90 | + ->with( |
|
91 | + '<info>Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")</info>' |
|
92 | + ); |
|
93 | + |
|
94 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
95 | + } |
|
96 | + |
|
97 | + public function testAlreadyExists(): void { |
|
98 | + $tagId = '5'; |
|
99 | + $tagName = 'unwichtige Dateien'; |
|
100 | + $tagUserVisible = false; |
|
101 | + $tagUserAssignable = false; |
|
102 | + $newTagName = 'moderat wichtige Dateien'; |
|
103 | + $newTagAccess = 'restricted'; |
|
104 | + $newTagUserVisible = true; |
|
105 | + $newTagUserAssignable = false; |
|
106 | + |
|
107 | + $tag = $this->createMock(ISystemTag::class); |
|
108 | + $tag->method('getId')->willReturn($tagId); |
|
109 | + $tag->method('getName')->willReturn($tagName); |
|
110 | + $tag->method('isUserVisible')->willReturn($tagUserVisible); |
|
111 | + $tag->method('isUserAssignable')->willReturn($tagUserAssignable); |
|
112 | + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
113 | + |
|
114 | + $this->systemTagManager->method('getTagsByIds') |
|
115 | + ->with($tagId) |
|
116 | + ->willReturn([$tag]); |
|
117 | + |
|
118 | + $this->input->method('getArgument') |
|
119 | + ->willReturnCallback(function ($arg) use ($tagId) { |
|
120 | + if ($arg === 'id') { |
|
121 | + return $tagId; |
|
122 | + } |
|
123 | + throw new \Exception(); |
|
124 | + }); |
|
125 | + |
|
126 | + $this->input->method('getOption') |
|
127 | + ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { |
|
128 | + if ($arg === 'name') { |
|
129 | + return $newTagName; |
|
130 | + } elseif ($arg === 'access') { |
|
131 | + return $newTagAccess; |
|
132 | + } |
|
133 | + throw new \Exception(); |
|
134 | + }); |
|
135 | + |
|
136 | + $this->systemTagManager->method('updateTag') |
|
137 | + ->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable) { |
|
138 | + throw new TagAlreadyExistsException( |
|
139 | + 'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists' |
|
140 | + ); |
|
141 | + }); |
|
142 | + |
|
143 | + $this->systemTagManager->expects($this->once()) |
|
144 | + ->method('updateTag') |
|
145 | + ->with( |
|
146 | + $tagId, |
|
147 | + $newTagName, |
|
148 | + $newTagUserVisible, |
|
149 | + $newTagUserAssignable, |
|
150 | + '' |
|
151 | + ); |
|
152 | + |
|
153 | + $this->output->expects($this->once()) |
|
154 | + ->method('writeln') |
|
155 | + ->with( |
|
156 | + '<error>Tag ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ') already exists</error>' |
|
157 | + ); |
|
158 | + |
|
159 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
160 | + } |
|
161 | + |
|
162 | + public function testNotFound(): void { |
|
163 | + $tagId = '404'; |
|
164 | + |
|
165 | + $this->input->method('getArgument') |
|
166 | + ->willReturnCallback(function ($arg) use ($tagId) { |
|
167 | + if ($arg === 'id') { |
|
168 | + return $tagId; |
|
169 | + } |
|
170 | + throw new \Exception(); |
|
171 | + }); |
|
172 | + |
|
173 | + $this->systemTagManager->method('getTagsByIds') |
|
174 | + ->with($tagId) |
|
175 | + ->willReturn([]); |
|
176 | + |
|
177 | + $this->output->expects($this->once()) |
|
178 | + ->method('writeln') |
|
179 | + ->with( |
|
180 | + '<error>Tag not found</error>' |
|
181 | + ); |
|
182 | + |
|
183 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
184 | + } |
|
185 | 185 | } |
@@ -15,106 +15,106 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class AddTest extends TestCase { |
18 | - /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | - private $systemTagManager; |
|
20 | - |
|
21 | - /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - private $command; |
|
23 | - |
|
24 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - private $input; |
|
26 | - |
|
27 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - private $output; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
34 | - $this->command = $this->getMockBuilder(Add::class) |
|
35 | - ->setConstructorArgs([$this->systemTagManager]) |
|
36 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | - ->getMock(); |
|
38 | - |
|
39 | - $this->input = $this->createMock(InputInterface::class); |
|
40 | - $this->output = $this->createMock(OutputInterface::class); |
|
41 | - } |
|
42 | - |
|
43 | - public function testExecute(): void { |
|
44 | - $tagId = '42'; |
|
45 | - $tagName = 'wichtig'; |
|
46 | - $tagAccess = 'public'; |
|
47 | - |
|
48 | - $tag = $this->createMock(ISystemTag::class); |
|
49 | - $tag->method('getId')->willReturn($tagId); |
|
50 | - $tag->method('getName')->willReturn($tagName); |
|
51 | - $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
52 | - |
|
53 | - $this->systemTagManager->method('createTag') |
|
54 | - ->with( |
|
55 | - $tagName, |
|
56 | - true, |
|
57 | - true |
|
58 | - )->willReturn($tag); |
|
59 | - |
|
60 | - $this->input->method('getArgument') |
|
61 | - ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { |
|
62 | - if ($arg === 'name') { |
|
63 | - return $tagName; |
|
64 | - } elseif ($arg === 'access') { |
|
65 | - return $tagAccess; |
|
66 | - } |
|
67 | - throw new \Exception(); |
|
68 | - }); |
|
69 | - |
|
70 | - $this->command->expects($this->once()) |
|
71 | - ->method('writeArrayInOutputFormat') |
|
72 | - ->with( |
|
73 | - $this->equalTo($this->input), |
|
74 | - $this->equalTo($this->output), |
|
75 | - [ |
|
76 | - 'id' => $tagId, |
|
77 | - 'name' => $tagName, |
|
78 | - 'access' => $tagAccess, |
|
79 | - ] |
|
80 | - ); |
|
81 | - |
|
82 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
83 | - } |
|
84 | - |
|
85 | - public function testAlreadyExists(): void { |
|
86 | - $tagId = '42'; |
|
87 | - $tagName = 'wichtig'; |
|
88 | - $tagAccess = 'public'; |
|
89 | - |
|
90 | - $tag = $this->createMock(ISystemTag::class); |
|
91 | - $tag->method('getId')->willReturn($tagId); |
|
92 | - $tag->method('getName')->willReturn($tagName); |
|
93 | - $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
94 | - |
|
95 | - $this->systemTagManager->method('createTag') |
|
96 | - ->willReturnCallback(function ($tagName, $userVisible, $userAssignable) { |
|
97 | - throw new TagAlreadyExistsException( |
|
98 | - 'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists' |
|
99 | - ); |
|
100 | - }); |
|
101 | - |
|
102 | - $this->input->method('getArgument') |
|
103 | - ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { |
|
104 | - if ($arg === 'name') { |
|
105 | - return $tagName; |
|
106 | - } elseif ($arg === 'access') { |
|
107 | - return $tagAccess; |
|
108 | - } |
|
109 | - throw new \Exception(); |
|
110 | - }); |
|
111 | - |
|
112 | - $this->output->expects($this->once()) |
|
113 | - ->method('writeln') |
|
114 | - ->with( |
|
115 | - '<error>Tag ("wichtig", 1, 1) already exists</error>' |
|
116 | - ); |
|
117 | - |
|
118 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
119 | - } |
|
18 | + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | + private $systemTagManager; |
|
20 | + |
|
21 | + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + private $command; |
|
23 | + |
|
24 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + private $input; |
|
26 | + |
|
27 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + private $output; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
34 | + $this->command = $this->getMockBuilder(Add::class) |
|
35 | + ->setConstructorArgs([$this->systemTagManager]) |
|
36 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | + ->getMock(); |
|
38 | + |
|
39 | + $this->input = $this->createMock(InputInterface::class); |
|
40 | + $this->output = $this->createMock(OutputInterface::class); |
|
41 | + } |
|
42 | + |
|
43 | + public function testExecute(): void { |
|
44 | + $tagId = '42'; |
|
45 | + $tagName = 'wichtig'; |
|
46 | + $tagAccess = 'public'; |
|
47 | + |
|
48 | + $tag = $this->createMock(ISystemTag::class); |
|
49 | + $tag->method('getId')->willReturn($tagId); |
|
50 | + $tag->method('getName')->willReturn($tagName); |
|
51 | + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
52 | + |
|
53 | + $this->systemTagManager->method('createTag') |
|
54 | + ->with( |
|
55 | + $tagName, |
|
56 | + true, |
|
57 | + true |
|
58 | + )->willReturn($tag); |
|
59 | + |
|
60 | + $this->input->method('getArgument') |
|
61 | + ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { |
|
62 | + if ($arg === 'name') { |
|
63 | + return $tagName; |
|
64 | + } elseif ($arg === 'access') { |
|
65 | + return $tagAccess; |
|
66 | + } |
|
67 | + throw new \Exception(); |
|
68 | + }); |
|
69 | + |
|
70 | + $this->command->expects($this->once()) |
|
71 | + ->method('writeArrayInOutputFormat') |
|
72 | + ->with( |
|
73 | + $this->equalTo($this->input), |
|
74 | + $this->equalTo($this->output), |
|
75 | + [ |
|
76 | + 'id' => $tagId, |
|
77 | + 'name' => $tagName, |
|
78 | + 'access' => $tagAccess, |
|
79 | + ] |
|
80 | + ); |
|
81 | + |
|
82 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
83 | + } |
|
84 | + |
|
85 | + public function testAlreadyExists(): void { |
|
86 | + $tagId = '42'; |
|
87 | + $tagName = 'wichtig'; |
|
88 | + $tagAccess = 'public'; |
|
89 | + |
|
90 | + $tag = $this->createMock(ISystemTag::class); |
|
91 | + $tag->method('getId')->willReturn($tagId); |
|
92 | + $tag->method('getName')->willReturn($tagName); |
|
93 | + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
94 | + |
|
95 | + $this->systemTagManager->method('createTag') |
|
96 | + ->willReturnCallback(function ($tagName, $userVisible, $userAssignable) { |
|
97 | + throw new TagAlreadyExistsException( |
|
98 | + 'Tag ("' . $tagName . '", ' . $userVisible . ', ' . $userAssignable . ') already exists' |
|
99 | + ); |
|
100 | + }); |
|
101 | + |
|
102 | + $this->input->method('getArgument') |
|
103 | + ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { |
|
104 | + if ($arg === 'name') { |
|
105 | + return $tagName; |
|
106 | + } elseif ($arg === 'access') { |
|
107 | + return $tagAccess; |
|
108 | + } |
|
109 | + throw new \Exception(); |
|
110 | + }); |
|
111 | + |
|
112 | + $this->output->expects($this->once()) |
|
113 | + ->method('writeln') |
|
114 | + ->with( |
|
115 | + '<error>Tag ("wichtig", 1, 1) already exists</error>' |
|
116 | + ); |
|
117 | + |
|
118 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
119 | + } |
|
120 | 120 | } |
@@ -14,69 +14,69 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class DeleteTest extends TestCase { |
17 | - /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - private $systemTagManager; |
|
19 | - |
|
20 | - /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - private $command; |
|
22 | - |
|
23 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | - private $input; |
|
25 | - |
|
26 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | - private $output; |
|
28 | - |
|
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
31 | - |
|
32 | - $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
33 | - $this->command = $this->getMockBuilder(Delete::class) |
|
34 | - ->setConstructorArgs([$this->systemTagManager]) |
|
35 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | - ->getMock(); |
|
37 | - |
|
38 | - $this->input = $this->createMock(InputInterface::class); |
|
39 | - $this->output = $this->createMock(OutputInterface::class); |
|
40 | - } |
|
41 | - |
|
42 | - public function testExecute(): void { |
|
43 | - $tagId = 69; |
|
44 | - |
|
45 | - $this->input->method('getArgument') |
|
46 | - ->willReturnCallback(function ($arg) use ($tagId) { |
|
47 | - if ($arg === 'id') { |
|
48 | - return $tagId; |
|
49 | - } |
|
50 | - throw new \Exception(); |
|
51 | - }); |
|
52 | - |
|
53 | - $this->output->expects($this->once()) |
|
54 | - ->method('writeln') |
|
55 | - ->with('<info>The specified tag was deleted</info>'); |
|
56 | - |
|
57 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
58 | - } |
|
59 | - |
|
60 | - public function testNotFound(): void { |
|
61 | - $tagId = 69; |
|
62 | - |
|
63 | - $this->input->method('getArgument') |
|
64 | - ->willReturnCallback(function ($arg) use ($tagId) { |
|
65 | - if ($arg === 'id') { |
|
66 | - return $tagId; |
|
67 | - } |
|
68 | - throw new \Exception(); |
|
69 | - }); |
|
70 | - |
|
71 | - $this->systemTagManager->method('deleteTags') |
|
72 | - ->willReturnCallback(function ($tagId) { |
|
73 | - throw new TagNotFoundException(); |
|
74 | - }); |
|
75 | - |
|
76 | - $this->output->expects($this->once()) |
|
77 | - ->method('writeln') |
|
78 | - ->with('<error>Tag not found</error>'); |
|
79 | - |
|
80 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | - } |
|
17 | + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + private $systemTagManager; |
|
19 | + |
|
20 | + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + private $command; |
|
22 | + |
|
23 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | + private $input; |
|
25 | + |
|
26 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | + private $output; |
|
28 | + |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | + |
|
32 | + $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
33 | + $this->command = $this->getMockBuilder(Delete::class) |
|
34 | + ->setConstructorArgs([$this->systemTagManager]) |
|
35 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | + ->getMock(); |
|
37 | + |
|
38 | + $this->input = $this->createMock(InputInterface::class); |
|
39 | + $this->output = $this->createMock(OutputInterface::class); |
|
40 | + } |
|
41 | + |
|
42 | + public function testExecute(): void { |
|
43 | + $tagId = 69; |
|
44 | + |
|
45 | + $this->input->method('getArgument') |
|
46 | + ->willReturnCallback(function ($arg) use ($tagId) { |
|
47 | + if ($arg === 'id') { |
|
48 | + return $tagId; |
|
49 | + } |
|
50 | + throw new \Exception(); |
|
51 | + }); |
|
52 | + |
|
53 | + $this->output->expects($this->once()) |
|
54 | + ->method('writeln') |
|
55 | + ->with('<info>The specified tag was deleted</info>'); |
|
56 | + |
|
57 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
58 | + } |
|
59 | + |
|
60 | + public function testNotFound(): void { |
|
61 | + $tagId = 69; |
|
62 | + |
|
63 | + $this->input->method('getArgument') |
|
64 | + ->willReturnCallback(function ($arg) use ($tagId) { |
|
65 | + if ($arg === 'id') { |
|
66 | + return $tagId; |
|
67 | + } |
|
68 | + throw new \Exception(); |
|
69 | + }); |
|
70 | + |
|
71 | + $this->systemTagManager->method('deleteTags') |
|
72 | + ->willReturnCallback(function ($tagId) { |
|
73 | + throw new TagNotFoundException(); |
|
74 | + }); |
|
75 | + |
|
76 | + $this->output->expects($this->once()) |
|
77 | + ->method('writeln') |
|
78 | + ->with('<error>Tag not found</error>'); |
|
79 | + |
|
80 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
81 | + } |
|
82 | 82 | } |
@@ -14,82 +14,82 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class ListCommandTest extends TestCase { |
17 | - /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - private $systemTagManager; |
|
17 | + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + private $systemTagManager; |
|
19 | 19 | |
20 | - /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - private $command; |
|
20 | + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + private $command; |
|
22 | 22 | |
23 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | - private $input; |
|
23 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | + private $input; |
|
25 | 25 | |
26 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | - private $output; |
|
26 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | + private $output; |
|
28 | 28 | |
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | 31 | |
32 | - $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
33 | - $this->command = $this->getMockBuilder(ListCommand::class) |
|
34 | - ->setConstructorArgs([$this->systemTagManager]) |
|
35 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | - ->getMock(); |
|
32 | + $this->systemTagManager = $this->createMock(ISystemTagManager::class); |
|
33 | + $this->command = $this->getMockBuilder(ListCommand::class) |
|
34 | + ->setConstructorArgs([$this->systemTagManager]) |
|
35 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | + ->getMock(); |
|
37 | 37 | |
38 | - $this->input = $this->createMock(InputInterface::class); |
|
39 | - $this->output = $this->createMock(OutputInterface::class); |
|
40 | - } |
|
38 | + $this->input = $this->createMock(InputInterface::class); |
|
39 | + $this->output = $this->createMock(OutputInterface::class); |
|
40 | + } |
|
41 | 41 | |
42 | - public function testExecute(): void { |
|
43 | - $tag1 = $this->createMock(ISystemTag::class); |
|
44 | - $tag1->method('getId')->willReturn('1'); |
|
45 | - $tag1->method('getName')->willReturn('public_tag'); |
|
46 | - $tag1->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
47 | - $tag2 = $this->createMock(ISystemTag::class); |
|
48 | - $tag2->method('getId')->willReturn('2'); |
|
49 | - $tag2->method('getName')->willReturn('restricted_tag'); |
|
50 | - $tag2->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_RESTRICTED); |
|
51 | - $tag3 = $this->createMock(ISystemTag::class); |
|
52 | - $tag3->method('getId')->willReturn('3'); |
|
53 | - $tag3->method('getName')->willReturn('invisible_tag'); |
|
54 | - $tag3->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
42 | + public function testExecute(): void { |
|
43 | + $tag1 = $this->createMock(ISystemTag::class); |
|
44 | + $tag1->method('getId')->willReturn('1'); |
|
45 | + $tag1->method('getName')->willReturn('public_tag'); |
|
46 | + $tag1->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); |
|
47 | + $tag2 = $this->createMock(ISystemTag::class); |
|
48 | + $tag2->method('getId')->willReturn('2'); |
|
49 | + $tag2->method('getName')->willReturn('restricted_tag'); |
|
50 | + $tag2->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_RESTRICTED); |
|
51 | + $tag3 = $this->createMock(ISystemTag::class); |
|
52 | + $tag3->method('getId')->willReturn('3'); |
|
53 | + $tag3->method('getName')->willReturn('invisible_tag'); |
|
54 | + $tag3->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); |
|
55 | 55 | |
56 | - $this->systemTagManager->method('getAllTags') |
|
57 | - ->with( |
|
58 | - null, |
|
59 | - null |
|
60 | - )->willReturn([$tag1, $tag2, $tag3]); |
|
56 | + $this->systemTagManager->method('getAllTags') |
|
57 | + ->with( |
|
58 | + null, |
|
59 | + null |
|
60 | + )->willReturn([$tag1, $tag2, $tag3]); |
|
61 | 61 | |
62 | - $this->input->method('getOption') |
|
63 | - ->willReturnCallback(function ($arg) { |
|
64 | - if ($arg === 'visibilityFilter') { |
|
65 | - return null; |
|
66 | - } elseif ($arg === 'nameSearchPattern') { |
|
67 | - return null; |
|
68 | - } |
|
69 | - throw new \Exception(); |
|
70 | - }); |
|
62 | + $this->input->method('getOption') |
|
63 | + ->willReturnCallback(function ($arg) { |
|
64 | + if ($arg === 'visibilityFilter') { |
|
65 | + return null; |
|
66 | + } elseif ($arg === 'nameSearchPattern') { |
|
67 | + return null; |
|
68 | + } |
|
69 | + throw new \Exception(); |
|
70 | + }); |
|
71 | 71 | |
72 | - $this->command->expects($this->once()) |
|
73 | - ->method('writeArrayInOutputFormat') |
|
74 | - ->with( |
|
75 | - $this->equalTo($this->input), |
|
76 | - $this->equalTo($this->output), |
|
77 | - [ |
|
78 | - '1' => [ |
|
79 | - 'name' => 'public_tag', |
|
80 | - 'access' => 'public', |
|
81 | - ], |
|
82 | - '2' => [ |
|
83 | - 'name' => 'restricted_tag', |
|
84 | - 'access' => 'restricted', |
|
85 | - ], |
|
86 | - '3' => [ |
|
87 | - 'name' => 'invisible_tag', |
|
88 | - 'access' => 'invisible', |
|
89 | - ] |
|
90 | - ] |
|
91 | - ); |
|
72 | + $this->command->expects($this->once()) |
|
73 | + ->method('writeArrayInOutputFormat') |
|
74 | + ->with( |
|
75 | + $this->equalTo($this->input), |
|
76 | + $this->equalTo($this->output), |
|
77 | + [ |
|
78 | + '1' => [ |
|
79 | + 'name' => 'public_tag', |
|
80 | + 'access' => 'public', |
|
81 | + ], |
|
82 | + '2' => [ |
|
83 | + 'name' => 'restricted_tag', |
|
84 | + 'access' => 'restricted', |
|
85 | + ], |
|
86 | + '3' => [ |
|
87 | + 'name' => 'invisible_tag', |
|
88 | + 'access' => 'invisible', |
|
89 | + ] |
|
90 | + ] |
|
91 | + ); |
|
92 | 92 | |
93 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
94 | - } |
|
93 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
94 | + } |
|
95 | 95 | } |
@@ -17,157 +17,157 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class UpdateDBTest extends TestCase { |
20 | - /** @var IMimeTypeDetector */ |
|
21 | - protected $detector; |
|
22 | - /** @var IMimeTypeLoader */ |
|
23 | - protected $loader; |
|
24 | - |
|
25 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
26 | - protected $consoleInput; |
|
27 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - protected $consoleOutput; |
|
29 | - |
|
30 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
31 | - protected $command; |
|
32 | - |
|
33 | - protected function setUp(): void { |
|
34 | - parent::setUp(); |
|
35 | - |
|
36 | - $this->detector = $this->createMock(Detection::class); |
|
37 | - $this->loader = $this->createMock(Loader::class); |
|
38 | - $this->consoleInput = $this->createMock(InputInterface::class); |
|
39 | - $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
40 | - |
|
41 | - $this->command = new UpdateDB($this->detector, $this->loader); |
|
42 | - } |
|
43 | - |
|
44 | - public function testNoop(): void { |
|
45 | - $this->consoleInput->method('getOption') |
|
46 | - ->with('repair-filecache') |
|
47 | - ->willReturn(false); |
|
48 | - |
|
49 | - $this->detector->expects($this->once()) |
|
50 | - ->method('getAllMappings') |
|
51 | - ->willReturn([ |
|
52 | - 'ext' => ['testing/existingmimetype'] |
|
53 | - ]); |
|
54 | - $this->loader->expects($this->once()) |
|
55 | - ->method('exists') |
|
56 | - ->with('testing/existingmimetype') |
|
57 | - ->willReturn(true); |
|
58 | - |
|
59 | - $this->loader->expects($this->never()) |
|
60 | - ->method('updateFilecache'); |
|
61 | - |
|
62 | - $calls = [ |
|
63 | - 'Added 0 new mimetypes', |
|
64 | - 'Updated 0 filecache rows', |
|
65 | - ]; |
|
66 | - $this->consoleOutput->expects($this->exactly(2)) |
|
67 | - ->method('writeln') |
|
68 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
69 | - $expected = array_shift($calls); |
|
70 | - $this->assertStringContainsString($expected, $message); |
|
71 | - }); |
|
72 | - |
|
73 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
74 | - } |
|
75 | - |
|
76 | - public function testAddMimetype(): void { |
|
77 | - $this->consoleInput->method('getOption') |
|
78 | - ->with('repair-filecache') |
|
79 | - ->willReturn(false); |
|
80 | - |
|
81 | - $this->detector->expects($this->once()) |
|
82 | - ->method('getAllMappings') |
|
83 | - ->willReturn([ |
|
84 | - 'ext' => ['testing/existingmimetype'], |
|
85 | - 'new' => ['testing/newmimetype'] |
|
86 | - ]); |
|
87 | - $this->loader->expects($this->exactly(2)) |
|
88 | - ->method('exists') |
|
89 | - ->willReturnMap([ |
|
90 | - ['testing/existingmimetype', true], |
|
91 | - ['testing/newmimetype', false], |
|
92 | - ]); |
|
93 | - $this->loader->expects($this->exactly(2)) |
|
94 | - ->method('getId') |
|
95 | - ->willReturnMap([ |
|
96 | - ['testing/existingmimetype', 1], |
|
97 | - ['testing/newmimetype', 2], |
|
98 | - ]); |
|
99 | - |
|
100 | - $this->loader->expects($this->once()) |
|
101 | - ->method('updateFilecache') |
|
102 | - ->with('new', 2) |
|
103 | - ->willReturn(3); |
|
104 | - |
|
105 | - $calls = [ |
|
106 | - 'Added mimetype "testing/newmimetype" to database', |
|
107 | - 'Updated 3 filecache rows for mimetype "testing/newmimetype"', |
|
108 | - 'Added 1 new mimetypes', |
|
109 | - 'Updated 3 filecache rows', |
|
110 | - ]; |
|
111 | - $this->consoleOutput->expects($this->exactly(4)) |
|
112 | - ->method('writeln') |
|
113 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
114 | - $expected = array_shift($calls); |
|
115 | - $this->assertStringContainsString($expected, $message); |
|
116 | - }); |
|
117 | - |
|
118 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
119 | - } |
|
120 | - |
|
121 | - public function testSkipComments(): void { |
|
122 | - $this->detector->expects($this->once()) |
|
123 | - ->method('getAllMappings') |
|
124 | - ->willReturn([ |
|
125 | - '_comment' => 'some comment in the JSON' |
|
126 | - ]); |
|
127 | - $this->loader->expects($this->never()) |
|
128 | - ->method('exists'); |
|
129 | - |
|
130 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
131 | - } |
|
132 | - |
|
133 | - public function testRepairFilecache(): void { |
|
134 | - $this->consoleInput->method('getOption') |
|
135 | - ->with('repair-filecache') |
|
136 | - ->willReturn(true); |
|
137 | - |
|
138 | - $this->detector->expects($this->once()) |
|
139 | - ->method('getAllMappings') |
|
140 | - ->willReturn([ |
|
141 | - 'ext' => ['testing/existingmimetype'], |
|
142 | - ]); |
|
143 | - $this->loader->expects($this->exactly(1)) |
|
144 | - ->method('exists') |
|
145 | - ->willReturnMap([ |
|
146 | - ['testing/existingmimetype', true], |
|
147 | - ]); |
|
148 | - $this->loader->expects($this->exactly(1)) |
|
149 | - ->method('getId') |
|
150 | - ->willReturnMap([ |
|
151 | - ['testing/existingmimetype', 1], |
|
152 | - ]); |
|
153 | - |
|
154 | - $this->loader->expects($this->once()) |
|
155 | - ->method('updateFilecache') |
|
156 | - ->with('ext', 1) |
|
157 | - ->willReturn(3); |
|
158 | - |
|
159 | - $calls = [ |
|
160 | - 'Updated 3 filecache rows for mimetype "testing/existingmimetype"', |
|
161 | - 'Added 0 new mimetypes', |
|
162 | - 'Updated 3 filecache rows', |
|
163 | - ]; |
|
164 | - $this->consoleOutput->expects($this->exactly(3)) |
|
165 | - ->method('writeln') |
|
166 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
167 | - $expected = array_shift($calls); |
|
168 | - $this->assertStringContainsString($expected, $message); |
|
169 | - }); |
|
170 | - |
|
171 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
172 | - } |
|
20 | + /** @var IMimeTypeDetector */ |
|
21 | + protected $detector; |
|
22 | + /** @var IMimeTypeLoader */ |
|
23 | + protected $loader; |
|
24 | + |
|
25 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
26 | + protected $consoleInput; |
|
27 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + protected $consoleOutput; |
|
29 | + |
|
30 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
31 | + protected $command; |
|
32 | + |
|
33 | + protected function setUp(): void { |
|
34 | + parent::setUp(); |
|
35 | + |
|
36 | + $this->detector = $this->createMock(Detection::class); |
|
37 | + $this->loader = $this->createMock(Loader::class); |
|
38 | + $this->consoleInput = $this->createMock(InputInterface::class); |
|
39 | + $this->consoleOutput = $this->createMock(OutputInterface::class); |
|
40 | + |
|
41 | + $this->command = new UpdateDB($this->detector, $this->loader); |
|
42 | + } |
|
43 | + |
|
44 | + public function testNoop(): void { |
|
45 | + $this->consoleInput->method('getOption') |
|
46 | + ->with('repair-filecache') |
|
47 | + ->willReturn(false); |
|
48 | + |
|
49 | + $this->detector->expects($this->once()) |
|
50 | + ->method('getAllMappings') |
|
51 | + ->willReturn([ |
|
52 | + 'ext' => ['testing/existingmimetype'] |
|
53 | + ]); |
|
54 | + $this->loader->expects($this->once()) |
|
55 | + ->method('exists') |
|
56 | + ->with('testing/existingmimetype') |
|
57 | + ->willReturn(true); |
|
58 | + |
|
59 | + $this->loader->expects($this->never()) |
|
60 | + ->method('updateFilecache'); |
|
61 | + |
|
62 | + $calls = [ |
|
63 | + 'Added 0 new mimetypes', |
|
64 | + 'Updated 0 filecache rows', |
|
65 | + ]; |
|
66 | + $this->consoleOutput->expects($this->exactly(2)) |
|
67 | + ->method('writeln') |
|
68 | + ->willReturnCallback(function ($message) use (&$calls) { |
|
69 | + $expected = array_shift($calls); |
|
70 | + $this->assertStringContainsString($expected, $message); |
|
71 | + }); |
|
72 | + |
|
73 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
74 | + } |
|
75 | + |
|
76 | + public function testAddMimetype(): void { |
|
77 | + $this->consoleInput->method('getOption') |
|
78 | + ->with('repair-filecache') |
|
79 | + ->willReturn(false); |
|
80 | + |
|
81 | + $this->detector->expects($this->once()) |
|
82 | + ->method('getAllMappings') |
|
83 | + ->willReturn([ |
|
84 | + 'ext' => ['testing/existingmimetype'], |
|
85 | + 'new' => ['testing/newmimetype'] |
|
86 | + ]); |
|
87 | + $this->loader->expects($this->exactly(2)) |
|
88 | + ->method('exists') |
|
89 | + ->willReturnMap([ |
|
90 | + ['testing/existingmimetype', true], |
|
91 | + ['testing/newmimetype', false], |
|
92 | + ]); |
|
93 | + $this->loader->expects($this->exactly(2)) |
|
94 | + ->method('getId') |
|
95 | + ->willReturnMap([ |
|
96 | + ['testing/existingmimetype', 1], |
|
97 | + ['testing/newmimetype', 2], |
|
98 | + ]); |
|
99 | + |
|
100 | + $this->loader->expects($this->once()) |
|
101 | + ->method('updateFilecache') |
|
102 | + ->with('new', 2) |
|
103 | + ->willReturn(3); |
|
104 | + |
|
105 | + $calls = [ |
|
106 | + 'Added mimetype "testing/newmimetype" to database', |
|
107 | + 'Updated 3 filecache rows for mimetype "testing/newmimetype"', |
|
108 | + 'Added 1 new mimetypes', |
|
109 | + 'Updated 3 filecache rows', |
|
110 | + ]; |
|
111 | + $this->consoleOutput->expects($this->exactly(4)) |
|
112 | + ->method('writeln') |
|
113 | + ->willReturnCallback(function ($message) use (&$calls) { |
|
114 | + $expected = array_shift($calls); |
|
115 | + $this->assertStringContainsString($expected, $message); |
|
116 | + }); |
|
117 | + |
|
118 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
119 | + } |
|
120 | + |
|
121 | + public function testSkipComments(): void { |
|
122 | + $this->detector->expects($this->once()) |
|
123 | + ->method('getAllMappings') |
|
124 | + ->willReturn([ |
|
125 | + '_comment' => 'some comment in the JSON' |
|
126 | + ]); |
|
127 | + $this->loader->expects($this->never()) |
|
128 | + ->method('exists'); |
|
129 | + |
|
130 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
131 | + } |
|
132 | + |
|
133 | + public function testRepairFilecache(): void { |
|
134 | + $this->consoleInput->method('getOption') |
|
135 | + ->with('repair-filecache') |
|
136 | + ->willReturn(true); |
|
137 | + |
|
138 | + $this->detector->expects($this->once()) |
|
139 | + ->method('getAllMappings') |
|
140 | + ->willReturn([ |
|
141 | + 'ext' => ['testing/existingmimetype'], |
|
142 | + ]); |
|
143 | + $this->loader->expects($this->exactly(1)) |
|
144 | + ->method('exists') |
|
145 | + ->willReturnMap([ |
|
146 | + ['testing/existingmimetype', true], |
|
147 | + ]); |
|
148 | + $this->loader->expects($this->exactly(1)) |
|
149 | + ->method('getId') |
|
150 | + ->willReturnMap([ |
|
151 | + ['testing/existingmimetype', 1], |
|
152 | + ]); |
|
153 | + |
|
154 | + $this->loader->expects($this->once()) |
|
155 | + ->method('updateFilecache') |
|
156 | + ->with('ext', 1) |
|
157 | + ->willReturn(3); |
|
158 | + |
|
159 | + $calls = [ |
|
160 | + 'Updated 3 filecache rows for mimetype "testing/existingmimetype"', |
|
161 | + 'Added 0 new mimetypes', |
|
162 | + 'Updated 3 filecache rows', |
|
163 | + ]; |
|
164 | + $this->consoleOutput->expects($this->exactly(3)) |
|
165 | + ->method('writeln') |
|
166 | + ->willReturnCallback(function ($message) use (&$calls) { |
|
167 | + $expected = array_shift($calls); |
|
168 | + $this->assertStringContainsString($expected, $message); |
|
169 | + }); |
|
170 | + |
|
171 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
172 | + } |
|
173 | 173 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ]; |
66 | 66 | $this->consoleOutput->expects($this->exactly(2)) |
67 | 67 | ->method('writeln') |
68 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
68 | + ->willReturnCallback(function($message) use (&$calls) { |
|
69 | 69 | $expected = array_shift($calls); |
70 | 70 | $this->assertStringContainsString($expected, $message); |
71 | 71 | }); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ]; |
111 | 111 | $this->consoleOutput->expects($this->exactly(4)) |
112 | 112 | ->method('writeln') |
113 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
113 | + ->willReturnCallback(function($message) use (&$calls) { |
|
114 | 114 | $expected = array_shift($calls); |
115 | 115 | $this->assertStringContainsString($expected, $message); |
116 | 116 | }); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | ]; |
164 | 164 | $this->consoleOutput->expects($this->exactly(3)) |
165 | 165 | ->method('writeln') |
166 | - ->willReturnCallback(function ($message) use (&$calls) { |
|
166 | + ->willReturnCallback(function($message) use (&$calls) { |
|
167 | 167 | $expected = array_shift($calls); |
168 | 168 | $this->assertStringContainsString($expected, $message); |
169 | 169 | }); |
@@ -18,133 +18,133 @@ |
||
18 | 18 | * @package Tests\Core\Command\Maintenance |
19 | 19 | */ |
20 | 20 | class ModeTest extends TestCase { |
21 | - /** |
|
22 | - * A config mock passed to the command. |
|
23 | - * |
|
24 | - * @var IConfig|MockObject |
|
25 | - */ |
|
26 | - private $config; |
|
21 | + /** |
|
22 | + * A config mock passed to the command. |
|
23 | + * |
|
24 | + * @var IConfig|MockObject |
|
25 | + */ |
|
26 | + private $config; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Holds a Mode command instance with a config mock. |
|
30 | - * |
|
31 | - * @var Mode |
|
32 | - */ |
|
33 | - private $mode; |
|
28 | + /** |
|
29 | + * Holds a Mode command instance with a config mock. |
|
30 | + * |
|
31 | + * @var Mode |
|
32 | + */ |
|
33 | + private $mode; |
|
34 | 34 | |
35 | - /** |
|
36 | - * An input mock for tests. |
|
37 | - * |
|
38 | - * @var InputInterface|MockObject |
|
39 | - */ |
|
40 | - private $input; |
|
35 | + /** |
|
36 | + * An input mock for tests. |
|
37 | + * |
|
38 | + * @var InputInterface|MockObject |
|
39 | + */ |
|
40 | + private $input; |
|
41 | 41 | |
42 | - /** |
|
43 | - * An output mock for tests. |
|
44 | - * |
|
45 | - * @var OutputInterface|MockObject |
|
46 | - */ |
|
47 | - private $output; |
|
42 | + /** |
|
43 | + * An output mock for tests. |
|
44 | + * |
|
45 | + * @var OutputInterface|MockObject |
|
46 | + */ |
|
47 | + private $output; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Setups the test environment. |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - protected function setUp(): void { |
|
55 | - parent::setUp(); |
|
56 | - $this->config = $this->getMockBuilder(IConfig::class) |
|
57 | - ->getMock(); |
|
58 | - $this->mode = new Mode($this->config); |
|
59 | - $this->input = $this->getMockBuilder(InputInterface::class) |
|
60 | - ->getMock(); |
|
61 | - $this->output = $this->getMockBuilder(OutputInterface::class) |
|
62 | - ->getMock(); |
|
63 | - } |
|
49 | + /** |
|
50 | + * Setups the test environment. |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + protected function setUp(): void { |
|
55 | + parent::setUp(); |
|
56 | + $this->config = $this->getMockBuilder(IConfig::class) |
|
57 | + ->getMock(); |
|
58 | + $this->mode = new Mode($this->config); |
|
59 | + $this->input = $this->getMockBuilder(InputInterface::class) |
|
60 | + ->getMock(); |
|
61 | + $this->output = $this->getMockBuilder(OutputInterface::class) |
|
62 | + ->getMock(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Provides test data for the execute test. |
|
67 | - * |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public static function getExecuteTestData(): array { |
|
71 | - return [ |
|
72 | - 'off -> on' => [ |
|
73 | - 'on', // command option |
|
74 | - false, // current maintenance mode state |
|
75 | - true, // expected maintenance mode state, null for no change |
|
76 | - 'Maintenance mode enabled', // expected output |
|
77 | - ], |
|
78 | - 'on -> off' => [ |
|
79 | - 'off', |
|
80 | - true, |
|
81 | - false, |
|
82 | - 'Maintenance mode disabled', |
|
83 | - ], |
|
84 | - 'on -> on' => [ |
|
85 | - 'on', |
|
86 | - true, |
|
87 | - null, |
|
88 | - 'Maintenance mode already enabled', |
|
89 | - ], |
|
90 | - 'off -> off' => [ |
|
91 | - 'off', |
|
92 | - false, |
|
93 | - null, |
|
94 | - 'Maintenance mode already disabled', |
|
95 | - ], |
|
96 | - 'no option, maintenance enabled' => [ |
|
97 | - '', |
|
98 | - true, |
|
99 | - null, |
|
100 | - 'Maintenance mode is currently enabled', |
|
101 | - ], |
|
102 | - 'no option, maintenance disabled' => [ |
|
103 | - '', |
|
104 | - false, |
|
105 | - null, |
|
106 | - 'Maintenance mode is currently disabled', |
|
107 | - ], |
|
108 | - ]; |
|
109 | - } |
|
65 | + /** |
|
66 | + * Provides test data for the execute test. |
|
67 | + * |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public static function getExecuteTestData(): array { |
|
71 | + return [ |
|
72 | + 'off -> on' => [ |
|
73 | + 'on', // command option |
|
74 | + false, // current maintenance mode state |
|
75 | + true, // expected maintenance mode state, null for no change |
|
76 | + 'Maintenance mode enabled', // expected output |
|
77 | + ], |
|
78 | + 'on -> off' => [ |
|
79 | + 'off', |
|
80 | + true, |
|
81 | + false, |
|
82 | + 'Maintenance mode disabled', |
|
83 | + ], |
|
84 | + 'on -> on' => [ |
|
85 | + 'on', |
|
86 | + true, |
|
87 | + null, |
|
88 | + 'Maintenance mode already enabled', |
|
89 | + ], |
|
90 | + 'off -> off' => [ |
|
91 | + 'off', |
|
92 | + false, |
|
93 | + null, |
|
94 | + 'Maintenance mode already disabled', |
|
95 | + ], |
|
96 | + 'no option, maintenance enabled' => [ |
|
97 | + '', |
|
98 | + true, |
|
99 | + null, |
|
100 | + 'Maintenance mode is currently enabled', |
|
101 | + ], |
|
102 | + 'no option, maintenance disabled' => [ |
|
103 | + '', |
|
104 | + false, |
|
105 | + null, |
|
106 | + 'Maintenance mode is currently disabled', |
|
107 | + ], |
|
108 | + ]; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Asserts that execute works as expected. |
|
113 | - * |
|
114 | - * @dataProvider getExecuteTestData |
|
115 | - * @param string $option The command option. |
|
116 | - * @param bool $currentMaintenanceState The current maintenance state. |
|
117 | - * @param null|bool $expectedMaintenanceState |
|
118 | - * The expected maintenance state. Null for no change. |
|
119 | - * @param string $expectedOutput The expected command output. |
|
120 | - * @throws \Exception |
|
121 | - */ |
|
122 | - public function testExecute( |
|
123 | - string $option, |
|
124 | - bool $currentMaintenanceState, |
|
125 | - $expectedMaintenanceState, |
|
126 | - string $expectedOutput, |
|
127 | - ): void { |
|
128 | - $this->config->expects($this->any()) |
|
129 | - ->method('getSystemValueBool') |
|
130 | - ->willReturn($currentMaintenanceState); |
|
111 | + /** |
|
112 | + * Asserts that execute works as expected. |
|
113 | + * |
|
114 | + * @dataProvider getExecuteTestData |
|
115 | + * @param string $option The command option. |
|
116 | + * @param bool $currentMaintenanceState The current maintenance state. |
|
117 | + * @param null|bool $expectedMaintenanceState |
|
118 | + * The expected maintenance state. Null for no change. |
|
119 | + * @param string $expectedOutput The expected command output. |
|
120 | + * @throws \Exception |
|
121 | + */ |
|
122 | + public function testExecute( |
|
123 | + string $option, |
|
124 | + bool $currentMaintenanceState, |
|
125 | + $expectedMaintenanceState, |
|
126 | + string $expectedOutput, |
|
127 | + ): void { |
|
128 | + $this->config->expects($this->any()) |
|
129 | + ->method('getSystemValueBool') |
|
130 | + ->willReturn($currentMaintenanceState); |
|
131 | 131 | |
132 | - if ($expectedMaintenanceState !== null) { |
|
133 | - $this->config->expects($this->once()) |
|
134 | - ->method('setSystemValue') |
|
135 | - ->with('maintenance', $expectedMaintenanceState); |
|
136 | - } |
|
132 | + if ($expectedMaintenanceState !== null) { |
|
133 | + $this->config->expects($this->once()) |
|
134 | + ->method('setSystemValue') |
|
135 | + ->with('maintenance', $expectedMaintenanceState); |
|
136 | + } |
|
137 | 137 | |
138 | - $this->input->expects($this->any()) |
|
139 | - ->method('getOption') |
|
140 | - ->willReturnCallback(function ($callOption) use ($option) { |
|
141 | - return $callOption === $option; |
|
142 | - }); |
|
138 | + $this->input->expects($this->any()) |
|
139 | + ->method('getOption') |
|
140 | + ->willReturnCallback(function ($callOption) use ($option) { |
|
141 | + return $callOption === $option; |
|
142 | + }); |
|
143 | 143 | |
144 | - $this->output->expects($this->once()) |
|
145 | - ->method('writeln') |
|
146 | - ->with($expectedOutput); |
|
144 | + $this->output->expects($this->once()) |
|
145 | + ->method('writeln') |
|
146 | + ->with($expectedOutput); |
|
147 | 147 | |
148 | - $this->mode->run($this->input, $this->output); |
|
149 | - } |
|
148 | + $this->mode->run($this->input, $this->output); |
|
149 | + } |
|
150 | 150 | } |
@@ -35,664 +35,664 @@ |
||
35 | 35 | use Test\TestCase; |
36 | 36 | |
37 | 37 | class LoginControllerTest extends TestCase { |
38 | - /** @var LoginController */ |
|
39 | - private $loginController; |
|
40 | - |
|
41 | - /** @var IRequest|MockObject */ |
|
42 | - private $request; |
|
43 | - |
|
44 | - /** @var IUserManager|MockObject */ |
|
45 | - private $userManager; |
|
46 | - |
|
47 | - /** @var IConfig|MockObject */ |
|
48 | - private $config; |
|
49 | - |
|
50 | - /** @var ISession|MockObject */ |
|
51 | - private $session; |
|
52 | - |
|
53 | - /** @var Session|MockObject */ |
|
54 | - private $userSession; |
|
55 | - |
|
56 | - /** @var IURLGenerator|MockObject */ |
|
57 | - private $urlGenerator; |
|
58 | - |
|
59 | - /** @var Manager|MockObject */ |
|
60 | - private $twoFactorManager; |
|
61 | - |
|
62 | - /** @var Defaults|MockObject */ |
|
63 | - private $defaults; |
|
64 | - |
|
65 | - /** @var IThrottler|MockObject */ |
|
66 | - private $throttler; |
|
67 | - |
|
68 | - /** @var IInitialState|MockObject */ |
|
69 | - private $initialState; |
|
70 | - |
|
71 | - /** @var \OC\Authentication\WebAuthn\Manager|MockObject */ |
|
72 | - private $webAuthnManager; |
|
73 | - |
|
74 | - /** @var IManager|MockObject */ |
|
75 | - private $notificationManager; |
|
76 | - |
|
77 | - /** @var IL10N|MockObject */ |
|
78 | - private $l; |
|
79 | - |
|
80 | - /** @var IAppManager|MockObject */ |
|
81 | - private $appManager; |
|
82 | - |
|
83 | - protected function setUp(): void { |
|
84 | - parent::setUp(); |
|
85 | - $this->request = $this->createMock(IRequest::class); |
|
86 | - $this->userManager = $this->createMock(\OC\User\Manager::class); |
|
87 | - $this->config = $this->createMock(IConfig::class); |
|
88 | - $this->session = $this->createMock(ISession::class); |
|
89 | - $this->userSession = $this->createMock(Session::class); |
|
90 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
91 | - $this->twoFactorManager = $this->createMock(Manager::class); |
|
92 | - $this->defaults = $this->createMock(Defaults::class); |
|
93 | - $this->throttler = $this->createMock(IThrottler::class); |
|
94 | - $this->initialState = $this->createMock(IInitialState::class); |
|
95 | - $this->webAuthnManager = $this->createMock(\OC\Authentication\WebAuthn\Manager::class); |
|
96 | - $this->notificationManager = $this->createMock(IManager::class); |
|
97 | - $this->l = $this->createMock(IL10N::class); |
|
98 | - $this->appManager = $this->createMock(IAppManager::class); |
|
99 | - |
|
100 | - $this->l->expects($this->any()) |
|
101 | - ->method('t') |
|
102 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
103 | - return vsprintf($text, $parameters); |
|
104 | - }); |
|
105 | - |
|
106 | - |
|
107 | - $this->request->method('getRemoteAddress') |
|
108 | - ->willReturn('1.2.3.4'); |
|
109 | - $this->request->method('getHeader') |
|
110 | - ->with('Origin') |
|
111 | - ->willReturn('domain.example.com'); |
|
112 | - $this->throttler->method('getDelay') |
|
113 | - ->with( |
|
114 | - $this->equalTo('1.2.3.4'), |
|
115 | - $this->equalTo('') |
|
116 | - )->willReturn(1000); |
|
117 | - |
|
118 | - $this->loginController = new LoginController( |
|
119 | - 'core', |
|
120 | - $this->request, |
|
121 | - $this->userManager, |
|
122 | - $this->config, |
|
123 | - $this->session, |
|
124 | - $this->userSession, |
|
125 | - $this->urlGenerator, |
|
126 | - $this->defaults, |
|
127 | - $this->throttler, |
|
128 | - $this->initialState, |
|
129 | - $this->webAuthnManager, |
|
130 | - $this->notificationManager, |
|
131 | - $this->l, |
|
132 | - $this->appManager, |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - public function testLogoutWithoutToken(): void { |
|
137 | - $this->request |
|
138 | - ->expects($this->once()) |
|
139 | - ->method('getCookie') |
|
140 | - ->with('nc_token') |
|
141 | - ->willReturn(null); |
|
142 | - $this->request |
|
143 | - ->method('getServerProtocol') |
|
144 | - ->willReturn('https'); |
|
145 | - $this->request |
|
146 | - ->expects($this->once()) |
|
147 | - ->method('isUserAgent') |
|
148 | - ->willReturn(false); |
|
149 | - $this->config |
|
150 | - ->expects($this->never()) |
|
151 | - ->method('deleteUserValue'); |
|
152 | - $this->urlGenerator |
|
153 | - ->expects($this->once()) |
|
154 | - ->method('linkToRouteAbsolute') |
|
155 | - ->with('core.login.showLoginForm') |
|
156 | - ->willReturn('/login'); |
|
157 | - |
|
158 | - $expected = new RedirectResponse('/login'); |
|
159 | - $expected->addHeader('Clear-Site-Data', '"cache", "storage"'); |
|
160 | - $this->assertEquals($expected, $this->loginController->logout()); |
|
161 | - } |
|
162 | - |
|
163 | - public function testLogoutNoClearSiteData(): void { |
|
164 | - $this->request |
|
165 | - ->expects($this->once()) |
|
166 | - ->method('getCookie') |
|
167 | - ->with('nc_token') |
|
168 | - ->willReturn(null); |
|
169 | - $this->request |
|
170 | - ->method('getServerProtocol') |
|
171 | - ->willReturn('https'); |
|
172 | - $this->request |
|
173 | - ->expects($this->once()) |
|
174 | - ->method('isUserAgent') |
|
175 | - ->willReturn(true); |
|
176 | - $this->urlGenerator |
|
177 | - ->expects($this->once()) |
|
178 | - ->method('linkToRouteAbsolute') |
|
179 | - ->with('core.login.showLoginForm') |
|
180 | - ->willReturn('/login'); |
|
181 | - |
|
182 | - $expected = new RedirectResponse('/login'); |
|
183 | - $this->assertEquals($expected, $this->loginController->logout()); |
|
184 | - } |
|
185 | - |
|
186 | - public function testLogoutWithToken(): void { |
|
187 | - $this->request |
|
188 | - ->expects($this->once()) |
|
189 | - ->method('getCookie') |
|
190 | - ->with('nc_token') |
|
191 | - ->willReturn('MyLoginToken'); |
|
192 | - $this->request |
|
193 | - ->method('getServerProtocol') |
|
194 | - ->willReturn('https'); |
|
195 | - $this->request |
|
196 | - ->expects($this->once()) |
|
197 | - ->method('isUserAgent') |
|
198 | - ->willReturn(false); |
|
199 | - $user = $this->createMock(IUser::class); |
|
200 | - $user |
|
201 | - ->expects($this->once()) |
|
202 | - ->method('getUID') |
|
203 | - ->willReturn('JohnDoe'); |
|
204 | - $this->userSession |
|
205 | - ->expects($this->once()) |
|
206 | - ->method('getUser') |
|
207 | - ->willReturn($user); |
|
208 | - $this->config |
|
209 | - ->expects($this->once()) |
|
210 | - ->method('deleteUserValue') |
|
211 | - ->with('JohnDoe', 'login_token', 'MyLoginToken'); |
|
212 | - $this->urlGenerator |
|
213 | - ->expects($this->once()) |
|
214 | - ->method('linkToRouteAbsolute') |
|
215 | - ->with('core.login.showLoginForm') |
|
216 | - ->willReturn('/login'); |
|
217 | - |
|
218 | - $expected = new RedirectResponse('/login'); |
|
219 | - $expected->addHeader('Clear-Site-Data', '"cache", "storage"'); |
|
220 | - $this->assertEquals($expected, $this->loginController->logout()); |
|
221 | - } |
|
222 | - |
|
223 | - public function testShowLoginFormForLoggedInUsers(): void { |
|
224 | - $this->userSession |
|
225 | - ->expects($this->once()) |
|
226 | - ->method('isLoggedIn') |
|
227 | - ->willReturn(true); |
|
228 | - $this->urlGenerator |
|
229 | - ->expects($this->once()) |
|
230 | - ->method('linkToDefaultPageUrl') |
|
231 | - ->willReturn('/default/foo'); |
|
232 | - |
|
233 | - $expectedResponse = new RedirectResponse('/default/foo'); |
|
234 | - $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '')); |
|
235 | - } |
|
236 | - |
|
237 | - public function testShowLoginFormWithErrorsInSession(): void { |
|
238 | - $this->userSession |
|
239 | - ->expects($this->once()) |
|
240 | - ->method('isLoggedIn') |
|
241 | - ->willReturn(false); |
|
242 | - $this->session |
|
243 | - ->expects($this->once()) |
|
244 | - ->method('get') |
|
245 | - ->with('loginMessages') |
|
246 | - ->willReturn( |
|
247 | - [ |
|
248 | - [ |
|
249 | - 'ErrorArray1', |
|
250 | - 'ErrorArray2', |
|
251 | - ], |
|
252 | - [ |
|
253 | - 'MessageArray1', |
|
254 | - 'MessageArray2', |
|
255 | - ], |
|
256 | - ] |
|
257 | - ); |
|
258 | - |
|
259 | - $calls = [ |
|
260 | - [ |
|
261 | - 'loginMessages', |
|
262 | - [ |
|
263 | - 'MessageArray1', |
|
264 | - 'MessageArray2', |
|
265 | - 'This community release of Nextcloud is unsupported and push notifications are limited.', |
|
266 | - ], |
|
267 | - ], |
|
268 | - [ |
|
269 | - 'loginErrors', |
|
270 | - [ |
|
271 | - 'ErrorArray1', |
|
272 | - 'ErrorArray2', |
|
273 | - ], |
|
274 | - ], |
|
275 | - [ |
|
276 | - 'loginUsername', |
|
277 | - '', |
|
278 | - ] |
|
279 | - ]; |
|
280 | - $this->initialState->expects($this->exactly(13)) |
|
281 | - ->method('provideInitialState') |
|
282 | - ->willReturnCallback(function () use (&$calls) { |
|
283 | - $expected = array_shift($calls); |
|
284 | - if (!empty($expected)) { |
|
285 | - $this->assertEquals($expected, func_get_args()); |
|
286 | - } |
|
287 | - }); |
|
288 | - |
|
289 | - $expectedResponse = new TemplateResponse( |
|
290 | - 'core', |
|
291 | - 'login', |
|
292 | - [ |
|
293 | - 'alt_login' => [], |
|
294 | - 'pageTitle' => 'Login' |
|
295 | - ], |
|
296 | - 'guest' |
|
297 | - ); |
|
298 | - $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '')); |
|
299 | - } |
|
300 | - |
|
301 | - public function testShowLoginFormForFlowAuth(): void { |
|
302 | - $this->userSession |
|
303 | - ->expects($this->once()) |
|
304 | - ->method('isLoggedIn') |
|
305 | - ->willReturn(false); |
|
306 | - $calls = [ |
|
307 | - [], [], [], |
|
308 | - [ |
|
309 | - 'loginAutocomplete', |
|
310 | - false |
|
311 | - ], |
|
312 | - [ |
|
313 | - 'loginRedirectUrl', |
|
314 | - 'login/flow' |
|
315 | - ], |
|
316 | - ]; |
|
317 | - $this->initialState->expects($this->exactly(14)) |
|
318 | - ->method('provideInitialState') |
|
319 | - ->willReturnCallback(function () use (&$calls) { |
|
320 | - $expected = array_shift($calls); |
|
321 | - if (!empty($expected)) { |
|
322 | - $this->assertEquals($expected, func_get_args()); |
|
323 | - } |
|
324 | - }); |
|
325 | - |
|
326 | - $expectedResponse = new TemplateResponse( |
|
327 | - 'core', |
|
328 | - 'login', |
|
329 | - [ |
|
330 | - 'alt_login' => [], |
|
331 | - 'pageTitle' => 'Login' |
|
332 | - ], |
|
333 | - 'guest' |
|
334 | - ); |
|
335 | - $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', 'login/flow')); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @return array |
|
340 | - */ |
|
341 | - public static function passwordResetDataProvider(): array { |
|
342 | - return [ |
|
343 | - [ |
|
344 | - true, |
|
345 | - true, |
|
346 | - ], |
|
347 | - [ |
|
348 | - false, |
|
349 | - false, |
|
350 | - ], |
|
351 | - ]; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * @dataProvider passwordResetDataProvider |
|
356 | - */ |
|
357 | - public function testShowLoginFormWithPasswordResetOption($canChangePassword, |
|
358 | - $expectedResult): void { |
|
359 | - $this->userSession |
|
360 | - ->expects($this->once()) |
|
361 | - ->method('isLoggedIn') |
|
362 | - ->willReturn(false); |
|
363 | - $this->config |
|
364 | - ->expects(self::once()) |
|
365 | - ->method('getSystemValue') |
|
366 | - ->willReturnMap([ |
|
367 | - ['login_form_autocomplete', true, true], |
|
368 | - ]); |
|
369 | - $this->config |
|
370 | - ->expects(self::once()) |
|
371 | - ->method('getSystemValueString') |
|
372 | - ->willReturnMap([ |
|
373 | - ['lost_password_link', '', ''], |
|
374 | - ]); |
|
375 | - $user = $this->createMock(IUser::class); |
|
376 | - $user |
|
377 | - ->expects($this->once()) |
|
378 | - ->method('canChangePassword') |
|
379 | - ->willReturn($canChangePassword); |
|
380 | - $this->userManager |
|
381 | - ->expects($this->once()) |
|
382 | - ->method('get') |
|
383 | - ->with('LdapUser') |
|
384 | - ->willReturn($user); |
|
385 | - $calls = [ |
|
386 | - [], [], |
|
387 | - [ |
|
388 | - 'loginUsername', |
|
389 | - 'LdapUser' |
|
390 | - ], |
|
391 | - [], [], [], |
|
392 | - [ |
|
393 | - 'loginCanResetPassword', |
|
394 | - $expectedResult |
|
395 | - ], |
|
396 | - ]; |
|
397 | - $this->initialState->expects($this->exactly(13)) |
|
398 | - ->method('provideInitialState') |
|
399 | - ->willReturnCallback(function () use (&$calls) { |
|
400 | - $expected = array_shift($calls); |
|
401 | - if (!empty($expected)) { |
|
402 | - $this->assertEquals($expected, func_get_args()); |
|
403 | - } |
|
404 | - }); |
|
405 | - |
|
406 | - $expectedResponse = new TemplateResponse( |
|
407 | - 'core', |
|
408 | - 'login', |
|
409 | - [ |
|
410 | - 'alt_login' => [], |
|
411 | - 'pageTitle' => 'Login' |
|
412 | - ], |
|
413 | - 'guest' |
|
414 | - ); |
|
415 | - $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('LdapUser', '')); |
|
416 | - } |
|
417 | - |
|
418 | - public function testShowLoginFormForUserNamed0(): void { |
|
419 | - $this->userSession |
|
420 | - ->expects($this->once()) |
|
421 | - ->method('isLoggedIn') |
|
422 | - ->willReturn(false); |
|
423 | - $this->config |
|
424 | - ->expects(self::once()) |
|
425 | - ->method('getSystemValue') |
|
426 | - ->willReturnMap([ |
|
427 | - ['login_form_autocomplete', true, true], |
|
428 | - ]); |
|
429 | - $this->config |
|
430 | - ->expects(self::once()) |
|
431 | - ->method('getSystemValueString') |
|
432 | - ->willReturnMap([ |
|
433 | - ['lost_password_link', '', ''], |
|
434 | - ]); |
|
435 | - $user = $this->createMock(IUser::class); |
|
436 | - $user->expects($this->once()) |
|
437 | - ->method('canChangePassword') |
|
438 | - ->willReturn(false); |
|
439 | - $this->userManager |
|
440 | - ->expects($this->once()) |
|
441 | - ->method('get') |
|
442 | - ->with('0') |
|
443 | - ->willReturn($user); |
|
444 | - $calls = [ |
|
445 | - [], [], [], |
|
446 | - [ |
|
447 | - 'loginAutocomplete', |
|
448 | - true |
|
449 | - ], |
|
450 | - [], |
|
451 | - [ |
|
452 | - 'loginResetPasswordLink', |
|
453 | - false |
|
454 | - ], |
|
455 | - [ |
|
456 | - 'loginCanResetPassword', |
|
457 | - false |
|
458 | - ], |
|
459 | - ]; |
|
460 | - $this->initialState->expects($this->exactly(13)) |
|
461 | - ->method('provideInitialState') |
|
462 | - ->willReturnCallback(function () use (&$calls) { |
|
463 | - $expected = array_shift($calls); |
|
464 | - if (!empty($expected)) { |
|
465 | - $this->assertEquals($expected, func_get_args()); |
|
466 | - } |
|
467 | - }); |
|
468 | - |
|
469 | - $expectedResponse = new TemplateResponse( |
|
470 | - 'core', |
|
471 | - 'login', |
|
472 | - [ |
|
473 | - 'alt_login' => [], |
|
474 | - 'pageTitle' => 'Login' |
|
475 | - ], |
|
476 | - 'guest' |
|
477 | - ); |
|
478 | - $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('0', '')); |
|
479 | - } |
|
480 | - |
|
481 | - public function testLoginWithInvalidCredentials(): void { |
|
482 | - $user = 'MyUserName'; |
|
483 | - $password = 'secret'; |
|
484 | - $loginPageUrl = '/login?redirect_url=/apps/files'; |
|
485 | - $loginChain = $this->createMock(LoginChain::class); |
|
486 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
487 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
488 | - $this->request |
|
489 | - ->expects($this->once()) |
|
490 | - ->method('passesCSRFCheck') |
|
491 | - ->willReturn(true); |
|
492 | - $loginData = new LoginData( |
|
493 | - $this->request, |
|
494 | - $user, |
|
495 | - $password, |
|
496 | - '/apps/files' |
|
497 | - ); |
|
498 | - $loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD); |
|
499 | - $loginChain->expects($this->once()) |
|
500 | - ->method('process') |
|
501 | - ->with($this->equalTo($loginData)) |
|
502 | - ->willReturn($loginResult); |
|
503 | - $this->urlGenerator->expects($this->once()) |
|
504 | - ->method('linkToRoute') |
|
505 | - ->with('core.login.showLoginForm', [ |
|
506 | - 'user' => $user, |
|
507 | - 'redirect_url' => '/apps/files', |
|
508 | - 'direct' => 1, |
|
509 | - ]) |
|
510 | - ->willReturn($loginPageUrl); |
|
511 | - $expected = new RedirectResponse($loginPageUrl); |
|
512 | - $expected->throttle(['user' => 'MyUserName']); |
|
513 | - |
|
514 | - $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password, '/apps/files'); |
|
515 | - |
|
516 | - $this->assertEquals($expected, $response); |
|
517 | - } |
|
518 | - |
|
519 | - public function testLoginWithValidCredentials(): void { |
|
520 | - $user = 'MyUserName'; |
|
521 | - $password = 'secret'; |
|
522 | - $loginChain = $this->createMock(LoginChain::class); |
|
523 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
524 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
525 | - $this->request |
|
526 | - ->expects($this->once()) |
|
527 | - ->method('passesCSRFCheck') |
|
528 | - ->willReturn(true); |
|
529 | - $loginData = new LoginData( |
|
530 | - $this->request, |
|
531 | - $user, |
|
532 | - $password |
|
533 | - ); |
|
534 | - $loginResult = LoginResult::success($loginData); |
|
535 | - $loginChain->expects($this->once()) |
|
536 | - ->method('process') |
|
537 | - ->with($this->equalTo($loginData)) |
|
538 | - ->willReturn($loginResult); |
|
539 | - $this->urlGenerator |
|
540 | - ->expects($this->once()) |
|
541 | - ->method('linkToDefaultPageUrl') |
|
542 | - ->willReturn('/default/foo'); |
|
543 | - |
|
544 | - $expected = new RedirectResponse('/default/foo'); |
|
545 | - $this->assertEquals($expected, $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password)); |
|
546 | - } |
|
547 | - |
|
548 | - public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn(): void { |
|
549 | - /** @var IUser|MockObject $user */ |
|
550 | - $user = $this->createMock(IUser::class); |
|
551 | - $user->expects($this->any()) |
|
552 | - ->method('getUID') |
|
553 | - ->willReturn('jane'); |
|
554 | - $password = 'secret'; |
|
555 | - $originalUrl = 'another%20url'; |
|
556 | - $loginChain = $this->createMock(LoginChain::class); |
|
557 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
558 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
559 | - $this->request |
|
560 | - ->expects($this->once()) |
|
561 | - ->method('passesCSRFCheck') |
|
562 | - ->willReturn(false); |
|
563 | - $this->userSession |
|
564 | - ->method('isLoggedIn') |
|
565 | - ->with() |
|
566 | - ->willReturn(false); |
|
567 | - $this->config->expects($this->never()) |
|
568 | - ->method('deleteUserValue'); |
|
569 | - $this->userSession->expects($this->never()) |
|
570 | - ->method('createRememberMeToken'); |
|
571 | - |
|
572 | - $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, 'Jane', $password, $originalUrl); |
|
573 | - |
|
574 | - $expected = new RedirectResponse(''); |
|
575 | - $expected->throttle(['user' => 'Jane']); |
|
576 | - $this->assertEquals($expected, $response); |
|
577 | - } |
|
578 | - |
|
579 | - public function testLoginWithoutPassedCsrfCheckAndLoggedIn(): void { |
|
580 | - /** @var IUser|MockObject $user */ |
|
581 | - $user = $this->createMock(IUser::class); |
|
582 | - $user->expects($this->any()) |
|
583 | - ->method('getUID') |
|
584 | - ->willReturn('jane'); |
|
585 | - $password = 'secret'; |
|
586 | - $originalUrl = 'another url'; |
|
587 | - $redirectUrl = 'http://localhost/another url'; |
|
588 | - $loginChain = $this->createMock(LoginChain::class); |
|
589 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
590 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
591 | - $this->request |
|
592 | - ->expects($this->once()) |
|
593 | - ->method('passesCSRFCheck') |
|
594 | - ->willReturn(false); |
|
595 | - $this->userSession |
|
596 | - ->method('isLoggedIn') |
|
597 | - ->with() |
|
598 | - ->willReturn(true); |
|
599 | - $this->urlGenerator->expects($this->once()) |
|
600 | - ->method('getAbsoluteURL') |
|
601 | - ->with(urldecode($originalUrl)) |
|
602 | - ->willReturn($redirectUrl); |
|
603 | - $this->config->expects($this->never()) |
|
604 | - ->method('deleteUserValue'); |
|
605 | - $this->userSession->expects($this->never()) |
|
606 | - ->method('createRememberMeToken'); |
|
607 | - $this->config |
|
608 | - ->method('getSystemValue') |
|
609 | - ->with('remember_login_cookie_lifetime') |
|
610 | - ->willReturn(1234); |
|
611 | - |
|
612 | - $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, 'Jane', $password, $originalUrl); |
|
613 | - |
|
614 | - $expected = new RedirectResponse($redirectUrl); |
|
615 | - $this->assertEquals($expected, $response); |
|
616 | - } |
|
617 | - |
|
618 | - public function testLoginWithValidCredentialsAndRedirectUrl(): void { |
|
619 | - $user = 'MyUserName'; |
|
620 | - $password = 'secret'; |
|
621 | - $redirectUrl = 'https://next.cloud/apps/mail'; |
|
622 | - $loginChain = $this->createMock(LoginChain::class); |
|
623 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
624 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
625 | - $this->request |
|
626 | - ->expects($this->once()) |
|
627 | - ->method('passesCSRFCheck') |
|
628 | - ->willReturn(true); |
|
629 | - $loginData = new LoginData( |
|
630 | - $this->request, |
|
631 | - $user, |
|
632 | - $password, |
|
633 | - '/apps/mail' |
|
634 | - ); |
|
635 | - $loginResult = LoginResult::success($loginData); |
|
636 | - $loginChain->expects($this->once()) |
|
637 | - ->method('process') |
|
638 | - ->with($this->equalTo($loginData)) |
|
639 | - ->willReturn($loginResult); |
|
640 | - $this->userSession->expects($this->once()) |
|
641 | - ->method('isLoggedIn') |
|
642 | - ->willReturn(true); |
|
643 | - $this->urlGenerator->expects($this->once()) |
|
644 | - ->method('getAbsoluteURL') |
|
645 | - ->with('/apps/mail') |
|
646 | - ->willReturn($redirectUrl); |
|
647 | - $expected = new RedirectResponse($redirectUrl); |
|
648 | - |
|
649 | - $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password, '/apps/mail'); |
|
650 | - |
|
651 | - $this->assertEquals($expected, $response); |
|
652 | - } |
|
653 | - |
|
654 | - public function testToNotLeakLoginName(): void { |
|
655 | - $loginChain = $this->createMock(LoginChain::class); |
|
656 | - $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
657 | - $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
658 | - $this->request |
|
659 | - ->expects($this->once()) |
|
660 | - ->method('passesCSRFCheck') |
|
661 | - ->willReturn(true); |
|
662 | - $loginPageUrl = '/login?redirect_url=/apps/files'; |
|
663 | - $loginData = new LoginData( |
|
664 | - $this->request, |
|
665 | - '[email protected]', |
|
666 | - 'just wrong', |
|
667 | - '/apps/files' |
|
668 | - ); |
|
669 | - $loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD); |
|
670 | - $loginChain->expects($this->once()) |
|
671 | - ->method('process') |
|
672 | - ->with($this->equalTo($loginData)) |
|
673 | - ->willReturnCallback(function (LoginData $data) use ($loginResult) { |
|
674 | - $data->setUsername('john'); |
|
675 | - return $loginResult; |
|
676 | - }); |
|
677 | - $this->urlGenerator->expects($this->once()) |
|
678 | - ->method('linkToRoute') |
|
679 | - ->with('core.login.showLoginForm', [ |
|
680 | - 'user' => '[email protected]', |
|
681 | - 'redirect_url' => '/apps/files', |
|
682 | - 'direct' => 1, |
|
683 | - ]) |
|
684 | - ->willReturn($loginPageUrl); |
|
685 | - $expected = new RedirectResponse($loginPageUrl); |
|
686 | - $expected->throttle(['user' => 'john']); |
|
687 | - |
|
688 | - $response = $this->loginController->tryLogin( |
|
689 | - $loginChain, |
|
690 | - $trustedDomainHelper, |
|
691 | - '[email protected]', |
|
692 | - 'just wrong', |
|
693 | - '/apps/files' |
|
694 | - ); |
|
695 | - |
|
696 | - $this->assertEquals($expected, $response); |
|
697 | - } |
|
38 | + /** @var LoginController */ |
|
39 | + private $loginController; |
|
40 | + |
|
41 | + /** @var IRequest|MockObject */ |
|
42 | + private $request; |
|
43 | + |
|
44 | + /** @var IUserManager|MockObject */ |
|
45 | + private $userManager; |
|
46 | + |
|
47 | + /** @var IConfig|MockObject */ |
|
48 | + private $config; |
|
49 | + |
|
50 | + /** @var ISession|MockObject */ |
|
51 | + private $session; |
|
52 | + |
|
53 | + /** @var Session|MockObject */ |
|
54 | + private $userSession; |
|
55 | + |
|
56 | + /** @var IURLGenerator|MockObject */ |
|
57 | + private $urlGenerator; |
|
58 | + |
|
59 | + /** @var Manager|MockObject */ |
|
60 | + private $twoFactorManager; |
|
61 | + |
|
62 | + /** @var Defaults|MockObject */ |
|
63 | + private $defaults; |
|
64 | + |
|
65 | + /** @var IThrottler|MockObject */ |
|
66 | + private $throttler; |
|
67 | + |
|
68 | + /** @var IInitialState|MockObject */ |
|
69 | + private $initialState; |
|
70 | + |
|
71 | + /** @var \OC\Authentication\WebAuthn\Manager|MockObject */ |
|
72 | + private $webAuthnManager; |
|
73 | + |
|
74 | + /** @var IManager|MockObject */ |
|
75 | + private $notificationManager; |
|
76 | + |
|
77 | + /** @var IL10N|MockObject */ |
|
78 | + private $l; |
|
79 | + |
|
80 | + /** @var IAppManager|MockObject */ |
|
81 | + private $appManager; |
|
82 | + |
|
83 | + protected function setUp(): void { |
|
84 | + parent::setUp(); |
|
85 | + $this->request = $this->createMock(IRequest::class); |
|
86 | + $this->userManager = $this->createMock(\OC\User\Manager::class); |
|
87 | + $this->config = $this->createMock(IConfig::class); |
|
88 | + $this->session = $this->createMock(ISession::class); |
|
89 | + $this->userSession = $this->createMock(Session::class); |
|
90 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
91 | + $this->twoFactorManager = $this->createMock(Manager::class); |
|
92 | + $this->defaults = $this->createMock(Defaults::class); |
|
93 | + $this->throttler = $this->createMock(IThrottler::class); |
|
94 | + $this->initialState = $this->createMock(IInitialState::class); |
|
95 | + $this->webAuthnManager = $this->createMock(\OC\Authentication\WebAuthn\Manager::class); |
|
96 | + $this->notificationManager = $this->createMock(IManager::class); |
|
97 | + $this->l = $this->createMock(IL10N::class); |
|
98 | + $this->appManager = $this->createMock(IAppManager::class); |
|
99 | + |
|
100 | + $this->l->expects($this->any()) |
|
101 | + ->method('t') |
|
102 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
103 | + return vsprintf($text, $parameters); |
|
104 | + }); |
|
105 | + |
|
106 | + |
|
107 | + $this->request->method('getRemoteAddress') |
|
108 | + ->willReturn('1.2.3.4'); |
|
109 | + $this->request->method('getHeader') |
|
110 | + ->with('Origin') |
|
111 | + ->willReturn('domain.example.com'); |
|
112 | + $this->throttler->method('getDelay') |
|
113 | + ->with( |
|
114 | + $this->equalTo('1.2.3.4'), |
|
115 | + $this->equalTo('') |
|
116 | + )->willReturn(1000); |
|
117 | + |
|
118 | + $this->loginController = new LoginController( |
|
119 | + 'core', |
|
120 | + $this->request, |
|
121 | + $this->userManager, |
|
122 | + $this->config, |
|
123 | + $this->session, |
|
124 | + $this->userSession, |
|
125 | + $this->urlGenerator, |
|
126 | + $this->defaults, |
|
127 | + $this->throttler, |
|
128 | + $this->initialState, |
|
129 | + $this->webAuthnManager, |
|
130 | + $this->notificationManager, |
|
131 | + $this->l, |
|
132 | + $this->appManager, |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + public function testLogoutWithoutToken(): void { |
|
137 | + $this->request |
|
138 | + ->expects($this->once()) |
|
139 | + ->method('getCookie') |
|
140 | + ->with('nc_token') |
|
141 | + ->willReturn(null); |
|
142 | + $this->request |
|
143 | + ->method('getServerProtocol') |
|
144 | + ->willReturn('https'); |
|
145 | + $this->request |
|
146 | + ->expects($this->once()) |
|
147 | + ->method('isUserAgent') |
|
148 | + ->willReturn(false); |
|
149 | + $this->config |
|
150 | + ->expects($this->never()) |
|
151 | + ->method('deleteUserValue'); |
|
152 | + $this->urlGenerator |
|
153 | + ->expects($this->once()) |
|
154 | + ->method('linkToRouteAbsolute') |
|
155 | + ->with('core.login.showLoginForm') |
|
156 | + ->willReturn('/login'); |
|
157 | + |
|
158 | + $expected = new RedirectResponse('/login'); |
|
159 | + $expected->addHeader('Clear-Site-Data', '"cache", "storage"'); |
|
160 | + $this->assertEquals($expected, $this->loginController->logout()); |
|
161 | + } |
|
162 | + |
|
163 | + public function testLogoutNoClearSiteData(): void { |
|
164 | + $this->request |
|
165 | + ->expects($this->once()) |
|
166 | + ->method('getCookie') |
|
167 | + ->with('nc_token') |
|
168 | + ->willReturn(null); |
|
169 | + $this->request |
|
170 | + ->method('getServerProtocol') |
|
171 | + ->willReturn('https'); |
|
172 | + $this->request |
|
173 | + ->expects($this->once()) |
|
174 | + ->method('isUserAgent') |
|
175 | + ->willReturn(true); |
|
176 | + $this->urlGenerator |
|
177 | + ->expects($this->once()) |
|
178 | + ->method('linkToRouteAbsolute') |
|
179 | + ->with('core.login.showLoginForm') |
|
180 | + ->willReturn('/login'); |
|
181 | + |
|
182 | + $expected = new RedirectResponse('/login'); |
|
183 | + $this->assertEquals($expected, $this->loginController->logout()); |
|
184 | + } |
|
185 | + |
|
186 | + public function testLogoutWithToken(): void { |
|
187 | + $this->request |
|
188 | + ->expects($this->once()) |
|
189 | + ->method('getCookie') |
|
190 | + ->with('nc_token') |
|
191 | + ->willReturn('MyLoginToken'); |
|
192 | + $this->request |
|
193 | + ->method('getServerProtocol') |
|
194 | + ->willReturn('https'); |
|
195 | + $this->request |
|
196 | + ->expects($this->once()) |
|
197 | + ->method('isUserAgent') |
|
198 | + ->willReturn(false); |
|
199 | + $user = $this->createMock(IUser::class); |
|
200 | + $user |
|
201 | + ->expects($this->once()) |
|
202 | + ->method('getUID') |
|
203 | + ->willReturn('JohnDoe'); |
|
204 | + $this->userSession |
|
205 | + ->expects($this->once()) |
|
206 | + ->method('getUser') |
|
207 | + ->willReturn($user); |
|
208 | + $this->config |
|
209 | + ->expects($this->once()) |
|
210 | + ->method('deleteUserValue') |
|
211 | + ->with('JohnDoe', 'login_token', 'MyLoginToken'); |
|
212 | + $this->urlGenerator |
|
213 | + ->expects($this->once()) |
|
214 | + ->method('linkToRouteAbsolute') |
|
215 | + ->with('core.login.showLoginForm') |
|
216 | + ->willReturn('/login'); |
|
217 | + |
|
218 | + $expected = new RedirectResponse('/login'); |
|
219 | + $expected->addHeader('Clear-Site-Data', '"cache", "storage"'); |
|
220 | + $this->assertEquals($expected, $this->loginController->logout()); |
|
221 | + } |
|
222 | + |
|
223 | + public function testShowLoginFormForLoggedInUsers(): void { |
|
224 | + $this->userSession |
|
225 | + ->expects($this->once()) |
|
226 | + ->method('isLoggedIn') |
|
227 | + ->willReturn(true); |
|
228 | + $this->urlGenerator |
|
229 | + ->expects($this->once()) |
|
230 | + ->method('linkToDefaultPageUrl') |
|
231 | + ->willReturn('/default/foo'); |
|
232 | + |
|
233 | + $expectedResponse = new RedirectResponse('/default/foo'); |
|
234 | + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '')); |
|
235 | + } |
|
236 | + |
|
237 | + public function testShowLoginFormWithErrorsInSession(): void { |
|
238 | + $this->userSession |
|
239 | + ->expects($this->once()) |
|
240 | + ->method('isLoggedIn') |
|
241 | + ->willReturn(false); |
|
242 | + $this->session |
|
243 | + ->expects($this->once()) |
|
244 | + ->method('get') |
|
245 | + ->with('loginMessages') |
|
246 | + ->willReturn( |
|
247 | + [ |
|
248 | + [ |
|
249 | + 'ErrorArray1', |
|
250 | + 'ErrorArray2', |
|
251 | + ], |
|
252 | + [ |
|
253 | + 'MessageArray1', |
|
254 | + 'MessageArray2', |
|
255 | + ], |
|
256 | + ] |
|
257 | + ); |
|
258 | + |
|
259 | + $calls = [ |
|
260 | + [ |
|
261 | + 'loginMessages', |
|
262 | + [ |
|
263 | + 'MessageArray1', |
|
264 | + 'MessageArray2', |
|
265 | + 'This community release of Nextcloud is unsupported and push notifications are limited.', |
|
266 | + ], |
|
267 | + ], |
|
268 | + [ |
|
269 | + 'loginErrors', |
|
270 | + [ |
|
271 | + 'ErrorArray1', |
|
272 | + 'ErrorArray2', |
|
273 | + ], |
|
274 | + ], |
|
275 | + [ |
|
276 | + 'loginUsername', |
|
277 | + '', |
|
278 | + ] |
|
279 | + ]; |
|
280 | + $this->initialState->expects($this->exactly(13)) |
|
281 | + ->method('provideInitialState') |
|
282 | + ->willReturnCallback(function () use (&$calls) { |
|
283 | + $expected = array_shift($calls); |
|
284 | + if (!empty($expected)) { |
|
285 | + $this->assertEquals($expected, func_get_args()); |
|
286 | + } |
|
287 | + }); |
|
288 | + |
|
289 | + $expectedResponse = new TemplateResponse( |
|
290 | + 'core', |
|
291 | + 'login', |
|
292 | + [ |
|
293 | + 'alt_login' => [], |
|
294 | + 'pageTitle' => 'Login' |
|
295 | + ], |
|
296 | + 'guest' |
|
297 | + ); |
|
298 | + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '')); |
|
299 | + } |
|
300 | + |
|
301 | + public function testShowLoginFormForFlowAuth(): void { |
|
302 | + $this->userSession |
|
303 | + ->expects($this->once()) |
|
304 | + ->method('isLoggedIn') |
|
305 | + ->willReturn(false); |
|
306 | + $calls = [ |
|
307 | + [], [], [], |
|
308 | + [ |
|
309 | + 'loginAutocomplete', |
|
310 | + false |
|
311 | + ], |
|
312 | + [ |
|
313 | + 'loginRedirectUrl', |
|
314 | + 'login/flow' |
|
315 | + ], |
|
316 | + ]; |
|
317 | + $this->initialState->expects($this->exactly(14)) |
|
318 | + ->method('provideInitialState') |
|
319 | + ->willReturnCallback(function () use (&$calls) { |
|
320 | + $expected = array_shift($calls); |
|
321 | + if (!empty($expected)) { |
|
322 | + $this->assertEquals($expected, func_get_args()); |
|
323 | + } |
|
324 | + }); |
|
325 | + |
|
326 | + $expectedResponse = new TemplateResponse( |
|
327 | + 'core', |
|
328 | + 'login', |
|
329 | + [ |
|
330 | + 'alt_login' => [], |
|
331 | + 'pageTitle' => 'Login' |
|
332 | + ], |
|
333 | + 'guest' |
|
334 | + ); |
|
335 | + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', 'login/flow')); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @return array |
|
340 | + */ |
|
341 | + public static function passwordResetDataProvider(): array { |
|
342 | + return [ |
|
343 | + [ |
|
344 | + true, |
|
345 | + true, |
|
346 | + ], |
|
347 | + [ |
|
348 | + false, |
|
349 | + false, |
|
350 | + ], |
|
351 | + ]; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * @dataProvider passwordResetDataProvider |
|
356 | + */ |
|
357 | + public function testShowLoginFormWithPasswordResetOption($canChangePassword, |
|
358 | + $expectedResult): void { |
|
359 | + $this->userSession |
|
360 | + ->expects($this->once()) |
|
361 | + ->method('isLoggedIn') |
|
362 | + ->willReturn(false); |
|
363 | + $this->config |
|
364 | + ->expects(self::once()) |
|
365 | + ->method('getSystemValue') |
|
366 | + ->willReturnMap([ |
|
367 | + ['login_form_autocomplete', true, true], |
|
368 | + ]); |
|
369 | + $this->config |
|
370 | + ->expects(self::once()) |
|
371 | + ->method('getSystemValueString') |
|
372 | + ->willReturnMap([ |
|
373 | + ['lost_password_link', '', ''], |
|
374 | + ]); |
|
375 | + $user = $this->createMock(IUser::class); |
|
376 | + $user |
|
377 | + ->expects($this->once()) |
|
378 | + ->method('canChangePassword') |
|
379 | + ->willReturn($canChangePassword); |
|
380 | + $this->userManager |
|
381 | + ->expects($this->once()) |
|
382 | + ->method('get') |
|
383 | + ->with('LdapUser') |
|
384 | + ->willReturn($user); |
|
385 | + $calls = [ |
|
386 | + [], [], |
|
387 | + [ |
|
388 | + 'loginUsername', |
|
389 | + 'LdapUser' |
|
390 | + ], |
|
391 | + [], [], [], |
|
392 | + [ |
|
393 | + 'loginCanResetPassword', |
|
394 | + $expectedResult |
|
395 | + ], |
|
396 | + ]; |
|
397 | + $this->initialState->expects($this->exactly(13)) |
|
398 | + ->method('provideInitialState') |
|
399 | + ->willReturnCallback(function () use (&$calls) { |
|
400 | + $expected = array_shift($calls); |
|
401 | + if (!empty($expected)) { |
|
402 | + $this->assertEquals($expected, func_get_args()); |
|
403 | + } |
|
404 | + }); |
|
405 | + |
|
406 | + $expectedResponse = new TemplateResponse( |
|
407 | + 'core', |
|
408 | + 'login', |
|
409 | + [ |
|
410 | + 'alt_login' => [], |
|
411 | + 'pageTitle' => 'Login' |
|
412 | + ], |
|
413 | + 'guest' |
|
414 | + ); |
|
415 | + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('LdapUser', '')); |
|
416 | + } |
|
417 | + |
|
418 | + public function testShowLoginFormForUserNamed0(): void { |
|
419 | + $this->userSession |
|
420 | + ->expects($this->once()) |
|
421 | + ->method('isLoggedIn') |
|
422 | + ->willReturn(false); |
|
423 | + $this->config |
|
424 | + ->expects(self::once()) |
|
425 | + ->method('getSystemValue') |
|
426 | + ->willReturnMap([ |
|
427 | + ['login_form_autocomplete', true, true], |
|
428 | + ]); |
|
429 | + $this->config |
|
430 | + ->expects(self::once()) |
|
431 | + ->method('getSystemValueString') |
|
432 | + ->willReturnMap([ |
|
433 | + ['lost_password_link', '', ''], |
|
434 | + ]); |
|
435 | + $user = $this->createMock(IUser::class); |
|
436 | + $user->expects($this->once()) |
|
437 | + ->method('canChangePassword') |
|
438 | + ->willReturn(false); |
|
439 | + $this->userManager |
|
440 | + ->expects($this->once()) |
|
441 | + ->method('get') |
|
442 | + ->with('0') |
|
443 | + ->willReturn($user); |
|
444 | + $calls = [ |
|
445 | + [], [], [], |
|
446 | + [ |
|
447 | + 'loginAutocomplete', |
|
448 | + true |
|
449 | + ], |
|
450 | + [], |
|
451 | + [ |
|
452 | + 'loginResetPasswordLink', |
|
453 | + false |
|
454 | + ], |
|
455 | + [ |
|
456 | + 'loginCanResetPassword', |
|
457 | + false |
|
458 | + ], |
|
459 | + ]; |
|
460 | + $this->initialState->expects($this->exactly(13)) |
|
461 | + ->method('provideInitialState') |
|
462 | + ->willReturnCallback(function () use (&$calls) { |
|
463 | + $expected = array_shift($calls); |
|
464 | + if (!empty($expected)) { |
|
465 | + $this->assertEquals($expected, func_get_args()); |
|
466 | + } |
|
467 | + }); |
|
468 | + |
|
469 | + $expectedResponse = new TemplateResponse( |
|
470 | + 'core', |
|
471 | + 'login', |
|
472 | + [ |
|
473 | + 'alt_login' => [], |
|
474 | + 'pageTitle' => 'Login' |
|
475 | + ], |
|
476 | + 'guest' |
|
477 | + ); |
|
478 | + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('0', '')); |
|
479 | + } |
|
480 | + |
|
481 | + public function testLoginWithInvalidCredentials(): void { |
|
482 | + $user = 'MyUserName'; |
|
483 | + $password = 'secret'; |
|
484 | + $loginPageUrl = '/login?redirect_url=/apps/files'; |
|
485 | + $loginChain = $this->createMock(LoginChain::class); |
|
486 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
487 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
488 | + $this->request |
|
489 | + ->expects($this->once()) |
|
490 | + ->method('passesCSRFCheck') |
|
491 | + ->willReturn(true); |
|
492 | + $loginData = new LoginData( |
|
493 | + $this->request, |
|
494 | + $user, |
|
495 | + $password, |
|
496 | + '/apps/files' |
|
497 | + ); |
|
498 | + $loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD); |
|
499 | + $loginChain->expects($this->once()) |
|
500 | + ->method('process') |
|
501 | + ->with($this->equalTo($loginData)) |
|
502 | + ->willReturn($loginResult); |
|
503 | + $this->urlGenerator->expects($this->once()) |
|
504 | + ->method('linkToRoute') |
|
505 | + ->with('core.login.showLoginForm', [ |
|
506 | + 'user' => $user, |
|
507 | + 'redirect_url' => '/apps/files', |
|
508 | + 'direct' => 1, |
|
509 | + ]) |
|
510 | + ->willReturn($loginPageUrl); |
|
511 | + $expected = new RedirectResponse($loginPageUrl); |
|
512 | + $expected->throttle(['user' => 'MyUserName']); |
|
513 | + |
|
514 | + $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password, '/apps/files'); |
|
515 | + |
|
516 | + $this->assertEquals($expected, $response); |
|
517 | + } |
|
518 | + |
|
519 | + public function testLoginWithValidCredentials(): void { |
|
520 | + $user = 'MyUserName'; |
|
521 | + $password = 'secret'; |
|
522 | + $loginChain = $this->createMock(LoginChain::class); |
|
523 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
524 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
525 | + $this->request |
|
526 | + ->expects($this->once()) |
|
527 | + ->method('passesCSRFCheck') |
|
528 | + ->willReturn(true); |
|
529 | + $loginData = new LoginData( |
|
530 | + $this->request, |
|
531 | + $user, |
|
532 | + $password |
|
533 | + ); |
|
534 | + $loginResult = LoginResult::success($loginData); |
|
535 | + $loginChain->expects($this->once()) |
|
536 | + ->method('process') |
|
537 | + ->with($this->equalTo($loginData)) |
|
538 | + ->willReturn($loginResult); |
|
539 | + $this->urlGenerator |
|
540 | + ->expects($this->once()) |
|
541 | + ->method('linkToDefaultPageUrl') |
|
542 | + ->willReturn('/default/foo'); |
|
543 | + |
|
544 | + $expected = new RedirectResponse('/default/foo'); |
|
545 | + $this->assertEquals($expected, $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password)); |
|
546 | + } |
|
547 | + |
|
548 | + public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn(): void { |
|
549 | + /** @var IUser|MockObject $user */ |
|
550 | + $user = $this->createMock(IUser::class); |
|
551 | + $user->expects($this->any()) |
|
552 | + ->method('getUID') |
|
553 | + ->willReturn('jane'); |
|
554 | + $password = 'secret'; |
|
555 | + $originalUrl = 'another%20url'; |
|
556 | + $loginChain = $this->createMock(LoginChain::class); |
|
557 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
558 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
559 | + $this->request |
|
560 | + ->expects($this->once()) |
|
561 | + ->method('passesCSRFCheck') |
|
562 | + ->willReturn(false); |
|
563 | + $this->userSession |
|
564 | + ->method('isLoggedIn') |
|
565 | + ->with() |
|
566 | + ->willReturn(false); |
|
567 | + $this->config->expects($this->never()) |
|
568 | + ->method('deleteUserValue'); |
|
569 | + $this->userSession->expects($this->never()) |
|
570 | + ->method('createRememberMeToken'); |
|
571 | + |
|
572 | + $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, 'Jane', $password, $originalUrl); |
|
573 | + |
|
574 | + $expected = new RedirectResponse(''); |
|
575 | + $expected->throttle(['user' => 'Jane']); |
|
576 | + $this->assertEquals($expected, $response); |
|
577 | + } |
|
578 | + |
|
579 | + public function testLoginWithoutPassedCsrfCheckAndLoggedIn(): void { |
|
580 | + /** @var IUser|MockObject $user */ |
|
581 | + $user = $this->createMock(IUser::class); |
|
582 | + $user->expects($this->any()) |
|
583 | + ->method('getUID') |
|
584 | + ->willReturn('jane'); |
|
585 | + $password = 'secret'; |
|
586 | + $originalUrl = 'another url'; |
|
587 | + $redirectUrl = 'http://localhost/another url'; |
|
588 | + $loginChain = $this->createMock(LoginChain::class); |
|
589 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
590 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
591 | + $this->request |
|
592 | + ->expects($this->once()) |
|
593 | + ->method('passesCSRFCheck') |
|
594 | + ->willReturn(false); |
|
595 | + $this->userSession |
|
596 | + ->method('isLoggedIn') |
|
597 | + ->with() |
|
598 | + ->willReturn(true); |
|
599 | + $this->urlGenerator->expects($this->once()) |
|
600 | + ->method('getAbsoluteURL') |
|
601 | + ->with(urldecode($originalUrl)) |
|
602 | + ->willReturn($redirectUrl); |
|
603 | + $this->config->expects($this->never()) |
|
604 | + ->method('deleteUserValue'); |
|
605 | + $this->userSession->expects($this->never()) |
|
606 | + ->method('createRememberMeToken'); |
|
607 | + $this->config |
|
608 | + ->method('getSystemValue') |
|
609 | + ->with('remember_login_cookie_lifetime') |
|
610 | + ->willReturn(1234); |
|
611 | + |
|
612 | + $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, 'Jane', $password, $originalUrl); |
|
613 | + |
|
614 | + $expected = new RedirectResponse($redirectUrl); |
|
615 | + $this->assertEquals($expected, $response); |
|
616 | + } |
|
617 | + |
|
618 | + public function testLoginWithValidCredentialsAndRedirectUrl(): void { |
|
619 | + $user = 'MyUserName'; |
|
620 | + $password = 'secret'; |
|
621 | + $redirectUrl = 'https://next.cloud/apps/mail'; |
|
622 | + $loginChain = $this->createMock(LoginChain::class); |
|
623 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
624 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
625 | + $this->request |
|
626 | + ->expects($this->once()) |
|
627 | + ->method('passesCSRFCheck') |
|
628 | + ->willReturn(true); |
|
629 | + $loginData = new LoginData( |
|
630 | + $this->request, |
|
631 | + $user, |
|
632 | + $password, |
|
633 | + '/apps/mail' |
|
634 | + ); |
|
635 | + $loginResult = LoginResult::success($loginData); |
|
636 | + $loginChain->expects($this->once()) |
|
637 | + ->method('process') |
|
638 | + ->with($this->equalTo($loginData)) |
|
639 | + ->willReturn($loginResult); |
|
640 | + $this->userSession->expects($this->once()) |
|
641 | + ->method('isLoggedIn') |
|
642 | + ->willReturn(true); |
|
643 | + $this->urlGenerator->expects($this->once()) |
|
644 | + ->method('getAbsoluteURL') |
|
645 | + ->with('/apps/mail') |
|
646 | + ->willReturn($redirectUrl); |
|
647 | + $expected = new RedirectResponse($redirectUrl); |
|
648 | + |
|
649 | + $response = $this->loginController->tryLogin($loginChain, $trustedDomainHelper, $user, $password, '/apps/mail'); |
|
650 | + |
|
651 | + $this->assertEquals($expected, $response); |
|
652 | + } |
|
653 | + |
|
654 | + public function testToNotLeakLoginName(): void { |
|
655 | + $loginChain = $this->createMock(LoginChain::class); |
|
656 | + $trustedDomainHelper = $this->createMock(ITrustedDomainHelper::class); |
|
657 | + $trustedDomainHelper->method('isTrustedUrl')->willReturn(true); |
|
658 | + $this->request |
|
659 | + ->expects($this->once()) |
|
660 | + ->method('passesCSRFCheck') |
|
661 | + ->willReturn(true); |
|
662 | + $loginPageUrl = '/login?redirect_url=/apps/files'; |
|
663 | + $loginData = new LoginData( |
|
664 | + $this->request, |
|
665 | + '[email protected]', |
|
666 | + 'just wrong', |
|
667 | + '/apps/files' |
|
668 | + ); |
|
669 | + $loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD); |
|
670 | + $loginChain->expects($this->once()) |
|
671 | + ->method('process') |
|
672 | + ->with($this->equalTo($loginData)) |
|
673 | + ->willReturnCallback(function (LoginData $data) use ($loginResult) { |
|
674 | + $data->setUsername('john'); |
|
675 | + return $loginResult; |
|
676 | + }); |
|
677 | + $this->urlGenerator->expects($this->once()) |
|
678 | + ->method('linkToRoute') |
|
679 | + ->with('core.login.showLoginForm', [ |
|
680 | + 'user' => '[email protected]', |
|
681 | + 'redirect_url' => '/apps/files', |
|
682 | + 'direct' => 1, |
|
683 | + ]) |
|
684 | + ->willReturn($loginPageUrl); |
|
685 | + $expected = new RedirectResponse($loginPageUrl); |
|
686 | + $expected->throttle(['user' => 'john']); |
|
687 | + |
|
688 | + $response = $this->loginController->tryLogin( |
|
689 | + $loginChain, |
|
690 | + $trustedDomainHelper, |
|
691 | + '[email protected]', |
|
692 | + 'just wrong', |
|
693 | + '/apps/files' |
|
694 | + ); |
|
695 | + |
|
696 | + $this->assertEquals($expected, $response); |
|
697 | + } |
|
698 | 698 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $this->l->expects($this->any()) |
101 | 101 | ->method('t') |
102 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
102 | + ->willReturnCallback(function($text, $parameters = []) { |
|
103 | 103 | return vsprintf($text, $parameters); |
104 | 104 | }); |
105 | 105 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | ]; |
280 | 280 | $this->initialState->expects($this->exactly(13)) |
281 | 281 | ->method('provideInitialState') |
282 | - ->willReturnCallback(function () use (&$calls) { |
|
282 | + ->willReturnCallback(function() use (&$calls) { |
|
283 | 283 | $expected = array_shift($calls); |
284 | 284 | if (!empty($expected)) { |
285 | 285 | $this->assertEquals($expected, func_get_args()); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | ]; |
317 | 317 | $this->initialState->expects($this->exactly(14)) |
318 | 318 | ->method('provideInitialState') |
319 | - ->willReturnCallback(function () use (&$calls) { |
|
319 | + ->willReturnCallback(function() use (&$calls) { |
|
320 | 320 | $expected = array_shift($calls); |
321 | 321 | if (!empty($expected)) { |
322 | 322 | $this->assertEquals($expected, func_get_args()); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | ]; |
397 | 397 | $this->initialState->expects($this->exactly(13)) |
398 | 398 | ->method('provideInitialState') |
399 | - ->willReturnCallback(function () use (&$calls) { |
|
399 | + ->willReturnCallback(function() use (&$calls) { |
|
400 | 400 | $expected = array_shift($calls); |
401 | 401 | if (!empty($expected)) { |
402 | 402 | $this->assertEquals($expected, func_get_args()); |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | ]; |
460 | 460 | $this->initialState->expects($this->exactly(13)) |
461 | 461 | ->method('provideInitialState') |
462 | - ->willReturnCallback(function () use (&$calls) { |
|
462 | + ->willReturnCallback(function() use (&$calls) { |
|
463 | 463 | $expected = array_shift($calls); |
464 | 464 | if (!empty($expected)) { |
465 | 465 | $this->assertEquals($expected, func_get_args()); |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | $loginChain->expects($this->once()) |
671 | 671 | ->method('process') |
672 | 672 | ->with($this->equalTo($loginData)) |
673 | - ->willReturnCallback(function (LoginData $data) use ($loginResult) { |
|
673 | + ->willReturnCallback(function(LoginData $data) use ($loginResult) { |
|
674 | 674 | $data->setUsername('john'); |
675 | 675 | return $loginResult; |
676 | 676 | }); |