1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/* Copyright (C) 2015-2017 Michael Giesler, Stephan Kreutzer |
6
|
|
|
* |
7
|
|
|
* This file is part of Dembelo. |
8
|
|
|
* |
9
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License 3 for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
20
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @package DembeloMain |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace DembeloMain\Tests\Controller; |
29
|
|
|
|
30
|
|
|
use DembeloMain\Document\Textnode; |
31
|
|
|
use DembeloMain\Document\User; |
32
|
|
|
use DembeloMain\Model\FavoriteManager; |
33
|
|
|
use DembeloMain\Model\FeatureToggle; |
34
|
|
|
use DembeloMain\Model\Readpath; |
35
|
|
|
use DembeloMain\Model\Repository\TextNodeRepositoryInterface; |
36
|
|
|
use DembeloMain\Model\Repository\UserRepositoryInterface; |
37
|
|
|
use DembeloMain\Service\ReadpathUndoService; |
38
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
39
|
|
|
use DembeloMain\Controller\DefaultController; |
40
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
41
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
42
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
43
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as Templating; |
44
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
45
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Class DefaultControllerTest |
49
|
|
|
*/ |
50
|
|
|
class DefaultControllerTest extends WebTestCase |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* @var DefaultController |
54
|
|
|
*/ |
55
|
|
|
private $controller; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var FeatureToggle|\PHPUnit_Framework_MockObject_MockObject |
59
|
|
|
*/ |
60
|
|
|
private $featureToggleMock; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject |
64
|
|
|
*/ |
65
|
|
|
private $authorizationCheckerMock; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
69
|
|
|
*/ |
70
|
|
|
private $userRepositoryMock; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
74
|
|
|
*/ |
75
|
|
|
private $textnodeRepositoryMock; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var Templating|\PHPUnit_Framework_MockObject_MockObject |
79
|
|
|
*/ |
80
|
|
|
private $templatingMock; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var Router|\PHPUnit_Framework_MockObject_MockObject |
84
|
|
|
*/ |
85
|
|
|
private $routerMock; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var TokenStorage|\PHPUnit_Framework_MockObject_MockObject |
89
|
|
|
*/ |
90
|
|
|
private $tokenStorageMock; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var ReadPath|\PHPUnit_Framework_MockObject_MockObject |
94
|
|
|
*/ |
95
|
|
|
private $readpathMock; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var FavoriteManager|\PHPUnit_Framework_MockObject_MockObject |
99
|
|
|
*/ |
100
|
|
|
private $favoriteManagerMock; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var ReadpathUndoService|\PHPUnit_Framework_MockObject_MockObject |
104
|
|
|
*/ |
105
|
|
|
private $readpathUndoServiceMock; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
|
|
public function setUp(): void |
111
|
|
|
{ |
112
|
|
|
$this->featureToggleMock = $this->createFeatureToggleMock(); |
|
|
|
|
113
|
|
|
$this->authorizationCheckerMock = $this->createAuthorizationCheckerMock(); |
|
|
|
|
114
|
|
|
$this->userRepositoryMock = $this->createUserRepositoryMock(); |
|
|
|
|
115
|
|
|
$this->textnodeRepositoryMock = $this->createTextnodeRepositoryMock(); |
|
|
|
|
116
|
|
|
$this->templatingMock = $this->createTemplatingMock(); |
|
|
|
|
117
|
|
|
$this->routerMock = $this->createRouterMock(); |
|
|
|
|
118
|
|
|
$this->tokenStorageMock = $this->createTokenStorageMock(); |
|
|
|
|
119
|
|
|
$this->readpathMock = $this->createReadpathMock(); |
|
|
|
|
120
|
|
|
$this->favoriteManagerMock = $this->createFavoriteManagerMock(); |
|
|
|
|
121
|
|
|
$this->readpathUndoServiceMock = $this->createReadpathUndoServiceMock(); |
|
|
|
|
122
|
|
|
|
123
|
|
|
$this->controller = new DefaultController( |
124
|
|
|
$this->featureToggleMock, |
125
|
|
|
$this->authorizationCheckerMock, |
126
|
|
|
$this->userRepositoryMock, |
127
|
|
|
$this->textnodeRepositoryMock, |
128
|
|
|
$this->templatingMock, |
129
|
|
|
$this->routerMock, |
130
|
|
|
$this->tokenStorageMock, |
131
|
|
|
$this->readpathMock, |
132
|
|
|
$this->favoriteManagerMock, |
133
|
|
|
$this->readpathUndoServiceMock |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* tests readTopicAction with guest user and enabled login feature |
139
|
|
|
* Tests the index action. |
140
|
|
|
*/ |
141
|
|
View Code Duplication |
public function testReadTopicActionWithLoggedOutUserAndEnabledLoginFeature(): void |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
$topicId = 'someTopicId'; |
144
|
|
|
|
145
|
|
|
$this->featureToggleMock->expects(self::once()) |
146
|
|
|
->method('hasFeature') |
147
|
|
|
->willReturn(true); |
148
|
|
|
$this->authorizationCheckerMock->expects(self::any()) |
149
|
|
|
->method('isGranted') |
150
|
|
|
->willReturn(false); |
151
|
|
|
$this->routerMock->expects(self::once()) |
152
|
|
|
->method('generate') |
153
|
|
|
->with('login_route', []); |
|
|
|
|
154
|
|
|
|
155
|
|
|
$result = $this->controller->readTopicAction($topicId); |
156
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* tests readTOpicAction for invalid topic id |
161
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
162
|
|
|
*/ |
163
|
|
View Code Duplication |
public function testReadTopicActionForInvalidTopicId(): void |
|
|
|
|
164
|
|
|
{ |
165
|
|
|
$topicId = 'someTopicId'; |
166
|
|
|
|
167
|
|
|
$this->featureToggleMock->expects(self::once()) |
168
|
|
|
->method('hasFeature') |
169
|
|
|
->willReturn(false); |
170
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
171
|
|
|
->method('getTextnodeToRead') |
172
|
|
|
->with($topicId) |
|
|
|
|
173
|
|
|
->willReturn(null); |
174
|
|
|
|
175
|
|
|
$this->controller->readTopicAction($topicId); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* test readtopicAction for valid topic and guest user |
180
|
|
|
*/ |
181
|
|
|
public function testReadTopicActionForValidTopicIdAndGuestUser(): void |
182
|
|
|
{ |
183
|
|
|
$topicId = 'someTopicId'; |
184
|
|
|
|
185
|
|
|
$textnode = new Textnode(); |
186
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
187
|
|
|
$textnode->appendHitch([ |
188
|
|
|
'textnodeId' => '1', |
189
|
|
|
'description' => 2, |
190
|
|
|
'status' => Textnode::HITCH_STATUS_ACTIVE, |
191
|
|
|
]); |
192
|
|
|
|
193
|
|
|
$this->featureToggleMock->expects(self::once()) |
194
|
|
|
->method('hasFeature') |
195
|
|
|
->willReturn(false); |
196
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
197
|
|
|
->method('getTextnodeToRead') |
198
|
|
|
->with($topicId) |
|
|
|
|
199
|
|
|
->willReturn($textnode); |
200
|
|
|
$this->tokenStorageMock->expects(self::once()) |
201
|
|
|
->method('getToken') |
202
|
|
|
->willReturn(null); |
203
|
|
|
$this->routerMock->expects(self::once()) |
204
|
|
|
->method('generate') |
205
|
|
|
->with('text', ['textnodeArbitraryId' => 'someArbitraryId']); |
206
|
|
|
|
207
|
|
|
$result = $this->controller->readTopicAction($topicId); |
208
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* tests readTopicACtion for valid topic id and guest user for a finance node |
213
|
|
|
*/ |
214
|
|
|
public function testReadTopicActionForValidTopicIdAndGuestUserForAFinanceNode(): void |
215
|
|
|
{ |
216
|
|
|
$topicId = 'someTopicId'; |
217
|
|
|
|
218
|
|
|
$textnode = new Textnode(); |
219
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
220
|
|
|
|
221
|
|
|
$this->featureToggleMock->expects(self::once()) |
222
|
|
|
->method('hasFeature') |
223
|
|
|
->willReturn(false); |
224
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
225
|
|
|
->method('getTextnodeToRead') |
226
|
|
|
->with($topicId) |
|
|
|
|
227
|
|
|
->willReturn($textnode); |
228
|
|
|
$this->tokenStorageMock->expects(self::once()) |
229
|
|
|
->method('getToken') |
230
|
|
|
->willReturn(null); |
231
|
|
|
$this->routerMock->expects(self::once()) |
232
|
|
|
->method('generate') |
233
|
|
|
->with('financenode', ['textnodeArbitraryId' => 'someArbitraryId']); |
234
|
|
|
|
235
|
|
|
$result = $this->controller->readTopicAction($topicId); |
236
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* tests readTopicAction for valid topic Id and logged in user |
241
|
|
|
*/ |
242
|
|
|
public function testReadTopicActionForValidTopicIdAndLoggedInUser(): void |
243
|
|
|
{ |
244
|
|
|
$topicId = 'someTopicId'; |
245
|
|
|
|
246
|
|
|
$textnode = new Textnode(); |
247
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
248
|
|
|
$textnode->appendHitch([ |
249
|
|
|
'textnodeId' => '1', |
250
|
|
|
'description' => 2, |
251
|
|
|
'status' => Textnode::HITCH_STATUS_ACTIVE, |
252
|
|
|
]); |
253
|
|
|
|
254
|
|
|
$user = new User(); |
255
|
|
|
|
256
|
|
|
$this->userRepositoryMock->expects(self::once()) |
257
|
|
|
->method('save') |
258
|
|
|
->with($user); |
|
|
|
|
259
|
|
|
|
260
|
|
|
$tokenMock = $this->createTokenMock(); |
261
|
|
|
$tokenMock->expects(self::once()) |
|
|
|
|
262
|
|
|
->method('getUser') |
263
|
|
|
->willReturn($user); |
264
|
|
|
|
265
|
|
|
$this->featureToggleMock->expects(self::once()) |
266
|
|
|
->method('hasFeature') |
267
|
|
|
->willReturn(false); |
268
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
269
|
|
|
->method('getTextnodeToRead') |
270
|
|
|
->with($topicId) |
|
|
|
|
271
|
|
|
->willReturn($textnode); |
272
|
|
|
$this->tokenStorageMock->expects(self::once()) |
273
|
|
|
->method('getToken') |
274
|
|
|
->willReturn($tokenMock); |
275
|
|
|
$this->routerMock->expects(self::once()) |
276
|
|
|
->method('generate') |
277
|
|
|
->with('text', ['textnodeArbitraryId' => 'someArbitraryId']); |
278
|
|
|
|
279
|
|
|
$result = $this->controller->readTopicAction($topicId); |
280
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
281
|
|
|
self::assertSame($topicId, $user->getLastTopicId()); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* tests imprint action |
286
|
|
|
*/ |
287
|
|
|
public function testImprintAction(): void |
288
|
|
|
{ |
289
|
|
|
$this->templatingMock->expects(self::once()) |
290
|
|
|
->method('renderResponse') |
291
|
|
|
->with('DembeloMain::default/imprint.html.twig') |
|
|
|
|
292
|
|
|
->willReturn('responseString'); |
293
|
|
|
$result = $this->controller->imprintAction(); |
294
|
|
|
self::assertSame('responseString', $result); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* tests back action |
299
|
|
|
*/ |
300
|
|
|
public function testBackActionSuccess(): void |
301
|
|
|
{ |
302
|
|
|
$textnode = new Textnode(); |
303
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
304
|
|
|
|
305
|
|
|
$this->readpathUndoServiceMock->expects(self::once()) |
306
|
|
|
->method('undo') |
307
|
|
|
->willReturn(true); |
308
|
|
|
$this->readpathUndoServiceMock->expects(self::once()) |
309
|
|
|
->method('getCurrentItem') |
310
|
|
|
->willReturn(5); |
311
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
312
|
|
|
->method('find') |
313
|
|
|
->with(5) |
|
|
|
|
314
|
|
|
->willReturn($textnode); |
315
|
|
|
$this->routerMock->expects(self::once()) |
316
|
|
|
->method('generate') |
317
|
|
|
->with('text', ['textnodeArbitraryId' => 'someArbitraryId']) |
|
|
|
|
318
|
|
|
->willReturn('someUrl'); |
319
|
|
|
|
320
|
|
|
$result = $this->controller->backAction(); |
321
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
322
|
|
|
self::assertSame('someUrl', $result->getTargetUrl()); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* tests back action when undo() ist not successful |
327
|
|
|
*/ |
328
|
|
|
public function testBackActionUnsuccessfulForGuestUser(): void |
329
|
|
|
{ |
330
|
|
|
$textnode = new Textnode(); |
331
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
332
|
|
|
|
333
|
|
|
$this->readpathUndoServiceMock->expects(self::once()) |
334
|
|
|
->method('undo') |
335
|
|
|
->willReturn(false); |
336
|
|
|
$this->readpathUndoServiceMock->expects(self::never()) |
337
|
|
|
->method('getCurrentItem'); |
338
|
|
|
$this->routerMock->expects(self::once()) |
339
|
|
|
->method('generate') |
340
|
|
|
->with('mainpage') |
|
|
|
|
341
|
|
|
->willReturn('someUrl'); |
342
|
|
|
|
343
|
|
|
$result = $this->controller->backAction(); |
344
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
345
|
|
|
self::assertSame('someUrl', $result->getTargetUrl()); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* tests back action when undo() ist not successful |
350
|
|
|
*/ |
351
|
|
|
public function testBackActionUnsuccessfulForLoggedInUser(): void |
352
|
|
|
{ |
353
|
|
|
$textnode = new Textnode(); |
354
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
355
|
|
|
|
356
|
|
|
$user = new User(); |
357
|
|
|
$user->setLastTopicId('someLastTopicId'); |
358
|
|
|
|
359
|
|
|
$tokenMock = $this->createTokenMock(); |
360
|
|
|
$tokenMock->expects(self::once()) |
361
|
|
|
->method('getUser') |
362
|
|
|
->willReturn($user); |
363
|
|
|
|
364
|
|
|
$this->tokenStorageMock->expects(self::once()) |
365
|
|
|
->method('getToken') |
366
|
|
|
->willReturn($tokenMock); |
367
|
|
|
$this->readpathUndoServiceMock->expects(self::once()) |
368
|
|
|
->method('undo') |
369
|
|
|
->willReturn(false); |
370
|
|
|
$this->readpathUndoServiceMock->expects(self::never()) |
371
|
|
|
->method('getCurrentItem'); |
372
|
|
|
$this->routerMock->expects(self::once()) |
373
|
|
|
->method('generate') |
374
|
|
|
->with('themenfeld', ['topicId' => 'someLastTopicId']) |
|
|
|
|
375
|
|
|
->willReturn('someUrl'); |
376
|
|
|
|
377
|
|
|
$result = $this->controller->backAction(); |
378
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
379
|
|
|
self::assertSame('someUrl', $result->getTargetUrl()); |
380
|
|
|
} |
381
|
|
|
/** |
382
|
|
|
* tests readTextnodeAction with guest user and enabled login feature |
383
|
|
|
*/ |
384
|
|
View Code Duplication |
public function testReadTextnodeActionWithGuestUserAndEnabledLoginFeature(): void |
|
|
|
|
385
|
|
|
{ |
386
|
|
|
$textnodeArbitraryId = 'someTopicId'; |
387
|
|
|
|
388
|
|
|
$this->featureToggleMock->expects(self::once()) |
389
|
|
|
->method('hasFeature') |
390
|
|
|
->willReturn(true); |
391
|
|
|
$this->authorizationCheckerMock->expects(self::any()) |
392
|
|
|
->method('isGranted') |
393
|
|
|
->willReturn(false); |
394
|
|
|
$this->routerMock->expects(self::once()) |
395
|
|
|
->method('generate') |
396
|
|
|
->with('login_route', []); |
|
|
|
|
397
|
|
|
|
398
|
|
|
$result = $this->controller->readTextnodeAction($textnodeArbitraryId); |
399
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* tests readTextnodeAction for invalid Id |
404
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
405
|
|
|
*/ |
406
|
|
View Code Duplication |
public function testReadTextnodeActionForInvalidId(): void |
|
|
|
|
407
|
|
|
{ |
408
|
|
|
$textnodeArbitraryId = 'someId'; |
409
|
|
|
|
410
|
|
|
$this->featureToggleMock->expects(self::once()) |
411
|
|
|
->method('hasFeature') |
412
|
|
|
->willReturn(false); |
413
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
414
|
|
|
->method('findOneActiveByArbitraryId') |
415
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
416
|
|
|
->willReturn(null); |
417
|
|
|
|
418
|
|
|
$this->controller->readTextnodeAction($textnodeArbitraryId); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* test readTextnodeAction for valid textnode |
423
|
|
|
*/ |
424
|
|
|
public function testReadTextnodeActionForValidTextnode(): void |
425
|
|
|
{ |
426
|
|
|
$textnodeArbitraryId = 'someArbitraryId'; |
427
|
|
|
$textnodeId = 'someId'; |
428
|
|
|
|
429
|
|
|
$textnode = new Textnode(); |
430
|
|
|
$textnode->setId($textnodeId); |
431
|
|
|
$textnode->setArbitraryId($textnodeArbitraryId); |
432
|
|
|
$textnode->appendHitch([ |
433
|
|
|
'textnodeId' => '1', |
434
|
|
|
'description' => 2, |
435
|
|
|
'status' => Textnode::HITCH_STATUS_ACTIVE, |
436
|
|
|
]); |
437
|
|
|
|
438
|
|
|
$this->featureToggleMock->expects(self::once()) |
439
|
|
|
->method('hasFeature') |
440
|
|
|
->willReturn(false); |
441
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
442
|
|
|
->method('findOneActiveByArbitraryId') |
443
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
444
|
|
|
->willReturn($textnode); |
445
|
|
|
$this->tokenStorageMock->expects(self::once()) |
446
|
|
|
->method('getToken') |
447
|
|
|
->willReturn(null); |
448
|
|
|
$this->templatingMock->expects(self::once()) |
449
|
|
|
->method('renderResponse') |
450
|
|
|
->with( |
451
|
|
|
'DembeloMain::default/read.html.twig', |
452
|
|
|
[ |
453
|
|
|
'textnode' => $textnode, |
454
|
|
|
'hitches' => [], |
455
|
|
|
] |
456
|
|
|
); |
457
|
|
|
$this->readpathUndoServiceMock->expects(self::once()) |
458
|
|
|
->method('add') |
459
|
|
|
->with($textnodeId); |
460
|
|
|
|
461
|
|
|
$this->controller->readTextnodeAction($textnodeArbitraryId); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* tests readTextnodeAction for finance node |
466
|
|
|
*/ |
467
|
|
|
public function testReadTextnodeActionForFinanceNode(): void |
468
|
|
|
{ |
469
|
|
|
$textnodeArbitraryId = 'someId'; |
470
|
|
|
|
471
|
|
|
$textnode = new Textnode(); |
472
|
|
|
$textnode->setArbitraryId('someArbId'); |
473
|
|
|
|
474
|
|
|
$this->featureToggleMock->expects(self::once()) |
475
|
|
|
->method('hasFeature') |
476
|
|
|
->willReturn(false); |
477
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
478
|
|
|
->method('findOneActiveByArbitraryId') |
479
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
480
|
|
|
->willReturn($textnode); |
481
|
|
|
|
482
|
|
|
$result = $this->controller->readTextnodeAction($textnodeArbitraryId); |
483
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* @return TokenInterface|\PHPUnit_Framework_MockObject_MockObject |
488
|
|
|
*/ |
489
|
|
|
private function createTokenMock(): TokenInterface |
490
|
|
|
{ |
491
|
|
|
return $this->createMock(TokenInterface::class); |
|
|
|
|
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* @return FeatureToggle|\PHPUnit_Framework_MockObject_MockObject |
496
|
|
|
*/ |
497
|
|
|
private function createFeatureToggleMock(): FeatureToggle |
498
|
|
|
{ |
499
|
|
|
return $this->createMock(FeatureToggle::class); |
|
|
|
|
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* @return AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject |
504
|
|
|
*/ |
505
|
|
|
private function createAuthorizationCheckerMock(): AuthorizationCheckerInterface |
506
|
|
|
{ |
507
|
|
|
return $this->createMock(AuthorizationCheckerInterface::class); |
|
|
|
|
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @return UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
512
|
|
|
*/ |
513
|
|
|
private function createUserRepositoryMock(): UserRepositoryInterface |
514
|
|
|
{ |
515
|
|
|
return $this->createMock(UserRepositoryInterface::class); |
|
|
|
|
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* @return TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
520
|
|
|
*/ |
521
|
|
|
private function createTextnodeRepositoryMock(): TextNodeRepositoryInterface |
522
|
|
|
{ |
523
|
|
|
return $this->createMock(TextNodeRepositoryInterface::class); |
|
|
|
|
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @return Templating|\PHPUnit_Framework_MockObject_MockObject |
528
|
|
|
*/ |
529
|
|
|
private function createTemplatingMock(): Templating |
530
|
|
|
{ |
531
|
|
|
return $this->createMock(Templating::class); |
|
|
|
|
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* @return Router|\PHPUnit_Framework_MockObject_MockObject |
536
|
|
|
*/ |
537
|
|
|
private function createRouterMock(): Router |
538
|
|
|
{ |
539
|
|
|
$mock = $this->createMock(Router::class); |
540
|
|
|
$mock->expects(self::any()) |
541
|
|
|
->method('generate') |
542
|
|
|
->willReturn('someUrl'); |
543
|
|
|
|
544
|
|
|
return $mock; |
|
|
|
|
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* @return TokenStorage|\PHPUnit_Framework_MockObject_MockObject |
549
|
|
|
*/ |
550
|
|
|
private function createTokenStorageMock(): TokenStorage |
551
|
|
|
{ |
552
|
|
|
return $this->createMock(TokenStorage::class); |
|
|
|
|
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* @return ReadPath|\PHPUnit_Framework_MockObject_MockObject |
557
|
|
|
*/ |
558
|
|
|
private function createReadpathMock(): Readpath |
559
|
|
|
{ |
560
|
|
|
return $this->createMock(Readpath::class); |
|
|
|
|
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @return FavoriteManager|\PHPUnit_Framework_MockObject_MockObject |
565
|
|
|
*/ |
566
|
|
|
private function createFavoriteManagerMock(): FavoriteManager |
567
|
|
|
{ |
568
|
|
|
return $this->createMock(FavoriteManager::class); |
|
|
|
|
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* @return ReadpathUndoService|\PHPUnit_Framework_MockObject_MockObject |
573
|
|
|
*/ |
574
|
|
|
private function createReadpathUndoServiceMock(): ReadpathUndoService |
575
|
|
|
{ |
576
|
|
|
return $this->createMock(ReadpathUndoService::class); |
|
|
|
|
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..