@@ 80-103 (lines=24) @@ | ||
77 | /** |
|
78 | * @test |
|
79 | */ |
|
80 | public function shouldCheckIfAccessIsGranted() |
|
81 | { |
|
82 | $this->expectException(AccessDeniedException::class); |
|
83 | ||
84 | /** @var Request $request */ |
|
85 | $request = $this->createMock(Request::class); |
|
86 | ||
87 | $this->controllerHelper->expects($this->once())->method('denyAccessUnlessGranted')->with( |
|
88 | $this->equalTo('some-attribute'), |
|
89 | $this->equalTo($request) |
|
90 | )->will($this->returnCallback( |
|
91 | function () { |
|
92 | throw new AccessDeniedException('Lorem ipsum!'); |
|
93 | } |
|
94 | )); |
|
95 | ||
96 | /** @var mixed $controller */ |
|
97 | $controller = new GenericTemplateRenderController($this->controllerHelper, $this->argumentCompiler, [ |
|
98 | 'template' => "@foo/bar/baz.html", |
|
99 | 'authorization-attribute' => 'some-attribute', |
|
100 | ]); |
|
101 | ||
102 | $controller->renderTemplate($request); |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * @test |
@@ 354-377 (lines=24) @@ | ||
351 | /** |
|
352 | * @test |
|
353 | */ |
|
354 | public function shouldRejectNonExistingFactory() |
|
355 | { |
|
356 | $controller = new GenericEntityCreateController( |
|
357 | $this->controllerHelper, |
|
358 | $this->argumentBuilder, |
|
359 | $this->container, |
|
360 | [ |
|
361 | 'entity-class' => SampleEntity::class, |
|
362 | 'factory' => '@some_factory_service::serialize' |
|
363 | ] |
|
364 | ); |
|
365 | ||
366 | $this->container->expects($this->once())->method('get')->with( |
|
367 | $this->equalTo('some_factory_service') |
|
368 | )->willReturn(null); |
|
369 | ||
370 | /** @var Request $request */ |
|
371 | $request = $this->createMock(Request::class); |
|
372 | ||
373 | $this->expectException(InvalidArgumentException::class); |
|
374 | $this->expectExceptionMessage("Did not find service 'some_factory_service'!"); |
|
375 | ||
376 | $controller->createEntity($request); |
|
377 | } |
|
378 | ||
379 | /** |
|
380 | * @test |
|
@@ 405-430 (lines=26) @@ | ||
402 | /** |
|
403 | * @test |
|
404 | */ |
|
405 | public function shouldRejectNonExistingFactoryMethod() |
|
406 | { |
|
407 | $controller = new GenericEntityCreateController( |
|
408 | $this->controllerHelper, |
|
409 | $this->argumentBuilder, |
|
410 | $this->container, |
|
411 | [ |
|
412 | 'entity-class' => SampleEntity::class, |
|
413 | 'factory' => '@some_factory_service::MethodDoesNotExist' |
|
414 | ] |
|
415 | ); |
|
416 | ||
417 | /** @var Serializable $factoryMock */ |
|
418 | $factoryMock = $this->createMock(Serializable::class); |
|
419 | ||
420 | $this->container->expects($this->once())->method('get')->with( |
|
421 | $this->equalTo('some_factory_service') |
|
422 | )->willReturn($factoryMock); |
|
423 | ||
424 | /** @var Request $request */ |
|
425 | $request = $this->createMock(Request::class); |
|
426 | ||
427 | $this->expectException(ReflectionException::class); |
|
428 | ||
429 | $controller->createEntity($request); |
|
430 | } |
|
431 | ||
432 | /** |
|
433 | * @test |
@@ 193-215 (lines=23) @@ | ||
190 | /** |
|
191 | * @test |
|
192 | */ |
|
193 | public function shouldCheckIfAccessIsGranted() |
|
194 | { |
|
195 | /** @var Request $request */ |
|
196 | $request = $this->createMock(Request::class); |
|
197 | ||
198 | $this->expectException(AccessDeniedException::class); |
|
199 | ||
200 | $this->controllerHelper->expects($this->once())->method('denyAccessUnlessGranted')->with( |
|
201 | $this->equalTo('some-attribute'), |
|
202 | $this->identicalTo($request) |
|
203 | )->will($this->returnCallback( |
|
204 | function () { |
|
205 | throw new AccessDeniedException('Lorem ipsum!'); |
|
206 | } |
|
207 | )); |
|
208 | ||
209 | $controller = new GenericEntityListingController($this->controllerHelper, $this->argumentCompiler, [ |
|
210 | 'entity-class' => SampleEntity::class, |
|
211 | 'authorization-attribute' => 'some-attribute', |
|
212 | ]); |
|
213 | ||
214 | $controller->listEntities($request); |
|
215 | } |
|
216 | ||
217 | } |
|
218 |
@@ 162-190 (lines=29) @@ | ||
159 | /** |
|
160 | * @test |
|
161 | */ |
|
162 | public function shouldCheckIfAccessIsGranted() |
|
163 | { |
|
164 | $this->expectException(AccessDeniedException::class); |
|
165 | ||
166 | /** @var Request $request */ |
|
167 | $request = $this->createMock(Request::class); |
|
168 | ||
169 | $this->controllerHelper->expects($this->once())->method('denyAccessUnlessGranted')->with( |
|
170 | $this->equalTo('bar'), |
|
171 | $this->identicalTo($request) |
|
172 | )->will($this->returnCallback( |
|
173 | function () { |
|
174 | throw new AccessDeniedException("Lorem ipsum"); |
|
175 | } |
|
176 | )); |
|
177 | ||
178 | $controller = new GenericServiceInvokeController( |
|
179 | $this->controllerHelper, |
|
180 | $this->argumentCompiler, |
|
181 | $this->container, |
|
182 | [ |
|
183 | 'service' => 'some_service', |
|
184 | 'method' => 'doFoo', |
|
185 | 'authorization-attributes' => 'bar' |
|
186 | ] |
|
187 | ); |
|
188 | ||
189 | $controller->callService($request); |
|
190 | } |
|
191 | ||
192 | /** |
|
193 | * @test |