|
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\TextnodeHitch; |
|
32
|
|
|
use DembeloMain\Document\User; |
|
33
|
|
|
use DembeloMain\Model\FavoriteManager; |
|
34
|
|
|
use DembeloMain\Model\FeatureToggle; |
|
35
|
|
|
use DembeloMain\Model\Readpath; |
|
36
|
|
|
use DembeloMain\Model\Repository\TextNodeRepositoryInterface; |
|
37
|
|
|
use DembeloMain\Model\Repository\UserRepositoryInterface; |
|
38
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
39
|
|
|
use Doctrine\Common\Collections\Collection; |
|
40
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
41
|
|
|
use DembeloMain\Controller\DefaultController; |
|
42
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
|
43
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
44
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
45
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
|
46
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as Templating; |
|
47
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
48
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Class DefaultControllerTest |
|
52
|
|
|
*/ |
|
53
|
|
|
class DefaultControllerTest extends WebTestCase |
|
54
|
|
|
{ |
|
55
|
|
|
/** |
|
56
|
|
|
* @var DefaultController |
|
57
|
|
|
*/ |
|
58
|
|
|
private $controller; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var FeatureToggle|\PHPUnit_Framework_MockObject_MockObject |
|
62
|
|
|
*/ |
|
63
|
|
|
private $featureToggleMock; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject |
|
67
|
|
|
*/ |
|
68
|
|
|
private $authorizationCheckerMock; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
|
72
|
|
|
*/ |
|
73
|
|
|
private $userRepositoryMock; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
|
77
|
|
|
*/ |
|
78
|
|
|
private $textnodeRepositoryMock; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var Templating|\PHPUnit_Framework_MockObject_MockObject |
|
82
|
|
|
*/ |
|
83
|
|
|
private $templatingMock; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var Router|\PHPUnit_Framework_MockObject_MockObject |
|
87
|
|
|
*/ |
|
88
|
|
|
private $routerMock; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var TokenStorage|\PHPUnit_Framework_MockObject_MockObject |
|
92
|
|
|
*/ |
|
93
|
|
|
private $tokenStorageMock; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var ReadPath|\PHPUnit_Framework_MockObject_MockObject |
|
97
|
|
|
*/ |
|
98
|
|
|
private $readpathMock; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var FavoriteManager|\PHPUnit_Framework_MockObject_MockObject |
|
102
|
|
|
*/ |
|
103
|
|
|
private $favoriteManagerMock; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @inheritdoc |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setUp(): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->featureToggleMock = $this->createFeatureToggleMock(); |
|
111
|
|
|
$this->authorizationCheckerMock = $this->createAuthorizationCheckerMock(); |
|
112
|
|
|
$this->userRepositoryMock = $this->createUserRepositoryMock(); |
|
113
|
|
|
$this->textnodeRepositoryMock = $this->createTextnodeRepositoryMock(); |
|
114
|
|
|
$this->templatingMock = $this->createTemplatingMock(); |
|
115
|
|
|
$this->routerMock = $this->createRouterMock(); |
|
116
|
|
|
$this->tokenStorageMock = $this->createTokenStorageMock(); |
|
117
|
|
|
$this->readpathMock = $this->createReadpathMock(); |
|
118
|
|
|
$this->favoriteManagerMock = $this->createFavoriteManagerMock(); |
|
119
|
|
|
|
|
120
|
|
|
$this->controller = new DefaultController( |
|
121
|
|
|
$this->featureToggleMock, |
|
122
|
|
|
$this->authorizationCheckerMock, |
|
123
|
|
|
$this->userRepositoryMock, |
|
124
|
|
|
$this->textnodeRepositoryMock, |
|
125
|
|
|
$this->templatingMock, |
|
126
|
|
|
$this->routerMock, |
|
127
|
|
|
$this->tokenStorageMock, |
|
128
|
|
|
$this->readpathMock, |
|
129
|
|
|
$this->favoriteManagerMock |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* tests readTopicAction with guest user and enabled login feature |
|
135
|
|
|
* Tests the index action. |
|
136
|
|
|
*/ |
|
137
|
|
|
public function testReadTopicActionWithLoggedOutUserAndEnabledLoginFeature(): void |
|
138
|
|
|
{ |
|
139
|
|
|
$topicId = 'someTopicId'; |
|
140
|
|
|
|
|
141
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
142
|
|
|
->method('hasFeature') |
|
143
|
|
|
->willReturn(true); |
|
144
|
|
|
$this->authorizationCheckerMock->expects(self::any()) |
|
145
|
|
|
->method('isGranted') |
|
146
|
|
|
->willReturn(false); |
|
147
|
|
|
$this->routerMock->expects(self::once()) |
|
148
|
|
|
->method('generate') |
|
149
|
|
|
->with('login_route', []); |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
$result = $this->controller->readTopicAction($topicId); |
|
152
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* tests readTOpicAction for invalid topic id |
|
157
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
158
|
|
|
*/ |
|
159
|
|
|
public function testReadTopicActionForInvalidTopicId(): void |
|
160
|
|
|
{ |
|
161
|
|
|
$topicId = 'someTopicId'; |
|
162
|
|
|
|
|
163
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
164
|
|
|
->method('hasFeature') |
|
165
|
|
|
->willReturn(false); |
|
166
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
167
|
|
|
->method('getTextnodeToRead') |
|
168
|
|
|
->with($topicId) |
|
|
|
|
|
|
169
|
|
|
->willReturn(null); |
|
170
|
|
|
|
|
171
|
|
|
$this->controller->readTopicAction($topicId); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* test readtopicAction for valid topic and guest user |
|
176
|
|
|
*/ |
|
177
|
|
|
public function testReadTopicActionForValidTopicIdAndGuestUser(): void |
|
178
|
|
|
{ |
|
179
|
|
|
$topicId = 'someTopicId'; |
|
180
|
|
|
|
|
181
|
|
|
$childTextnodeMock = $this->createMock(Textnode::class); |
|
182
|
|
|
|
|
183
|
|
|
$hitchMock = $this->createMock(TextnodeHitch::class); |
|
184
|
|
|
$hitchMock->method('getTargetTextnode')->willReturn($childTextnodeMock); |
|
|
|
|
|
|
185
|
|
|
$hitchMock->method('getDescription')->willReturn(2); |
|
186
|
|
|
$hitchMock->method('getStatus')->willReturn(TextnodeHitch::STATUS_ACTIVE); |
|
187
|
|
|
|
|
188
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
189
|
|
|
$textnodeMock->method('getArbitraryId')->willReturn('someArbitraryId'); |
|
190
|
|
|
|
|
191
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
192
|
|
|
->method('hasFeature') |
|
193
|
|
|
->willReturn(false); |
|
194
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
195
|
|
|
->method('getTextnodeToRead') |
|
196
|
|
|
->with($topicId) |
|
|
|
|
|
|
197
|
|
|
->willReturn($textnodeMock); |
|
198
|
|
|
$this->tokenStorageMock->expects(self::once()) |
|
199
|
|
|
->method('getToken') |
|
200
|
|
|
->willReturn(null); |
|
201
|
|
|
$this->routerMock->expects(self::once()) |
|
202
|
|
|
->method('generate') |
|
203
|
|
|
->with('text', ['textnodeArbitraryId' => 'someArbitraryId']); |
|
204
|
|
|
|
|
205
|
|
|
$result = $this->controller->readTopicAction($topicId); |
|
206
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* tests readTopicACtion for valid topic id and guest user for a finance node |
|
211
|
|
|
*/ |
|
212
|
|
|
public function testReadTopicActionForValidTopicIdAndGuestUserForAFinanceNode(): void |
|
213
|
|
|
{ |
|
214
|
|
|
$topicId = 'someTopicId'; |
|
215
|
|
|
|
|
216
|
|
|
$textnode = new Textnode(); |
|
217
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
|
218
|
|
|
|
|
219
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
220
|
|
|
->method('hasFeature') |
|
221
|
|
|
->willReturn(false); |
|
222
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
223
|
|
|
->method('getTextnodeToRead') |
|
224
|
|
|
->with($topicId) |
|
|
|
|
|
|
225
|
|
|
->willReturn($textnode); |
|
226
|
|
|
$this->tokenStorageMock->expects(self::once()) |
|
227
|
|
|
->method('getToken') |
|
228
|
|
|
->willReturn(null); |
|
229
|
|
|
$this->routerMock->expects(self::once()) |
|
230
|
|
|
->method('generate') |
|
231
|
|
|
->with('financenode', ['textnodeArbitraryId' => 'someArbitraryId']); |
|
232
|
|
|
|
|
233
|
|
|
$result = $this->controller->readTopicAction($topicId); |
|
234
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* tests readTopicAction for valid topic Id and logged in user |
|
239
|
|
|
*/ |
|
240
|
|
|
public function testReadTopicActionForValidTopicIdAndLoggedInUser(): void |
|
241
|
|
|
{ |
|
242
|
|
|
$topicId = 'someTopicId'; |
|
243
|
|
|
|
|
244
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
245
|
|
|
$textnodeMock->method('getArbitraryId')->willReturn('someArbitraryId'); |
|
246
|
|
|
|
|
247
|
|
|
$hitchMock = $this->createMock(TextnodeHitch::class); |
|
248
|
|
|
$hitchMock->method('getTargetTextnode')->willReturn($textnodeMock); |
|
249
|
|
|
$hitchMock->method('getDescription')->willReturn(2); |
|
250
|
|
|
$hitchMock->method('getStatus')->willReturn(TextnodeHitch::STATUS_ACTIVE); |
|
251
|
|
|
|
|
252
|
|
|
$user = new User(); |
|
253
|
|
|
|
|
254
|
|
|
$this->userRepositoryMock->expects(self::once()) |
|
255
|
|
|
->method('save') |
|
256
|
|
|
->with($user); |
|
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
$tokenMock = $this->createTokenMock(); |
|
259
|
|
|
$tokenMock->expects(self::once()) |
|
|
|
|
|
|
260
|
|
|
->method('getUser') |
|
261
|
|
|
->willReturn($user); |
|
262
|
|
|
|
|
263
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
264
|
|
|
->method('hasFeature') |
|
265
|
|
|
->willReturn(false); |
|
266
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
267
|
|
|
->method('getTextnodeToRead') |
|
268
|
|
|
->with($topicId) |
|
|
|
|
|
|
269
|
|
|
->willReturn($textnodeMock); |
|
270
|
|
|
$this->tokenStorageMock->expects(self::once()) |
|
271
|
|
|
->method('getToken') |
|
272
|
|
|
->willReturn($tokenMock); |
|
273
|
|
|
$this->routerMock->expects(self::once()) |
|
274
|
|
|
->method('generate') |
|
275
|
|
|
->with('text', ['textnodeArbitraryId' => 'someArbitraryId']); |
|
276
|
|
|
|
|
277
|
|
|
$result = $this->controller->readTopicAction($topicId); |
|
278
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
279
|
|
|
self::assertSame($topicId, $user->getLastTopicId()); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* tests imprint action |
|
284
|
|
|
*/ |
|
285
|
|
|
public function testImprintAction(): void |
|
286
|
|
|
{ |
|
287
|
|
|
$responseMock = $this->createMock(Response::class); |
|
288
|
|
|
$this->templatingMock->expects(self::once()) |
|
289
|
|
|
->method('renderResponse') |
|
290
|
|
|
->with('DembeloMain::default/imprint.html.twig') |
|
|
|
|
|
|
291
|
|
|
->willReturn($responseMock); |
|
292
|
|
|
$result = $this->controller->imprintAction(); |
|
293
|
|
|
self::assertSame($responseMock, $result); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* @return void |
|
298
|
|
|
*/ |
|
299
|
|
|
public function testBackActionNoReadpath(): void |
|
300
|
|
|
{ |
|
301
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn(null); |
|
|
|
|
|
|
302
|
|
|
|
|
303
|
|
|
$result = $this->controller->backAction(); |
|
304
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
305
|
|
|
self::assertSame('mainpage', $result->getTargetUrl()); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* @return void |
|
310
|
|
|
*/ |
|
311
|
|
|
public function testBackActionCurrentTextnodeNotFound(): void |
|
312
|
|
|
{ |
|
313
|
|
|
$lastTextnodeId = 'someTextnodeId'; |
|
314
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn($lastTextnodeId); |
|
315
|
|
|
$this->textnodeRepositoryMock->method('find')->with($lastTextnodeId)->willReturn(null); |
|
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
$result = $this->controller->backAction(); |
|
318
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
319
|
|
|
self::assertSame('mainpage', $result->getTargetUrl()); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* @return void |
|
324
|
|
|
*/ |
|
325
|
|
|
public function testBackActionNoParentHitches(): void |
|
326
|
|
|
{ |
|
327
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
328
|
|
|
$lastTextnodeId = 'someTextnodeId'; |
|
329
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn($lastTextnodeId); |
|
330
|
|
|
$this->textnodeRepositoryMock->method('find')->with($lastTextnodeId)->willReturn($textnodeMock); |
|
331
|
|
|
|
|
332
|
|
|
$result = $this->controller->backAction(); |
|
333
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
334
|
|
|
self::assertSame('mainpage', $result->getTargetUrl()); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @return void |
|
339
|
|
|
*/ |
|
340
|
|
|
public function testBackActionForEmptyHitchCollection(): void |
|
341
|
|
|
{ |
|
342
|
|
|
$hitchCollectionMock = $this->createMock(Collection::class); |
|
343
|
|
|
$hitchCollectionMock->method('isEmpty')->willReturn(true); |
|
344
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
345
|
|
|
$lastTextnodeId = 'someTextnodeId'; |
|
346
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn($lastTextnodeId); |
|
347
|
|
|
$this->textnodeRepositoryMock->method('find')->with($lastTextnodeId)->willReturn($textnodeMock); |
|
348
|
|
|
$textnodeMock->method('getParentHitches')->willReturn($hitchCollectionMock); |
|
349
|
|
|
|
|
350
|
|
|
$result = $this->controller->backAction(); |
|
351
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
352
|
|
|
self::assertSame('mainpage', $result->getTargetUrl()); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @return void |
|
357
|
|
|
*/ |
|
358
|
|
|
public function testBackActionForParentIsAccessNode(): void |
|
359
|
|
|
{ |
|
360
|
|
|
$parentTextnodeMock = $this->createMock(Textnode::class); |
|
361
|
|
|
$parentTextnodeMock->method('getAccess')->willReturn(true); |
|
362
|
|
|
|
|
363
|
|
|
$hitchMock = $this->createMock(TextnodeHitch::class); |
|
364
|
|
|
$hitchMock->method('getSourceTextnode')->willReturn($parentTextnodeMock); |
|
365
|
|
|
|
|
366
|
|
|
$hitchCollectionMock = $this->createMock(Collection::class); |
|
367
|
|
|
$hitchCollectionMock->method('isEmpty')->willReturn(false); |
|
368
|
|
|
$hitchCollectionMock->method('first')->willReturn($hitchMock); |
|
369
|
|
|
|
|
370
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
371
|
|
|
$lastTextnodeId = 'someTextnodeId'; |
|
372
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn($lastTextnodeId); |
|
373
|
|
|
$this->textnodeRepositoryMock->method('find')->with($lastTextnodeId)->willReturn($textnodeMock); |
|
374
|
|
|
$textnodeMock->method('getParentHitches')->willReturn($hitchCollectionMock); |
|
375
|
|
|
|
|
376
|
|
|
$result = $this->controller->backAction(); |
|
377
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
378
|
|
|
self::assertSame('themenfeld', $result->getTargetUrl()); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @return void |
|
383
|
|
|
*/ |
|
384
|
|
|
public function testBackActionForParentIsNotAccessNode(): void |
|
385
|
|
|
{ |
|
386
|
|
|
$parentTextnodeMock = $this->createMock(Textnode::class); |
|
387
|
|
|
$parentTextnodeMock->method('getAccess')->willReturn(false); |
|
388
|
|
|
|
|
389
|
|
|
$hitchMock = $this->createMock(TextnodeHitch::class); |
|
390
|
|
|
$hitchMock->method('getSourceTextnode')->willReturn($parentTextnodeMock); |
|
391
|
|
|
|
|
392
|
|
|
$hitchCollectionMock = $this->createMock(Collection::class); |
|
393
|
|
|
$hitchCollectionMock->method('isEmpty')->willReturn(false); |
|
394
|
|
|
$hitchCollectionMock->method('first')->willReturn($hitchMock); |
|
395
|
|
|
|
|
396
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
397
|
|
|
$lastTextnodeId = 'someTextnodeId'; |
|
398
|
|
|
$this->readpathMock->method('getCurrentTextnodeId')->willReturn($lastTextnodeId); |
|
399
|
|
|
$this->textnodeRepositoryMock->method('find')->with($lastTextnodeId)->willReturn($textnodeMock); |
|
400
|
|
|
$textnodeMock->method('getParentHitches')->willReturn($hitchCollectionMock); |
|
401
|
|
|
|
|
402
|
|
|
$result = $this->controller->backAction(); |
|
403
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
404
|
|
|
self::assertSame('text', $result->getTargetUrl()); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* tests readTextnodeAction with guest user and enabled login feature |
|
409
|
|
|
*/ |
|
410
|
|
|
public function testReadTextnodeActionWithGuestUserAndEnabledLoginFeature(): void |
|
411
|
|
|
{ |
|
412
|
|
|
$textnodeArbitraryId = 'someTopicId'; |
|
413
|
|
|
|
|
414
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
415
|
|
|
->method('hasFeature') |
|
416
|
|
|
->willReturn(true); |
|
417
|
|
|
$this->authorizationCheckerMock->expects(self::any()) |
|
418
|
|
|
->method('isGranted') |
|
419
|
|
|
->willReturn(false); |
|
420
|
|
|
$this->routerMock->expects(self::once()) |
|
421
|
|
|
->method('generate') |
|
422
|
|
|
->with('login_route', []); |
|
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
$result = $this->controller->readTextnodeAction($textnodeArbitraryId); |
|
425
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* tests readTextnodeAction for invalid Id |
|
430
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
431
|
|
|
*/ |
|
432
|
|
|
public function testReadTextnodeActionForInvalidId(): void |
|
433
|
|
|
{ |
|
434
|
|
|
$textnodeArbitraryId = 'someId'; |
|
435
|
|
|
|
|
436
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
437
|
|
|
->method('hasFeature') |
|
438
|
|
|
->willReturn(false); |
|
439
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
440
|
|
|
->method('findOneActiveByArbitraryId') |
|
441
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
|
|
442
|
|
|
->willReturn(null); |
|
443
|
|
|
|
|
444
|
|
|
$this->controller->readTextnodeAction($textnodeArbitraryId); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
/** |
|
448
|
|
|
* test readTextnodeAction for valid textnode |
|
449
|
|
|
*/ |
|
450
|
|
|
public function testReadTextnodeActionForValidTextnode(): void |
|
451
|
|
|
{ |
|
452
|
|
|
$textnodeArbitraryId = 'someArbitraryId'; |
|
453
|
|
|
$textnodeId = 'someId'; |
|
454
|
|
|
|
|
455
|
|
|
$sourceTextnode = $this->createMock(Textnode::class); |
|
456
|
|
|
$sourceTextnode->method('getArbitraryId')->willReturn($textnodeArbitraryId); |
|
457
|
|
|
$sourceTextnode->method('getChildHitches')->willReturn(new ArrayCollection()); |
|
458
|
|
|
$sourceTextnode->method('getId')->willReturn($textnodeId); |
|
459
|
|
|
|
|
460
|
|
|
$responseMock = $this->createMock(Response::class); |
|
461
|
|
|
|
|
462
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
463
|
|
|
->method('hasFeature') |
|
464
|
|
|
->willReturn(false); |
|
465
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
466
|
|
|
->method('findOneActiveByArbitraryId') |
|
467
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
|
|
468
|
|
|
->willReturn($sourceTextnode); |
|
469
|
|
|
$this->tokenStorageMock->expects(self::once()) |
|
470
|
|
|
->method('getToken') |
|
471
|
|
|
->willReturn(null); |
|
472
|
|
|
$this->templatingMock->expects(self::once()) |
|
473
|
|
|
->method('renderResponse') |
|
474
|
|
|
->with( |
|
475
|
|
|
'DembeloMain::default/read.html.twig', |
|
476
|
|
|
[ |
|
477
|
|
|
'textnode' => $sourceTextnode, |
|
478
|
|
|
'hitches' => [], |
|
479
|
|
|
'showBackButton' => false, |
|
480
|
|
|
] |
|
481
|
|
|
) |
|
482
|
|
|
->willReturn($responseMock); |
|
483
|
|
|
|
|
484
|
|
|
$returnValue = $this->controller->readTextnodeAction($textnodeArbitraryId); |
|
485
|
|
|
self::assertEquals($responseMock, $returnValue); |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* tests readTextnodeAction for finance node |
|
490
|
|
|
*/ |
|
491
|
|
|
public function testReadTextnodeActionForFinanceNode(): void |
|
492
|
|
|
{ |
|
493
|
|
|
$textnodeArbitraryId = 'someId'; |
|
494
|
|
|
|
|
495
|
|
|
$textnode = new Textnode(); |
|
496
|
|
|
$textnode->setArbitraryId('someArbId'); |
|
497
|
|
|
|
|
498
|
|
|
$this->featureToggleMock->expects(self::once()) |
|
499
|
|
|
->method('hasFeature') |
|
500
|
|
|
->willReturn(false); |
|
501
|
|
|
$this->textnodeRepositoryMock->expects(self::once()) |
|
502
|
|
|
->method('findOneActiveByArbitraryId') |
|
503
|
|
|
->with($textnodeArbitraryId) |
|
|
|
|
|
|
504
|
|
|
->willReturn($textnode); |
|
505
|
|
|
|
|
506
|
|
|
$result = $this->controller->readTextnodeAction($textnodeArbitraryId); |
|
507
|
|
|
self::assertInstanceOf(RedirectResponse::class, $result); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
/** |
|
511
|
|
|
* @return TokenInterface|\PHPUnit_Framework_MockObject_MockObject |
|
512
|
|
|
*/ |
|
513
|
|
|
private function createTokenMock(): TokenInterface |
|
514
|
|
|
{ |
|
515
|
|
|
return $this->createMock(TokenInterface::class); |
|
|
|
|
|
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
/** |
|
519
|
|
|
* @return FeatureToggle|\PHPUnit_Framework_MockObject_MockObject |
|
520
|
|
|
*/ |
|
521
|
|
|
private function createFeatureToggleMock(): FeatureToggle |
|
522
|
|
|
{ |
|
523
|
|
|
return $this->createMock(FeatureToggle::class); |
|
|
|
|
|
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* @return AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject |
|
528
|
|
|
*/ |
|
529
|
|
|
private function createAuthorizationCheckerMock(): AuthorizationCheckerInterface |
|
530
|
|
|
{ |
|
531
|
|
|
return $this->createMock(AuthorizationCheckerInterface::class); |
|
|
|
|
|
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* @return UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
|
536
|
|
|
*/ |
|
537
|
|
|
private function createUserRepositoryMock(): UserRepositoryInterface |
|
538
|
|
|
{ |
|
539
|
|
|
return $this->createMock(UserRepositoryInterface::class); |
|
|
|
|
|
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* @return TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
|
544
|
|
|
*/ |
|
545
|
|
|
private function createTextnodeRepositoryMock(): TextNodeRepositoryInterface |
|
546
|
|
|
{ |
|
547
|
|
|
return $this->createMock(TextNodeRepositoryInterface::class); |
|
|
|
|
|
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
/** |
|
551
|
|
|
* @return Templating|\PHPUnit_Framework_MockObject_MockObject |
|
552
|
|
|
*/ |
|
553
|
|
|
private function createTemplatingMock(): Templating |
|
554
|
|
|
{ |
|
555
|
|
|
return $this->createMock(Templating::class); |
|
|
|
|
|
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
/** |
|
559
|
|
|
* @return Router|\PHPUnit_Framework_MockObject_MockObject |
|
560
|
|
|
*/ |
|
561
|
|
|
private function createRouterMock(): Router |
|
562
|
|
|
{ |
|
563
|
|
|
$mock = $this->createMock(Router::class); |
|
564
|
|
|
$mock->expects(self::any()) |
|
565
|
|
|
->method('generate') |
|
566
|
|
|
->willReturnArgument(0); |
|
567
|
|
|
|
|
568
|
|
|
return $mock; |
|
|
|
|
|
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
/** |
|
572
|
|
|
* @return TokenStorage|\PHPUnit_Framework_MockObject_MockObject |
|
573
|
|
|
*/ |
|
574
|
|
|
private function createTokenStorageMock(): TokenStorage |
|
575
|
|
|
{ |
|
576
|
|
|
return $this->createMock(TokenStorage::class); |
|
|
|
|
|
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
/** |
|
580
|
|
|
* @return ReadPath|\PHPUnit_Framework_MockObject_MockObject |
|
581
|
|
|
*/ |
|
582
|
|
|
private function createReadpathMock(): Readpath |
|
583
|
|
|
{ |
|
584
|
|
|
return $this->createMock(Readpath::class); |
|
|
|
|
|
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* @return FavoriteManager|\PHPUnit_Framework_MockObject_MockObject |
|
589
|
|
|
*/ |
|
590
|
|
|
private function createFavoriteManagerMock(): FavoriteManager |
|
591
|
|
|
{ |
|
592
|
|
|
return $this->createMock(FavoriteManager::class); |
|
|
|
|
|
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
|