1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\Controller; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use Psr\Log\LoggerInterface; |
19
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
20
|
|
|
use Sonata\AdminBundle\Admin\BreadcrumbsBuilder; |
21
|
|
|
use Sonata\AdminBundle\Admin\FieldDescriptionCollection; |
22
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
23
|
|
|
use Sonata\AdminBundle\Bridge\Exporter\AdminExporter; |
24
|
|
|
use Sonata\AdminBundle\Controller\CRUDController; |
25
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridInterface; |
26
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
27
|
|
|
use Sonata\AdminBundle\Exception\LockException; |
28
|
|
|
use Sonata\AdminBundle\Exception\ModelManagerException; |
29
|
|
|
use Sonata\AdminBundle\Model\AuditManagerInterface; |
30
|
|
|
use Sonata\AdminBundle\Model\AuditReaderInterface; |
31
|
|
|
use Sonata\AdminBundle\Model\ModelManagerInterface; |
32
|
|
|
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap; |
33
|
|
|
use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface; |
34
|
|
|
use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
35
|
|
|
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController; |
36
|
|
|
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController; |
37
|
|
|
use Sonata\AdminBundle\Util\AdminObjectAclData; |
38
|
|
|
use Sonata\AdminBundle\Util\AdminObjectAclManipulator; |
39
|
|
|
use Sonata\Exporter\Exporter; |
40
|
|
|
use Sonata\Exporter\Source\SourceIteratorInterface; |
41
|
|
|
use Sonata\Exporter\Writer\JsonWriter; |
42
|
|
|
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; |
43
|
|
|
use Symfony\Component\DependencyInjection\Container; |
44
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
45
|
|
|
use Symfony\Component\Form\Form; |
46
|
|
|
use Symfony\Component\Form\FormError; |
47
|
|
|
use Symfony\Component\Form\FormRenderer; |
48
|
|
|
use Symfony\Component\Form\FormView; |
49
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
50
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
51
|
|
|
use Symfony\Component\HttpFoundation\Request; |
52
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
53
|
|
|
use Symfony\Component\HttpFoundation\Response; |
54
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
55
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
56
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
57
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
58
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
59
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
60
|
|
|
use Symfony\Component\Security\Csrf\CsrfToken; |
61
|
|
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; |
62
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
63
|
|
|
use Twig\Environment; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test for CRUDController. |
67
|
|
|
* |
68
|
|
|
* @author Andrej Hudec <[email protected]> |
69
|
|
|
*/ |
70
|
|
|
class CRUDControllerTest extends TestCase |
71
|
|
|
{ |
72
|
|
|
use ExpectDeprecationTrait; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var CRUDController |
76
|
|
|
*/ |
77
|
|
|
private $controller; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var Request |
81
|
|
|
*/ |
82
|
|
|
private $request; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var AdminInterface |
86
|
|
|
*/ |
87
|
|
|
private $admin; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var TemplateRegistryInterface |
91
|
|
|
*/ |
92
|
|
|
private $templateRegistry; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var Pool |
96
|
|
|
*/ |
97
|
|
|
private $pool; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var array |
101
|
|
|
*/ |
102
|
|
|
private $parameters; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var Session |
106
|
|
|
*/ |
107
|
|
|
private $session; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var AuditManagerInterface |
111
|
|
|
*/ |
112
|
|
|
private $auditManager; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var ContainerInterface |
116
|
|
|
*/ |
117
|
|
|
private $container; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var AdminObjectAclManipulator |
121
|
|
|
*/ |
122
|
|
|
private $adminObjectAclManipulator; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var string |
126
|
|
|
*/ |
127
|
|
|
private $template; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var array |
131
|
|
|
*/ |
132
|
|
|
private $protectedTestedMethods; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var CsrfTokenManagerInterface |
136
|
|
|
*/ |
137
|
|
|
private $csrfProvider; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @var TranslatorInterface |
141
|
|
|
*/ |
142
|
|
|
private $translator; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @var Exporter |
146
|
|
|
*/ |
147
|
|
|
private $exporter; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @var LoggerInterface|MockObject |
151
|
|
|
*/ |
152
|
|
|
private $logger; |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* {@inheritdoc} |
156
|
|
|
*/ |
157
|
|
|
protected function setUp(): void |
158
|
|
|
{ |
159
|
|
|
$this->container = new Container(); |
160
|
|
|
$this->request = new Request(); |
161
|
|
|
$this->pool = new Pool($this->container, 'title', 'logo.png'); |
162
|
|
|
$this->pool->setAdminServiceIds(['foo.admin']); |
163
|
|
|
$this->request->attributes->set('_sonata_admin', 'foo.admin'); |
164
|
|
|
$this->admin = $this->createMock(AdminInterface::class); |
165
|
|
|
$this->translator = $this->createMock(TranslatorInterface::class); |
166
|
|
|
$this->parameters = []; |
167
|
|
|
$this->template = ''; |
168
|
|
|
|
169
|
|
|
$this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
170
|
|
|
|
171
|
|
|
$this->session = new Session(new MockArraySessionStorage()); |
172
|
|
|
|
173
|
|
|
$this->exporter = new Exporter([new JsonWriter(sys_get_temp_dir().'/sonataadmin/export.json')]); |
174
|
|
|
|
175
|
|
|
$this->auditManager = $this->createMock(AuditManagerInterface::class); |
176
|
|
|
|
177
|
|
|
$this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class) |
178
|
|
|
->disableOriginalConstructor() |
179
|
|
|
->getMock(); |
180
|
|
|
|
181
|
|
|
$this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class) |
182
|
|
|
->getMock(); |
183
|
|
|
|
184
|
|
|
$this->csrfProvider |
185
|
|
|
->method('getToken') |
186
|
|
|
->willReturnCallback(static function (string $intention): CsrfToken { |
187
|
|
|
return new CsrfToken($intention, sprintf('csrf-token-123_%s', $intention)); |
188
|
|
|
}); |
189
|
|
|
|
190
|
|
|
$this->csrfProvider |
191
|
|
|
->method('isTokenValid') |
192
|
|
|
->willReturnCallback(static function (CsrfToken $token): bool { |
193
|
|
|
return $token->getValue() === sprintf('csrf-token-123_%s', $token->getId()); |
194
|
|
|
}); |
195
|
|
|
|
196
|
|
|
$this->logger = $this->createMock(LoggerInterface::class); |
197
|
|
|
|
198
|
|
|
$requestStack = new RequestStack(); |
199
|
|
|
$requestStack->push($this->request); |
200
|
|
|
|
201
|
|
|
$this->container->set('sonata.admin.pool', $this->pool); |
202
|
|
|
$this->container->set('request_stack', $requestStack); |
203
|
|
|
$this->container->set('foo.admin', $this->admin); |
204
|
|
|
$this->container->set('foo.admin.template_registry', $this->templateRegistry->reveal()); |
205
|
|
|
$this->container->set('twig', $this->createTwig()); |
206
|
|
|
$this->container->set('session', $this->session); |
207
|
|
|
$this->container->set('sonata.exporter.exporter', $this->exporter); |
208
|
|
|
$this->container->set('sonata.admin.audit.manager', $this->auditManager); |
209
|
|
|
$this->container->set('sonata.admin.object.manipulator.acl.admin', $this->adminObjectAclManipulator); |
210
|
|
|
$this->container->set('security.csrf.token_manager', $this->csrfProvider); |
211
|
|
|
$this->container->set('logger', $this->logger); |
212
|
|
|
$this->container->set('translator', $this->translator); |
213
|
|
|
$this->container->set('sonata.admin.breadcrumbs_builder', new BreadcrumbsBuilder([])); |
214
|
|
|
|
215
|
|
|
$this->container->setParameter( |
216
|
|
|
'security.role_hierarchy.roles', |
217
|
|
|
['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']] |
218
|
|
|
); |
219
|
|
|
$this->container->setParameter('sonata.admin.security.acl_user_manager', null); |
220
|
|
|
|
221
|
|
|
$this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig'); |
222
|
|
|
$this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig'); |
223
|
|
|
$this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig'); |
224
|
|
|
$this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig'); |
225
|
|
|
$this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig'); |
226
|
|
|
$this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig'); |
227
|
|
|
$this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig'); |
228
|
|
|
$this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig'); |
229
|
|
|
$this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig'); |
230
|
|
|
$this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig'); |
231
|
|
|
$this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig'); |
232
|
|
|
$this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig'); |
233
|
|
|
$this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig'); |
234
|
|
|
$this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig'); |
235
|
|
|
|
236
|
|
|
$this->admin |
237
|
|
|
->method('getIdParameter') |
238
|
|
|
->willReturn('id'); |
239
|
|
|
|
240
|
|
|
$this->admin |
241
|
|
|
->method('getAccessMapping') |
242
|
|
|
->willReturn([]); |
243
|
|
|
|
244
|
|
|
$this->admin |
245
|
|
|
->method('generateUrl') |
246
|
|
|
->willReturnCallback( |
247
|
|
|
static function ($name, array $parameters = []) { |
248
|
|
|
$result = $name; |
249
|
|
|
if (!empty($parameters)) { |
250
|
|
|
$result .= '?'.http_build_query($parameters); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
return $result; |
254
|
|
|
} |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
$this->admin |
258
|
|
|
->method('generateObjectUrl') |
259
|
|
|
->willReturnCallback( |
260
|
|
|
static function (string $name, $object, array $parameters = []): string { |
261
|
|
|
$result = sprintf('%s_%s', \get_class($object), $name); |
262
|
|
|
if (!empty($parameters)) { |
263
|
|
|
$result .= '?'.http_build_query($parameters); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
return $result; |
267
|
|
|
} |
268
|
|
|
); |
269
|
|
|
|
270
|
|
|
$this->admin |
271
|
|
|
->method('getCode') |
272
|
|
|
->willReturn('foo.admin'); |
273
|
|
|
|
274
|
|
|
$this->controller = $this->createController(); |
275
|
|
|
|
276
|
|
|
// Make some methods public to test them |
277
|
|
|
$testedMethods = [ |
278
|
|
|
'renderJson', |
279
|
|
|
'isXmlHttpRequest', |
280
|
|
|
'configure', |
281
|
|
|
'getBaseTemplate', |
282
|
|
|
'redirectTo', |
283
|
|
|
'addFlash', |
284
|
|
|
]; |
285
|
|
|
foreach ($testedMethods as $testedMethod) { |
286
|
|
|
$method = new \ReflectionMethod(CRUDController::class, $testedMethod); |
287
|
|
|
$method->setAccessible(true); |
288
|
|
|
$this->protectedTestedMethods[$testedMethod] = $method; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function testRenderJson1(): void |
293
|
|
|
{ |
294
|
|
|
$data = ['example' => '123', 'foo' => 'bar']; |
295
|
|
|
|
296
|
|
|
$this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded'); |
297
|
|
|
$response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); |
298
|
|
|
|
299
|
|
|
$this->assertSame($response->headers->get('Content-Type'), 'application/json'); |
300
|
|
|
$this->assertSame(json_encode($data), $response->getContent()); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function testRenderJson2(): void |
304
|
|
|
{ |
305
|
|
|
$data = ['example' => '123', 'foo' => 'bar']; |
306
|
|
|
|
307
|
|
|
$this->request->headers->set('Content-Type', 'multipart/form-data'); |
308
|
|
|
$response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); |
309
|
|
|
|
310
|
|
|
$this->assertSame($response->headers->get('Content-Type'), 'application/json'); |
311
|
|
|
$this->assertSame(json_encode($data), $response->getContent()); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function testRenderJsonAjax(): void |
315
|
|
|
{ |
316
|
|
|
$data = ['example' => '123', 'foo' => 'bar']; |
317
|
|
|
|
318
|
|
|
$this->request->attributes->set('_xml_http_request', true); |
319
|
|
|
$this->request->headers->set('Content-Type', 'multipart/form-data'); |
320
|
|
|
$response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); |
321
|
|
|
|
322
|
|
|
$this->assertSame($response->headers->get('Content-Type'), 'application/json'); |
323
|
|
|
$this->assertSame(json_encode($data), $response->getContent()); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public function testIsXmlHttpRequest(): void |
327
|
|
|
{ |
328
|
|
|
$this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request)); |
329
|
|
|
|
330
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
331
|
|
|
|
332
|
|
|
$this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request)); |
333
|
|
|
|
334
|
|
|
$this->request->headers->remove('X-Requested-With'); |
335
|
|
|
$this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request)); |
336
|
|
|
|
337
|
|
|
$this->request->attributes->set('_xml_http_request', true); |
338
|
|
|
$this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request)); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function testConfigure(): void |
342
|
|
|
{ |
343
|
|
|
$uniqueId = ''; |
344
|
|
|
|
345
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
346
|
|
|
->method('setUniqid') |
347
|
|
|
->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void { |
348
|
|
|
$uniqueId = $uniqid; |
349
|
|
|
}); |
350
|
|
|
|
351
|
|
|
$this->request->query->set('uniqid', '123456'); |
352
|
|
|
$this->protectedTestedMethods['configure']->invoke($this->controller); |
353
|
|
|
|
354
|
|
|
$this->assertSame('123456', $uniqueId); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
public function testConfigureChild(): void |
358
|
|
|
{ |
359
|
|
|
$uniqueId = ''; |
360
|
|
|
|
361
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
362
|
|
|
->method('setUniqid') |
363
|
|
|
->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void { |
364
|
|
|
$uniqueId = $uniqid; |
365
|
|
|
}); |
366
|
|
|
|
367
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
368
|
|
|
->method('isChild') |
369
|
|
|
->willReturn(true); |
370
|
|
|
|
371
|
|
|
$adminParent = $this->getMockBuilder(AdminInterface::class) |
372
|
|
|
->disableOriginalConstructor() |
373
|
|
|
->getMock(); |
374
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
375
|
|
|
->method('getParent') |
376
|
|
|
->willReturn($adminParent); |
377
|
|
|
|
378
|
|
|
$this->request->query->set('uniqid', '123456'); |
379
|
|
|
$this->protectedTestedMethods['configure']->invoke($this->controller); |
380
|
|
|
|
381
|
|
|
$this->assertSame('123456', $uniqueId); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
public function testConfigureWithException(): void |
385
|
|
|
{ |
386
|
|
|
$this->expectException(\RuntimeException::class); |
387
|
|
|
$this->expectExceptionMessage( |
388
|
|
|
'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`' |
389
|
|
|
); |
390
|
|
|
|
391
|
|
|
$this->request->attributes->remove('_sonata_admin'); |
392
|
|
|
$this->protectedTestedMethods['configure']->invoke($this->controller); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
public function testConfigureWithException2(): void |
396
|
|
|
{ |
397
|
|
|
$this->expectException(\RuntimeException::class); |
398
|
|
|
$this->expectExceptionMessage('Unable to find the admin class related to the current controller'); |
399
|
|
|
|
400
|
|
|
$this->pool->setAdminServiceIds(['nonexistent.admin']); |
401
|
|
|
$this->request->attributes->set('_sonata_admin', 'nonexistent.admin'); |
402
|
|
|
|
403
|
|
|
$this->protectedTestedMethods['configure']->invoke($this->controller); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
public function testGetBaseTemplate(): void |
407
|
|
|
{ |
408
|
|
|
$this->assertSame( |
409
|
|
|
'@SonataAdmin/standard_layout.html.twig', |
410
|
|
|
$this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request) |
411
|
|
|
); |
412
|
|
|
|
413
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
414
|
|
|
$this->assertSame( |
415
|
|
|
'@SonataAdmin/ajax_layout.html.twig', |
416
|
|
|
$this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request) |
417
|
|
|
); |
418
|
|
|
|
419
|
|
|
$this->request->headers->remove('X-Requested-With'); |
420
|
|
|
$this->assertSame( |
421
|
|
|
'@SonataAdmin/standard_layout.html.twig', |
422
|
|
|
$this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request) |
423
|
|
|
); |
424
|
|
|
|
425
|
|
|
$this->request->attributes->set('_xml_http_request', true); |
426
|
|
|
$this->assertSame( |
427
|
|
|
'@SonataAdmin/ajax_layout.html.twig', |
428
|
|
|
$this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request) |
429
|
|
|
); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
public function testRender(): void |
433
|
|
|
{ |
434
|
|
|
$this->parameters = []; |
435
|
|
|
$this->assertInstanceOf( |
436
|
|
|
Response::class, |
437
|
|
|
$this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', []) |
438
|
|
|
); |
439
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
440
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
441
|
|
|
$this->assertSame('@FooAdmin/foo.html.twig', $this->template); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function testRenderWithResponse(): void |
445
|
|
|
{ |
446
|
|
|
$this->parameters = []; |
447
|
|
|
$response = new Response(); |
448
|
|
|
$response->headers->set('X-foo', 'bar'); |
449
|
|
|
$responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response); |
450
|
|
|
|
451
|
|
|
$this->assertSame($response, $responseResult); |
452
|
|
|
$this->assertSame('bar', $responseResult->headers->get('X-foo')); |
453
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
454
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
455
|
|
|
$this->assertSame('@FooAdmin/foo.html.twig', $this->template); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
public function testRenderCustomParams(): void |
459
|
|
|
{ |
460
|
|
|
$this->parameters = []; |
461
|
|
|
$this->assertInstanceOf( |
462
|
|
|
Response::class, |
463
|
|
|
$this->controller->renderWithExtraParams( |
464
|
|
|
'@FooAdmin/foo.html.twig', |
465
|
|
|
['foo' => 'bar'], |
466
|
|
|
null |
467
|
|
|
) |
468
|
|
|
); |
469
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
470
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
471
|
|
|
$this->assertSame('bar', $this->parameters['foo']); |
472
|
|
|
$this->assertSame('@FooAdmin/foo.html.twig', $this->template); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
public function testRenderAjax(): void |
476
|
|
|
{ |
477
|
|
|
$this->parameters = []; |
478
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
479
|
|
|
$this->assertInstanceOf( |
480
|
|
|
Response::class, |
481
|
|
|
$this->controller->renderWithExtraParams( |
482
|
|
|
'@FooAdmin/foo.html.twig', |
483
|
|
|
['foo' => 'bar'], |
484
|
|
|
null |
485
|
|
|
) |
486
|
|
|
); |
487
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
488
|
|
|
$this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']); |
489
|
|
|
$this->assertSame('bar', $this->parameters['foo']); |
490
|
|
|
$this->assertSame('@FooAdmin/foo.html.twig', $this->template); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
public function testListActionAccessDenied(): void |
494
|
|
|
{ |
495
|
|
|
$this->expectException(AccessDeniedException::class); |
496
|
|
|
|
497
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
498
|
|
|
->method('checkAccess') |
499
|
|
|
->with($this->equalTo('list')) |
500
|
|
|
->will($this->throwException(new AccessDeniedException())); |
501
|
|
|
|
502
|
|
|
$this->controller->listAction($this->request); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
public function testPreList(): void |
506
|
|
|
{ |
507
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
|
|
|
|
508
|
|
|
|
509
|
|
|
$this->admin |
|
|
|
|
510
|
|
|
->method('hasRoute') |
511
|
|
|
->with($this->equalTo('list')) |
512
|
|
|
->willReturn(true); |
513
|
|
|
|
514
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
515
|
|
|
->method('checkAccess') |
516
|
|
|
->with($this->equalTo('list')); |
517
|
|
|
|
518
|
|
|
$controller = $this->createController(PreCRUDController::class); |
519
|
|
|
|
520
|
|
|
$response = $controller->listAction($this->request); |
521
|
|
|
$this->assertInstanceOf(Response::class, $response); |
522
|
|
|
$this->assertSame('preList called', $response->getContent()); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
public function testListAction(): void |
526
|
|
|
{ |
527
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
528
|
|
|
|
529
|
|
|
$this->admin |
|
|
|
|
530
|
|
|
->method('hasRoute') |
531
|
|
|
->with($this->equalTo('list')) |
532
|
|
|
->willReturn(true); |
533
|
|
|
|
534
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
535
|
|
|
->method('checkAccess') |
536
|
|
|
->with($this->equalTo('list')); |
537
|
|
|
|
538
|
|
|
$form = $this->getMockBuilder(Form::class) |
539
|
|
|
->disableOriginalConstructor() |
540
|
|
|
->getMock(); |
541
|
|
|
|
542
|
|
|
$form->expects($this->once()) |
543
|
|
|
->method('createView') |
544
|
|
|
->willReturn($this->createMock(FormView::class)); |
545
|
|
|
|
546
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
547
|
|
|
->method('getDatagrid') |
548
|
|
|
->willReturn($datagrid); |
549
|
|
|
|
550
|
|
|
$datagrid->expects($this->once()) |
551
|
|
|
->method('getForm') |
552
|
|
|
->willReturn($form); |
553
|
|
|
|
554
|
|
|
$this->parameters = []; |
555
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->listAction($this->request)); |
556
|
|
|
|
557
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
558
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
559
|
|
|
|
560
|
|
|
$this->assertSame('list', $this->parameters['action']); |
561
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
562
|
|
|
$this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']); |
563
|
|
|
$this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']); |
564
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
565
|
|
|
$this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
public function testBatchActionDeleteAccessDenied(): void |
569
|
|
|
{ |
570
|
|
|
$this->expectException(AccessDeniedException::class); |
571
|
|
|
|
572
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
573
|
|
|
->method('checkAccess') |
574
|
|
|
->with($this->equalTo('batchDelete')) |
575
|
|
|
->will($this->throwException(new AccessDeniedException())); |
576
|
|
|
|
577
|
|
|
$this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
public function testBatchActionDelete(): void |
581
|
|
|
{ |
582
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
583
|
|
|
|
584
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
585
|
|
|
->method('checkAccess') |
586
|
|
|
->with($this->equalTo('batchDelete')); |
587
|
|
|
|
588
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
589
|
|
|
->method('getModelManager') |
590
|
|
|
->willReturn($modelManager); |
591
|
|
|
|
592
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
593
|
|
|
->method('getFilterParameters') |
594
|
|
|
->willReturn(['foo' => 'bar']); |
595
|
|
|
|
596
|
|
|
$this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle'); |
597
|
|
|
|
598
|
|
|
$result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); |
599
|
|
|
|
600
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
601
|
|
|
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
602
|
|
|
$this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl()); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
public function testBatchActionDeleteWithModelManagerException(): void |
606
|
|
|
{ |
607
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
608
|
|
|
$this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete'); |
609
|
|
|
|
610
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
611
|
|
|
->method('getModelManager') |
612
|
|
|
->willReturn($modelManager); |
613
|
|
|
|
614
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
615
|
|
|
->method('getFilterParameters') |
616
|
|
|
->willReturn(['foo' => 'bar']); |
617
|
|
|
|
618
|
|
|
$this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle'); |
619
|
|
|
|
620
|
|
|
$result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); |
621
|
|
|
|
622
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
623
|
|
|
$this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error')); |
624
|
|
|
$this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl()); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void |
628
|
|
|
{ |
629
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
630
|
|
|
$this->expectException(ModelManagerException::class); |
631
|
|
|
|
632
|
|
|
$modelManager->expects($this->once()) |
633
|
|
|
->method('batchDelete') |
634
|
|
|
->willReturnCallback(static function (): void { |
635
|
|
|
throw new ModelManagerException(); |
636
|
|
|
}); |
637
|
|
|
|
638
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
639
|
|
|
->method('getModelManager') |
640
|
|
|
->willReturn($modelManager); |
641
|
|
|
|
642
|
|
|
$this->controller = $this->createController(CRUDController::class, true); |
643
|
|
|
|
644
|
|
|
$this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
public function testShowActionNotFoundException(): void |
648
|
|
|
{ |
649
|
|
|
$this->expectException(NotFoundHttpException::class); |
650
|
|
|
|
651
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
652
|
|
|
->method('getObject') |
653
|
|
|
->willReturn(null); |
654
|
|
|
|
655
|
|
|
$this->controller->showAction($this->request); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
public function testShowActionAccessDenied(): void |
659
|
|
|
{ |
660
|
|
|
$this->expectException(AccessDeniedException::class); |
661
|
|
|
|
662
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
663
|
|
|
->method('getObject') |
664
|
|
|
->willReturn(new \stdClass()); |
665
|
|
|
|
666
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
667
|
|
|
->method('checkAccess') |
668
|
|
|
->with($this->equalTo('show')) |
669
|
|
|
->will($this->throwException(new AccessDeniedException())); |
670
|
|
|
|
671
|
|
|
$this->controller->showAction($this->request); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
public function testPreShow(): void |
675
|
|
|
{ |
676
|
|
|
$object = new \stdClass(); |
677
|
|
|
$object->foo = 123456; |
678
|
|
|
|
679
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
680
|
|
|
->method('getObject') |
681
|
|
|
->willReturn($object); |
682
|
|
|
|
683
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
684
|
|
|
->method('checkAccess') |
685
|
|
|
->with($this->equalTo('show')); |
686
|
|
|
|
687
|
|
|
$this->container->set('foo.admin', $this->admin); |
688
|
|
|
$controller = $this->createController(PreCRUDController::class); |
689
|
|
|
|
690
|
|
|
$response = $controller->showAction($this->request); |
691
|
|
|
$this->assertInstanceOf(Response::class, $response); |
692
|
|
|
$this->assertSame('preShow called: 123456', $response->getContent()); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
public function testShowAction(): void |
696
|
|
|
{ |
697
|
|
|
$object = new \stdClass(); |
698
|
|
|
|
699
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
700
|
|
|
->method('getObject') |
701
|
|
|
->willReturn($object); |
702
|
|
|
|
703
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
704
|
|
|
->method('checkAccess') |
705
|
|
|
->with($this->equalTo('show')); |
706
|
|
|
|
707
|
|
|
$show = new FieldDescriptionCollection(); |
708
|
|
|
|
709
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
710
|
|
|
->method('getShow') |
711
|
|
|
->willReturn($show); |
712
|
|
|
|
713
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->showAction($this->request)); |
714
|
|
|
|
715
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
716
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
717
|
|
|
|
718
|
|
|
$this->assertSame('show', $this->parameters['action']); |
719
|
|
|
$this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']); |
720
|
|
|
$this->assertSame($object, $this->parameters['object']); |
721
|
|
|
|
722
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
723
|
|
|
$this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* @dataProvider getRedirectToTests |
728
|
|
|
*/ |
729
|
|
|
public function testRedirectTo( |
730
|
|
|
string $expected, |
731
|
|
|
string $route, |
732
|
|
|
array $queryParams, |
733
|
|
|
array $requestParams, |
734
|
|
|
bool $hasActiveSubclass |
735
|
|
|
): void { |
736
|
|
|
$this->admin |
|
|
|
|
737
|
|
|
->method('hasActiveSubclass') |
738
|
|
|
->willReturn($hasActiveSubclass); |
739
|
|
|
|
740
|
|
|
$object = new \stdClass(); |
741
|
|
|
|
742
|
|
|
foreach ($queryParams as $key => $value) { |
743
|
|
|
$this->request->query->set($key, $value); |
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
foreach ($requestParams as $key => $value) { |
747
|
|
|
$this->request->request->set($key, $value); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
$this->admin |
|
|
|
|
751
|
|
|
->method('hasRoute') |
752
|
|
|
->with($this->equalTo($route)) |
753
|
|
|
->willReturn(true); |
754
|
|
|
|
755
|
|
|
$this->admin |
|
|
|
|
756
|
|
|
->method('hasAccess') |
757
|
|
|
->with($this->equalTo($route)) |
758
|
|
|
->willReturn(true); |
759
|
|
|
|
760
|
|
|
$response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request); |
761
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
762
|
|
|
$this->assertSame($expected, $response->getTargetUrl()); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
public function testRedirectToWithObject(): void |
766
|
|
|
{ |
767
|
|
|
$this->admin |
|
|
|
|
768
|
|
|
->method('hasActiveSubclass') |
769
|
|
|
->willReturn(false); |
770
|
|
|
|
771
|
|
|
$object = new \stdClass(); |
772
|
|
|
|
773
|
|
|
$this->admin->expects($this->at(0)) |
|
|
|
|
774
|
|
|
->method('hasRoute') |
775
|
|
|
->with($this->equalTo('edit')) |
776
|
|
|
->willReturn(true); |
777
|
|
|
|
778
|
|
|
$this->admin |
|
|
|
|
779
|
|
|
->method('hasAccess') |
780
|
|
|
->with($this->equalTo('edit'), $object) |
781
|
|
|
->willReturn(false); |
782
|
|
|
|
783
|
|
|
$response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request); |
784
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
785
|
|
|
$this->assertSame('list', $response->getTargetUrl()); |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
public function getRedirectToTests() |
789
|
|
|
{ |
790
|
|
|
return [ |
791
|
|
|
['stdClass_edit', 'edit', [], [], false], |
792
|
|
|
['list', 'list', ['btn_update_and_list' => true], [], false], |
793
|
|
|
['list', 'list', ['btn_create_and_list' => true], [], false], |
794
|
|
|
['create', 'create', ['btn_create_and_create' => true], [], false], |
795
|
|
|
['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true], |
796
|
|
|
['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false], |
797
|
|
|
]; |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
public function testDeleteActionNotFoundException(): void |
801
|
|
|
{ |
802
|
|
|
$this->expectException(NotFoundHttpException::class); |
803
|
|
|
|
804
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
805
|
|
|
->method('getObject') |
806
|
|
|
->willReturn(null); |
807
|
|
|
|
808
|
|
|
$this->controller->deleteAction($this->request); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
public function testDeleteActionAccessDenied(): void |
812
|
|
|
{ |
813
|
|
|
$this->expectException(AccessDeniedException::class); |
814
|
|
|
|
815
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
816
|
|
|
->method('getObject') |
817
|
|
|
->willReturn(new \stdClass()); |
818
|
|
|
|
819
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
820
|
|
|
->method('checkAccess') |
821
|
|
|
->with($this->equalTo('delete')) |
822
|
|
|
->will($this->throwException(new AccessDeniedException())); |
823
|
|
|
|
824
|
|
|
$this->controller->deleteAction($this->request); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
public function testPreDelete(): void |
828
|
|
|
{ |
829
|
|
|
$object = new \stdClass(); |
830
|
|
|
$object->foo = 123456; |
831
|
|
|
|
832
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
833
|
|
|
->method('getObject') |
834
|
|
|
->willReturn($object); |
835
|
|
|
|
836
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
837
|
|
|
->method('checkAccess') |
838
|
|
|
->with($this->equalTo('delete')); |
839
|
|
|
|
840
|
|
|
$controller = $this->createController(PreCRUDController::class); |
841
|
|
|
|
842
|
|
|
$response = $controller->deleteAction($this->request); |
843
|
|
|
$this->assertInstanceOf(Response::class, $response); |
844
|
|
|
$this->assertSame('preDelete called: 123456', $response->getContent()); |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
public function testDeleteAction(): void |
848
|
|
|
{ |
849
|
|
|
$object = new \stdClass(); |
850
|
|
|
|
851
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
852
|
|
|
->method('getObject') |
853
|
|
|
->willReturn($object); |
854
|
|
|
|
855
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
856
|
|
|
->method('checkAccess') |
857
|
|
|
->with($this->equalTo('delete')); |
858
|
|
|
|
859
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request)); |
860
|
|
|
|
861
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
862
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
863
|
|
|
|
864
|
|
|
$this->assertSame('delete', $this->parameters['action']); |
865
|
|
|
$this->assertSame($object, $this->parameters['object']); |
866
|
|
|
$this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']); |
867
|
|
|
|
868
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
869
|
|
|
$this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template); |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
public function testDeleteActionNoCsrfToken(): void |
873
|
|
|
{ |
874
|
|
|
$this->csrfProvider = null; |
875
|
|
|
|
876
|
|
|
$object = new \stdClass(); |
877
|
|
|
|
878
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
879
|
|
|
->method('getObject') |
880
|
|
|
->willReturn($object); |
881
|
|
|
|
882
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
883
|
|
|
->method('checkAccess') |
884
|
|
|
->with($this->equalTo('delete')); |
885
|
|
|
|
886
|
|
|
$controller = $this->createController(); |
887
|
|
|
|
888
|
|
|
$this->assertInstanceOf(Response::class, $controller->deleteAction($this->request)); |
889
|
|
|
|
890
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
891
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
892
|
|
|
|
893
|
|
|
$this->assertSame('delete', $this->parameters['action']); |
894
|
|
|
$this->assertSame($object, $this->parameters['object']); |
895
|
|
|
$this->assertFalse($this->parameters['csrf_token']); |
896
|
|
|
|
897
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
898
|
|
|
$this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template); |
899
|
|
|
} |
900
|
|
|
|
901
|
|
|
public function testDeleteActionAjaxSuccess1(): void |
902
|
|
|
{ |
903
|
|
|
$object = new \stdClass(); |
904
|
|
|
|
905
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
906
|
|
|
->method('getObject') |
907
|
|
|
->willReturn($object); |
908
|
|
|
|
909
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
910
|
|
|
->method('checkAccess') |
911
|
|
|
->with($this->equalTo('delete')); |
912
|
|
|
|
913
|
|
|
$this->request->setMethod(Request::METHOD_DELETE); |
914
|
|
|
|
915
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
916
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
917
|
|
|
|
918
|
|
|
$response = $this->controller->deleteAction($this->request); |
919
|
|
|
|
920
|
|
|
$this->assertInstanceOf(Response::class, $response); |
921
|
|
|
$this->assertSame(json_encode(['result' => 'ok']), $response->getContent()); |
922
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
public function testDeleteActionAjaxSuccess2(): void |
926
|
|
|
{ |
927
|
|
|
$object = new \stdClass(); |
928
|
|
|
|
929
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
930
|
|
|
->method('getObject') |
931
|
|
|
->willReturn($object); |
932
|
|
|
|
933
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
934
|
|
|
->method('checkAccess') |
935
|
|
|
->with($this->equalTo('delete')); |
936
|
|
|
|
937
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
938
|
|
|
$this->request->request->set('_method', Request::METHOD_DELETE); |
939
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
940
|
|
|
|
941
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
942
|
|
|
|
943
|
|
|
$response = $this->controller->deleteAction($this->request); |
944
|
|
|
|
945
|
|
|
$this->assertInstanceOf(Response::class, $response); |
946
|
|
|
$this->assertSame(json_encode(['result' => 'ok']), $response->getContent()); |
947
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
public function testDeleteActionAjaxError(): void |
951
|
|
|
{ |
952
|
|
|
$object = new \stdClass(); |
953
|
|
|
|
954
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
955
|
|
|
->method('getObject') |
956
|
|
|
->willReturn($object); |
957
|
|
|
|
958
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
959
|
|
|
->method('checkAccess') |
960
|
|
|
->with($this->equalTo('delete')); |
961
|
|
|
|
962
|
|
|
$this->admin |
|
|
|
|
963
|
|
|
->method('getClass') |
964
|
|
|
->willReturn(\stdClass::class); |
965
|
|
|
|
966
|
|
|
$this->assertLoggerLogsModelManagerException($this->admin, 'delete'); |
967
|
|
|
|
968
|
|
|
$this->request->setMethod(Request::METHOD_DELETE); |
969
|
|
|
|
970
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
971
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
972
|
|
|
|
973
|
|
|
$response = $this->controller->deleteAction($this->request); |
974
|
|
|
|
975
|
|
|
$this->assertInstanceOf(Response::class, $response); |
976
|
|
|
$this->assertSame(json_encode(['result' => 'error']), $response->getContent()); |
977
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
978
|
|
|
} |
979
|
|
|
|
980
|
|
|
public function testDeleteActionWithModelManagerExceptionInDebugMode(): void |
981
|
|
|
{ |
982
|
|
|
$this->expectException(ModelManagerException::class); |
983
|
|
|
|
984
|
|
|
$object = new \stdClass(); |
985
|
|
|
|
986
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
987
|
|
|
->method('getObject') |
988
|
|
|
->willReturn($object); |
989
|
|
|
|
990
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
991
|
|
|
->method('checkAccess') |
992
|
|
|
->with($this->equalTo('delete')); |
993
|
|
|
|
994
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
995
|
|
|
->method('delete') |
996
|
|
|
->willReturnCallback(static function (): void { |
997
|
|
|
throw new ModelManagerException(); |
998
|
|
|
}); |
999
|
|
|
|
1000
|
|
|
$this->controller = $this->createController(CRUDController::class, true); |
1001
|
|
|
|
1002
|
|
|
$this->request->setMethod(Request::METHOD_DELETE); |
1003
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
1004
|
|
|
|
1005
|
|
|
$this->controller->deleteAction($this->request); |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
/** |
1009
|
|
|
* @dataProvider getToStringValues |
1010
|
|
|
*/ |
1011
|
|
|
public function testDeleteActionSuccess1(string $expectedToStringValue, string $toStringValue): void |
1012
|
|
|
{ |
1013
|
|
|
$object = new \stdClass(); |
1014
|
|
|
|
1015
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1016
|
|
|
->method('getObject') |
1017
|
|
|
->willReturn($object); |
1018
|
|
|
|
1019
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1020
|
|
|
->method('toString') |
1021
|
|
|
->with($this->equalTo($object)) |
1022
|
|
|
->willReturn($toStringValue); |
1023
|
|
|
|
1024
|
|
|
$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1025
|
|
|
|
1026
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1027
|
|
|
->method('checkAccess') |
1028
|
|
|
->with($this->equalTo('delete')); |
1029
|
|
|
|
1030
|
|
|
$this->request->setMethod(Request::METHOD_DELETE); |
1031
|
|
|
|
1032
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
1033
|
|
|
|
1034
|
|
|
$response = $this->controller->deleteAction($this->request); |
1035
|
|
|
|
1036
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1037
|
|
|
$this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
1038
|
|
|
$this->assertSame('list', $response->getTargetUrl()); |
1039
|
|
|
} |
1040
|
|
|
|
1041
|
|
|
/** |
1042
|
|
|
* @dataProvider getToStringValues |
1043
|
|
|
*/ |
1044
|
|
|
public function testDeleteActionSuccess2(string $expectedToStringValue, string $toStringValue): void |
1045
|
|
|
{ |
1046
|
|
|
$object = new \stdClass(); |
1047
|
|
|
|
1048
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1049
|
|
|
->method('getObject') |
1050
|
|
|
->willReturn($object); |
1051
|
|
|
|
1052
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1053
|
|
|
->method('checkAccess') |
1054
|
|
|
->with($this->equalTo('delete')); |
1055
|
|
|
|
1056
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1057
|
|
|
->method('toString') |
1058
|
|
|
->with($this->equalTo($object)) |
1059
|
|
|
->willReturn($toStringValue); |
1060
|
|
|
|
1061
|
|
|
$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1062
|
|
|
|
1063
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1064
|
|
|
$this->request->request->set('_method', Request::METHOD_DELETE); |
1065
|
|
|
|
1066
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
1067
|
|
|
|
1068
|
|
|
$response = $this->controller->deleteAction($this->request); |
1069
|
|
|
|
1070
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1071
|
|
|
$this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
1072
|
|
|
$this->assertSame('list', $response->getTargetUrl()); |
1073
|
|
|
} |
1074
|
|
|
|
1075
|
|
|
/** |
1076
|
|
|
* @dataProvider getToStringValues |
1077
|
|
|
*/ |
1078
|
|
|
public function testDeleteActionSuccessNoCsrfTokenProvider(string $expectedToStringValue, string $toStringValue): void |
1079
|
|
|
{ |
1080
|
|
|
$this->csrfProvider = null; |
1081
|
|
|
|
1082
|
|
|
$object = new \stdClass(); |
1083
|
|
|
|
1084
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1085
|
|
|
->method('getObject') |
1086
|
|
|
->willReturn($object); |
1087
|
|
|
|
1088
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1089
|
|
|
->method('checkAccess') |
1090
|
|
|
->with($this->equalTo('delete')); |
1091
|
|
|
|
1092
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1093
|
|
|
->method('toString') |
1094
|
|
|
->with($this->equalTo($object)) |
1095
|
|
|
->willReturn($toStringValue); |
1096
|
|
|
|
1097
|
|
|
$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1098
|
|
|
|
1099
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1100
|
|
|
$this->request->request->set('_method', Request::METHOD_DELETE); |
1101
|
|
|
|
1102
|
|
|
$this->controller = $this->createController(); |
1103
|
|
|
$response = $this->controller->deleteAction($this->request); |
1104
|
|
|
|
1105
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1106
|
|
|
$this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
1107
|
|
|
$this->assertSame('list', $response->getTargetUrl()); |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
|
public function testDeleteActionWrongRequestMethod(): void |
1111
|
|
|
{ |
1112
|
|
|
$object = new \stdClass(); |
1113
|
|
|
|
1114
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1115
|
|
|
->method('getObject') |
1116
|
|
|
->willReturn($object); |
1117
|
|
|
|
1118
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1119
|
|
|
->method('checkAccess') |
1120
|
|
|
->with($this->equalTo('delete')); |
1121
|
|
|
|
1122
|
|
|
//without POST request parameter "_method" should not be used as real REST method |
1123
|
|
|
$this->request->query->set('_method', Request::METHOD_DELETE); |
1124
|
|
|
|
1125
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request)); |
1126
|
|
|
|
1127
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1128
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1129
|
|
|
|
1130
|
|
|
$this->assertSame('delete', $this->parameters['action']); |
1131
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1132
|
|
|
$this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']); |
1133
|
|
|
|
1134
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
1135
|
|
|
$this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template); |
1136
|
|
|
} |
1137
|
|
|
|
1138
|
|
|
/** |
1139
|
|
|
* @dataProvider getToStringValues |
1140
|
|
|
*/ |
1141
|
|
|
public function testDeleteActionError(string $expectedToStringValue, string $toStringValue): void |
1142
|
|
|
{ |
1143
|
|
|
$object = new \stdClass(); |
1144
|
|
|
|
1145
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1146
|
|
|
->method('getObject') |
1147
|
|
|
->willReturn($object); |
1148
|
|
|
|
1149
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1150
|
|
|
->method('checkAccess') |
1151
|
|
|
->with($this->equalTo('delete')); |
1152
|
|
|
|
1153
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1154
|
|
|
->method('toString') |
1155
|
|
|
->with($this->equalTo($object)) |
1156
|
|
|
->willReturn($toStringValue); |
1157
|
|
|
|
1158
|
|
|
$this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1159
|
|
|
|
1160
|
|
|
$this->assertLoggerLogsModelManagerException($this->admin, 'delete'); |
1161
|
|
|
|
1162
|
|
|
$this->request->setMethod(Request::METHOD_DELETE); |
1163
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete'); |
1164
|
|
|
|
1165
|
|
|
$response = $this->controller->deleteAction($this->request); |
1166
|
|
|
|
1167
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1168
|
|
|
$this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error')); |
1169
|
|
|
$this->assertSame('list', $response->getTargetUrl()); |
1170
|
|
|
} |
1171
|
|
|
|
1172
|
|
|
public function testDeleteActionInvalidCsrfToken(): void |
1173
|
|
|
{ |
1174
|
|
|
$object = new \stdClass(); |
1175
|
|
|
|
1176
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1177
|
|
|
->method('getObject') |
1178
|
|
|
->willReturn($object); |
1179
|
|
|
|
1180
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1181
|
|
|
->method('checkAccess') |
1182
|
|
|
->with($this->equalTo('delete')); |
1183
|
|
|
|
1184
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1185
|
|
|
$this->request->request->set('_method', Request::METHOD_DELETE); |
1186
|
|
|
$this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID'); |
1187
|
|
|
|
1188
|
|
|
try { |
1189
|
|
|
$this->controller->deleteAction($this->request); |
1190
|
|
|
} catch (HttpException $e) { |
1191
|
|
|
$this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage()); |
1192
|
|
|
$this->assertSame(400, $e->getStatusCode()); |
1193
|
|
|
} |
1194
|
|
|
} |
1195
|
|
|
|
1196
|
|
|
public function testEditActionNotFoundException(): void |
1197
|
|
|
{ |
1198
|
|
|
$this->expectException(NotFoundHttpException::class); |
1199
|
|
|
|
1200
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1201
|
|
|
->method('getObject') |
1202
|
|
|
->willReturn(null); |
1203
|
|
|
|
1204
|
|
|
$this->controller->editAction($this->request); |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
public function testEditActionAccessDenied(): void |
1208
|
|
|
{ |
1209
|
|
|
$this->expectException(AccessDeniedException::class); |
1210
|
|
|
|
1211
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1212
|
|
|
->method('getObject') |
1213
|
|
|
->willReturn(new \stdClass()); |
1214
|
|
|
|
1215
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1216
|
|
|
->method('checkAccess') |
1217
|
|
|
->with($this->equalTo('edit')) |
1218
|
|
|
->will($this->throwException(new AccessDeniedException())); |
1219
|
|
|
|
1220
|
|
|
$this->controller->editAction($this->request); |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
public function testPreEdit(): void |
1224
|
|
|
{ |
1225
|
|
|
$object = new \stdClass(); |
1226
|
|
|
$object->foo = 123456; |
1227
|
|
|
|
1228
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1229
|
|
|
->method('getObject') |
1230
|
|
|
->willReturn($object); |
1231
|
|
|
|
1232
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1233
|
|
|
->method('checkAccess') |
1234
|
|
|
->with($this->equalTo('edit')); |
1235
|
|
|
|
1236
|
|
|
$controller = $this->createController(PreCRUDController::class); |
1237
|
|
|
|
1238
|
|
|
$response = $controller->editAction($this->request); |
1239
|
|
|
$this->assertInstanceOf(Response::class, $response); |
1240
|
|
|
$this->assertSame('preEdit called: 123456', $response->getContent()); |
1241
|
|
|
} |
1242
|
|
|
|
1243
|
|
|
public function testEditAction(): void |
1244
|
|
|
{ |
1245
|
|
|
$object = new \stdClass(); |
1246
|
|
|
|
1247
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1248
|
|
|
->method('getObject') |
1249
|
|
|
->willReturn($object); |
1250
|
|
|
|
1251
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1252
|
|
|
->method('checkAccess') |
1253
|
|
|
->with($this->equalTo('edit')); |
1254
|
|
|
|
1255
|
|
|
$form = $this->createMock(Form::class); |
1256
|
|
|
|
1257
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1258
|
|
|
->method('getForm') |
1259
|
|
|
->willReturn($form); |
1260
|
|
|
|
1261
|
|
|
$formView = $this->createMock(FormView::class); |
1262
|
|
|
|
1263
|
|
|
$form |
1264
|
|
|
->method('createView') |
1265
|
|
|
->willReturn($formView); |
1266
|
|
|
|
1267
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->editAction($this->request)); |
1268
|
|
|
|
1269
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1270
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1271
|
|
|
|
1272
|
|
|
$this->assertSame('edit', $this->parameters['action']); |
1273
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1274
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1275
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
1276
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* @dataProvider getToStringValues |
1281
|
|
|
*/ |
1282
|
|
|
public function testEditActionSuccess(string $expectedToStringValue, string $toStringValue): void |
1283
|
|
|
{ |
1284
|
|
|
$object = new \stdClass(); |
1285
|
|
|
|
1286
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1287
|
|
|
->method('getObject') |
1288
|
|
|
->willReturn($object); |
1289
|
|
|
|
1290
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1291
|
|
|
->method('update') |
1292
|
|
|
->willReturnArgument(0); |
1293
|
|
|
|
1294
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1295
|
|
|
->method('checkAccess') |
1296
|
|
|
->with($this->equalTo('edit')); |
1297
|
|
|
|
1298
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1299
|
|
|
->method('hasRoute') |
1300
|
|
|
->with($this->equalTo('edit')) |
1301
|
|
|
->willReturn(true); |
1302
|
|
|
|
1303
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1304
|
|
|
->method('hasAccess') |
1305
|
|
|
->with($this->equalTo('edit')) |
1306
|
|
|
->willReturn(true); |
1307
|
|
|
|
1308
|
|
|
$form = $this->createMock(Form::class); |
1309
|
|
|
|
1310
|
|
|
$form->expects($this->once()) |
1311
|
|
|
->method('getData') |
1312
|
|
|
->willReturn($object); |
1313
|
|
|
|
1314
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1315
|
|
|
->method('getForm') |
1316
|
|
|
->willReturn($form); |
1317
|
|
|
|
1318
|
|
|
$form->expects($this->once()) |
1319
|
|
|
->method('isSubmitted') |
1320
|
|
|
->willReturn(true); |
1321
|
|
|
|
1322
|
|
|
$form->expects($this->once()) |
1323
|
|
|
->method('isValid') |
1324
|
|
|
->willReturn(true); |
1325
|
|
|
|
1326
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1327
|
|
|
->method('toString') |
1328
|
|
|
->with($this->equalTo($object)) |
1329
|
|
|
->willReturn($toStringValue); |
1330
|
|
|
|
1331
|
|
|
$this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1332
|
|
|
|
1333
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1334
|
|
|
|
1335
|
|
|
$response = $this->controller->editAction($this->request); |
1336
|
|
|
|
1337
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1338
|
|
|
$this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
1339
|
|
|
$this->assertSame('stdClass_edit', $response->getTargetUrl()); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
/** |
1343
|
|
|
* @dataProvider getToStringValues |
1344
|
|
|
*/ |
1345
|
|
|
public function testEditActionError(string $expectedToStringValue, string $toStringValue): void |
1346
|
|
|
{ |
1347
|
|
|
$object = new \stdClass(); |
1348
|
|
|
|
1349
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1350
|
|
|
->method('getObject') |
1351
|
|
|
->willReturn($object); |
1352
|
|
|
|
1353
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1354
|
|
|
->method('checkAccess') |
1355
|
|
|
->with($this->equalTo('edit')); |
1356
|
|
|
|
1357
|
|
|
$form = $this->createMock(Form::class); |
1358
|
|
|
|
1359
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1360
|
|
|
->method('getForm') |
1361
|
|
|
->willReturn($form); |
1362
|
|
|
|
1363
|
|
|
$form->expects($this->once()) |
1364
|
|
|
->method('isSubmitted') |
1365
|
|
|
->willReturn(true); |
1366
|
|
|
|
1367
|
|
|
$form->expects($this->once()) |
1368
|
|
|
->method('isValid') |
1369
|
|
|
->willReturn(false); |
1370
|
|
|
|
1371
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1372
|
|
|
->method('toString') |
1373
|
|
|
->with($this->equalTo($object)) |
1374
|
|
|
->willReturn($toStringValue); |
1375
|
|
|
|
1376
|
|
|
$this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1377
|
|
|
|
1378
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1379
|
|
|
|
1380
|
|
|
$formView = $this->createMock(FormView::class); |
1381
|
|
|
|
1382
|
|
|
$form |
1383
|
|
|
->method('createView') |
1384
|
|
|
->willReturn($formView); |
1385
|
|
|
|
1386
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->editAction($this->request)); |
1387
|
|
|
|
1388
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1389
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1390
|
|
|
|
1391
|
|
|
$this->assertSame('edit', $this->parameters['action']); |
1392
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1393
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1394
|
|
|
|
1395
|
|
|
$this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all()); |
1396
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
public function testEditActionAjaxSuccess(): void |
1400
|
|
|
{ |
1401
|
|
|
$object = new \stdClass(); |
1402
|
|
|
|
1403
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1404
|
|
|
->method('getObject') |
1405
|
|
|
->willReturn($object); |
1406
|
|
|
|
1407
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1408
|
|
|
->method('update') |
1409
|
|
|
->willReturnArgument(0); |
1410
|
|
|
|
1411
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1412
|
|
|
->method('checkAccess') |
1413
|
|
|
->with($this->equalTo('edit')); |
1414
|
|
|
|
1415
|
|
|
$form = $this->createMock(Form::class); |
1416
|
|
|
|
1417
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1418
|
|
|
->method('getForm') |
1419
|
|
|
->willReturn($form); |
1420
|
|
|
|
1421
|
|
|
$form->expects($this->once()) |
1422
|
|
|
->method('isSubmitted') |
1423
|
|
|
->willReturn(true); |
1424
|
|
|
|
1425
|
|
|
$form->expects($this->once()) |
1426
|
|
|
->method('isValid') |
1427
|
|
|
->willReturn(true); |
1428
|
|
|
|
1429
|
|
|
$form->expects($this->once()) |
1430
|
|
|
->method('getData') |
1431
|
|
|
->willReturn($object); |
1432
|
|
|
|
1433
|
|
|
$this->admin |
|
|
|
|
1434
|
|
|
->method('getNormalizedIdentifier') |
1435
|
|
|
->with($this->equalTo($object)) |
1436
|
|
|
->willReturn('foo_normalized'); |
1437
|
|
|
|
1438
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1439
|
|
|
->method('toString') |
1440
|
|
|
->willReturn('foo'); |
1441
|
|
|
|
1442
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1443
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
1444
|
|
|
$this->request->headers->set('Accept', 'application/json'); |
1445
|
|
|
|
1446
|
|
|
$response = $this->controller->editAction($this->request); |
1447
|
|
|
|
1448
|
|
|
$this->assertInstanceOf(Response::class, $response); |
1449
|
|
|
$this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent()); |
1450
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
1451
|
|
|
} |
1452
|
|
|
|
1453
|
|
|
public function testEditActionAjaxError(): void |
1454
|
|
|
{ |
1455
|
|
|
$object = new \stdClass(); |
1456
|
|
|
|
1457
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1458
|
|
|
->method('getObject') |
1459
|
|
|
->willReturn($object); |
1460
|
|
|
|
1461
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1462
|
|
|
->method('checkAccess') |
1463
|
|
|
->with($this->equalTo('edit')); |
1464
|
|
|
|
1465
|
|
|
$form = $this->createMock(Form::class); |
1466
|
|
|
|
1467
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1468
|
|
|
->method('getForm') |
1469
|
|
|
->willReturn($form); |
1470
|
|
|
|
1471
|
|
|
$form->expects($this->once()) |
1472
|
|
|
->method('isSubmitted') |
1473
|
|
|
->willReturn(true); |
1474
|
|
|
|
1475
|
|
|
$form->expects($this->once()) |
1476
|
|
|
->method('isValid') |
1477
|
|
|
->willReturn(false); |
1478
|
|
|
|
1479
|
|
|
$formError = $this->createMock(FormError::class); |
1480
|
|
|
$formError->expects($this->atLeastOnce()) |
1481
|
|
|
->method('getMessage') |
1482
|
|
|
->willReturn('Form error message'); |
1483
|
|
|
|
1484
|
|
|
$form->expects($this->once()) |
1485
|
|
|
->method('getErrors') |
1486
|
|
|
->with(true) |
1487
|
|
|
->willReturn([$formError]); |
1488
|
|
|
|
1489
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1490
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
1491
|
|
|
$this->request->headers->set('Accept', 'application/json'); |
1492
|
|
|
|
1493
|
|
|
$this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction($this->request)); |
1494
|
|
|
$this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent()); |
1495
|
|
|
} |
1496
|
|
|
|
1497
|
|
|
public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void |
1498
|
|
|
{ |
1499
|
|
|
$object = new \stdClass(); |
1500
|
|
|
|
1501
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1502
|
|
|
->method('getObject') |
1503
|
|
|
->willReturn($object); |
1504
|
|
|
|
1505
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1506
|
|
|
->method('checkAccess') |
1507
|
|
|
->with($this->equalTo('edit')); |
1508
|
|
|
|
1509
|
|
|
$form = $this->createMock(Form::class); |
1510
|
|
|
|
1511
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1512
|
|
|
->method('getForm') |
1513
|
|
|
->willReturn($form); |
1514
|
|
|
|
1515
|
|
|
$form->expects($this->once()) |
1516
|
|
|
->method('isSubmitted') |
1517
|
|
|
->willReturn(true); |
1518
|
|
|
|
1519
|
|
|
$form->expects($this->once()) |
1520
|
|
|
->method('isValid') |
1521
|
|
|
->willReturn(false); |
1522
|
|
|
|
1523
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1524
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
1525
|
|
|
|
1526
|
|
|
$formView = $this->createMock(FormView::class); |
1527
|
|
|
$form |
1528
|
|
|
->method('createView') |
1529
|
|
|
->willReturn($formView); |
1530
|
|
|
|
1531
|
|
|
$this->assertInstanceOf(Response::class, $response = $this->controller->editAction($this->request)); |
1532
|
|
|
$this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode()); |
1533
|
|
|
} |
1534
|
|
|
|
1535
|
|
|
/** |
1536
|
|
|
* @dataProvider getToStringValues |
1537
|
|
|
*/ |
1538
|
|
|
public function testEditActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void |
1539
|
|
|
{ |
1540
|
|
|
$object = new \stdClass(); |
1541
|
|
|
|
1542
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1543
|
|
|
->method('getObject') |
1544
|
|
|
->willReturn($object); |
1545
|
|
|
|
1546
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1547
|
|
|
->method('checkAccess') |
1548
|
|
|
->with($this->equalTo('edit')); |
1549
|
|
|
|
1550
|
|
|
$this->admin |
|
|
|
|
1551
|
|
|
->method('getClass') |
1552
|
|
|
->willReturn(\stdClass::class); |
1553
|
|
|
|
1554
|
|
|
$form = $this->createMock(Form::class); |
1555
|
|
|
|
1556
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1557
|
|
|
->method('getForm') |
1558
|
|
|
->willReturn($form); |
1559
|
|
|
|
1560
|
|
|
$form->expects($this->once()) |
1561
|
|
|
->method('isValid') |
1562
|
|
|
->willReturn(true); |
1563
|
|
|
|
1564
|
|
|
$form->expects($this->once()) |
1565
|
|
|
->method('getData') |
1566
|
|
|
->willReturn($object); |
1567
|
|
|
|
1568
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1569
|
|
|
->method('toString') |
1570
|
|
|
->with($this->equalTo($object)) |
1571
|
|
|
->willReturn($toStringValue); |
1572
|
|
|
|
1573
|
|
|
$this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1574
|
|
|
|
1575
|
|
|
$form->expects($this->once()) |
1576
|
|
|
->method('isSubmitted') |
1577
|
|
|
->willReturn(true); |
1578
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1579
|
|
|
|
1580
|
|
|
$formView = $this->createMock(FormView::class); |
1581
|
|
|
|
1582
|
|
|
$form |
1583
|
|
|
->method('createView') |
1584
|
|
|
->willReturn($formView); |
1585
|
|
|
|
1586
|
|
|
$this->assertLoggerLogsModelManagerException($this->admin, 'update'); |
1587
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->editAction($this->request)); |
1588
|
|
|
|
1589
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1590
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1591
|
|
|
|
1592
|
|
|
$this->assertSame('edit', $this->parameters['action']); |
1593
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1594
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1595
|
|
|
|
1596
|
|
|
$this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all()); |
1597
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
1598
|
|
|
} |
1599
|
|
|
|
1600
|
|
|
public function testEditActionWithPreview(): void |
1601
|
|
|
{ |
1602
|
|
|
$object = new \stdClass(); |
1603
|
|
|
|
1604
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1605
|
|
|
->method('getObject') |
1606
|
|
|
->willReturn($object); |
1607
|
|
|
|
1608
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1609
|
|
|
->method('checkAccess') |
1610
|
|
|
->with($this->equalTo('edit')); |
1611
|
|
|
|
1612
|
|
|
$form = $this->createMock(Form::class); |
1613
|
|
|
|
1614
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1615
|
|
|
->method('getForm') |
1616
|
|
|
->willReturn($form); |
1617
|
|
|
|
1618
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1619
|
|
|
->method('supportsPreviewMode') |
1620
|
|
|
->willReturn(true); |
1621
|
|
|
|
1622
|
|
|
$formView = $this->createMock(FormView::class); |
1623
|
|
|
|
1624
|
|
|
$form |
1625
|
|
|
->method('createView') |
1626
|
|
|
->willReturn($formView); |
1627
|
|
|
|
1628
|
|
|
$form->expects($this->once()) |
1629
|
|
|
->method('isSubmitted') |
1630
|
|
|
->willReturn(true); |
1631
|
|
|
|
1632
|
|
|
$form->expects($this->once()) |
1633
|
|
|
->method('isValid') |
1634
|
|
|
->willReturn(true); |
1635
|
|
|
|
1636
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1637
|
|
|
$this->request->request->set('btn_preview', 'Preview'); |
1638
|
|
|
|
1639
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->editAction($this->request)); |
1640
|
|
|
|
1641
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1642
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1643
|
|
|
|
1644
|
|
|
$this->assertSame('edit', $this->parameters['action']); |
1645
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1646
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1647
|
|
|
|
1648
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
1649
|
|
|
$this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template); |
1650
|
|
|
} |
1651
|
|
|
|
1652
|
|
|
public function testEditActionWithLockException(): void |
1653
|
|
|
{ |
1654
|
|
|
$object = new \stdClass(); |
1655
|
|
|
$class = \get_class($object); |
1656
|
|
|
|
1657
|
|
|
$this->admin |
|
|
|
|
1658
|
|
|
->method('getObject') |
1659
|
|
|
->willReturn($object); |
1660
|
|
|
|
1661
|
|
|
$this->admin |
|
|
|
|
1662
|
|
|
->method('checkAccess') |
1663
|
|
|
->with($this->equalTo('edit')); |
1664
|
|
|
|
1665
|
|
|
$this->admin |
|
|
|
|
1666
|
|
|
->method('getClass') |
1667
|
|
|
->willReturn($class); |
1668
|
|
|
|
1669
|
|
|
$form = $this->createMock(Form::class); |
1670
|
|
|
|
1671
|
|
|
$form |
1672
|
|
|
->method('isValid') |
1673
|
|
|
->willReturn(true); |
1674
|
|
|
|
1675
|
|
|
$form->expects($this->once()) |
1676
|
|
|
->method('getData') |
1677
|
|
|
->willReturn($object); |
1678
|
|
|
|
1679
|
|
|
$this->admin |
|
|
|
|
1680
|
|
|
->method('getForm') |
1681
|
|
|
->willReturn($form); |
1682
|
|
|
|
1683
|
|
|
$form |
1684
|
|
|
->method('isSubmitted') |
1685
|
|
|
->willReturn(true); |
1686
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1687
|
|
|
|
1688
|
|
|
$this->admin |
|
|
|
|
1689
|
|
|
->method('update') |
1690
|
|
|
->will($this->throwException(new LockException())); |
1691
|
|
|
|
1692
|
|
|
$this->admin |
|
|
|
|
1693
|
|
|
->method('toString') |
1694
|
|
|
->with($this->equalTo($object)) |
1695
|
|
|
->willReturn($class); |
1696
|
|
|
|
1697
|
|
|
$formView = $this->createMock(FormView::class); |
1698
|
|
|
|
1699
|
|
|
$form |
1700
|
|
|
->method('createView') |
1701
|
|
|
->willReturn($formView); |
1702
|
|
|
|
1703
|
|
|
$this->expectTranslate('flash_lock_error', [ |
1704
|
|
|
'%name%' => $class, |
1705
|
|
|
'%link_start%' => '<a href="stdClass_edit">', |
1706
|
|
|
'%link_end%' => '</a>', |
1707
|
|
|
], 'SonataAdminBundle'); |
1708
|
|
|
|
1709
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->editAction($this->request)); |
1710
|
|
|
} |
1711
|
|
|
|
1712
|
|
|
public function testCreateActionAccessDenied(): void |
1713
|
|
|
{ |
1714
|
|
|
$this->expectException(AccessDeniedException::class); |
1715
|
|
|
|
1716
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1717
|
|
|
->method('checkAccess') |
1718
|
|
|
->with($this->equalTo('create')) |
1719
|
|
|
->will($this->throwException(new AccessDeniedException())); |
1720
|
|
|
|
1721
|
|
|
$this->controller->createAction($this->request); |
1722
|
|
|
} |
1723
|
|
|
|
1724
|
|
|
public function testPreCreate(): void |
1725
|
|
|
{ |
1726
|
|
|
$object = new \stdClass(); |
1727
|
|
|
$object->foo = 123456; |
1728
|
|
|
|
1729
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1730
|
|
|
->method('checkAccess') |
1731
|
|
|
->with($this->equalTo('create')); |
1732
|
|
|
|
1733
|
|
|
$this->admin |
|
|
|
|
1734
|
|
|
->method('getClass') |
1735
|
|
|
->willReturn(\stdClass::class); |
1736
|
|
|
|
1737
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1738
|
|
|
->method('getNewInstance') |
1739
|
|
|
->willReturn($object); |
1740
|
|
|
|
1741
|
|
|
$controller = $this->createController(PreCRUDController::class); |
1742
|
|
|
|
1743
|
|
|
$response = $controller->createAction($this->request); |
1744
|
|
|
$this->assertInstanceOf(Response::class, $response); |
1745
|
|
|
$this->assertSame('preCreate called: 123456', $response->getContent()); |
1746
|
|
|
} |
1747
|
|
|
|
1748
|
|
|
public function testCreateAction(): void |
1749
|
|
|
{ |
1750
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1751
|
|
|
->method('checkAccess') |
1752
|
|
|
->with($this->equalTo('create')); |
1753
|
|
|
|
1754
|
|
|
$object = new \stdClass(); |
1755
|
|
|
|
1756
|
|
|
$this->admin |
|
|
|
|
1757
|
|
|
->method('getClass') |
1758
|
|
|
->willReturn(\stdClass::class); |
1759
|
|
|
|
1760
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1761
|
|
|
->method('getNewInstance') |
1762
|
|
|
->willReturn($object); |
1763
|
|
|
|
1764
|
|
|
$form = $this->createMock(Form::class); |
1765
|
|
|
|
1766
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1767
|
|
|
->method('getForm') |
1768
|
|
|
->willReturn($form); |
1769
|
|
|
|
1770
|
|
|
$formView = $this->createMock(FormView::class); |
1771
|
|
|
|
1772
|
|
|
$form |
1773
|
|
|
->method('createView') |
1774
|
|
|
->willReturn($formView); |
1775
|
|
|
|
1776
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->createAction($this->request)); |
1777
|
|
|
|
1778
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1779
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1780
|
|
|
|
1781
|
|
|
$this->assertSame('create', $this->parameters['action']); |
1782
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1783
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1784
|
|
|
|
1785
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
1786
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
1787
|
|
|
} |
1788
|
|
|
|
1789
|
|
|
/** |
1790
|
|
|
* @dataProvider getToStringValues |
1791
|
|
|
*/ |
1792
|
|
|
public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void |
1793
|
|
|
{ |
1794
|
|
|
$object = new \stdClass(); |
1795
|
|
|
|
1796
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
1797
|
|
|
->method('checkAccess') |
1798
|
|
|
->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void { |
1799
|
|
|
if ('edit' === $name) { |
1800
|
|
|
return; |
1801
|
|
|
} |
1802
|
|
|
|
1803
|
|
|
if ('create' !== $name) { |
1804
|
|
|
throw new AccessDeniedException(); |
1805
|
|
|
} |
1806
|
|
|
|
1807
|
|
|
if (null === $objectIn) { |
1808
|
|
|
return; |
1809
|
|
|
} |
1810
|
|
|
|
1811
|
|
|
if ($objectIn !== $object) { |
1812
|
|
|
throw new AccessDeniedException(); |
1813
|
|
|
} |
1814
|
|
|
}); |
1815
|
|
|
|
1816
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1817
|
|
|
->method('hasRoute') |
1818
|
|
|
->with($this->equalTo('edit')) |
1819
|
|
|
->willReturn(true); |
1820
|
|
|
|
1821
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1822
|
|
|
->method('hasAccess') |
1823
|
|
|
->with($this->equalTo('edit')) |
1824
|
|
|
->willReturn(true); |
1825
|
|
|
|
1826
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1827
|
|
|
->method('getNewInstance') |
1828
|
|
|
->willReturn($object); |
1829
|
|
|
|
1830
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1831
|
|
|
->method('create') |
1832
|
|
|
->willReturnArgument(0); |
1833
|
|
|
|
1834
|
|
|
$form = $this->createMock(Form::class); |
1835
|
|
|
|
1836
|
|
|
$this->admin |
|
|
|
|
1837
|
|
|
->method('getClass') |
1838
|
|
|
->willReturn(\stdClass::class); |
1839
|
|
|
|
1840
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1841
|
|
|
->method('getForm') |
1842
|
|
|
->willReturn($form); |
1843
|
|
|
|
1844
|
|
|
$form->expects($this->once()) |
1845
|
|
|
->method('isSubmitted') |
1846
|
|
|
->willReturn(true); |
1847
|
|
|
|
1848
|
|
|
$form->expects($this->once()) |
1849
|
|
|
->method('isValid') |
1850
|
|
|
->willReturn(true); |
1851
|
|
|
|
1852
|
|
|
$form->expects($this->once()) |
1853
|
|
|
->method('getData') |
1854
|
|
|
->willReturn($object); |
1855
|
|
|
|
1856
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1857
|
|
|
->method('toString') |
1858
|
|
|
->with($this->equalTo($object)) |
1859
|
|
|
->willReturn($toStringValue); |
1860
|
|
|
|
1861
|
|
|
$this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1862
|
|
|
|
1863
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1864
|
|
|
|
1865
|
|
|
$response = $this->controller->createAction($this->request); |
1866
|
|
|
|
1867
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
1868
|
|
|
$this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
1869
|
|
|
$this->assertSame('stdClass_edit', $response->getTargetUrl()); |
1870
|
|
|
} |
1871
|
|
|
|
1872
|
|
|
public function testCreateActionAccessDenied2(): void |
1873
|
|
|
{ |
1874
|
|
|
$this->expectException(AccessDeniedException::class); |
1875
|
|
|
|
1876
|
|
|
$object = new \stdClass(); |
1877
|
|
|
|
1878
|
|
|
$this->admin |
|
|
|
|
1879
|
|
|
->method('checkAccess') |
1880
|
|
|
->willReturnCallback(static function (string $name, $object = null): void { |
1881
|
|
|
if ('create' !== $name) { |
1882
|
|
|
throw new AccessDeniedException(); |
1883
|
|
|
} |
1884
|
|
|
if (null === $object) { |
1885
|
|
|
return; |
1886
|
|
|
} |
1887
|
|
|
|
1888
|
|
|
throw new AccessDeniedException(); |
1889
|
|
|
}); |
1890
|
|
|
|
1891
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1892
|
|
|
->method('getNewInstance') |
1893
|
|
|
->willReturn($object); |
1894
|
|
|
|
1895
|
|
|
$form = $this->createMock(Form::class); |
1896
|
|
|
|
1897
|
|
|
$this->admin |
|
|
|
|
1898
|
|
|
->method('getClass') |
1899
|
|
|
->willReturn(\stdClass::class); |
1900
|
|
|
|
1901
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1902
|
|
|
->method('getForm') |
1903
|
|
|
->willReturn($form); |
1904
|
|
|
|
1905
|
|
|
$form->expects($this->once()) |
1906
|
|
|
->method('isSubmitted') |
1907
|
|
|
->willReturn(true); |
1908
|
|
|
|
1909
|
|
|
$form->expects($this->once()) |
1910
|
|
|
->method('getData') |
1911
|
|
|
->willReturn($object); |
1912
|
|
|
|
1913
|
|
|
$form->expects($this->once()) |
1914
|
|
|
->method('isValid') |
1915
|
|
|
->willReturn(true); |
1916
|
|
|
|
1917
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1918
|
|
|
|
1919
|
|
|
$this->controller->createAction($this->request); |
1920
|
|
|
} |
1921
|
|
|
|
1922
|
|
|
/** |
1923
|
|
|
* @dataProvider getToStringValues |
1924
|
|
|
*/ |
1925
|
|
|
public function testCreateActionError(string $expectedToStringValue, string $toStringValue): void |
1926
|
|
|
{ |
1927
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1928
|
|
|
->method('checkAccess') |
1929
|
|
|
->with($this->equalTo('create')); |
1930
|
|
|
|
1931
|
|
|
$object = new \stdClass(); |
1932
|
|
|
|
1933
|
|
|
$this->admin |
|
|
|
|
1934
|
|
|
->method('getClass') |
1935
|
|
|
->willReturn(\stdClass::class); |
1936
|
|
|
|
1937
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1938
|
|
|
->method('getNewInstance') |
1939
|
|
|
->willReturn($object); |
1940
|
|
|
|
1941
|
|
|
$form = $this->createMock(Form::class); |
1942
|
|
|
|
1943
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1944
|
|
|
->method('getForm') |
1945
|
|
|
->willReturn($form); |
1946
|
|
|
|
1947
|
|
|
$form->expects($this->once()) |
1948
|
|
|
->method('isSubmitted') |
1949
|
|
|
->willReturn(true); |
1950
|
|
|
|
1951
|
|
|
$form->expects($this->once()) |
1952
|
|
|
->method('isValid') |
1953
|
|
|
->willReturn(false); |
1954
|
|
|
|
1955
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1956
|
|
|
->method('toString') |
1957
|
|
|
->with($this->equalTo($object)) |
1958
|
|
|
->willReturn($toStringValue); |
1959
|
|
|
|
1960
|
|
|
$this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
1961
|
|
|
|
1962
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
1963
|
|
|
|
1964
|
|
|
$formView = $this->createMock(FormView::class); |
1965
|
|
|
|
1966
|
|
|
$form |
1967
|
|
|
->method('createView') |
1968
|
|
|
->willReturn($formView); |
1969
|
|
|
|
1970
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->createAction($this->request)); |
1971
|
|
|
|
1972
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
1973
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
1974
|
|
|
|
1975
|
|
|
$this->assertSame('create', $this->parameters['action']); |
1976
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
1977
|
|
|
$this->assertSame($object, $this->parameters['object']); |
1978
|
|
|
|
1979
|
|
|
$this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all()); |
1980
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
1981
|
|
|
} |
1982
|
|
|
|
1983
|
|
|
/** |
1984
|
|
|
* @dataProvider getToStringValues |
1985
|
|
|
*/ |
1986
|
|
|
public function testCreateActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void |
1987
|
|
|
{ |
1988
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
1989
|
|
|
->method('checkAccess') |
1990
|
|
|
->with($this->equalTo('create')); |
1991
|
|
|
|
1992
|
|
|
$this->admin |
|
|
|
|
1993
|
|
|
->method('getClass') |
1994
|
|
|
->willReturn(\stdClass::class); |
1995
|
|
|
|
1996
|
|
|
$object = new \stdClass(); |
1997
|
|
|
|
1998
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
1999
|
|
|
->method('getNewInstance') |
2000
|
|
|
->willReturn($object); |
2001
|
|
|
|
2002
|
|
|
$form = $this->createMock(Form::class); |
2003
|
|
|
|
2004
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2005
|
|
|
->method('getForm') |
2006
|
|
|
->willReturn($form); |
2007
|
|
|
|
2008
|
|
|
$form->expects($this->once()) |
2009
|
|
|
->method('isValid') |
2010
|
|
|
->willReturn(true); |
2011
|
|
|
|
2012
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2013
|
|
|
->method('toString') |
2014
|
|
|
->with($this->equalTo($object)) |
2015
|
|
|
->willReturn($toStringValue); |
2016
|
|
|
|
2017
|
|
|
$this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle'); |
2018
|
|
|
|
2019
|
|
|
$form->expects($this->once()) |
2020
|
|
|
->method('isSubmitted') |
2021
|
|
|
->willReturn(true); |
2022
|
|
|
|
2023
|
|
|
$form->expects($this->once()) |
2024
|
|
|
->method('getData') |
2025
|
|
|
->willReturn($object); |
2026
|
|
|
|
2027
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2028
|
|
|
|
2029
|
|
|
$formView = $this->createMock(FormView::class); |
2030
|
|
|
|
2031
|
|
|
$form |
2032
|
|
|
->method('createView') |
2033
|
|
|
->willReturn($formView); |
2034
|
|
|
|
2035
|
|
|
$this->assertLoggerLogsModelManagerException($this->admin, 'create'); |
2036
|
|
|
|
2037
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->createAction($this->request)); |
2038
|
|
|
|
2039
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2040
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2041
|
|
|
|
2042
|
|
|
$this->assertSame('create', $this->parameters['action']); |
2043
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
2044
|
|
|
$this->assertSame($object, $this->parameters['object']); |
2045
|
|
|
|
2046
|
|
|
$this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all()); |
2047
|
|
|
$this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template); |
2048
|
|
|
} |
2049
|
|
|
|
2050
|
|
|
public function testCreateActionAjaxSuccess(): void |
2051
|
|
|
{ |
2052
|
|
|
$object = new \stdClass(); |
2053
|
|
|
|
2054
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
2055
|
|
|
->method('checkAccess') |
2056
|
|
|
->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void { |
2057
|
|
|
if ('create' !== $name) { |
2058
|
|
|
throw new AccessDeniedException(); |
2059
|
|
|
} |
2060
|
|
|
|
2061
|
|
|
if (null === $objectIn) { |
2062
|
|
|
return; |
2063
|
|
|
} |
2064
|
|
|
|
2065
|
|
|
if ($objectIn !== $object) { |
2066
|
|
|
throw new AccessDeniedException(); |
2067
|
|
|
} |
2068
|
|
|
}); |
2069
|
|
|
|
2070
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2071
|
|
|
->method('getNewInstance') |
2072
|
|
|
->willReturn($object); |
2073
|
|
|
|
2074
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2075
|
|
|
->method('create') |
2076
|
|
|
->willReturnArgument(0); |
2077
|
|
|
|
2078
|
|
|
$form = $this->createMock(Form::class); |
2079
|
|
|
|
2080
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2081
|
|
|
->method('getForm') |
2082
|
|
|
->willReturn($form); |
2083
|
|
|
|
2084
|
|
|
$form->expects($this->once()) |
2085
|
|
|
->method('isSubmitted') |
2086
|
|
|
->willReturn(true); |
2087
|
|
|
|
2088
|
|
|
$form->expects($this->once()) |
2089
|
|
|
->method('isValid') |
2090
|
|
|
->willReturn(true); |
2091
|
|
|
|
2092
|
|
|
$form->expects($this->once()) |
2093
|
|
|
->method('getData') |
2094
|
|
|
->willReturn($object); |
2095
|
|
|
|
2096
|
|
|
$this->admin |
|
|
|
|
2097
|
|
|
->method('getClass') |
2098
|
|
|
->willReturn(\stdClass::class); |
2099
|
|
|
|
2100
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2101
|
|
|
->method('getNormalizedIdentifier') |
2102
|
|
|
->with($this->equalTo($object)) |
2103
|
|
|
->willReturn('foo_normalized'); |
2104
|
|
|
|
2105
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2106
|
|
|
->method('toString') |
2107
|
|
|
->willReturn('foo'); |
2108
|
|
|
|
2109
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2110
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
2111
|
|
|
$this->request->headers->set('Accept', 'application/json'); |
2112
|
|
|
|
2113
|
|
|
$response = $this->controller->createAction($this->request); |
2114
|
|
|
|
2115
|
|
|
$this->assertInstanceOf(Response::class, $response); |
2116
|
|
|
$this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent()); |
2117
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2118
|
|
|
} |
2119
|
|
|
|
2120
|
|
|
public function testCreateActionAjaxError(): void |
2121
|
|
|
{ |
2122
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2123
|
|
|
->method('checkAccess') |
2124
|
|
|
->with($this->equalTo('create')); |
2125
|
|
|
|
2126
|
|
|
$object = new \stdClass(); |
2127
|
|
|
|
2128
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2129
|
|
|
->method('getNewInstance') |
2130
|
|
|
->willReturn($object); |
2131
|
|
|
|
2132
|
|
|
$form = $this->createMock(Form::class); |
2133
|
|
|
|
2134
|
|
|
$this->admin |
|
|
|
|
2135
|
|
|
->method('getClass') |
2136
|
|
|
->willReturn(\stdClass::class); |
2137
|
|
|
|
2138
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2139
|
|
|
->method('getForm') |
2140
|
|
|
->willReturn($form); |
2141
|
|
|
|
2142
|
|
|
$form->expects($this->once()) |
2143
|
|
|
->method('isSubmitted') |
2144
|
|
|
->willReturn(true); |
2145
|
|
|
|
2146
|
|
|
$form->expects($this->once()) |
2147
|
|
|
->method('isValid') |
2148
|
|
|
->willReturn(false); |
2149
|
|
|
|
2150
|
|
|
$formError = $this->createMock(FormError::class); |
2151
|
|
|
$formError->expects($this->atLeastOnce()) |
2152
|
|
|
->method('getMessage') |
2153
|
|
|
->willReturn('Form error message'); |
2154
|
|
|
|
2155
|
|
|
$form->expects($this->once()) |
2156
|
|
|
->method('getErrors') |
2157
|
|
|
->with(true) |
2158
|
|
|
->willReturn([$formError]); |
2159
|
|
|
|
2160
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2161
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
2162
|
|
|
$this->request->headers->set('Accept', 'application/json'); |
2163
|
|
|
|
2164
|
|
|
$this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request)); |
2165
|
|
|
$this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent()); |
2166
|
|
|
} |
2167
|
|
|
|
2168
|
|
|
public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void |
2169
|
|
|
{ |
2170
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2171
|
|
|
->method('checkAccess') |
2172
|
|
|
->with($this->equalTo('create')); |
2173
|
|
|
|
2174
|
|
|
$object = new \stdClass(); |
2175
|
|
|
|
2176
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2177
|
|
|
->method('getNewInstance') |
2178
|
|
|
->willReturn($object); |
2179
|
|
|
|
2180
|
|
|
$form = $this->createMock(Form::class); |
2181
|
|
|
|
2182
|
|
|
$this->admin |
|
|
|
|
2183
|
|
|
->method('getClass') |
2184
|
|
|
->willReturn(\stdClass::class); |
2185
|
|
|
|
2186
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2187
|
|
|
->method('getForm') |
2188
|
|
|
->willReturn($form); |
2189
|
|
|
|
2190
|
|
|
$form->expects($this->once()) |
2191
|
|
|
->method('isSubmitted') |
2192
|
|
|
->willReturn(true); |
2193
|
|
|
|
2194
|
|
|
$form->expects($this->once()) |
2195
|
|
|
->method('isValid') |
2196
|
|
|
->willReturn(false); |
2197
|
|
|
|
2198
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2199
|
|
|
$this->request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
2200
|
|
|
|
2201
|
|
|
$formView = $this->createMock(FormView::class); |
2202
|
|
|
$form |
2203
|
|
|
->method('createView') |
2204
|
|
|
->willReturn($formView); |
2205
|
|
|
|
2206
|
|
|
$this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request)); |
2207
|
|
|
$this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode()); |
2208
|
|
|
} |
2209
|
|
|
|
2210
|
|
|
public function testCreateActionWithPreview(): void |
2211
|
|
|
{ |
2212
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2213
|
|
|
->method('checkAccess') |
2214
|
|
|
->with($this->equalTo('create')); |
2215
|
|
|
|
2216
|
|
|
$object = new \stdClass(); |
2217
|
|
|
|
2218
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2219
|
|
|
->method('getNewInstance') |
2220
|
|
|
->willReturn($object); |
2221
|
|
|
|
2222
|
|
|
$form = $this->createMock(Form::class); |
2223
|
|
|
|
2224
|
|
|
$this->admin |
|
|
|
|
2225
|
|
|
->method('getClass') |
2226
|
|
|
->willReturn(\stdClass::class); |
2227
|
|
|
|
2228
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2229
|
|
|
->method('getForm') |
2230
|
|
|
->willReturn($form); |
2231
|
|
|
|
2232
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2233
|
|
|
->method('supportsPreviewMode') |
2234
|
|
|
->willReturn(true); |
2235
|
|
|
|
2236
|
|
|
$formView = $this->createMock(FormView::class); |
2237
|
|
|
|
2238
|
|
|
$form |
2239
|
|
|
->method('createView') |
2240
|
|
|
->willReturn($formView); |
2241
|
|
|
|
2242
|
|
|
$form->expects($this->once()) |
2243
|
|
|
->method('isSubmitted') |
2244
|
|
|
->willReturn(true); |
2245
|
|
|
|
2246
|
|
|
$form->expects($this->once()) |
2247
|
|
|
->method('isValid') |
2248
|
|
|
->willReturn(true); |
2249
|
|
|
|
2250
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2251
|
|
|
$this->request->request->set('btn_preview', 'Preview'); |
2252
|
|
|
|
2253
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->createAction($this->request)); |
2254
|
|
|
|
2255
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2256
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2257
|
|
|
|
2258
|
|
|
$this->assertSame('create', $this->parameters['action']); |
2259
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
2260
|
|
|
$this->assertSame($object, $this->parameters['object']); |
2261
|
|
|
|
2262
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2263
|
|
|
$this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template); |
2264
|
|
|
} |
2265
|
|
|
|
2266
|
|
|
public function testExportActionAccessDenied(): void |
2267
|
|
|
{ |
2268
|
|
|
$this->expectException(AccessDeniedException::class); |
2269
|
|
|
|
2270
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2271
|
|
|
->method('checkAccess') |
2272
|
|
|
->with($this->equalTo('export')) |
2273
|
|
|
->will($this->throwException(new AccessDeniedException())); |
2274
|
|
|
|
2275
|
|
|
$this->controller->exportAction($this->request); |
2276
|
|
|
} |
2277
|
|
|
|
2278
|
|
|
public function testExportActionWrongFormat(): void |
2279
|
|
|
{ |
2280
|
|
|
$this->expectException(\RuntimeException::class); |
2281
|
|
|
$this->expectExceptionMessage( |
2282
|
|
|
'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`' |
2283
|
|
|
); |
2284
|
|
|
|
2285
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2286
|
|
|
->method('checkAccess') |
2287
|
|
|
->with($this->equalTo('export')); |
2288
|
|
|
|
2289
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2290
|
|
|
->method('getExportFormats') |
2291
|
|
|
->willReturn(['json']); |
2292
|
|
|
|
2293
|
|
|
$this->admin |
|
|
|
|
2294
|
|
|
->method('getClass') |
2295
|
|
|
->willReturn('Foo'); |
2296
|
|
|
|
2297
|
|
|
$this->request->query->set('format', 'csv'); |
2298
|
|
|
|
2299
|
|
|
$this->controller->exportAction($this->request); |
2300
|
|
|
} |
2301
|
|
|
|
2302
|
|
|
public function testExportAction(): void |
2303
|
|
|
{ |
2304
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2305
|
|
|
->method('checkAccess') |
2306
|
|
|
->with($this->equalTo('export')); |
2307
|
|
|
|
2308
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2309
|
|
|
->method('getExportFormats') |
2310
|
|
|
->willReturn(['json']); |
2311
|
|
|
|
2312
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2313
|
|
|
->method('getClass') |
2314
|
|
|
->willReturn(\stdClass::class); |
2315
|
|
|
|
2316
|
|
|
$dataSourceIterator = $this->createMock(SourceIteratorInterface::class); |
2317
|
|
|
|
2318
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2319
|
|
|
->method('getDataSourceIterator') |
2320
|
|
|
->willReturn($dataSourceIterator); |
2321
|
|
|
|
2322
|
|
|
$this->request->query->set('format', 'json'); |
2323
|
|
|
|
2324
|
|
|
$response = $this->controller->exportAction($this->request); |
2325
|
|
|
$this->assertInstanceOf(StreamedResponse::class, $response); |
2326
|
|
|
$this->assertSame(Response::HTTP_OK, $response->getStatusCode()); |
2327
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2328
|
|
|
} |
2329
|
|
|
|
2330
|
|
|
public function testHistoryActionAccessDenied(): void |
2331
|
|
|
{ |
2332
|
|
|
$this->expectException(AccessDeniedException::class); |
2333
|
|
|
|
2334
|
|
|
$this->admin |
|
|
|
|
2335
|
|
|
->method('getObject') |
2336
|
|
|
->willReturn(new \stdClass()); |
2337
|
|
|
|
2338
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2339
|
|
|
->method('checkAccess') |
2340
|
|
|
->with($this->equalTo('history')) |
2341
|
|
|
->will($this->throwException(new AccessDeniedException())); |
2342
|
|
|
|
2343
|
|
|
$this->controller->historyAction($this->request); |
2344
|
|
|
} |
2345
|
|
|
|
2346
|
|
|
public function testHistoryActionNotFoundException(): void |
2347
|
|
|
{ |
2348
|
|
|
$this->expectException(NotFoundHttpException::class); |
2349
|
|
|
|
2350
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2351
|
|
|
->method('getObject') |
2352
|
|
|
->willReturn(null); |
2353
|
|
|
|
2354
|
|
|
$this->controller->historyAction($this->request); |
2355
|
|
|
} |
2356
|
|
|
|
2357
|
|
|
public function testHistoryActionNoReader(): void |
2358
|
|
|
{ |
2359
|
|
|
$this->expectException(NotFoundHttpException::class); |
2360
|
|
|
$this->expectExceptionMessage('unable to find the audit reader for class : Foo'); |
2361
|
|
|
|
2362
|
|
|
$this->request->query->set('id', 123); |
2363
|
|
|
|
2364
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2365
|
|
|
->method('checkAccess') |
2366
|
|
|
->with($this->equalTo('history')); |
2367
|
|
|
|
2368
|
|
|
$object = new \stdClass(); |
2369
|
|
|
|
2370
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2371
|
|
|
->method('getObject') |
2372
|
|
|
->willReturn($object); |
2373
|
|
|
|
2374
|
|
|
$this->admin |
|
|
|
|
2375
|
|
|
->method('getClass') |
2376
|
|
|
->willReturn('Foo'); |
2377
|
|
|
|
2378
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2379
|
|
|
->method('hasReader') |
2380
|
|
|
->with($this->equalTo('Foo')) |
2381
|
|
|
->willReturn(false); |
2382
|
|
|
|
2383
|
|
|
$this->controller->historyAction($this->request); |
2384
|
|
|
} |
2385
|
|
|
|
2386
|
|
|
public function testHistoryAction(): void |
2387
|
|
|
{ |
2388
|
|
|
$this->request->query->set('id', 123); |
2389
|
|
|
|
2390
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2391
|
|
|
->method('checkAccess') |
2392
|
|
|
->with($this->equalTo('history')); |
2393
|
|
|
|
2394
|
|
|
$object = new \stdClass(); |
2395
|
|
|
|
2396
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2397
|
|
|
->method('getObject') |
2398
|
|
|
->willReturn($object); |
2399
|
|
|
|
2400
|
|
|
$this->admin |
|
|
|
|
2401
|
|
|
->method('getClass') |
2402
|
|
|
->willReturn('Foo'); |
2403
|
|
|
|
2404
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2405
|
|
|
->method('hasReader') |
2406
|
|
|
->with($this->equalTo('Foo')) |
2407
|
|
|
->willReturn(true); |
2408
|
|
|
|
2409
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
2410
|
|
|
|
2411
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2412
|
|
|
->method('getReader') |
2413
|
|
|
->with($this->equalTo('Foo')) |
2414
|
|
|
->willReturn($reader); |
2415
|
|
|
|
2416
|
|
|
$reader->expects($this->once()) |
2417
|
|
|
->method('findRevisions') |
2418
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123)) |
2419
|
|
|
->willReturn([]); |
2420
|
|
|
|
2421
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->historyAction($this->request)); |
2422
|
|
|
|
2423
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2424
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2425
|
|
|
|
2426
|
|
|
$this->assertSame('history', $this->parameters['action']); |
2427
|
|
|
$this->assertSame([], $this->parameters['revisions']); |
2428
|
|
|
$this->assertSame($object, $this->parameters['object']); |
2429
|
|
|
|
2430
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2431
|
|
|
$this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template); |
2432
|
|
|
} |
2433
|
|
|
|
2434
|
|
|
public function testAclActionAclNotEnabled(): void |
2435
|
|
|
{ |
2436
|
|
|
$this->expectException(NotFoundHttpException::class); |
2437
|
|
|
$this->expectExceptionMessage('ACL are not enabled for this admin'); |
2438
|
|
|
|
2439
|
|
|
$this->controller->aclAction($this->request); |
2440
|
|
|
} |
2441
|
|
|
|
2442
|
|
|
public function testAclActionNotFoundException(): void |
2443
|
|
|
{ |
2444
|
|
|
$this->expectException(NotFoundHttpException::class); |
2445
|
|
|
|
2446
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2447
|
|
|
->method('isAclEnabled') |
2448
|
|
|
->willReturn(true); |
2449
|
|
|
|
2450
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2451
|
|
|
->method('getObject') |
2452
|
|
|
->willReturn(null); |
2453
|
|
|
|
2454
|
|
|
$this->controller->aclAction($this->request); |
2455
|
|
|
} |
2456
|
|
|
|
2457
|
|
|
public function testAclActionAccessDenied(): void |
2458
|
|
|
{ |
2459
|
|
|
$this->expectException(AccessDeniedException::class); |
2460
|
|
|
|
2461
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2462
|
|
|
->method('isAclEnabled') |
2463
|
|
|
->willReturn(true); |
2464
|
|
|
|
2465
|
|
|
$object = new \stdClass(); |
2466
|
|
|
|
2467
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2468
|
|
|
->method('getObject') |
2469
|
|
|
->willReturn($object); |
2470
|
|
|
|
2471
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2472
|
|
|
->method('checkAccess') |
2473
|
|
|
->with($this->equalTo('acl'), $this->equalTo($object)) |
2474
|
|
|
->will($this->throwException(new AccessDeniedException())); |
2475
|
|
|
|
2476
|
|
|
$this->controller->aclAction($this->request); |
2477
|
|
|
} |
2478
|
|
|
|
2479
|
|
|
public function testAclAction(): void |
2480
|
|
|
{ |
2481
|
|
|
$this->request->query->set('id', 123); |
2482
|
|
|
|
2483
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
2484
|
|
|
->method('isAclEnabled') |
2485
|
|
|
->willReturn(true); |
2486
|
|
|
|
2487
|
|
|
$object = new \stdClass(); |
2488
|
|
|
|
2489
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2490
|
|
|
->method('getObject') |
2491
|
|
|
->willReturn($object); |
2492
|
|
|
|
2493
|
|
|
$this->admin |
|
|
|
|
2494
|
|
|
->expects($this->once()) |
2495
|
|
|
->method('checkAccess'); |
2496
|
|
|
|
2497
|
|
|
$this->admin |
|
|
|
|
2498
|
|
|
->method('getSecurityInformation') |
2499
|
|
|
->willReturn([]); |
2500
|
|
|
|
2501
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2502
|
|
|
->method('getMaskBuilderClass') |
2503
|
|
|
->willReturn(AdminPermissionMap::class); |
2504
|
|
|
|
2505
|
|
|
$aclUsersForm = $this->getMockBuilder(Form::class) |
2506
|
|
|
->disableOriginalConstructor() |
2507
|
|
|
->getMock(); |
2508
|
|
|
|
2509
|
|
|
$aclUsersForm->expects($this->once()) |
2510
|
|
|
->method('createView') |
2511
|
|
|
->willReturn($this->createMock(FormView::class)); |
2512
|
|
|
|
2513
|
|
|
$aclRolesForm = $this->getMockBuilder(Form::class) |
2514
|
|
|
->disableOriginalConstructor() |
2515
|
|
|
->getMock(); |
2516
|
|
|
|
2517
|
|
|
$aclRolesForm->expects($this->once()) |
2518
|
|
|
->method('createView') |
2519
|
|
|
->willReturn($this->createMock(FormView::class)); |
2520
|
|
|
|
2521
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2522
|
|
|
->method('createAclUsersForm') |
2523
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2524
|
|
|
->willReturn($aclUsersForm); |
2525
|
|
|
|
2526
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2527
|
|
|
->method('createAclRolesForm') |
2528
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2529
|
|
|
->willReturn($aclRolesForm); |
2530
|
|
|
|
2531
|
|
|
$aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
2532
|
|
|
|
2533
|
|
|
$aclSecurityHandler |
2534
|
|
|
->method('getObjectPermissions') |
2535
|
|
|
->willReturn([]); |
2536
|
|
|
|
2537
|
|
|
$this->admin |
|
|
|
|
2538
|
|
|
->method('getSecurityHandler') |
2539
|
|
|
->willReturn($aclSecurityHandler); |
2540
|
|
|
|
2541
|
|
|
$controller = $this->createController(); |
2542
|
|
|
|
2543
|
|
|
$this->assertInstanceOf(Response::class, $controller->aclAction($this->request)); |
2544
|
|
|
|
2545
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2546
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2547
|
|
|
|
2548
|
|
|
$this->assertSame('acl', $this->parameters['action']); |
2549
|
|
|
$this->assertSame([], $this->parameters['permissions']); |
2550
|
|
|
$this->assertSame($object, $this->parameters['object']); |
2551
|
|
|
$this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']); |
2552
|
|
|
$this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']); |
2553
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']); |
2554
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']); |
2555
|
|
|
|
2556
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2557
|
|
|
$this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template); |
2558
|
|
|
} |
2559
|
|
|
|
2560
|
|
|
public function testAclActionInvalidUpdate(): void |
2561
|
|
|
{ |
2562
|
|
|
$this->request->query->set('id', 123); |
2563
|
|
|
$this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []); |
2564
|
|
|
|
2565
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
2566
|
|
|
->method('isAclEnabled') |
2567
|
|
|
->willReturn(true); |
2568
|
|
|
|
2569
|
|
|
$object = new \stdClass(); |
2570
|
|
|
|
2571
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2572
|
|
|
->method('getObject') |
2573
|
|
|
->willReturn($object); |
2574
|
|
|
|
2575
|
|
|
$this->admin |
|
|
|
|
2576
|
|
|
->expects($this->once()) |
2577
|
|
|
->method('checkAccess'); |
2578
|
|
|
|
2579
|
|
|
$this->admin |
|
|
|
|
2580
|
|
|
->method('getSecurityInformation') |
2581
|
|
|
->willReturn([]); |
2582
|
|
|
|
2583
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2584
|
|
|
->method('getMaskBuilderClass') |
2585
|
|
|
->willReturn(AdminPermissionMap::class); |
2586
|
|
|
|
2587
|
|
|
$aclUsersForm = $this->getMockBuilder(Form::class) |
2588
|
|
|
->disableOriginalConstructor() |
2589
|
|
|
->getMock(); |
2590
|
|
|
|
2591
|
|
|
$aclUsersForm->expects($this->once()) |
2592
|
|
|
->method('isValid') |
2593
|
|
|
->willReturn(false); |
2594
|
|
|
|
2595
|
|
|
$aclUsersForm->expects($this->once()) |
2596
|
|
|
->method('createView') |
2597
|
|
|
->willReturn($this->createMock(FormView::class)); |
2598
|
|
|
|
2599
|
|
|
$aclRolesForm = $this->getMockBuilder(Form::class) |
2600
|
|
|
->disableOriginalConstructor() |
2601
|
|
|
->getMock(); |
2602
|
|
|
|
2603
|
|
|
$aclRolesForm->expects($this->once()) |
2604
|
|
|
->method('createView') |
2605
|
|
|
->willReturn($this->createMock(FormView::class)); |
2606
|
|
|
|
2607
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2608
|
|
|
->method('createAclUsersForm') |
2609
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2610
|
|
|
->willReturn($aclUsersForm); |
2611
|
|
|
|
2612
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2613
|
|
|
->method('createAclRolesForm') |
2614
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2615
|
|
|
->willReturn($aclRolesForm); |
2616
|
|
|
|
2617
|
|
|
$aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
2618
|
|
|
|
2619
|
|
|
$aclSecurityHandler |
2620
|
|
|
->method('getObjectPermissions') |
2621
|
|
|
->willReturn([]); |
2622
|
|
|
|
2623
|
|
|
$this->admin |
|
|
|
|
2624
|
|
|
->method('getSecurityHandler') |
2625
|
|
|
->willReturn($aclSecurityHandler); |
2626
|
|
|
|
2627
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2628
|
|
|
|
2629
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request)); |
2630
|
|
|
|
2631
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2632
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2633
|
|
|
|
2634
|
|
|
$this->assertSame('acl', $this->parameters['action']); |
2635
|
|
|
$this->assertSame([], $this->parameters['permissions']); |
2636
|
|
|
$this->assertSame($object, $this->parameters['object']); |
2637
|
|
|
$this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']); |
2638
|
|
|
$this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']); |
2639
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']); |
2640
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']); |
2641
|
|
|
|
2642
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2643
|
|
|
$this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template); |
2644
|
|
|
} |
2645
|
|
|
|
2646
|
|
|
public function testAclActionSuccessfulUpdate(): void |
2647
|
|
|
{ |
2648
|
|
|
$this->request->query->set('id', 123); |
2649
|
|
|
$this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []); |
2650
|
|
|
|
2651
|
|
|
$this->admin->expects($this->exactly(2)) |
|
|
|
|
2652
|
|
|
->method('isAclEnabled') |
2653
|
|
|
->willReturn(true); |
2654
|
|
|
|
2655
|
|
|
$object = new \stdClass(); |
2656
|
|
|
|
2657
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2658
|
|
|
->method('getObject') |
2659
|
|
|
->willReturn($object); |
2660
|
|
|
|
2661
|
|
|
$this->admin |
|
|
|
|
2662
|
|
|
->expects($this->once()) |
2663
|
|
|
->method('checkAccess'); |
2664
|
|
|
|
2665
|
|
|
$this->admin |
|
|
|
|
2666
|
|
|
->method('getSecurityInformation') |
2667
|
|
|
->willReturn([]); |
2668
|
|
|
|
2669
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2670
|
|
|
->method('getMaskBuilderClass') |
2671
|
|
|
->willReturn(AdminPermissionMap::class); |
2672
|
|
|
|
2673
|
|
|
$aclUsersForm = $this->getMockBuilder(Form::class) |
2674
|
|
|
->disableOriginalConstructor() |
2675
|
|
|
->getMock(); |
2676
|
|
|
|
2677
|
|
|
$aclUsersForm |
2678
|
|
|
->method('createView') |
2679
|
|
|
->willReturn($this->createMock(FormView::class)); |
2680
|
|
|
|
2681
|
|
|
$aclRolesForm = $this->getMockBuilder(Form::class) |
2682
|
|
|
->disableOriginalConstructor() |
2683
|
|
|
->getMock(); |
2684
|
|
|
|
2685
|
|
|
$aclRolesForm |
2686
|
|
|
->method('createView') |
2687
|
|
|
->willReturn($this->createMock(FormView::class)); |
2688
|
|
|
|
2689
|
|
|
$aclRolesForm->expects($this->once()) |
2690
|
|
|
->method('isValid') |
2691
|
|
|
->willReturn(true); |
2692
|
|
|
|
2693
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2694
|
|
|
->method('createAclUsersForm') |
2695
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2696
|
|
|
->willReturn($aclUsersForm); |
2697
|
|
|
|
2698
|
|
|
$this->adminObjectAclManipulator->expects($this->once()) |
|
|
|
|
2699
|
|
|
->method('createAclRolesForm') |
2700
|
|
|
->with($this->isInstanceOf(AdminObjectAclData::class)) |
2701
|
|
|
->willReturn($aclRolesForm); |
2702
|
|
|
|
2703
|
|
|
$aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
2704
|
|
|
|
2705
|
|
|
$aclSecurityHandler |
2706
|
|
|
->method('getObjectPermissions') |
2707
|
|
|
->willReturn([]); |
2708
|
|
|
|
2709
|
|
|
$this->admin |
|
|
|
|
2710
|
|
|
->method('getSecurityHandler') |
2711
|
|
|
->willReturn($aclSecurityHandler); |
2712
|
|
|
|
2713
|
|
|
$this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle'); |
2714
|
|
|
|
2715
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
2716
|
|
|
|
2717
|
|
|
$controller = $this->createController(); |
2718
|
|
|
$response = $controller->aclAction($this->request); |
2719
|
|
|
|
2720
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
2721
|
|
|
|
2722
|
|
|
$this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
2723
|
|
|
$this->assertSame('stdClass_acl', $response->getTargetUrl()); |
2724
|
|
|
} |
2725
|
|
|
|
2726
|
|
|
public function testHistoryViewRevisionActionAccessDenied(): void |
2727
|
|
|
{ |
2728
|
|
|
$this->admin |
|
|
|
|
2729
|
|
|
->method('getObject') |
2730
|
|
|
->willReturn(new \stdClass()); |
2731
|
|
|
|
2732
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2733
|
|
|
->method('checkAccess') |
2734
|
|
|
->with($this->equalTo('historyViewRevision')) |
2735
|
|
|
->will($this->throwException(new AccessDeniedException())); |
2736
|
|
|
|
2737
|
|
|
$this->expectException(AccessDeniedException::class); |
2738
|
|
|
|
2739
|
|
|
$this->controller->historyViewRevisionAction($this->request, null); |
2740
|
|
|
} |
2741
|
|
|
|
2742
|
|
|
public function testHistoryViewRevisionActionNotFoundException(): void |
2743
|
|
|
{ |
2744
|
|
|
$this->request->query->set('id', 123); |
2745
|
|
|
|
2746
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2747
|
|
|
->method('getObject') |
2748
|
|
|
->willReturn(null); |
2749
|
|
|
|
2750
|
|
|
$this->expectException(NotFoundHttpException::class); |
2751
|
|
|
$this->expectExceptionMessage('unable to find the object with id: 123'); |
2752
|
|
|
|
2753
|
|
|
$this->controller->historyViewRevisionAction($this->request, null); |
2754
|
|
|
} |
2755
|
|
|
|
2756
|
|
|
public function testHistoryViewRevisionActionNoReader(): void |
2757
|
|
|
{ |
2758
|
|
|
$this->expectException(NotFoundHttpException::class); |
2759
|
|
|
$this->expectExceptionMessage('unable to find the audit reader for class : Foo'); |
2760
|
|
|
|
2761
|
|
|
$this->request->query->set('id', 123); |
2762
|
|
|
|
2763
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2764
|
|
|
->method('checkAccess') |
2765
|
|
|
->with($this->equalTo('historyViewRevision')); |
2766
|
|
|
|
2767
|
|
|
$object = new \stdClass(); |
2768
|
|
|
|
2769
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2770
|
|
|
->method('getObject') |
2771
|
|
|
->willReturn($object); |
2772
|
|
|
|
2773
|
|
|
$this->admin |
|
|
|
|
2774
|
|
|
->method('getClass') |
2775
|
|
|
->willReturn('Foo'); |
2776
|
|
|
|
2777
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2778
|
|
|
->method('hasReader') |
2779
|
|
|
->with($this->equalTo('Foo')) |
2780
|
|
|
->willReturn(false); |
2781
|
|
|
|
2782
|
|
|
$this->controller->historyViewRevisionAction($this->request, null); |
2783
|
|
|
} |
2784
|
|
|
|
2785
|
|
|
public function testHistoryViewRevisionActionNotFoundRevision(): void |
2786
|
|
|
{ |
2787
|
|
|
$this->expectException(NotFoundHttpException::class); |
2788
|
|
|
$this->expectExceptionMessage( |
2789
|
|
|
'unable to find the targeted object `123` from the revision `456` with classname : `Foo`' |
2790
|
|
|
); |
2791
|
|
|
|
2792
|
|
|
$this->request->query->set('id', 123); |
2793
|
|
|
|
2794
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2795
|
|
|
->method('checkAccess') |
2796
|
|
|
->with($this->equalTo('historyViewRevision')); |
2797
|
|
|
|
2798
|
|
|
$object = new \stdClass(); |
2799
|
|
|
|
2800
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2801
|
|
|
->method('getObject') |
2802
|
|
|
->willReturn($object); |
2803
|
|
|
|
2804
|
|
|
$this->admin |
|
|
|
|
2805
|
|
|
->method('getClass') |
2806
|
|
|
->willReturn('Foo'); |
2807
|
|
|
|
2808
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2809
|
|
|
->method('hasReader') |
2810
|
|
|
->with($this->equalTo('Foo')) |
2811
|
|
|
->willReturn(true); |
2812
|
|
|
|
2813
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
2814
|
|
|
|
2815
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2816
|
|
|
->method('getReader') |
2817
|
|
|
->with($this->equalTo('Foo')) |
2818
|
|
|
->willReturn($reader); |
2819
|
|
|
|
2820
|
|
|
$reader->expects($this->once()) |
2821
|
|
|
->method('find') |
2822
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456)) |
2823
|
|
|
->willReturn(null); |
2824
|
|
|
|
2825
|
|
|
$this->controller->historyViewRevisionAction($this->request, 456); |
2826
|
|
|
} |
2827
|
|
|
|
2828
|
|
|
public function testHistoryViewRevisionAction(): void |
2829
|
|
|
{ |
2830
|
|
|
$this->request->query->set('id', 123); |
2831
|
|
|
|
2832
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2833
|
|
|
->method('checkAccess') |
2834
|
|
|
->with($this->equalTo('historyViewRevision')); |
2835
|
|
|
|
2836
|
|
|
$object = new \stdClass(); |
2837
|
|
|
|
2838
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2839
|
|
|
->method('getObject') |
2840
|
|
|
->willReturn($object); |
2841
|
|
|
|
2842
|
|
|
$this->admin |
|
|
|
|
2843
|
|
|
->method('getClass') |
2844
|
|
|
->willReturn('Foo'); |
2845
|
|
|
|
2846
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2847
|
|
|
->method('hasReader') |
2848
|
|
|
->with($this->equalTo('Foo')) |
2849
|
|
|
->willReturn(true); |
2850
|
|
|
|
2851
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
2852
|
|
|
|
2853
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2854
|
|
|
->method('getReader') |
2855
|
|
|
->with($this->equalTo('Foo')) |
2856
|
|
|
->willReturn($reader); |
2857
|
|
|
|
2858
|
|
|
$objectRevision = new \stdClass(); |
2859
|
|
|
$objectRevision->revision = 456; |
2860
|
|
|
|
2861
|
|
|
$reader->expects($this->once()) |
2862
|
|
|
->method('find') |
2863
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456)) |
2864
|
|
|
->willReturn($objectRevision); |
2865
|
|
|
|
2866
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2867
|
|
|
->method('setSubject') |
2868
|
|
|
->with($this->equalTo($objectRevision)); |
2869
|
|
|
|
2870
|
|
|
$fieldDescriptionCollection = new FieldDescriptionCollection(); |
2871
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2872
|
|
|
->method('getShow') |
2873
|
|
|
->willReturn($fieldDescriptionCollection); |
2874
|
|
|
|
2875
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction($this->request, 456)); |
2876
|
|
|
|
2877
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
2878
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
2879
|
|
|
|
2880
|
|
|
$this->assertSame('show', $this->parameters['action']); |
2881
|
|
|
$this->assertSame($objectRevision, $this->parameters['object']); |
2882
|
|
|
$this->assertSame($fieldDescriptionCollection, $this->parameters['elements']); |
2883
|
|
|
|
2884
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
2885
|
|
|
$this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template); |
2886
|
|
|
} |
2887
|
|
|
|
2888
|
|
|
public function testHistoryCompareRevisionsActionAccessDenied(): void |
2889
|
|
|
{ |
2890
|
|
|
$this->expectException(AccessDeniedException::class); |
2891
|
|
|
|
2892
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2893
|
|
|
->method('checkAccess') |
2894
|
|
|
->with($this->equalTo('historyCompareRevisions')) |
2895
|
|
|
->will($this->throwException(new AccessDeniedException())); |
2896
|
|
|
|
2897
|
|
|
$this->controller->historyCompareRevisionsAction($this->request, null, null); |
2898
|
|
|
} |
2899
|
|
|
|
2900
|
|
|
public function testHistoryCompareRevisionsActionNotFoundException(): void |
2901
|
|
|
{ |
2902
|
|
|
$this->expectException(NotFoundHttpException::class); |
2903
|
|
|
$this->expectExceptionMessage('unable to find the object with id: 123'); |
2904
|
|
|
|
2905
|
|
|
$this->request->query->set('id', 123); |
2906
|
|
|
|
2907
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2908
|
|
|
->method('checkAccess') |
2909
|
|
|
->with($this->equalTo('historyCompareRevisions')); |
2910
|
|
|
|
2911
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2912
|
|
|
->method('getObject') |
2913
|
|
|
->willReturn(null); |
2914
|
|
|
|
2915
|
|
|
$this->controller->historyCompareRevisionsAction($this->request, null, null); |
2916
|
|
|
} |
2917
|
|
|
|
2918
|
|
|
public function testHistoryCompareRevisionsActionNoReader(): void |
2919
|
|
|
{ |
2920
|
|
|
$this->expectException(NotFoundHttpException::class); |
2921
|
|
|
$this->expectExceptionMessage('unable to find the audit reader for class : Foo'); |
2922
|
|
|
|
2923
|
|
|
$this->request->query->set('id', 123); |
2924
|
|
|
|
2925
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2926
|
|
|
->method('checkAccess') |
2927
|
|
|
->with($this->equalTo('historyCompareRevisions')); |
2928
|
|
|
|
2929
|
|
|
$object = new \stdClass(); |
2930
|
|
|
|
2931
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2932
|
|
|
->method('getObject') |
2933
|
|
|
->willReturn($object); |
2934
|
|
|
|
2935
|
|
|
$this->admin |
|
|
|
|
2936
|
|
|
->method('getClass') |
2937
|
|
|
->willReturn('Foo'); |
2938
|
|
|
|
2939
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2940
|
|
|
->method('hasReader') |
2941
|
|
|
->with($this->equalTo('Foo')) |
2942
|
|
|
->willReturn(false); |
2943
|
|
|
|
2944
|
|
|
$this->controller->historyCompareRevisionsAction($this->request, null, null); |
2945
|
|
|
} |
2946
|
|
|
|
2947
|
|
|
public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void |
2948
|
|
|
{ |
2949
|
|
|
$this->expectException(NotFoundHttpException::class); |
2950
|
|
|
$this->expectExceptionMessage( |
2951
|
|
|
'unable to find the targeted object `123` from the revision `456` with classname : `Foo`' |
2952
|
|
|
); |
2953
|
|
|
|
2954
|
|
|
$this->request->query->set('id', 123); |
2955
|
|
|
|
2956
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2957
|
|
|
->method('checkAccess') |
2958
|
|
|
->with($this->equalTo('historyCompareRevisions')); |
2959
|
|
|
|
2960
|
|
|
$object = new \stdClass(); |
2961
|
|
|
|
2962
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
2963
|
|
|
->method('getObject') |
2964
|
|
|
->willReturn($object); |
2965
|
|
|
|
2966
|
|
|
$this->admin |
|
|
|
|
2967
|
|
|
->method('getClass') |
2968
|
|
|
->willReturn('Foo'); |
2969
|
|
|
|
2970
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2971
|
|
|
->method('hasReader') |
2972
|
|
|
->with($this->equalTo('Foo')) |
2973
|
|
|
->willReturn(true); |
2974
|
|
|
|
2975
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
2976
|
|
|
|
2977
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
2978
|
|
|
->method('getReader') |
2979
|
|
|
->with($this->equalTo('Foo')) |
2980
|
|
|
->willReturn($reader); |
2981
|
|
|
|
2982
|
|
|
// once because it will not be found and therefore the second call won't be executed |
2983
|
|
|
$reader->expects($this->once()) |
2984
|
|
|
->method('find') |
2985
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456)) |
2986
|
|
|
->willReturn(null); |
2987
|
|
|
|
2988
|
|
|
$this->controller->historyCompareRevisionsAction($this->request, 456, 789); |
2989
|
|
|
} |
2990
|
|
|
|
2991
|
|
|
public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void |
2992
|
|
|
{ |
2993
|
|
|
$this->expectException(NotFoundHttpException::class); |
2994
|
|
|
$this->expectExceptionMessage( |
2995
|
|
|
'unable to find the targeted object `123` from the revision `789` with classname : `Foo`' |
2996
|
|
|
); |
2997
|
|
|
|
2998
|
|
|
$this->request->query->set('id', 123); |
2999
|
|
|
|
3000
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3001
|
|
|
->method('checkAccess') |
3002
|
|
|
->with($this->equalTo('historyCompareRevisions')); |
3003
|
|
|
|
3004
|
|
|
$object = new \stdClass(); |
3005
|
|
|
|
3006
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3007
|
|
|
->method('getObject') |
3008
|
|
|
->willReturn($object); |
3009
|
|
|
|
3010
|
|
|
$this->admin |
|
|
|
|
3011
|
|
|
->method('getClass') |
3012
|
|
|
->willReturn('Foo'); |
3013
|
|
|
|
3014
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
3015
|
|
|
->method('hasReader') |
3016
|
|
|
->with($this->equalTo('Foo')) |
3017
|
|
|
->willReturn(true); |
3018
|
|
|
|
3019
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
3020
|
|
|
|
3021
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
3022
|
|
|
->method('getReader') |
3023
|
|
|
->with($this->equalTo('Foo')) |
3024
|
|
|
->willReturn($reader); |
3025
|
|
|
|
3026
|
|
|
$objectRevision = new \stdClass(); |
3027
|
|
|
$objectRevision->revision = 456; |
3028
|
|
|
|
3029
|
|
|
// first call should return, so the second call will throw an exception |
3030
|
|
|
$reader->expects($this->at(0)) |
3031
|
|
|
->method('find') |
3032
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456)) |
3033
|
|
|
->willReturn($objectRevision); |
3034
|
|
|
|
3035
|
|
|
$reader->expects($this->at(1)) |
3036
|
|
|
->method('find') |
3037
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789)) |
3038
|
|
|
->willReturn(null); |
3039
|
|
|
|
3040
|
|
|
$this->controller->historyCompareRevisionsAction($this->request, 456, 789); |
3041
|
|
|
} |
3042
|
|
|
|
3043
|
|
|
public function testHistoryCompareRevisionsActionAction(): void |
3044
|
|
|
{ |
3045
|
|
|
$this->request->query->set('id', 123); |
3046
|
|
|
|
3047
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3048
|
|
|
->method('checkAccess') |
3049
|
|
|
->with($this->equalTo('historyCompareRevisions')); |
3050
|
|
|
|
3051
|
|
|
$object = new \stdClass(); |
3052
|
|
|
|
3053
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3054
|
|
|
->method('getObject') |
3055
|
|
|
->willReturn($object); |
3056
|
|
|
|
3057
|
|
|
$this->admin |
|
|
|
|
3058
|
|
|
->method('getClass') |
3059
|
|
|
->willReturn('Foo'); |
3060
|
|
|
|
3061
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
3062
|
|
|
->method('hasReader') |
3063
|
|
|
->with($this->equalTo('Foo')) |
3064
|
|
|
->willReturn(true); |
3065
|
|
|
|
3066
|
|
|
$reader = $this->createMock(AuditReaderInterface::class); |
3067
|
|
|
|
3068
|
|
|
$this->auditManager->expects($this->once()) |
|
|
|
|
3069
|
|
|
->method('getReader') |
3070
|
|
|
->with($this->equalTo('Foo')) |
3071
|
|
|
->willReturn($reader); |
3072
|
|
|
|
3073
|
|
|
$objectRevision = new \stdClass(); |
3074
|
|
|
$objectRevision->revision = 456; |
3075
|
|
|
|
3076
|
|
|
$compareObjectRevision = new \stdClass(); |
3077
|
|
|
$compareObjectRevision->revision = 789; |
3078
|
|
|
|
3079
|
|
|
$reader->expects($this->at(0)) |
3080
|
|
|
->method('find') |
3081
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456)) |
3082
|
|
|
->willReturn($objectRevision); |
3083
|
|
|
|
3084
|
|
|
$reader->expects($this->at(1)) |
3085
|
|
|
->method('find') |
3086
|
|
|
->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789)) |
3087
|
|
|
->willReturn($compareObjectRevision); |
3088
|
|
|
|
3089
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3090
|
|
|
->method('setSubject') |
3091
|
|
|
->with($this->equalTo($objectRevision)); |
3092
|
|
|
|
3093
|
|
|
$fieldDescriptionCollection = new FieldDescriptionCollection(); |
3094
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3095
|
|
|
->method('getShow') |
3096
|
|
|
->willReturn($fieldDescriptionCollection); |
3097
|
|
|
|
3098
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction($this->request, 456, 789)); |
3099
|
|
|
|
3100
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
3101
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
3102
|
|
|
|
3103
|
|
|
$this->assertSame('show', $this->parameters['action']); |
3104
|
|
|
$this->assertSame($objectRevision, $this->parameters['object']); |
3105
|
|
|
$this->assertSame($compareObjectRevision, $this->parameters['object_compare']); |
3106
|
|
|
$this->assertSame($fieldDescriptionCollection, $this->parameters['elements']); |
3107
|
|
|
|
3108
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
3109
|
|
|
$this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template); |
3110
|
|
|
} |
3111
|
|
|
|
3112
|
|
|
public function testBatchActionWrongMethod(): void |
3113
|
|
|
{ |
3114
|
|
|
$this->expectException(NotFoundHttpException::class); |
3115
|
|
|
$this->expectExceptionMessage('Invalid request method given "GET", POST expected'); |
3116
|
|
|
|
3117
|
|
|
$this->controller->batchAction($this->request); |
3118
|
|
|
} |
3119
|
|
|
|
3120
|
|
|
public function testBatchActionActionNotDefined(): void |
3121
|
|
|
{ |
3122
|
|
|
$this->expectException(\RuntimeException::class); |
3123
|
|
|
$this->expectExceptionMessage('The `foo` batch action is not defined'); |
3124
|
|
|
|
3125
|
|
|
$batchActions = []; |
3126
|
|
|
|
3127
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3128
|
|
|
->method('getBatchActions') |
3129
|
|
|
->willReturn($batchActions); |
3130
|
|
|
|
3131
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3132
|
|
|
$this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false])); |
3133
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3134
|
|
|
|
3135
|
|
|
$this->controller->batchAction($this->request); |
3136
|
|
|
} |
3137
|
|
|
|
3138
|
|
|
public function testBatchActionActionInvalidCsrfToken(): void |
3139
|
|
|
{ |
3140
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3141
|
|
|
$this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false])); |
3142
|
|
|
$this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID'); |
3143
|
|
|
|
3144
|
|
|
try { |
3145
|
|
|
$this->controller->batchAction($this->request); |
3146
|
|
|
} catch (HttpException $e) { |
3147
|
|
|
$this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage()); |
3148
|
|
|
$this->assertSame(400, $e->getStatusCode()); |
3149
|
|
|
} |
3150
|
|
|
} |
3151
|
|
|
|
3152
|
|
|
public function testBatchActionMethodNotExist(): void |
3153
|
|
|
{ |
3154
|
|
|
$this->expectException(\RuntimeException::class); |
3155
|
|
|
$this->expectExceptionMessage( |
3156
|
|
|
'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable' |
3157
|
|
|
); |
3158
|
|
|
|
3159
|
|
|
$batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3160
|
|
|
|
3161
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3162
|
|
|
->method('getBatchActions') |
3163
|
|
|
->willReturn($batchActions); |
3164
|
|
|
|
3165
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3166
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3167
|
|
|
->method('getDatagrid') |
3168
|
|
|
->willReturn($datagrid); |
3169
|
|
|
|
3170
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3171
|
|
|
$this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false])); |
3172
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3173
|
|
|
|
3174
|
|
|
$this->controller->batchAction($this->request); |
3175
|
|
|
} |
3176
|
|
|
|
3177
|
|
|
public function testBatchActionWithoutConfirmation(): void |
3178
|
|
|
{ |
3179
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3180
|
|
|
|
3181
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3182
|
|
|
->method('getBatchActions') |
3183
|
|
|
->willReturn($batchActions); |
3184
|
|
|
|
3185
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3186
|
|
|
|
3187
|
|
|
$query = $this->createMock(ProxyQueryInterface::class); |
3188
|
|
|
$datagrid->expects($this->once()) |
3189
|
|
|
->method('getQuery') |
3190
|
|
|
->willReturn($query); |
3191
|
|
|
|
3192
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3193
|
|
|
->method('getDatagrid') |
3194
|
|
|
->willReturn($datagrid); |
3195
|
|
|
|
3196
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
3197
|
|
|
|
3198
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3199
|
|
|
->method('checkAccess') |
3200
|
|
|
->with($this->equalTo('batchDelete')); |
3201
|
|
|
|
3202
|
|
|
$this->admin |
|
|
|
|
3203
|
|
|
->method('getModelManager') |
3204
|
|
|
->willReturn($modelManager); |
3205
|
|
|
|
3206
|
|
|
$this->admin |
|
|
|
|
3207
|
|
|
->method('getClass') |
3208
|
|
|
->willReturn('Foo'); |
3209
|
|
|
|
3210
|
|
|
$modelManager->expects($this->once()) |
3211
|
|
|
->method('addIdentifiersToQuery') |
3212
|
|
|
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456'])) |
3213
|
|
|
->willReturn(true); |
3214
|
|
|
|
3215
|
|
|
$this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle'); |
3216
|
|
|
|
3217
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3218
|
|
|
$this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false])); |
3219
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3220
|
|
|
|
3221
|
|
|
$result = $this->controller->batchAction($this->request); |
3222
|
|
|
|
3223
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3224
|
|
|
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
3225
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3226
|
|
|
} |
3227
|
|
|
|
3228
|
|
|
public function testBatchActionWithoutConfirmation2(): void |
3229
|
|
|
{ |
3230
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3231
|
|
|
|
3232
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3233
|
|
|
->method('getBatchActions') |
3234
|
|
|
->willReturn($batchActions); |
3235
|
|
|
|
3236
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3237
|
|
|
|
3238
|
|
|
$query = $this->createMock(ProxyQueryInterface::class); |
3239
|
|
|
$datagrid->expects($this->once()) |
3240
|
|
|
->method('getQuery') |
3241
|
|
|
->willReturn($query); |
3242
|
|
|
|
3243
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3244
|
|
|
->method('getDatagrid') |
3245
|
|
|
->willReturn($datagrid); |
3246
|
|
|
|
3247
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
3248
|
|
|
|
3249
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3250
|
|
|
->method('checkAccess') |
3251
|
|
|
->with($this->equalTo('batchDelete')); |
3252
|
|
|
|
3253
|
|
|
$this->admin |
|
|
|
|
3254
|
|
|
->method('getModelManager') |
3255
|
|
|
->willReturn($modelManager); |
3256
|
|
|
|
3257
|
|
|
$this->admin |
|
|
|
|
3258
|
|
|
->method('getClass') |
3259
|
|
|
->willReturn('Foo'); |
3260
|
|
|
|
3261
|
|
|
$modelManager->expects($this->once()) |
3262
|
|
|
->method('addIdentifiersToQuery') |
3263
|
|
|
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456'])) |
3264
|
|
|
->willReturn(true); |
3265
|
|
|
|
3266
|
|
|
$this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle'); |
3267
|
|
|
|
3268
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3269
|
|
|
$this->request->request->set('action', 'delete'); |
3270
|
|
|
$this->request->request->set('idx', ['123', '456']); |
3271
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3272
|
|
|
|
3273
|
|
|
$result = $this->controller->batchAction($this->request); |
3274
|
|
|
|
3275
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3276
|
|
|
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
3277
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3278
|
|
|
} |
3279
|
|
|
|
3280
|
|
|
public function testBatchActionWithConfirmation(): void |
3281
|
|
|
{ |
3282
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]]; |
3283
|
|
|
|
3284
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3285
|
|
|
->method('getBatchActions') |
3286
|
|
|
->willReturn($batchActions); |
3287
|
|
|
|
3288
|
|
|
$data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]; |
3289
|
|
|
|
3290
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3291
|
|
|
$this->request->request->set('data', json_encode($data)); |
3292
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3293
|
|
|
|
3294
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3295
|
|
|
|
3296
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3297
|
|
|
->method('getDatagrid') |
3298
|
|
|
->willReturn($datagrid); |
3299
|
|
|
|
3300
|
|
|
$form = $this->getMockBuilder(Form::class) |
3301
|
|
|
->disableOriginalConstructor() |
3302
|
|
|
->getMock(); |
3303
|
|
|
|
3304
|
|
|
$form->expects($this->once()) |
3305
|
|
|
->method('createView') |
3306
|
|
|
->willReturn($this->createMock(FormView::class)); |
3307
|
|
|
|
3308
|
|
|
$datagrid->expects($this->once()) |
3309
|
|
|
->method('getForm') |
3310
|
|
|
->willReturn($form); |
3311
|
|
|
|
3312
|
|
|
$this->assertInstanceOf(Response::class, $this->controller->batchAction($this->request)); |
3313
|
|
|
|
3314
|
|
|
$this->assertSame($this->admin, $this->parameters['admin']); |
3315
|
|
|
$this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); |
3316
|
|
|
|
3317
|
|
|
$this->assertSame('list', $this->parameters['action']); |
3318
|
|
|
$this->assertSame($datagrid, $this->parameters['datagrid']); |
3319
|
|
|
$this->assertInstanceOf(FormView::class, $this->parameters['form']); |
3320
|
|
|
$this->assertSame($data, $this->parameters['data']); |
3321
|
|
|
$this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']); |
3322
|
|
|
$this->assertSame('Foo Bar', $this->parameters['action_label']); |
3323
|
|
|
|
3324
|
|
|
$this->assertSame([], $this->session->getFlashBag()->all()); |
3325
|
|
|
$this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template); |
3326
|
|
|
} |
3327
|
|
|
|
3328
|
|
|
public function testBatchActionNonRelevantAction(): void |
3329
|
|
|
{ |
3330
|
|
|
$controller = $this->createController(BatchAdminController::class); |
3331
|
|
|
|
3332
|
|
|
$batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3333
|
|
|
|
3334
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3335
|
|
|
->method('getBatchActions') |
3336
|
|
|
->willReturn($batchActions); |
3337
|
|
|
|
3338
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3339
|
|
|
|
3340
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3341
|
|
|
->method('getDatagrid') |
3342
|
|
|
->willReturn($datagrid); |
3343
|
|
|
|
3344
|
|
|
$this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle'); |
3345
|
|
|
|
3346
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3347
|
|
|
$this->request->request->set('action', 'foo'); |
3348
|
|
|
$this->request->request->set('idx', ['789']); |
3349
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3350
|
|
|
|
3351
|
|
|
$result = $controller->batchAction($this->request); |
3352
|
|
|
|
3353
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3354
|
|
|
$this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info')); |
3355
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3356
|
|
|
} |
3357
|
|
|
|
3358
|
|
|
public function testBatchActionWithCustomConfirmationTemplate(): void |
3359
|
|
|
{ |
3360
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']]; |
3361
|
|
|
|
3362
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3363
|
|
|
->method('getBatchActions') |
3364
|
|
|
->willReturn($batchActions); |
3365
|
|
|
|
3366
|
|
|
$data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]; |
3367
|
|
|
|
3368
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3369
|
|
|
$this->request->request->set('data', json_encode($data)); |
3370
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3371
|
|
|
|
3372
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3373
|
|
|
|
3374
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3375
|
|
|
->method('getDatagrid') |
3376
|
|
|
->willReturn($datagrid); |
3377
|
|
|
|
3378
|
|
|
$form = $this->createMock(Form::class); |
3379
|
|
|
|
3380
|
|
|
$form->expects($this->once()) |
3381
|
|
|
->method('createView') |
3382
|
|
|
->willReturn($this->createMock(FormView::class)); |
3383
|
|
|
|
3384
|
|
|
$datagrid->expects($this->once()) |
3385
|
|
|
->method('getForm') |
3386
|
|
|
->willReturn($form); |
3387
|
|
|
|
3388
|
|
|
$this->controller->batchAction($this->request); |
3389
|
|
|
|
3390
|
|
|
$this->assertSame('custom_template.html.twig', $this->template); |
3391
|
|
|
} |
3392
|
|
|
|
3393
|
|
|
public function testBatchActionNonRelevantAction2(): void |
3394
|
|
|
{ |
3395
|
|
|
$controller = $this->createController(BatchAdminController::class); |
3396
|
|
|
|
3397
|
|
|
$batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3398
|
|
|
|
3399
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3400
|
|
|
->method('getBatchActions') |
3401
|
|
|
->willReturn($batchActions); |
3402
|
|
|
|
3403
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3404
|
|
|
|
3405
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3406
|
|
|
->method('getDatagrid') |
3407
|
|
|
->willReturn($datagrid); |
3408
|
|
|
|
3409
|
|
|
$this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle'); |
3410
|
|
|
|
3411
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3412
|
|
|
$this->request->request->set('action', 'foo'); |
3413
|
|
|
$this->request->request->set('idx', ['999']); |
3414
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3415
|
|
|
|
3416
|
|
|
$result = $controller->batchAction($this->request); |
3417
|
|
|
|
3418
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3419
|
|
|
$this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info')); |
3420
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3421
|
|
|
} |
3422
|
|
|
|
3423
|
|
|
public function testBatchActionNoItems(): void |
3424
|
|
|
{ |
3425
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]]; |
3426
|
|
|
|
3427
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3428
|
|
|
->method('getBatchActions') |
3429
|
|
|
->willReturn($batchActions); |
3430
|
|
|
|
3431
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3432
|
|
|
|
3433
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3434
|
|
|
->method('getDatagrid') |
3435
|
|
|
->willReturn($datagrid); |
3436
|
|
|
|
3437
|
|
|
$this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle'); |
3438
|
|
|
|
3439
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3440
|
|
|
$this->request->request->set('action', 'delete'); |
3441
|
|
|
$this->request->request->set('idx', []); |
3442
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3443
|
|
|
|
3444
|
|
|
$result = $this->controller->batchAction($this->request); |
3445
|
|
|
|
3446
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3447
|
|
|
$this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info')); |
3448
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3449
|
|
|
} |
3450
|
|
|
|
3451
|
|
|
public function testBatchActionNoItemsEmptyQuery(): void |
3452
|
|
|
{ |
3453
|
|
|
$controller = $this->createController(BatchAdminController::class); |
3454
|
|
|
|
3455
|
|
|
$batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3456
|
|
|
|
3457
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3458
|
|
|
->method('getBatchActions') |
3459
|
|
|
->willReturn($batchActions); |
3460
|
|
|
|
3461
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3462
|
|
|
|
3463
|
|
|
$query = $this->createMock(ProxyQueryInterface::class); |
3464
|
|
|
$datagrid->expects($this->once()) |
3465
|
|
|
->method('getQuery') |
3466
|
|
|
->willReturn($query); |
3467
|
|
|
|
3468
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3469
|
|
|
->method('getDatagrid') |
3470
|
|
|
->willReturn($datagrid); |
3471
|
|
|
|
3472
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
3473
|
|
|
|
3474
|
|
|
$this->admin |
|
|
|
|
3475
|
|
|
->method('getModelManager') |
3476
|
|
|
->willReturn($modelManager); |
3477
|
|
|
|
3478
|
|
|
$this->admin |
|
|
|
|
3479
|
|
|
->method('getClass') |
3480
|
|
|
->willReturn('Foo'); |
3481
|
|
|
|
3482
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3483
|
|
|
$this->request->request->set('action', 'bar'); |
3484
|
|
|
$this->request->request->set('idx', []); |
3485
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3486
|
|
|
|
3487
|
|
|
$this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle'); |
3488
|
|
|
$result = $controller->batchAction($this->request); |
3489
|
|
|
|
3490
|
|
|
$this->assertInstanceOf(Response::class, $result); |
3491
|
|
|
$this->assertRegExp('/Redirecting to list/', $result->getContent()); |
3492
|
|
|
} |
3493
|
|
|
|
3494
|
|
|
public function testBatchActionWithRequesData(): void |
3495
|
|
|
{ |
3496
|
|
|
$batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]]; |
3497
|
|
|
|
3498
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3499
|
|
|
->method('getBatchActions') |
3500
|
|
|
->willReturn($batchActions); |
3501
|
|
|
|
3502
|
|
|
$datagrid = $this->createMock(DatagridInterface::class); |
3503
|
|
|
|
3504
|
|
|
$query = $this->createMock(ProxyQueryInterface::class); |
3505
|
|
|
$datagrid->expects($this->once()) |
3506
|
|
|
->method('getQuery') |
3507
|
|
|
->willReturn($query); |
3508
|
|
|
|
3509
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3510
|
|
|
->method('getDatagrid') |
3511
|
|
|
->willReturn($datagrid); |
3512
|
|
|
|
3513
|
|
|
$modelManager = $this->createMock(ModelManagerInterface::class); |
3514
|
|
|
|
3515
|
|
|
$this->admin->expects($this->once()) |
|
|
|
|
3516
|
|
|
->method('checkAccess') |
3517
|
|
|
->with($this->equalTo('batchDelete')); |
3518
|
|
|
|
3519
|
|
|
$this->admin |
|
|
|
|
3520
|
|
|
->method('getModelManager') |
3521
|
|
|
->willReturn($modelManager); |
3522
|
|
|
|
3523
|
|
|
$this->admin |
|
|
|
|
3524
|
|
|
->method('getClass') |
3525
|
|
|
->willReturn('Foo'); |
3526
|
|
|
|
3527
|
|
|
$modelManager->expects($this->once()) |
3528
|
|
|
->method('addIdentifiersToQuery') |
3529
|
|
|
->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456'])) |
3530
|
|
|
->willReturn(true); |
3531
|
|
|
|
3532
|
|
|
$this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle'); |
3533
|
|
|
|
3534
|
|
|
$this->request->setMethod(Request::METHOD_POST); |
3535
|
|
|
$this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false])); |
3536
|
|
|
$this->request->request->set('foo', 'bar'); |
3537
|
|
|
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch'); |
3538
|
|
|
|
3539
|
|
|
$result = $this->controller->batchAction($this->request); |
3540
|
|
|
|
3541
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $result); |
3542
|
|
|
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success')); |
3543
|
|
|
$this->assertSame('list', $result->getTargetUrl()); |
3544
|
|
|
$this->assertSame('bar', $this->request->request->get('foo')); |
3545
|
|
|
} |
3546
|
|
|
|
3547
|
|
|
public function getCsrfProvider() |
3548
|
|
|
{ |
3549
|
|
|
return $this->csrfProvider; |
3550
|
|
|
} |
3551
|
|
|
|
3552
|
|
|
public function getToStringValues() |
3553
|
|
|
{ |
3554
|
|
|
return [ |
3555
|
|
|
['', ''], |
3556
|
|
|
['Foo', 'Foo'], |
3557
|
|
|
['<a href="http://foo">Bar</a>', '<a href="http://foo">Bar</a>'], |
3558
|
|
|
['<>&"'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'], |
3559
|
|
|
]; |
3560
|
|
|
} |
3561
|
|
|
|
3562
|
|
|
private function assertLoggerLogsModelManagerException($subject, string $method): void |
3563
|
|
|
{ |
3564
|
|
|
$exception = new ModelManagerException( |
3565
|
|
|
$message = 'message', |
3566
|
|
|
1234, |
3567
|
|
|
new \Exception($previousExceptionMessage = 'very useful message') |
3568
|
|
|
); |
3569
|
|
|
|
3570
|
|
|
$subject->expects($this->once()) |
3571
|
|
|
->method($method) |
3572
|
|
|
->willReturnCallback(static function () use ($exception): void { |
3573
|
|
|
throw $exception; |
3574
|
|
|
}); |
3575
|
|
|
|
3576
|
|
|
$this->logger->expects($this->once()) |
|
|
|
|
3577
|
|
|
->method('error') |
3578
|
|
|
->with($message, [ |
3579
|
|
|
'exception' => $exception, |
3580
|
|
|
'previous_exception_message' => $previousExceptionMessage, |
3581
|
|
|
]); |
3582
|
|
|
} |
3583
|
|
|
|
3584
|
|
|
private function expectTranslate( |
3585
|
|
|
string $id, |
3586
|
|
|
array $parameters = [], |
3587
|
|
|
?string $domain = null, |
3588
|
|
|
?string $locale = null |
3589
|
|
|
): void { |
3590
|
|
|
$this->translator->expects($this->once()) |
|
|
|
|
3591
|
|
|
->method('trans') |
3592
|
|
|
->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale)) |
3593
|
|
|
->willReturn($id); |
3594
|
|
|
} |
3595
|
|
|
|
3596
|
|
|
private function createTwig(): Environment |
3597
|
|
|
{ |
3598
|
|
|
$templatingRenderReturnCallback = $this->returnCallback(function ( |
3599
|
|
|
string $name, |
3600
|
|
|
array $context = [] |
3601
|
|
|
): string { |
3602
|
|
|
$this->template = $name; |
3603
|
|
|
|
3604
|
|
|
$this->parameters = $context; |
3605
|
|
|
|
3606
|
|
|
return ''; |
3607
|
|
|
}); |
3608
|
|
|
|
3609
|
|
|
$twig = $this->getMockBuilder(Environment::class) |
3610
|
|
|
->disableOriginalConstructor() |
3611
|
|
|
->getMock(); |
3612
|
|
|
|
3613
|
|
|
$twig |
3614
|
|
|
->method('getRuntime') |
3615
|
|
|
->willReturn($this->createMock(FormRenderer::class)); |
3616
|
|
|
|
3617
|
|
|
$twig |
3618
|
|
|
->method('render') |
3619
|
|
|
->will($templatingRenderReturnCallback); |
3620
|
|
|
|
3621
|
|
|
return $twig; |
3622
|
|
|
} |
3623
|
|
|
|
3624
|
|
|
private function createController( |
3625
|
|
|
string $classname = CRUDController::class, |
3626
|
|
|
bool $kernelDebug = false |
3627
|
|
|
): CRUDController { |
3628
|
|
|
$requestStack = new RequestStack(); |
3629
|
|
|
$requestStack->push($this->request); |
3630
|
|
|
|
3631
|
|
|
$pool = new Pool($this->container, 'title', 'logo.png'); |
3632
|
|
|
$pool->setAdminServiceIds(['foo.admin']); |
3633
|
|
|
|
3634
|
|
|
return new $classname( |
3635
|
|
|
$requestStack, |
3636
|
|
|
$pool, |
3637
|
|
|
$this->templateRegistry->reveal(), |
|
|
|
|
3638
|
|
|
new BreadcrumbsBuilder([]), |
3639
|
|
|
$this->createTwig(), |
3640
|
|
|
$this->translator, |
3641
|
|
|
$this->session, |
3642
|
|
|
$kernelDebug, |
3643
|
|
|
$this->auditManager, |
3644
|
|
|
$this->exporter, |
3645
|
|
|
new AdminExporter($this->exporter), |
3646
|
|
|
$this->csrfProvider, |
3647
|
|
|
$this->logger, |
3648
|
|
|
$this->adminObjectAclManipulator |
3649
|
|
|
); |
3650
|
|
|
} |
3651
|
|
|
} |
3652
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.