Completed
Pull Request — master (#6210)
by Jordi Sala
02:51 queued 10s
created

testBatchActionWithoutConfirmation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
rs 9.0909
cc 1
nc 1
nop 0
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\Component\DependencyInjection\Container;
43
use Symfony\Component\DependencyInjection\ContainerInterface;
44
use Symfony\Component\Form\Form;
45
use Symfony\Component\Form\FormError;
46
use Symfony\Component\Form\FormRenderer;
47
use Symfony\Component\Form\FormView;
48
use Symfony\Component\HttpFoundation\JsonResponse;
49
use Symfony\Component\HttpFoundation\RedirectResponse;
50
use Symfony\Component\HttpFoundation\Request;
51
use Symfony\Component\HttpFoundation\RequestStack;
52
use Symfony\Component\HttpFoundation\Response;
53
use Symfony\Component\HttpFoundation\Session\Session;
54
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
55
use Symfony\Component\HttpFoundation\StreamedResponse;
56
use Symfony\Component\HttpKernel\Exception\HttpException;
57
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
58
use Symfony\Component\HttpKernel\KernelInterface;
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
 * @group legacy
71
 */
72
class CRUDControllerTest extends TestCase
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 KernelInterface
141
     */
142
    private $kernel;
143
144
    /**
145
     * @var TranslatorInterface
146
     */
147
    private $translator;
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
        $templatingRenderReturnCallback = $this->returnCallback(function (
172
            string $name,
173
            array $context = []
174
        ): string {
175
            $this->template = $name;
176
177
            $this->parameters = $context;
178
179
            return '';
180
        });
181
182
        $this->session = new Session(new MockArraySessionStorage());
183
184
        $twig = $this->getMockBuilder(Environment::class)
185
            ->disableOriginalConstructor()
186
            ->getMock();
187
188
        $twig
189
            ->method('getRuntime')
190
            ->willReturn($this->createMock(FormRenderer::class));
191
192
        $twig
193
            ->method('render')
194
            ->will($templatingRenderReturnCallback);
195
196
        $exporter = new Exporter([new JsonWriter(sys_get_temp_dir().'/sonataadmin/export.json')]);
197
198
        $adminExporter = new AdminExporter($exporter);
199
200
        $this->auditManager = $this->createMock(AuditManagerInterface::class);
201
202
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
203
            ->disableOriginalConstructor()
204
            ->getMock();
205
206
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
207
            ->getMock();
208
209
        $this->csrfProvider
210
            ->method('getToken')
211
            ->willReturnCallback(static function (string $intention): CsrfToken {
212
                return new CsrfToken($intention, sprintf('csrf-token-123_%s', $intention));
213
            });
214
215
        $this->csrfProvider
216
            ->method('isTokenValid')
217
            ->willReturnCallback(static function (CsrfToken $token): bool {
218
                return $token->getValue() === sprintf('csrf-token-123_%s', $token->getId());
219
            });
220
221
        $this->logger = $this->createMock(LoggerInterface::class);
222
223
        $requestStack = new RequestStack();
224
        $requestStack->push($this->request);
225
226
        $this->kernel = $this->createMock(KernelInterface::class);
227
228
        $this->container->set('sonata.admin.pool', $this->pool);
229
        $this->container->set('request_stack', $requestStack);
230
        $this->container->set('foo.admin', $this->admin);
231
        $this->container->set('foo.admin.template_registry', $this->templateRegistry->reveal());
232
        $this->container->set('twig', $twig);
233
        $this->container->set('session', $this->session);
234
        $this->container->set('sonata.exporter.exporter', $exporter);
235
        $this->container->set('sonata.admin.admin_exporter', $adminExporter);
236
        $this->container->set('sonata.admin.audit.manager', $this->auditManager);
237
        $this->container->set('sonata.admin.object.manipulator.acl.admin', $this->adminObjectAclManipulator);
238
        $this->container->set('security.csrf.token_manager', $this->csrfProvider);
239
        $this->container->set('logger', $this->logger);
240
        $this->container->set('kernel', $this->kernel);
241
        $this->container->set('translator', $this->translator);
242
        $this->container->set('sonata.admin.breadcrumbs_builder', new BreadcrumbsBuilder([]));
243
244
        $this->container->setParameter(
245
            'security.role_hierarchy.roles',
246
            ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']]
247
        );
248
        $this->container->setParameter('sonata.admin.security.acl_user_manager', null);
249
250
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
251
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
252
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
253
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
254
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
255
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
256
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
257
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
258
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
259
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
260
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
261
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
262
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
263
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
264
265
        $this->admin
266
            ->method('getIdParameter')
267
            ->willReturn('id');
268
269
        $this->admin
270
            ->method('getAccessMapping')
271
            ->willReturn([]);
272
273
        $this->admin
274
            ->method('generateUrl')
275
            ->willReturnCallback(
276
                static function ($name, array $parameters = []) {
277
                    $result = $name;
278
                    if (!empty($parameters)) {
279
                        $result .= '?'.http_build_query($parameters);
280
                    }
281
282
                    return $result;
283
                }
284
            );
285
286
        $this->admin
287
            ->method('generateObjectUrl')
288
            ->willReturnCallback(
289
                static function (string $name, $object, array $parameters = []): string {
290
                    $result = sprintf('%s_%s', \get_class($object), $name);
291
                    if (!empty($parameters)) {
292
                        $result .= '?'.http_build_query($parameters);
293
                    }
294
295
                    return $result;
296
                }
297
            );
298
299
        $this->admin
300
            ->method('getCode')
301
            ->willReturn('foo.admin');
302
303
        $this->controller = new CRUDController();
304
        $this->controller->setContainer($this->container);
305
306
        // Make some methods public to test them
307
        $testedMethods = [
308
            'renderJson',
309
            'isXmlHttpRequest',
310
            'configure',
311
            'getBaseTemplate',
312
            'redirectTo',
313
            'addFlash',
314
        ];
315
        foreach ($testedMethods as $testedMethod) {
316
            $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
317
            $method->setAccessible(true);
318
            $this->protectedTestedMethods[$testedMethod] = $method;
319
        }
320
    }
321
322
    public function testRenderJson1(): void
323
    {
324
        $data = ['example' => '123', 'foo' => 'bar'];
325
326
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
327
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
328
329
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
330
        $this->assertSame(json_encode($data), $response->getContent());
331
    }
332
333
    public function testRenderJson2(): void
334
    {
335
        $data = ['example' => '123', 'foo' => 'bar'];
336
337
        $this->request->headers->set('Content-Type', 'multipart/form-data');
338
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
339
340
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
341
        $this->assertSame(json_encode($data), $response->getContent());
342
    }
343
344
    public function testRenderJsonAjax(): void
345
    {
346
        $data = ['example' => '123', 'foo' => 'bar'];
347
348
        $this->request->attributes->set('_xml_http_request', true);
349
        $this->request->headers->set('Content-Type', 'multipart/form-data');
350
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
351
352
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
353
        $this->assertSame(json_encode($data), $response->getContent());
354
    }
355
356
    public function testIsXmlHttpRequest(): void
357
    {
358
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
359
360
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
361
362
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
363
364
        $this->request->headers->remove('X-Requested-With');
365
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
366
367
        $this->request->attributes->set('_xml_http_request', true);
368
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
369
    }
370
371
    public function testConfigure(): void
372
    {
373
        $uniqueId = '';
374
375
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
376
            ->method('setUniqid')
377
            ->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void {
378
                $uniqueId = $uniqid;
379
            });
380
381
        $this->request->query->set('uniqid', '123456');
382
        $this->protectedTestedMethods['configure']->invoke($this->controller);
383
384
        $this->assertSame('123456', $uniqueId);
385
    }
386
387
    public function testConfigureChild(): void
388
    {
389
        $uniqueId = '';
390
391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
392
            ->method('setUniqid')
393
            ->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void {
394
                $uniqueId = $uniqid;
395
            });
396
397
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
398
            ->method('isChild')
399
            ->willReturn(true);
400
401
        $adminParent = $this->getMockBuilder(AdminInterface::class)
402
            ->disableOriginalConstructor()
403
            ->getMock();
404
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
405
            ->method('getParent')
406
            ->willReturn($adminParent);
407
408
        $this->request->query->set('uniqid', '123456');
409
        $this->protectedTestedMethods['configure']->invoke($this->controller);
410
411
        $this->assertSame('123456', $uniqueId);
412
    }
413
414
    public function testConfigureWithException(): void
415
    {
416
        $this->expectException(\RuntimeException::class);
417
        $this->expectExceptionMessage(
418
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
419
        );
420
421
        $this->request->attributes->remove('_sonata_admin');
422
        $this->protectedTestedMethods['configure']->invoke($this->controller);
423
    }
424
425
    public function testConfigureWithException2(): void
426
    {
427
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
428
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
429
430
        $this->expectException(\RuntimeException::class);
431
        $this->expectExceptionMessage('Unable to find the admin class related to the current controller (Sonata\AdminBundle\Controller\CRUDController)');
432
433
        $this->protectedTestedMethods['configure']->invoke($this->controller);
434
    }
435
436
    public function testGetBaseTemplate(): void
437
    {
438
        $this->assertSame(
439
            '@SonataAdmin/standard_layout.html.twig',
440
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
441
        );
442
443
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
444
        $this->assertSame(
445
            '@SonataAdmin/ajax_layout.html.twig',
446
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
447
        );
448
449
        $this->request->headers->remove('X-Requested-With');
450
        $this->assertSame(
451
            '@SonataAdmin/standard_layout.html.twig',
452
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
453
        );
454
455
        $this->request->attributes->set('_xml_http_request', true);
456
        $this->assertSame(
457
            '@SonataAdmin/ajax_layout.html.twig',
458
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
459
        );
460
    }
461
462
    public function testRender(): void
463
    {
464
        $this->parameters = [];
465
        $this->assertInstanceOf(
466
            Response::class,
467
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
468
        );
469
        $this->assertSame($this->admin, $this->parameters['admin']);
470
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
471
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
472
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
473
    }
474
475
    public function testRenderWithResponse(): void
476
    {
477
        $this->parameters = [];
478
        $response = new Response();
479
        $response->headers->set('X-foo', 'bar');
480
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
481
482
        $this->assertSame($response, $responseResult);
483
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
484
        $this->assertSame($this->admin, $this->parameters['admin']);
485
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
486
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
487
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
488
    }
489
490
    public function testRenderCustomParams(): void
491
    {
492
        $this->parameters = [];
493
        $this->assertInstanceOf(
494
            Response::class,
495
            $this->controller->renderWithExtraParams(
496
                '@FooAdmin/foo.html.twig',
497
                ['foo' => 'bar'],
498
                null
499
            )
500
        );
501
        $this->assertSame($this->admin, $this->parameters['admin']);
502
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
503
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
504
        $this->assertSame('bar', $this->parameters['foo']);
505
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
506
    }
507
508
    public function testRenderAjax(): void
509
    {
510
        $this->parameters = [];
511
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
512
        $this->assertInstanceOf(
513
            Response::class,
514
            $this->controller->renderWithExtraParams(
515
                '@FooAdmin/foo.html.twig',
516
                ['foo' => 'bar'],
517
                null
518
            )
519
        );
520
        $this->assertSame($this->admin, $this->parameters['admin']);
521
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
522
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
523
        $this->assertSame('bar', $this->parameters['foo']);
524
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
525
    }
526
527
    public function testListActionAccessDenied(): void
528
    {
529
        $this->expectException(AccessDeniedException::class);
530
531
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
532
            ->method('checkAccess')
533
            ->with($this->equalTo('list'))
534
            ->will($this->throwException(new AccessDeniedException()));
535
536
        $this->controller->listAction($this->request);
537
    }
538
539
    public function testPreList(): void
540
    {
541
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
542
            ->method('hasRoute')
543
            ->with($this->equalTo('list'))
544
            ->willReturn(true);
545
546
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
547
            ->method('checkAccess')
548
            ->with($this->equalTo('list'));
549
550
        $controller = new PreCRUDController();
551
        $controller->setContainer($this->container);
552
553
        $response = $controller->listAction($this->request);
554
        $this->assertInstanceOf(Response::class, $response);
555
        $this->assertSame('preList called', $response->getContent());
556
    }
557
558
    public function testListAction(): void
559
    {
560
        $datagrid = $this->createMock(DatagridInterface::class);
561
562
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
563
            ->method('hasRoute')
564
            ->with($this->equalTo('list'))
565
            ->willReturn(true);
566
567
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
568
            ->method('checkAccess')
569
            ->with($this->equalTo('list'));
570
571
        $form = $this->getMockBuilder(Form::class)
572
            ->disableOriginalConstructor()
573
            ->getMock();
574
575
        $form->expects($this->once())
576
            ->method('createView')
577
            ->willReturn($this->createMock(FormView::class));
578
579
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
580
            ->method('getDatagrid')
581
            ->willReturn($datagrid);
582
583
        $datagrid->expects($this->once())
584
            ->method('getForm')
585
            ->willReturn($form);
586
587
        $this->parameters = [];
588
        $this->assertInstanceOf(Response::class, $this->controller->listAction($this->request));
589
590
        $this->assertSame($this->admin, $this->parameters['admin']);
591
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
592
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
593
594
        $this->assertSame('list', $this->parameters['action']);
595
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
596
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
597
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
598
        $this->assertSame([], $this->session->getFlashBag()->all());
599
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
600
    }
601
602
    public function testBatchActionDeleteAccessDenied(): void
603
    {
604
        $this->expectException(AccessDeniedException::class);
605
606
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
607
            ->method('checkAccess')
608
            ->with($this->equalTo('batchDelete'))
609
            ->will($this->throwException(new AccessDeniedException()));
610
611
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
612
    }
613
614
    public function testBatchActionDelete(): void
615
    {
616
        $modelManager = $this->createMock(ModelManagerInterface::class);
617
618
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
619
            ->method('checkAccess')
620
            ->with($this->equalTo('batchDelete'));
621
622
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
623
            ->method('getModelManager')
624
            ->willReturn($modelManager);
625
626
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
627
            ->method('getFilterParameters')
628
            ->willReturn(['foo' => 'bar']);
629
630
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
631
632
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
633
634
        $this->assertInstanceOf(RedirectResponse::class, $result);
635
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
636
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
637
    }
638
639
    public function testBatchActionDeleteWithModelManagerException(): void
640
    {
641
        $modelManager = $this->createMock(ModelManagerInterface::class);
642
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
643
644
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
645
            ->method('getModelManager')
646
            ->willReturn($modelManager);
647
648
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
649
            ->method('getFilterParameters')
650
            ->willReturn(['foo' => 'bar']);
651
652
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
653
654
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
655
656
        $this->assertInstanceOf(RedirectResponse::class, $result);
657
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
658
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
659
    }
660
661
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
662
    {
663
        $modelManager = $this->createMock(ModelManagerInterface::class);
664
        $this->expectException(ModelManagerException::class);
665
666
        $modelManager->expects($this->once())
667
            ->method('batchDelete')
668
            ->willReturnCallback(static function (): void {
669
                throw new ModelManagerException();
670
            });
671
672
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
673
            ->method('getModelManager')
674
            ->willReturn($modelManager);
675
676
        $this->kernel->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

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.

Loading history...
677
            ->method('isDebug')
678
            ->willReturn(true);
679
680
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
681
    }
682
683
    public function testShowActionNotFoundException(): void
684
    {
685
        $this->expectException(NotFoundHttpException::class);
686
687
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
688
            ->method('getObject')
689
            ->willReturn(null);
690
691
        $this->controller->showAction($this->request);
692
    }
693
694
    public function testShowActionAccessDenied(): void
695
    {
696
        $this->expectException(AccessDeniedException::class);
697
698
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
699
            ->method('getObject')
700
            ->willReturn(new \stdClass());
701
702
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
703
            ->method('checkAccess')
704
            ->with($this->equalTo('show'))
705
            ->will($this->throwException(new AccessDeniedException()));
706
707
        $this->controller->showAction($this->request);
708
    }
709
710
    public function testPreShow(): void
711
    {
712
        $object = new \stdClass();
713
        $object->foo = 123456;
714
715
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
716
            ->method('getObject')
717
            ->willReturn($object);
718
719
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
720
            ->method('checkAccess')
721
            ->with($this->equalTo('show'));
722
723
        $controller = new PreCRUDController();
724
        $controller->setContainer($this->container);
725
726
        $response = $controller->showAction($this->request);
727
        $this->assertInstanceOf(Response::class, $response);
728
        $this->assertSame('preShow called: 123456', $response->getContent());
729
    }
730
731
    public function testShowAction(): void
732
    {
733
        $object = new \stdClass();
734
735
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
736
            ->method('getObject')
737
            ->willReturn($object);
738
739
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
740
            ->method('checkAccess')
741
            ->with($this->equalTo('show'));
742
743
        $show = new FieldDescriptionCollection();
744
745
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
746
            ->method('getShow')
747
            ->willReturn($show);
748
749
        $this->assertInstanceOf(Response::class, $this->controller->showAction($this->request));
750
751
        $this->assertSame($this->admin, $this->parameters['admin']);
752
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
753
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
754
755
        $this->assertSame('show', $this->parameters['action']);
756
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
757
        $this->assertSame($object, $this->parameters['object']);
758
759
        $this->assertSame([], $this->session->getFlashBag()->all());
760
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
761
    }
762
763
    /**
764
     * @dataProvider getRedirectToTests
765
     */
766
    public function testRedirectTo(
767
        string $expected,
768
        string $route,
769
        array $queryParams,
770
        array $requestParams,
771
        bool $hasActiveSubclass
772
    ): void {
773
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
774
            ->method('hasActiveSubclass')
775
            ->willReturn($hasActiveSubclass);
776
777
        $object = new \stdClass();
778
779
        foreach ($queryParams as $key => $value) {
780
            $this->request->query->set($key, $value);
781
        }
782
783
        foreach ($requestParams as $key => $value) {
784
            $this->request->request->set($key, $value);
785
        }
786
787
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
788
            ->method('hasRoute')
789
            ->with($this->equalTo($route))
790
            ->willReturn(true);
791
792
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
793
            ->method('hasAccess')
794
            ->with($this->equalTo($route))
795
            ->willReturn(true);
796
797
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
798
        $this->assertInstanceOf(RedirectResponse::class, $response);
799
        $this->assertSame($expected, $response->getTargetUrl());
800
    }
801
802
    public function testRedirectToWithObject(): void
803
    {
804
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
805
            ->method('hasActiveSubclass')
806
            ->willReturn(false);
807
808
        $object = new \stdClass();
809
810
        $this->admin->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
811
            ->method('hasRoute')
812
            ->with($this->equalTo('edit'))
813
            ->willReturn(true);
814
815
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
816
            ->method('hasAccess')
817
            ->with($this->equalTo('edit'), $object)
818
            ->willReturn(false);
819
820
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
821
        $this->assertInstanceOf(RedirectResponse::class, $response);
822
        $this->assertSame('list', $response->getTargetUrl());
823
    }
824
825
    public function getRedirectToTests()
826
    {
827
        return [
828
            ['stdClass_edit', 'edit', [], [], false],
829
            ['list', 'list', ['btn_update_and_list' => true], [], false],
830
            ['list', 'list', ['btn_create_and_list' => true], [], false],
831
            ['create', 'create', ['btn_create_and_create' => true], [], false],
832
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
833
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
834
        ];
835
    }
836
837
    public function testDeleteActionNotFoundException(): void
838
    {
839
        $this->expectException(NotFoundHttpException::class);
840
841
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
842
            ->method('getObject')
843
            ->willReturn(null);
844
845
        $this->controller->deleteAction($this->request);
846
    }
847
848
    public function testDeleteActionAccessDenied(): void
849
    {
850
        $this->expectException(AccessDeniedException::class);
851
852
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
853
            ->method('getObject')
854
            ->willReturn(new \stdClass());
855
856
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
857
            ->method('checkAccess')
858
            ->with($this->equalTo('delete'))
859
            ->will($this->throwException(new AccessDeniedException()));
860
861
        $this->controller->deleteAction($this->request);
862
    }
863
864
    public function testPreDelete(): void
865
    {
866
        $object = new \stdClass();
867
        $object->foo = 123456;
868
869
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
870
            ->method('getObject')
871
            ->willReturn($object);
872
873
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
874
            ->method('checkAccess')
875
            ->with($this->equalTo('delete'));
876
877
        $controller = new PreCRUDController();
878
        $controller->setContainer($this->container);
879
880
        $response = $controller->deleteAction($this->request);
881
        $this->assertInstanceOf(Response::class, $response);
882
        $this->assertSame('preDelete called: 123456', $response->getContent());
883
    }
884
885
    public function testDeleteAction(): void
886
    {
887
        $object = new \stdClass();
888
889
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
890
            ->method('getObject')
891
            ->willReturn($object);
892
893
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
894
            ->method('checkAccess')
895
            ->with($this->equalTo('delete'));
896
897
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
898
899
        $this->assertSame($this->admin, $this->parameters['admin']);
900
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
901
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
902
903
        $this->assertSame('delete', $this->parameters['action']);
904
        $this->assertSame($object, $this->parameters['object']);
905
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
906
907
        $this->assertSame([], $this->session->getFlashBag()->all());
908
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
909
    }
910
911
    public function testDeleteActionNoCsrfToken(): void
912
    {
913
        $this->container->set('security.csrf.token_manager', null);
914
915
        $object = new \stdClass();
916
917
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
918
            ->method('getObject')
919
            ->willReturn($object);
920
921
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
922
            ->method('checkAccess')
923
            ->with($this->equalTo('delete'));
924
925
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
926
927
        $this->assertSame($this->admin, $this->parameters['admin']);
928
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
929
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
930
931
        $this->assertSame('delete', $this->parameters['action']);
932
        $this->assertSame($object, $this->parameters['object']);
933
        $this->assertFalse($this->parameters['csrf_token']);
934
935
        $this->assertSame([], $this->session->getFlashBag()->all());
936
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
937
    }
938
939
    public function testDeleteActionAjaxSuccess1(): void
940
    {
941
        $object = new \stdClass();
942
943
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
944
            ->method('getObject')
945
            ->willReturn($object);
946
947
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
948
            ->method('checkAccess')
949
            ->with($this->equalTo('delete'));
950
951
        $this->request->setMethod(Request::METHOD_DELETE);
952
953
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
954
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
955
956
        $response = $this->controller->deleteAction($this->request);
957
958
        $this->assertInstanceOf(Response::class, $response);
959
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
960
        $this->assertSame([], $this->session->getFlashBag()->all());
961
    }
962
963
    public function testDeleteActionAjaxSuccess2(): void
964
    {
965
        $object = new \stdClass();
966
967
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
968
            ->method('getObject')
969
            ->willReturn($object);
970
971
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
972
            ->method('checkAccess')
973
            ->with($this->equalTo('delete'));
974
975
        $this->request->setMethod(Request::METHOD_POST);
976
        $this->request->request->set('_method', Request::METHOD_DELETE);
977
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
978
979
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
980
981
        $response = $this->controller->deleteAction($this->request);
982
983
        $this->assertInstanceOf(Response::class, $response);
984
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
985
        $this->assertSame([], $this->session->getFlashBag()->all());
986
    }
987
988
    public function testDeleteActionAjaxError(): void
989
    {
990
        $object = new \stdClass();
991
992
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
993
            ->method('getObject')
994
            ->willReturn($object);
995
996
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
997
            ->method('checkAccess')
998
            ->with($this->equalTo('delete'));
999
1000
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1001
            ->method('getClass')
1002
            ->willReturn(\stdClass::class);
1003
1004
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1005
1006
        $this->request->setMethod(Request::METHOD_DELETE);
1007
1008
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1009
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1010
1011
        $response = $this->controller->deleteAction($this->request);
1012
1013
        $this->assertInstanceOf(Response::class, $response);
1014
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1015
        $this->assertSame([], $this->session->getFlashBag()->all());
1016
    }
1017
1018
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1019
    {
1020
        $this->expectException(ModelManagerException::class);
1021
1022
        $object = new \stdClass();
1023
1024
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1025
            ->method('getObject')
1026
            ->willReturn($object);
1027
1028
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1029
            ->method('checkAccess')
1030
            ->with($this->equalTo('delete'));
1031
1032
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1033
            ->method('delete')
1034
            ->willReturnCallback(static function (): void {
1035
                throw new ModelManagerException();
1036
            });
1037
1038
        $this->kernel->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

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.

Loading history...
1039
            ->method('isDebug')
1040
            ->willReturn(true);
1041
1042
        $this->request->setMethod(Request::METHOD_DELETE);
1043
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1044
1045
        $this->controller->deleteAction($this->request);
1046
    }
1047
1048
    /**
1049
     * @dataProvider getToStringValues
1050
     */
1051
    public function testDeleteActionSuccess1(string $expectedToStringValue, string $toStringValue): void
1052
    {
1053
        $object = new \stdClass();
1054
1055
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1056
            ->method('getObject')
1057
            ->willReturn($object);
1058
1059
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1060
            ->method('toString')
1061
            ->with($this->equalTo($object))
1062
            ->willReturn($toStringValue);
1063
1064
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1065
1066
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1067
            ->method('checkAccess')
1068
            ->with($this->equalTo('delete'));
1069
1070
        $this->request->setMethod(Request::METHOD_DELETE);
1071
1072
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1073
1074
        $response = $this->controller->deleteAction($this->request);
1075
1076
        $this->assertInstanceOf(RedirectResponse::class, $response);
1077
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1078
        $this->assertSame('list', $response->getTargetUrl());
1079
    }
1080
1081
    /**
1082
     * @dataProvider getToStringValues
1083
     */
1084
    public function testDeleteActionSuccess2(string $expectedToStringValue, string $toStringValue): void
1085
    {
1086
        $object = new \stdClass();
1087
1088
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1089
            ->method('getObject')
1090
            ->willReturn($object);
1091
1092
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1093
            ->method('checkAccess')
1094
            ->with($this->equalTo('delete'));
1095
1096
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1097
            ->method('toString')
1098
            ->with($this->equalTo($object))
1099
            ->willReturn($toStringValue);
1100
1101
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1102
1103
        $this->request->setMethod(Request::METHOD_POST);
1104
        $this->request->request->set('_method', Request::METHOD_DELETE);
1105
1106
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1107
1108
        $response = $this->controller->deleteAction($this->request);
1109
1110
        $this->assertInstanceOf(RedirectResponse::class, $response);
1111
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1112
        $this->assertSame('list', $response->getTargetUrl());
1113
    }
1114
1115
    /**
1116
     * @dataProvider getToStringValues
1117
     */
1118
    public function testDeleteActionSuccessNoCsrfTokenProvider(string $expectedToStringValue, string $toStringValue): void
1119
    {
1120
        $this->container->set('security.csrf.token_manager', null);
1121
1122
        $object = new \stdClass();
1123
1124
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1125
            ->method('getObject')
1126
            ->willReturn($object);
1127
1128
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1129
            ->method('checkAccess')
1130
            ->with($this->equalTo('delete'));
1131
1132
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1133
            ->method('toString')
1134
            ->with($this->equalTo($object))
1135
            ->willReturn($toStringValue);
1136
1137
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1138
1139
        $this->request->setMethod(Request::METHOD_POST);
1140
        $this->request->request->set('_method', Request::METHOD_DELETE);
1141
1142
        $response = $this->controller->deleteAction($this->request);
1143
1144
        $this->assertInstanceOf(RedirectResponse::class, $response);
1145
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1146
        $this->assertSame('list', $response->getTargetUrl());
1147
    }
1148
1149
    public function testDeleteActionWrongRequestMethod(): void
1150
    {
1151
        $object = new \stdClass();
1152
1153
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1154
            ->method('getObject')
1155
            ->willReturn($object);
1156
1157
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1158
            ->method('checkAccess')
1159
            ->with($this->equalTo('delete'));
1160
1161
        //without POST request parameter "_method" should not be used as real REST method
1162
        $this->request->query->set('_method', Request::METHOD_DELETE);
1163
1164
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
1165
1166
        $this->assertSame($this->admin, $this->parameters['admin']);
1167
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1168
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1169
1170
        $this->assertSame('delete', $this->parameters['action']);
1171
        $this->assertSame($object, $this->parameters['object']);
1172
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1173
1174
        $this->assertSame([], $this->session->getFlashBag()->all());
1175
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1176
    }
1177
1178
    /**
1179
     * @dataProvider getToStringValues
1180
     */
1181
    public function testDeleteActionError(string $expectedToStringValue, string $toStringValue): void
1182
    {
1183
        $object = new \stdClass();
1184
1185
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1186
            ->method('getObject')
1187
            ->willReturn($object);
1188
1189
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1190
            ->method('checkAccess')
1191
            ->with($this->equalTo('delete'));
1192
1193
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1194
            ->method('toString')
1195
            ->with($this->equalTo($object))
1196
            ->willReturn($toStringValue);
1197
1198
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1199
1200
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1201
1202
        $this->request->setMethod(Request::METHOD_DELETE);
1203
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1204
1205
        $response = $this->controller->deleteAction($this->request);
1206
1207
        $this->assertInstanceOf(RedirectResponse::class, $response);
1208
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1209
        $this->assertSame('list', $response->getTargetUrl());
1210
    }
1211
1212
    public function testDeleteActionInvalidCsrfToken(): void
1213
    {
1214
        $object = new \stdClass();
1215
1216
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1217
            ->method('getObject')
1218
            ->willReturn($object);
1219
1220
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1221
            ->method('checkAccess')
1222
            ->with($this->equalTo('delete'));
1223
1224
        $this->request->setMethod(Request::METHOD_POST);
1225
        $this->request->request->set('_method', Request::METHOD_DELETE);
1226
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1227
1228
        try {
1229
            $this->controller->deleteAction($this->request);
1230
        } catch (HttpException $e) {
1231
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1232
            $this->assertSame(400, $e->getStatusCode());
1233
        }
1234
    }
1235
1236
    public function testEditActionNotFoundException(): void
1237
    {
1238
        $this->expectException(NotFoundHttpException::class);
1239
1240
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1241
            ->method('getObject')
1242
            ->willReturn(null);
1243
1244
        $this->controller->editAction($this->request);
1245
    }
1246
1247
    public function testEditActionAccessDenied(): void
1248
    {
1249
        $this->expectException(AccessDeniedException::class);
1250
1251
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1252
            ->method('getObject')
1253
            ->willReturn(new \stdClass());
1254
1255
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1256
            ->method('checkAccess')
1257
            ->with($this->equalTo('edit'))
1258
            ->will($this->throwException(new AccessDeniedException()));
1259
1260
        $this->controller->editAction($this->request);
1261
    }
1262
1263
    public function testPreEdit(): void
1264
    {
1265
        $object = new \stdClass();
1266
        $object->foo = 123456;
1267
1268
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1269
            ->method('getObject')
1270
            ->willReturn($object);
1271
1272
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1273
            ->method('checkAccess')
1274
            ->with($this->equalTo('edit'));
1275
1276
        $controller = new PreCRUDController();
1277
        $controller->setContainer($this->container);
1278
1279
        $response = $controller->editAction($this->request);
1280
        $this->assertInstanceOf(Response::class, $response);
1281
        $this->assertSame('preEdit called: 123456', $response->getContent());
1282
    }
1283
1284
    public function testEditAction(): void
1285
    {
1286
        $object = new \stdClass();
1287
1288
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1289
            ->method('getObject')
1290
            ->willReturn($object);
1291
1292
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1293
            ->method('checkAccess')
1294
            ->with($this->equalTo('edit'));
1295
1296
        $form = $this->createMock(Form::class);
1297
1298
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1299
            ->method('getForm')
1300
            ->willReturn($form);
1301
1302
        $formView = $this->createMock(FormView::class);
1303
1304
        $form
1305
            ->method('createView')
1306
            ->willReturn($formView);
1307
1308
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1309
1310
        $this->assertSame($this->admin, $this->parameters['admin']);
1311
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1312
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1313
1314
        $this->assertSame('edit', $this->parameters['action']);
1315
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1316
        $this->assertSame($object, $this->parameters['object']);
1317
        $this->assertSame([], $this->session->getFlashBag()->all());
1318
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1319
    }
1320
1321
    /**
1322
     * @dataProvider getToStringValues
1323
     */
1324
    public function testEditActionSuccess(string $expectedToStringValue, string $toStringValue): void
1325
    {
1326
        $object = new \stdClass();
1327
1328
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1329
            ->method('getObject')
1330
            ->willReturn($object);
1331
1332
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1333
            ->method('update')
1334
            ->willReturnArgument(0);
1335
1336
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1337
            ->method('checkAccess')
1338
            ->with($this->equalTo('edit'));
1339
1340
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1341
            ->method('hasRoute')
1342
            ->with($this->equalTo('edit'))
1343
            ->willReturn(true);
1344
1345
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1346
            ->method('hasAccess')
1347
            ->with($this->equalTo('edit'))
1348
            ->willReturn(true);
1349
1350
        $form = $this->createMock(Form::class);
1351
1352
        $form->expects($this->once())
1353
            ->method('getData')
1354
            ->willReturn($object);
1355
1356
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1357
            ->method('getForm')
1358
            ->willReturn($form);
1359
1360
        $form->expects($this->once())
1361
            ->method('isSubmitted')
1362
            ->willReturn(true);
1363
1364
        $form->expects($this->once())
1365
            ->method('isValid')
1366
            ->willReturn(true);
1367
1368
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1369
            ->method('toString')
1370
            ->with($this->equalTo($object))
1371
            ->willReturn($toStringValue);
1372
1373
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1374
1375
        $this->request->setMethod(Request::METHOD_POST);
1376
1377
        $response = $this->controller->editAction($this->request);
1378
1379
        $this->assertInstanceOf(RedirectResponse::class, $response);
1380
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1381
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1382
    }
1383
1384
    /**
1385
     * @dataProvider getToStringValues
1386
     */
1387
    public function testEditActionError(string $expectedToStringValue, string $toStringValue): void
1388
    {
1389
        $object = new \stdClass();
1390
1391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1392
            ->method('getObject')
1393
            ->willReturn($object);
1394
1395
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1396
            ->method('checkAccess')
1397
            ->with($this->equalTo('edit'));
1398
1399
        $form = $this->createMock(Form::class);
1400
1401
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1402
            ->method('getForm')
1403
            ->willReturn($form);
1404
1405
        $form->expects($this->once())
1406
            ->method('isSubmitted')
1407
            ->willReturn(true);
1408
1409
        $form->expects($this->once())
1410
            ->method('isValid')
1411
            ->willReturn(false);
1412
1413
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1414
            ->method('toString')
1415
            ->with($this->equalTo($object))
1416
            ->willReturn($toStringValue);
1417
1418
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1419
1420
        $this->request->setMethod(Request::METHOD_POST);
1421
1422
        $formView = $this->createMock(FormView::class);
1423
1424
        $form
1425
            ->method('createView')
1426
            ->willReturn($formView);
1427
1428
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1429
1430
        $this->assertSame($this->admin, $this->parameters['admin']);
1431
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1432
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1433
1434
        $this->assertSame('edit', $this->parameters['action']);
1435
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1436
        $this->assertSame($object, $this->parameters['object']);
1437
1438
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1439
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1440
    }
1441
1442
    public function testEditActionAjaxSuccess(): void
1443
    {
1444
        $object = new \stdClass();
1445
1446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1447
            ->method('getObject')
1448
            ->willReturn($object);
1449
1450
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1451
            ->method('update')
1452
            ->willReturnArgument(0);
1453
1454
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1455
            ->method('checkAccess')
1456
            ->with($this->equalTo('edit'));
1457
1458
        $form = $this->createMock(Form::class);
1459
1460
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1461
            ->method('getForm')
1462
            ->willReturn($form);
1463
1464
        $form->expects($this->once())
1465
            ->method('isSubmitted')
1466
            ->willReturn(true);
1467
1468
        $form->expects($this->once())
1469
            ->method('isValid')
1470
            ->willReturn(true);
1471
1472
        $form->expects($this->once())
1473
            ->method('getData')
1474
            ->willReturn($object);
1475
1476
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1477
            ->method('getNormalizedIdentifier')
1478
            ->with($this->equalTo($object))
1479
            ->willReturn('foo_normalized');
1480
1481
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1482
            ->method('toString')
1483
            ->willReturn('foo');
1484
1485
        $this->request->setMethod(Request::METHOD_POST);
1486
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1487
        $this->request->headers->set('Accept', 'application/json');
1488
1489
        $response = $this->controller->editAction($this->request);
1490
1491
        $this->assertInstanceOf(Response::class, $response);
1492
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1493
        $this->assertSame([], $this->session->getFlashBag()->all());
1494
    }
1495
1496
    public function testEditActionAjaxError(): void
1497
    {
1498
        $object = new \stdClass();
1499
1500
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1501
            ->method('getObject')
1502
            ->willReturn($object);
1503
1504
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1505
            ->method('checkAccess')
1506
            ->with($this->equalTo('edit'));
1507
1508
        $form = $this->createMock(Form::class);
1509
1510
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1511
            ->method('getForm')
1512
            ->willReturn($form);
1513
1514
        $form->expects($this->once())
1515
            ->method('isSubmitted')
1516
            ->willReturn(true);
1517
1518
        $form->expects($this->once())
1519
            ->method('isValid')
1520
            ->willReturn(false);
1521
1522
        $formError = $this->createMock(FormError::class);
1523
        $formError->expects($this->atLeastOnce())
1524
            ->method('getMessage')
1525
            ->willReturn('Form error message');
1526
1527
        $form->expects($this->once())
1528
            ->method('getErrors')
1529
            ->with(true)
1530
            ->willReturn([$formError]);
1531
1532
        $this->request->setMethod(Request::METHOD_POST);
1533
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1534
        $this->request->headers->set('Accept', 'application/json');
1535
1536
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction($this->request));
1537
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
1538
    }
1539
1540
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1541
    {
1542
        $object = new \stdClass();
1543
1544
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1545
            ->method('getObject')
1546
            ->willReturn($object);
1547
1548
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1549
            ->method('checkAccess')
1550
            ->with($this->equalTo('edit'));
1551
1552
        $form = $this->createMock(Form::class);
1553
1554
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1555
            ->method('getForm')
1556
            ->willReturn($form);
1557
1558
        $form->expects($this->once())
1559
            ->method('isSubmitted')
1560
            ->willReturn(true);
1561
1562
        $form->expects($this->once())
1563
            ->method('isValid')
1564
            ->willReturn(false);
1565
1566
        $this->request->setMethod(Request::METHOD_POST);
1567
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1568
1569
        $formView = $this->createMock(FormView::class);
1570
        $form
1571
            ->method('createView')
1572
            ->willReturn($formView);
1573
1574
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction($this->request));
1575
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
1576
    }
1577
1578
    /**
1579
     * @dataProvider getToStringValues
1580
     */
1581
    public function testEditActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
1582
    {
1583
        $object = new \stdClass();
1584
1585
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1586
            ->method('getObject')
1587
            ->willReturn($object);
1588
1589
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1590
            ->method('checkAccess')
1591
            ->with($this->equalTo('edit'));
1592
1593
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1594
            ->method('getClass')
1595
            ->willReturn(\stdClass::class);
1596
1597
        $form = $this->createMock(Form::class);
1598
1599
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1600
            ->method('getForm')
1601
            ->willReturn($form);
1602
1603
        $form->expects($this->once())
1604
            ->method('isValid')
1605
            ->willReturn(true);
1606
1607
        $form->expects($this->once())
1608
            ->method('getData')
1609
            ->willReturn($object);
1610
1611
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1612
            ->method('toString')
1613
            ->with($this->equalTo($object))
1614
            ->willReturn($toStringValue);
1615
1616
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1617
1618
        $form->expects($this->once())
1619
            ->method('isSubmitted')
1620
            ->willReturn(true);
1621
        $this->request->setMethod(Request::METHOD_POST);
1622
1623
        $formView = $this->createMock(FormView::class);
1624
1625
        $form
1626
            ->method('createView')
1627
            ->willReturn($formView);
1628
1629
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1630
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1631
1632
        $this->assertSame($this->admin, $this->parameters['admin']);
1633
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1634
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1635
1636
        $this->assertSame('edit', $this->parameters['action']);
1637
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1638
        $this->assertSame($object, $this->parameters['object']);
1639
1640
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1641
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1642
    }
1643
1644
    public function testEditActionWithPreview(): void
1645
    {
1646
        $object = new \stdClass();
1647
1648
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1649
            ->method('getObject')
1650
            ->willReturn($object);
1651
1652
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1653
            ->method('checkAccess')
1654
            ->with($this->equalTo('edit'));
1655
1656
        $form = $this->createMock(Form::class);
1657
1658
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1659
            ->method('getForm')
1660
            ->willReturn($form);
1661
1662
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1663
            ->method('supportsPreviewMode')
1664
            ->willReturn(true);
1665
1666
        $formView = $this->createMock(FormView::class);
1667
1668
        $form
1669
            ->method('createView')
1670
            ->willReturn($formView);
1671
1672
        $form->expects($this->once())
1673
            ->method('isSubmitted')
1674
            ->willReturn(true);
1675
1676
        $form->expects($this->once())
1677
            ->method('isValid')
1678
            ->willReturn(true);
1679
1680
        $this->request->setMethod(Request::METHOD_POST);
1681
        $this->request->request->set('btn_preview', 'Preview');
1682
1683
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1684
1685
        $this->assertSame($this->admin, $this->parameters['admin']);
1686
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1687
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1688
1689
        $this->assertSame('edit', $this->parameters['action']);
1690
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1691
        $this->assertSame($object, $this->parameters['object']);
1692
1693
        $this->assertSame([], $this->session->getFlashBag()->all());
1694
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1695
    }
1696
1697
    public function testEditActionWithLockException(): void
1698
    {
1699
        $object = new \stdClass();
1700
        $class = \get_class($object);
1701
1702
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1703
            ->method('getObject')
1704
            ->willReturn($object);
1705
1706
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1707
            ->method('checkAccess')
1708
            ->with($this->equalTo('edit'));
1709
1710
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1711
            ->method('getClass')
1712
            ->willReturn($class);
1713
1714
        $form = $this->createMock(Form::class);
1715
1716
        $form
1717
            ->method('isValid')
1718
            ->willReturn(true);
1719
1720
        $form->expects($this->once())
1721
            ->method('getData')
1722
            ->willReturn($object);
1723
1724
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1725
            ->method('getForm')
1726
            ->willReturn($form);
1727
1728
        $form
1729
            ->method('isSubmitted')
1730
            ->willReturn(true);
1731
        $this->request->setMethod(Request::METHOD_POST);
1732
1733
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1734
            ->method('update')
1735
            ->will($this->throwException(new LockException()));
1736
1737
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1738
            ->method('toString')
1739
            ->with($this->equalTo($object))
1740
            ->willReturn($class);
1741
1742
        $formView = $this->createMock(FormView::class);
1743
1744
        $form
1745
            ->method('createView')
1746
            ->willReturn($formView);
1747
1748
        $this->expectTranslate('flash_lock_error', [
1749
            '%name%' => $class,
1750
            '%link_start%' => '<a href="stdClass_edit">',
1751
            '%link_end%' => '</a>',
1752
        ], 'SonataAdminBundle');
1753
1754
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1755
    }
1756
1757
    public function testCreateActionAccessDenied(): void
1758
    {
1759
        $this->expectException(AccessDeniedException::class);
1760
1761
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1762
            ->method('checkAccess')
1763
            ->with($this->equalTo('create'))
1764
            ->will($this->throwException(new AccessDeniedException()));
1765
1766
        $this->controller->createAction($this->request);
1767
    }
1768
1769
    public function testPreCreate(): void
1770
    {
1771
        $object = new \stdClass();
1772
        $object->foo = 123456;
1773
1774
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1775
            ->method('checkAccess')
1776
            ->with($this->equalTo('create'));
1777
1778
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1779
            ->method('getClass')
1780
            ->willReturn(\stdClass::class);
1781
1782
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1783
            ->method('getNewInstance')
1784
            ->willReturn($object);
1785
1786
        $controller = new PreCRUDController();
1787
        $controller->setContainer($this->container);
1788
1789
        $response = $controller->createAction($this->request);
1790
        $this->assertInstanceOf(Response::class, $response);
1791
        $this->assertSame('preCreate called: 123456', $response->getContent());
1792
    }
1793
1794
    public function testCreateAction(): void
1795
    {
1796
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1797
            ->method('checkAccess')
1798
            ->with($this->equalTo('create'));
1799
1800
        $object = new \stdClass();
1801
1802
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1803
            ->method('getClass')
1804
            ->willReturn(\stdClass::class);
1805
1806
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1807
            ->method('getNewInstance')
1808
            ->willReturn($object);
1809
1810
        $form = $this->createMock(Form::class);
1811
1812
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1813
            ->method('getForm')
1814
            ->willReturn($form);
1815
1816
        $formView = $this->createMock(FormView::class);
1817
1818
        $form
1819
            ->method('createView')
1820
            ->willReturn($formView);
1821
1822
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
1823
1824
        $this->assertSame($this->admin, $this->parameters['admin']);
1825
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1826
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1827
1828
        $this->assertSame('create', $this->parameters['action']);
1829
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1830
        $this->assertSame($object, $this->parameters['object']);
1831
1832
        $this->assertSame([], $this->session->getFlashBag()->all());
1833
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1834
    }
1835
1836
    /**
1837
     * @dataProvider getToStringValues
1838
     */
1839
    public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void
1840
    {
1841
        $object = new \stdClass();
1842
1843
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1844
            ->method('checkAccess')
1845
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
1846
                if ('edit' === $name) {
1847
                    return;
1848
                }
1849
1850
                if ('create' !== $name) {
1851
                    throw new AccessDeniedException();
1852
                }
1853
1854
                if (null === $objectIn) {
1855
                    return;
1856
                }
1857
1858
                if ($objectIn !== $object) {
1859
                    throw new AccessDeniedException();
1860
                }
1861
            });
1862
1863
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1864
            ->method('hasRoute')
1865
            ->with($this->equalTo('edit'))
1866
            ->willReturn(true);
1867
1868
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1869
            ->method('hasAccess')
1870
            ->with($this->equalTo('edit'))
1871
            ->willReturn(true);
1872
1873
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1874
            ->method('getNewInstance')
1875
            ->willReturn($object);
1876
1877
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1878
            ->method('create')
1879
            ->willReturnArgument(0);
1880
1881
        $form = $this->createMock(Form::class);
1882
1883
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1884
            ->method('getClass')
1885
            ->willReturn(\stdClass::class);
1886
1887
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1888
            ->method('getForm')
1889
            ->willReturn($form);
1890
1891
        $form->expects($this->once())
1892
            ->method('isSubmitted')
1893
            ->willReturn(true);
1894
1895
        $form->expects($this->once())
1896
            ->method('isValid')
1897
            ->willReturn(true);
1898
1899
        $form->expects($this->once())
1900
            ->method('getData')
1901
            ->willReturn($object);
1902
1903
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1904
            ->method('toString')
1905
            ->with($this->equalTo($object))
1906
            ->willReturn($toStringValue);
1907
1908
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1909
1910
        $this->request->setMethod(Request::METHOD_POST);
1911
1912
        $response = $this->controller->createAction($this->request);
1913
1914
        $this->assertInstanceOf(RedirectResponse::class, $response);
1915
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1916
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1917
    }
1918
1919
    public function testCreateActionAccessDenied2(): void
1920
    {
1921
        $this->expectException(AccessDeniedException::class);
1922
1923
        $object = new \stdClass();
1924
1925
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1926
            ->method('checkAccess')
1927
            ->willReturnCallback(static function (string $name, $object = null): void {
1928
                if ('create' !== $name) {
1929
                    throw new AccessDeniedException();
1930
                }
1931
                if (null === $object) {
1932
                    return;
1933
                }
1934
1935
                throw new AccessDeniedException();
1936
            });
1937
1938
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1939
            ->method('getNewInstance')
1940
            ->willReturn($object);
1941
1942
        $form = $this->createMock(Form::class);
1943
1944
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1945
            ->method('getClass')
1946
            ->willReturn(\stdClass::class);
1947
1948
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1949
            ->method('getForm')
1950
            ->willReturn($form);
1951
1952
        $form->expects($this->once())
1953
            ->method('isSubmitted')
1954
            ->willReturn(true);
1955
1956
        $form->expects($this->once())
1957
            ->method('getData')
1958
            ->willReturn($object);
1959
1960
        $form->expects($this->once())
1961
            ->method('isValid')
1962
            ->willReturn(true);
1963
1964
        $this->request->setMethod(Request::METHOD_POST);
1965
1966
        $this->controller->createAction($this->request);
1967
    }
1968
1969
    /**
1970
     * @dataProvider getToStringValues
1971
     */
1972
    public function testCreateActionError(string $expectedToStringValue, string $toStringValue): void
1973
    {
1974
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1975
            ->method('checkAccess')
1976
            ->with($this->equalTo('create'));
1977
1978
        $object = new \stdClass();
1979
1980
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1981
            ->method('getClass')
1982
            ->willReturn(\stdClass::class);
1983
1984
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1985
            ->method('getNewInstance')
1986
            ->willReturn($object);
1987
1988
        $form = $this->createMock(Form::class);
1989
1990
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
1991
            ->method('getForm')
1992
            ->willReturn($form);
1993
1994
        $form->expects($this->once())
1995
            ->method('isSubmitted')
1996
            ->willReturn(true);
1997
1998
        $form->expects($this->once())
1999
            ->method('isValid')
2000
            ->willReturn(false);
2001
2002
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2003
            ->method('toString')
2004
            ->with($this->equalTo($object))
2005
            ->willReturn($toStringValue);
2006
2007
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2008
2009
        $this->request->setMethod(Request::METHOD_POST);
2010
2011
        $formView = $this->createMock(FormView::class);
2012
2013
        $form
2014
            ->method('createView')
2015
            ->willReturn($formView);
2016
2017
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2018
2019
        $this->assertSame($this->admin, $this->parameters['admin']);
2020
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2021
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2022
2023
        $this->assertSame('create', $this->parameters['action']);
2024
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2025
        $this->assertSame($object, $this->parameters['object']);
2026
2027
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2028
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2029
    }
2030
2031
    /**
2032
     * @dataProvider getToStringValues
2033
     */
2034
    public function testCreateActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
2035
    {
2036
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2037
            ->method('checkAccess')
2038
            ->with($this->equalTo('create'));
2039
2040
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2041
            ->method('getClass')
2042
            ->willReturn(\stdClass::class);
2043
2044
        $object = new \stdClass();
2045
2046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2047
            ->method('getNewInstance')
2048
            ->willReturn($object);
2049
2050
        $form = $this->createMock(Form::class);
2051
2052
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2053
            ->method('getForm')
2054
            ->willReturn($form);
2055
2056
        $form->expects($this->once())
2057
            ->method('isValid')
2058
            ->willReturn(true);
2059
2060
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2061
            ->method('toString')
2062
            ->with($this->equalTo($object))
2063
            ->willReturn($toStringValue);
2064
2065
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2066
2067
        $form->expects($this->once())
2068
            ->method('isSubmitted')
2069
            ->willReturn(true);
2070
2071
        $form->expects($this->once())
2072
            ->method('getData')
2073
            ->willReturn($object);
2074
2075
        $this->request->setMethod(Request::METHOD_POST);
2076
2077
        $formView = $this->createMock(FormView::class);
2078
2079
        $form
2080
            ->method('createView')
2081
            ->willReturn($formView);
2082
2083
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2084
2085
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2086
2087
        $this->assertSame($this->admin, $this->parameters['admin']);
2088
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2089
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2090
2091
        $this->assertSame('create', $this->parameters['action']);
2092
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2093
        $this->assertSame($object, $this->parameters['object']);
2094
2095
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2096
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2097
    }
2098
2099
    public function testCreateActionAjaxSuccess(): void
2100
    {
2101
        $object = new \stdClass();
2102
2103
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2104
            ->method('checkAccess')
2105
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
2106
                if ('create' !== $name) {
2107
                    throw new AccessDeniedException();
2108
                }
2109
2110
                if (null === $objectIn) {
2111
                    return;
2112
                }
2113
2114
                if ($objectIn !== $object) {
2115
                    throw new AccessDeniedException();
2116
                }
2117
            });
2118
2119
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2120
            ->method('getNewInstance')
2121
            ->willReturn($object);
2122
2123
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2124
            ->method('create')
2125
            ->willReturnArgument(0);
2126
2127
        $form = $this->createMock(Form::class);
2128
2129
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2130
            ->method('getForm')
2131
            ->willReturn($form);
2132
2133
        $form->expects($this->once())
2134
            ->method('isSubmitted')
2135
            ->willReturn(true);
2136
2137
        $form->expects($this->once())
2138
            ->method('isValid')
2139
            ->willReturn(true);
2140
2141
        $form->expects($this->once())
2142
            ->method('getData')
2143
            ->willReturn($object);
2144
2145
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2146
            ->method('getClass')
2147
            ->willReturn(\stdClass::class);
2148
2149
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2150
            ->method('getNormalizedIdentifier')
2151
            ->with($this->equalTo($object))
2152
            ->willReturn('foo_normalized');
2153
2154
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2155
            ->method('toString')
2156
            ->willReturn('foo');
2157
2158
        $this->request->setMethod(Request::METHOD_POST);
2159
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2160
        $this->request->headers->set('Accept', 'application/json');
2161
2162
        $response = $this->controller->createAction($this->request);
2163
2164
        $this->assertInstanceOf(Response::class, $response);
2165
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2166
        $this->assertSame([], $this->session->getFlashBag()->all());
2167
    }
2168
2169
    public function testCreateActionAjaxError(): void
2170
    {
2171
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2172
            ->method('checkAccess')
2173
            ->with($this->equalTo('create'));
2174
2175
        $object = new \stdClass();
2176
2177
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2178
            ->method('getNewInstance')
2179
            ->willReturn($object);
2180
2181
        $form = $this->createMock(Form::class);
2182
2183
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2184
            ->method('getClass')
2185
            ->willReturn(\stdClass::class);
2186
2187
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2188
            ->method('getForm')
2189
            ->willReturn($form);
2190
2191
        $form->expects($this->once())
2192
            ->method('isSubmitted')
2193
            ->willReturn(true);
2194
2195
        $form->expects($this->once())
2196
            ->method('isValid')
2197
            ->willReturn(false);
2198
2199
        $formError = $this->createMock(FormError::class);
2200
        $formError->expects($this->atLeastOnce())
2201
            ->method('getMessage')
2202
            ->willReturn('Form error message');
2203
2204
        $form->expects($this->once())
2205
            ->method('getErrors')
2206
            ->with(true)
2207
            ->willReturn([$formError]);
2208
2209
        $this->request->setMethod(Request::METHOD_POST);
2210
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2211
        $this->request->headers->set('Accept', 'application/json');
2212
2213
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request));
2214
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
2215
    }
2216
2217
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2218
    {
2219
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2220
            ->method('checkAccess')
2221
            ->with($this->equalTo('create'));
2222
2223
        $object = new \stdClass();
2224
2225
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2226
            ->method('getNewInstance')
2227
            ->willReturn($object);
2228
2229
        $form = $this->createMock(Form::class);
2230
2231
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2232
            ->method('getClass')
2233
            ->willReturn(\stdClass::class);
2234
2235
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2236
            ->method('getForm')
2237
            ->willReturn($form);
2238
2239
        $form->expects($this->once())
2240
            ->method('isSubmitted')
2241
            ->willReturn(true);
2242
2243
        $form->expects($this->once())
2244
            ->method('isValid')
2245
            ->willReturn(false);
2246
2247
        $this->request->setMethod(Request::METHOD_POST);
2248
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2249
2250
        $formView = $this->createMock(FormView::class);
2251
        $form
2252
            ->method('createView')
2253
            ->willReturn($formView);
2254
2255
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request));
2256
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
2257
    }
2258
2259
    public function testCreateActionWithPreview(): void
2260
    {
2261
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2262
            ->method('checkAccess')
2263
            ->with($this->equalTo('create'));
2264
2265
        $object = new \stdClass();
2266
2267
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2268
            ->method('getNewInstance')
2269
            ->willReturn($object);
2270
2271
        $form = $this->createMock(Form::class);
2272
2273
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2274
            ->method('getClass')
2275
            ->willReturn(\stdClass::class);
2276
2277
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2278
            ->method('getForm')
2279
            ->willReturn($form);
2280
2281
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2282
            ->method('supportsPreviewMode')
2283
            ->willReturn(true);
2284
2285
        $formView = $this->createMock(FormView::class);
2286
2287
        $form
2288
            ->method('createView')
2289
            ->willReturn($formView);
2290
2291
        $form->expects($this->once())
2292
            ->method('isSubmitted')
2293
            ->willReturn(true);
2294
2295
        $form->expects($this->once())
2296
            ->method('isValid')
2297
            ->willReturn(true);
2298
2299
        $this->request->setMethod(Request::METHOD_POST);
2300
        $this->request->request->set('btn_preview', 'Preview');
2301
2302
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2303
2304
        $this->assertSame($this->admin, $this->parameters['admin']);
2305
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2306
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2307
2308
        $this->assertSame('create', $this->parameters['action']);
2309
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2310
        $this->assertSame($object, $this->parameters['object']);
2311
2312
        $this->assertSame([], $this->session->getFlashBag()->all());
2313
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2314
    }
2315
2316
    public function testExportActionAccessDenied(): void
2317
    {
2318
        $this->expectException(AccessDeniedException::class);
2319
2320
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2321
            ->method('checkAccess')
2322
            ->with($this->equalTo('export'))
2323
            ->will($this->throwException(new AccessDeniedException()));
2324
2325
        $this->controller->exportAction($this->request);
2326
    }
2327
2328
    public function testExportActionWrongFormat(): void
2329
    {
2330
        $this->expectException(\RuntimeException::class);
2331
        $this->expectExceptionMessage(
2332
            'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`'
2333
        );
2334
2335
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2336
            ->method('checkAccess')
2337
            ->with($this->equalTo('export'));
2338
2339
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2340
            ->method('getExportFormats')
2341
            ->willReturn(['json']);
2342
2343
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2344
            ->method('getClass')
2345
            ->willReturn('Foo');
2346
2347
        $this->request->query->set('format', 'csv');
2348
2349
        $this->controller->exportAction($this->request);
2350
    }
2351
2352
    public function testExportAction(): void
2353
    {
2354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2355
            ->method('checkAccess')
2356
            ->with($this->equalTo('export'));
2357
2358
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2359
            ->method('getExportFormats')
2360
            ->willReturn(['json']);
2361
2362
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2363
            ->method('getClass')
2364
            ->willReturn(\stdClass::class);
2365
2366
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2367
2368
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2369
            ->method('getDataSourceIterator')
2370
            ->willReturn($dataSourceIterator);
2371
2372
        $this->request->query->set('format', 'json');
2373
2374
        $response = $this->controller->exportAction($this->request);
2375
        $this->assertInstanceOf(StreamedResponse::class, $response);
2376
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
2377
        $this->assertSame([], $this->session->getFlashBag()->all());
2378
    }
2379
2380
    public function testHistoryActionAccessDenied(): void
2381
    {
2382
        $this->expectException(AccessDeniedException::class);
2383
2384
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2385
            ->method('getObject')
2386
            ->willReturn(new \stdClass());
2387
2388
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2389
            ->method('checkAccess')
2390
            ->with($this->equalTo('history'))
2391
            ->will($this->throwException(new AccessDeniedException()));
2392
2393
        $this->controller->historyAction($this->request);
2394
    }
2395
2396
    public function testHistoryActionNotFoundException(): void
2397
    {
2398
        $this->expectException(NotFoundHttpException::class);
2399
2400
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2401
            ->method('getObject')
2402
            ->willReturn(null);
2403
2404
        $this->controller->historyAction($this->request);
2405
    }
2406
2407
    public function testHistoryActionNoReader(): void
2408
    {
2409
        $this->expectException(NotFoundHttpException::class);
2410
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2411
2412
        $this->request->query->set('id', 123);
2413
2414
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2415
            ->method('checkAccess')
2416
            ->with($this->equalTo('history'));
2417
2418
        $object = new \stdClass();
2419
2420
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2421
            ->method('getObject')
2422
            ->willReturn($object);
2423
2424
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2425
            ->method('getClass')
2426
            ->willReturn('Foo');
2427
2428
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2429
            ->method('hasReader')
2430
            ->with($this->equalTo('Foo'))
2431
            ->willReturn(false);
2432
2433
        $this->controller->historyAction($this->request);
2434
    }
2435
2436
    public function testHistoryAction(): void
2437
    {
2438
        $this->request->query->set('id', 123);
2439
2440
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2441
            ->method('checkAccess')
2442
            ->with($this->equalTo('history'));
2443
2444
        $object = new \stdClass();
2445
2446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2447
            ->method('getObject')
2448
            ->willReturn($object);
2449
2450
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2451
            ->method('getClass')
2452
            ->willReturn('Foo');
2453
2454
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2455
            ->method('hasReader')
2456
            ->with($this->equalTo('Foo'))
2457
            ->willReturn(true);
2458
2459
        $reader = $this->createMock(AuditReaderInterface::class);
2460
2461
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2462
            ->method('getReader')
2463
            ->with($this->equalTo('Foo'))
2464
            ->willReturn($reader);
2465
2466
        $reader->expects($this->once())
2467
            ->method('findRevisions')
2468
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2469
            ->willReturn([]);
2470
2471
        $this->assertInstanceOf(Response::class, $this->controller->historyAction($this->request));
2472
2473
        $this->assertSame($this->admin, $this->parameters['admin']);
2474
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2475
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2476
2477
        $this->assertSame('history', $this->parameters['action']);
2478
        $this->assertSame([], $this->parameters['revisions']);
2479
        $this->assertSame($object, $this->parameters['object']);
2480
2481
        $this->assertSame([], $this->session->getFlashBag()->all());
2482
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2483
    }
2484
2485
    public function testAclActionAclNotEnabled(): void
2486
    {
2487
        $this->expectException(NotFoundHttpException::class);
2488
        $this->expectExceptionMessage('ACL are not enabled for this admin');
2489
2490
        $this->controller->aclAction($this->request);
2491
    }
2492
2493
    public function testAclActionNotFoundException(): void
2494
    {
2495
        $this->expectException(NotFoundHttpException::class);
2496
2497
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2498
            ->method('isAclEnabled')
2499
            ->willReturn(true);
2500
2501
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2502
            ->method('getObject')
2503
            ->willReturn(null);
2504
2505
        $this->controller->aclAction($this->request);
2506
    }
2507
2508
    public function testAclActionAccessDenied(): void
2509
    {
2510
        $this->expectException(AccessDeniedException::class);
2511
2512
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2513
            ->method('isAclEnabled')
2514
            ->willReturn(true);
2515
2516
        $object = new \stdClass();
2517
2518
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2519
            ->method('getObject')
2520
            ->willReturn($object);
2521
2522
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2523
            ->method('checkAccess')
2524
            ->with($this->equalTo('acl'), $this->equalTo($object))
2525
            ->will($this->throwException(new AccessDeniedException()));
2526
2527
        $this->controller->aclAction($this->request);
2528
    }
2529
2530
    public function testAclAction(): void
2531
    {
2532
        $this->request->query->set('id', 123);
2533
2534
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2535
            ->method('isAclEnabled')
2536
            ->willReturn(true);
2537
2538
        $object = new \stdClass();
2539
2540
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2541
            ->method('getObject')
2542
            ->willReturn($object);
2543
2544
        $this->admin
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2545
            ->expects($this->once())
2546
            ->method('checkAccess');
2547
2548
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2549
            ->method('getSecurityInformation')
2550
            ->willReturn([]);
2551
2552
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2553
            ->method('getMaskBuilderClass')
2554
            ->willReturn(AdminPermissionMap::class);
2555
2556
        $aclUsersForm = $this->getMockBuilder(Form::class)
2557
            ->disableOriginalConstructor()
2558
            ->getMock();
2559
2560
        $aclUsersForm->expects($this->once())
2561
            ->method('createView')
2562
            ->willReturn($this->createMock(FormView::class));
2563
2564
        $aclRolesForm = $this->getMockBuilder(Form::class)
2565
            ->disableOriginalConstructor()
2566
            ->getMock();
2567
2568
        $aclRolesForm->expects($this->once())
2569
            ->method('createView')
2570
            ->willReturn($this->createMock(FormView::class));
2571
2572
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2573
            ->method('createAclUsersForm')
2574
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2575
            ->willReturn($aclUsersForm);
2576
2577
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2578
            ->method('createAclRolesForm')
2579
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2580
            ->willReturn($aclRolesForm);
2581
2582
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2583
2584
        $aclSecurityHandler
2585
            ->method('getObjectPermissions')
2586
            ->willReturn([]);
2587
2588
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2589
            ->method('getSecurityHandler')
2590
            ->willReturn($aclSecurityHandler);
2591
2592
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2593
2594
        $this->assertSame($this->admin, $this->parameters['admin']);
2595
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2596
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2597
2598
        $this->assertSame('acl', $this->parameters['action']);
2599
        $this->assertSame([], $this->parameters['permissions']);
2600
        $this->assertSame($object, $this->parameters['object']);
2601
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2602
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2603
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2604
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2605
2606
        $this->assertSame([], $this->session->getFlashBag()->all());
2607
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2608
    }
2609
2610
    public function testAclActionInvalidUpdate(): void
2611
    {
2612
        $this->request->query->set('id', 123);
2613
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2614
2615
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2616
            ->method('isAclEnabled')
2617
            ->willReturn(true);
2618
2619
        $object = new \stdClass();
2620
2621
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2622
            ->method('getObject')
2623
            ->willReturn($object);
2624
2625
        $this->admin
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2626
            ->expects($this->once())
2627
            ->method('checkAccess');
2628
2629
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2630
            ->method('getSecurityInformation')
2631
            ->willReturn([]);
2632
2633
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2634
            ->method('getMaskBuilderClass')
2635
            ->willReturn(AdminPermissionMap::class);
2636
2637
        $aclUsersForm = $this->getMockBuilder(Form::class)
2638
            ->disableOriginalConstructor()
2639
            ->getMock();
2640
2641
        $aclUsersForm->expects($this->once())
2642
            ->method('isValid')
2643
            ->willReturn(false);
2644
2645
        $aclUsersForm->expects($this->once())
2646
            ->method('createView')
2647
            ->willReturn($this->createMock(FormView::class));
2648
2649
        $aclRolesForm = $this->getMockBuilder(Form::class)
2650
            ->disableOriginalConstructor()
2651
            ->getMock();
2652
2653
        $aclRolesForm->expects($this->once())
2654
            ->method('createView')
2655
            ->willReturn($this->createMock(FormView::class));
2656
2657
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2658
            ->method('createAclUsersForm')
2659
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2660
            ->willReturn($aclUsersForm);
2661
2662
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2663
            ->method('createAclRolesForm')
2664
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2665
            ->willReturn($aclRolesForm);
2666
2667
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2668
2669
        $aclSecurityHandler
2670
            ->method('getObjectPermissions')
2671
            ->willReturn([]);
2672
2673
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2674
            ->method('getSecurityHandler')
2675
            ->willReturn($aclSecurityHandler);
2676
2677
        $this->request->setMethod(Request::METHOD_POST);
2678
2679
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2680
2681
        $this->assertSame($this->admin, $this->parameters['admin']);
2682
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2683
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2684
2685
        $this->assertSame('acl', $this->parameters['action']);
2686
        $this->assertSame([], $this->parameters['permissions']);
2687
        $this->assertSame($object, $this->parameters['object']);
2688
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2689
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2690
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2691
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2692
2693
        $this->assertSame([], $this->session->getFlashBag()->all());
2694
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2695
    }
2696
2697
    public function testAclActionSuccessfulUpdate(): void
2698
    {
2699
        $this->request->query->set('id', 123);
2700
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2701
2702
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2703
            ->method('isAclEnabled')
2704
            ->willReturn(true);
2705
2706
        $object = new \stdClass();
2707
2708
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2709
            ->method('getObject')
2710
            ->willReturn($object);
2711
2712
        $this->admin
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2713
            ->expects($this->once())
2714
            ->method('checkAccess');
2715
2716
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2717
            ->method('getSecurityInformation')
2718
            ->willReturn([]);
2719
2720
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2721
            ->method('getMaskBuilderClass')
2722
            ->willReturn(AdminPermissionMap::class);
2723
2724
        $aclUsersForm = $this->getMockBuilder(Form::class)
2725
            ->disableOriginalConstructor()
2726
            ->getMock();
2727
2728
        $aclUsersForm
2729
            ->method('createView')
2730
            ->willReturn($this->createMock(FormView::class));
2731
2732
        $aclRolesForm = $this->getMockBuilder(Form::class)
2733
            ->disableOriginalConstructor()
2734
            ->getMock();
2735
2736
        $aclRolesForm
2737
            ->method('createView')
2738
            ->willReturn($this->createMock(FormView::class));
2739
2740
        $aclRolesForm->expects($this->once())
2741
            ->method('isValid')
2742
            ->willReturn(true);
2743
2744
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2745
            ->method('createAclUsersForm')
2746
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2747
            ->willReturn($aclUsersForm);
2748
2749
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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.

Loading history...
2750
            ->method('createAclRolesForm')
2751
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2752
            ->willReturn($aclRolesForm);
2753
2754
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2755
2756
        $aclSecurityHandler
2757
            ->method('getObjectPermissions')
2758
            ->willReturn([]);
2759
2760
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2761
            ->method('getSecurityHandler')
2762
            ->willReturn($aclSecurityHandler);
2763
2764
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2765
2766
        $this->request->setMethod(Request::METHOD_POST);
2767
2768
        $response = $this->controller->aclAction($this->request);
2769
2770
        $this->assertInstanceOf(RedirectResponse::class, $response);
2771
2772
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2773
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2774
    }
2775
2776
    public function testHistoryViewRevisionActionAccessDenied(): void
2777
    {
2778
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2779
            ->method('getObject')
2780
            ->willReturn(new \stdClass());
2781
2782
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2783
            ->method('checkAccess')
2784
            ->with($this->equalTo('historyViewRevision'))
2785
            ->will($this->throwException(new AccessDeniedException()));
2786
2787
        $this->expectException(AccessDeniedException::class);
2788
2789
        $this->controller->historyViewRevisionAction($this->request, null);
2790
    }
2791
2792
    public function testHistoryViewRevisionActionNotFoundException(): void
2793
    {
2794
        $this->request->query->set('id', 123);
2795
2796
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2797
            ->method('getObject')
2798
            ->willReturn(null);
2799
2800
        $this->expectException(NotFoundHttpException::class);
2801
        $this->expectExceptionMessage('unable to find the object with id: 123');
2802
2803
        $this->controller->historyViewRevisionAction($this->request, null);
2804
    }
2805
2806
    public function testHistoryViewRevisionActionNoReader(): void
2807
    {
2808
        $this->expectException(NotFoundHttpException::class);
2809
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2810
2811
        $this->request->query->set('id', 123);
2812
2813
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2814
            ->method('checkAccess')
2815
            ->with($this->equalTo('historyViewRevision'));
2816
2817
        $object = new \stdClass();
2818
2819
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2820
            ->method('getObject')
2821
            ->willReturn($object);
2822
2823
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2824
            ->method('getClass')
2825
            ->willReturn('Foo');
2826
2827
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2828
            ->method('hasReader')
2829
            ->with($this->equalTo('Foo'))
2830
            ->willReturn(false);
2831
2832
        $this->controller->historyViewRevisionAction($this->request, null);
2833
    }
2834
2835
    public function testHistoryViewRevisionActionNotFoundRevision(): void
2836
    {
2837
        $this->expectException(NotFoundHttpException::class);
2838
        $this->expectExceptionMessage(
2839
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
2840
        );
2841
2842
        $this->request->query->set('id', 123);
2843
2844
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2845
            ->method('checkAccess')
2846
            ->with($this->equalTo('historyViewRevision'));
2847
2848
        $object = new \stdClass();
2849
2850
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2851
            ->method('getObject')
2852
            ->willReturn($object);
2853
2854
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2855
            ->method('getClass')
2856
            ->willReturn('Foo');
2857
2858
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2859
            ->method('hasReader')
2860
            ->with($this->equalTo('Foo'))
2861
            ->willReturn(true);
2862
2863
        $reader = $this->createMock(AuditReaderInterface::class);
2864
2865
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2866
            ->method('getReader')
2867
            ->with($this->equalTo('Foo'))
2868
            ->willReturn($reader);
2869
2870
        $reader->expects($this->once())
2871
            ->method('find')
2872
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2873
            ->willReturn(null);
2874
2875
        $this->controller->historyViewRevisionAction($this->request, 456);
2876
    }
2877
2878
    public function testHistoryViewRevisionAction(): void
2879
    {
2880
        $this->request->query->set('id', 123);
2881
2882
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2883
            ->method('checkAccess')
2884
            ->with($this->equalTo('historyViewRevision'));
2885
2886
        $object = new \stdClass();
2887
2888
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2889
            ->method('getObject')
2890
            ->willReturn($object);
2891
2892
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2893
            ->method('getClass')
2894
            ->willReturn('Foo');
2895
2896
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2897
            ->method('hasReader')
2898
            ->with($this->equalTo('Foo'))
2899
            ->willReturn(true);
2900
2901
        $reader = $this->createMock(AuditReaderInterface::class);
2902
2903
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2904
            ->method('getReader')
2905
            ->with($this->equalTo('Foo'))
2906
            ->willReturn($reader);
2907
2908
        $objectRevision = new \stdClass();
2909
        $objectRevision->revision = 456;
2910
2911
        $reader->expects($this->once())
2912
            ->method('find')
2913
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2914
            ->willReturn($objectRevision);
2915
2916
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2917
            ->method('setSubject')
2918
            ->with($this->equalTo($objectRevision));
2919
2920
        $fieldDescriptionCollection = new FieldDescriptionCollection();
2921
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2922
            ->method('getShow')
2923
            ->willReturn($fieldDescriptionCollection);
2924
2925
        $this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction($this->request, 456));
2926
2927
        $this->assertSame($this->admin, $this->parameters['admin']);
2928
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2929
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2930
2931
        $this->assertSame('show', $this->parameters['action']);
2932
        $this->assertSame($objectRevision, $this->parameters['object']);
2933
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
2934
2935
        $this->assertSame([], $this->session->getFlashBag()->all());
2936
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
2937
    }
2938
2939
    public function testHistoryCompareRevisionsActionAccessDenied(): void
2940
    {
2941
        $this->expectException(AccessDeniedException::class);
2942
2943
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2944
            ->method('checkAccess')
2945
            ->with($this->equalTo('historyCompareRevisions'))
2946
            ->will($this->throwException(new AccessDeniedException()));
2947
2948
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2949
    }
2950
2951
    public function testHistoryCompareRevisionsActionNotFoundException(): void
2952
    {
2953
        $this->expectException(NotFoundHttpException::class);
2954
        $this->expectExceptionMessage('unable to find the object with id: 123');
2955
2956
        $this->request->query->set('id', 123);
2957
2958
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2959
            ->method('checkAccess')
2960
            ->with($this->equalTo('historyCompareRevisions'));
2961
2962
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2963
            ->method('getObject')
2964
            ->willReturn(null);
2965
2966
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2967
    }
2968
2969
    public function testHistoryCompareRevisionsActionNoReader(): void
2970
    {
2971
        $this->expectException(NotFoundHttpException::class);
2972
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2973
2974
        $this->request->query->set('id', 123);
2975
2976
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2977
            ->method('checkAccess')
2978
            ->with($this->equalTo('historyCompareRevisions'));
2979
2980
        $object = new \stdClass();
2981
2982
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2983
            ->method('getObject')
2984
            ->willReturn($object);
2985
2986
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
2987
            ->method('getClass')
2988
            ->willReturn('Foo');
2989
2990
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
2991
            ->method('hasReader')
2992
            ->with($this->equalTo('Foo'))
2993
            ->willReturn(false);
2994
2995
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2996
    }
2997
2998
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
2999
    {
3000
        $this->expectException(NotFoundHttpException::class);
3001
        $this->expectExceptionMessage(
3002
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
3003
        );
3004
3005
        $this->request->query->set('id', 123);
3006
3007
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3008
            ->method('checkAccess')
3009
            ->with($this->equalTo('historyCompareRevisions'));
3010
3011
        $object = new \stdClass();
3012
3013
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3014
            ->method('getObject')
3015
            ->willReturn($object);
3016
3017
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3018
            ->method('getClass')
3019
            ->willReturn('Foo');
3020
3021
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3022
            ->method('hasReader')
3023
            ->with($this->equalTo('Foo'))
3024
            ->willReturn(true);
3025
3026
        $reader = $this->createMock(AuditReaderInterface::class);
3027
3028
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3029
            ->method('getReader')
3030
            ->with($this->equalTo('Foo'))
3031
            ->willReturn($reader);
3032
3033
        // once because it will not be found and therefore the second call won't be executed
3034
        $reader->expects($this->once())
3035
            ->method('find')
3036
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3037
            ->willReturn(null);
3038
3039
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3040
    }
3041
3042
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3043
    {
3044
        $this->expectException(NotFoundHttpException::class);
3045
        $this->expectExceptionMessage(
3046
            'unable to find the targeted object `123` from the revision `789` with classname : `Foo`'
3047
        );
3048
3049
        $this->request->query->set('id', 123);
3050
3051
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3052
            ->method('checkAccess')
3053
            ->with($this->equalTo('historyCompareRevisions'));
3054
3055
        $object = new \stdClass();
3056
3057
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3058
            ->method('getObject')
3059
            ->willReturn($object);
3060
3061
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3062
            ->method('getClass')
3063
            ->willReturn('Foo');
3064
3065
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3066
            ->method('hasReader')
3067
            ->with($this->equalTo('Foo'))
3068
            ->willReturn(true);
3069
3070
        $reader = $this->createMock(AuditReaderInterface::class);
3071
3072
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3073
            ->method('getReader')
3074
            ->with($this->equalTo('Foo'))
3075
            ->willReturn($reader);
3076
3077
        $objectRevision = new \stdClass();
3078
        $objectRevision->revision = 456;
3079
3080
        // first call should return, so the second call will throw an exception
3081
        $reader->expects($this->at(0))
3082
            ->method('find')
3083
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3084
            ->willReturn($objectRevision);
3085
3086
        $reader->expects($this->at(1))
3087
            ->method('find')
3088
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3089
            ->willReturn(null);
3090
3091
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3092
    }
3093
3094
    public function testHistoryCompareRevisionsActionAction(): void
3095
    {
3096
        $this->request->query->set('id', 123);
3097
3098
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3099
            ->method('checkAccess')
3100
            ->with($this->equalTo('historyCompareRevisions'));
3101
3102
        $object = new \stdClass();
3103
3104
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3105
            ->method('getObject')
3106
            ->willReturn($object);
3107
3108
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3109
            ->method('getClass')
3110
            ->willReturn('Foo');
3111
3112
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3113
            ->method('hasReader')
3114
            ->with($this->equalTo('Foo'))
3115
            ->willReturn(true);
3116
3117
        $reader = $this->createMock(AuditReaderInterface::class);
3118
3119
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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.

Loading history...
3120
            ->method('getReader')
3121
            ->with($this->equalTo('Foo'))
3122
            ->willReturn($reader);
3123
3124
        $objectRevision = new \stdClass();
3125
        $objectRevision->revision = 456;
3126
3127
        $compareObjectRevision = new \stdClass();
3128
        $compareObjectRevision->revision = 789;
3129
3130
        $reader->expects($this->at(0))
3131
            ->method('find')
3132
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3133
            ->willReturn($objectRevision);
3134
3135
        $reader->expects($this->at(1))
3136
            ->method('find')
3137
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3138
            ->willReturn($compareObjectRevision);
3139
3140
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3141
            ->method('setSubject')
3142
            ->with($this->equalTo($objectRevision));
3143
3144
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3145
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3146
            ->method('getShow')
3147
            ->willReturn($fieldDescriptionCollection);
3148
3149
        $this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction($this->request, 456, 789));
3150
3151
        $this->assertSame($this->admin, $this->parameters['admin']);
3152
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3153
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3154
3155
        $this->assertSame('show', $this->parameters['action']);
3156
        $this->assertSame($objectRevision, $this->parameters['object']);
3157
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3158
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3159
3160
        $this->assertSame([], $this->session->getFlashBag()->all());
3161
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3162
    }
3163
3164
    public function testBatchActionWrongMethod(): void
3165
    {
3166
        $this->expectException(NotFoundHttpException::class);
3167
        $this->expectExceptionMessage('Invalid request method given "GET", POST expected');
3168
3169
        $this->controller->batchAction($this->request);
3170
    }
3171
3172
    public function testBatchActionActionNotDefined(): void
3173
    {
3174
        $this->expectException(\RuntimeException::class);
3175
        $this->expectExceptionMessage('The `foo` batch action is not defined');
3176
3177
        $batchActions = [];
3178
3179
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3180
            ->method('getBatchActions')
3181
            ->willReturn($batchActions);
3182
3183
        $this->request->setMethod(Request::METHOD_POST);
3184
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3185
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3186
3187
        $this->controller->batchAction($this->request);
3188
    }
3189
3190
    public function testBatchActionActionInvalidCsrfToken(): void
3191
    {
3192
        $this->request->setMethod(Request::METHOD_POST);
3193
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3194
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3195
3196
        try {
3197
            $this->controller->batchAction($this->request);
3198
        } catch (HttpException $e) {
3199
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3200
            $this->assertSame(400, $e->getStatusCode());
3201
        }
3202
    }
3203
3204
    public function testBatchActionWithoutConfirmation(): void
3205
    {
3206
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3207
3208
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3209
            ->method('getBatchActions')
3210
            ->willReturn($batchActions);
3211
3212
        $datagrid = $this->createMock(DatagridInterface::class);
3213
3214
        $query = $this->createMock(ProxyQueryInterface::class);
3215
        $datagrid->expects($this->once())
3216
            ->method('getQuery')
3217
            ->willReturn($query);
3218
3219
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3220
            ->method('getDatagrid')
3221
            ->willReturn($datagrid);
3222
3223
        $modelManager = $this->createMock(ModelManagerInterface::class);
3224
3225
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3226
            ->method('checkAccess')
3227
            ->with($this->equalTo('batchDelete'));
3228
3229
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3230
            ->method('getModelManager')
3231
            ->willReturn($modelManager);
3232
3233
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3234
            ->method('getClass')
3235
            ->willReturn('Foo');
3236
3237
        $modelManager->expects($this->once())
3238
            ->method('addIdentifiersToQuery')
3239
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3240
            ->willReturn(true);
3241
3242
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3243
3244
        $this->request->setMethod(Request::METHOD_POST);
3245
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3246
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3247
3248
        $result = $this->controller->batchAction($this->request);
3249
3250
        $this->assertInstanceOf(RedirectResponse::class, $result);
3251
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3252
        $this->assertSame('list', $result->getTargetUrl());
3253
    }
3254
3255
    public function testBatchActionWithoutConfirmation2(): void
3256
    {
3257
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3258
3259
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3260
            ->method('getBatchActions')
3261
            ->willReturn($batchActions);
3262
3263
        $datagrid = $this->createMock(DatagridInterface::class);
3264
3265
        $query = $this->createMock(ProxyQueryInterface::class);
3266
        $datagrid->expects($this->once())
3267
            ->method('getQuery')
3268
            ->willReturn($query);
3269
3270
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3271
            ->method('getDatagrid')
3272
            ->willReturn($datagrid);
3273
3274
        $modelManager = $this->createMock(ModelManagerInterface::class);
3275
3276
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3277
            ->method('checkAccess')
3278
            ->with($this->equalTo('batchDelete'));
3279
3280
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3281
            ->method('getModelManager')
3282
            ->willReturn($modelManager);
3283
3284
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3285
            ->method('getClass')
3286
            ->willReturn('Foo');
3287
3288
        $modelManager->expects($this->once())
3289
            ->method('addIdentifiersToQuery')
3290
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3291
            ->willReturn(true);
3292
3293
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3294
3295
        $this->request->setMethod(Request::METHOD_POST);
3296
        $this->request->request->set('action', 'delete');
3297
        $this->request->request->set('idx', ['123', '456']);
3298
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3299
3300
        $result = $this->controller->batchAction($this->request);
3301
3302
        $this->assertInstanceOf(RedirectResponse::class, $result);
3303
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3304
        $this->assertSame('list', $result->getTargetUrl());
3305
    }
3306
3307
    public function testBatchActionWithConfirmation(): void
3308
    {
3309
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3310
3311
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3312
            ->method('getBatchActions')
3313
            ->willReturn($batchActions);
3314
3315
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3316
3317
        $this->request->setMethod(Request::METHOD_POST);
3318
        $this->request->request->set('data', json_encode($data));
3319
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3320
3321
        $datagrid = $this->createMock(DatagridInterface::class);
3322
3323
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3324
            ->method('getDatagrid')
3325
            ->willReturn($datagrid);
3326
3327
        $form = $this->getMockBuilder(Form::class)
3328
            ->disableOriginalConstructor()
3329
            ->getMock();
3330
3331
        $form->expects($this->once())
3332
            ->method('createView')
3333
            ->willReturn($this->createMock(FormView::class));
3334
3335
        $datagrid->expects($this->once())
3336
            ->method('getForm')
3337
            ->willReturn($form);
3338
3339
        $this->assertInstanceOf(Response::class, $this->controller->batchAction($this->request));
3340
3341
        $this->assertSame($this->admin, $this->parameters['admin']);
3342
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3343
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3344
3345
        $this->assertSame('list', $this->parameters['action']);
3346
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3347
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3348
        $this->assertSame($data, $this->parameters['data']);
3349
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3350
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3351
3352
        $this->assertSame([], $this->session->getFlashBag()->all());
3353
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3354
    }
3355
3356
    public function testBatchActionNonRelevantAction(): void
3357
    {
3358
        $controller = new BatchAdminController();
3359
        $controller->setContainer($this->container);
3360
3361
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3362
3363
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3364
            ->method('getBatchActions')
3365
            ->willReturn($batchActions);
3366
3367
        $datagrid = $this->createMock(DatagridInterface::class);
3368
3369
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3370
            ->method('getDatagrid')
3371
            ->willReturn($datagrid);
3372
3373
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3374
3375
        $this->request->setMethod(Request::METHOD_POST);
3376
        $this->request->request->set('action', 'foo');
3377
        $this->request->request->set('idx', ['789']);
3378
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3379
3380
        $result = $controller->batchAction($this->request);
3381
3382
        $this->assertInstanceOf(RedirectResponse::class, $result);
3383
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3384
        $this->assertSame('list', $result->getTargetUrl());
3385
    }
3386
3387
    public function testBatchActionWithCustomConfirmationTemplate(): void
3388
    {
3389
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3390
3391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3392
            ->method('getBatchActions')
3393
            ->willReturn($batchActions);
3394
3395
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3396
3397
        $this->request->setMethod(Request::METHOD_POST);
3398
        $this->request->request->set('data', json_encode($data));
3399
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3400
3401
        $datagrid = $this->createMock(DatagridInterface::class);
3402
3403
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3404
            ->method('getDatagrid')
3405
            ->willReturn($datagrid);
3406
3407
        $form = $this->createMock(Form::class);
3408
3409
        $form->expects($this->once())
3410
            ->method('createView')
3411
            ->willReturn($this->createMock(FormView::class));
3412
3413
        $datagrid->expects($this->once())
3414
            ->method('getForm')
3415
            ->willReturn($form);
3416
3417
        $this->controller->batchAction($this->request);
3418
3419
        $this->assertSame('custom_template.html.twig', $this->template);
3420
    }
3421
3422
    public function testBatchActionNonRelevantAction2(): void
3423
    {
3424
        $controller = new BatchAdminController();
3425
        $controller->setContainer($this->container);
3426
3427
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3428
3429
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3430
            ->method('getBatchActions')
3431
            ->willReturn($batchActions);
3432
3433
        $datagrid = $this->createMock(DatagridInterface::class);
3434
3435
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3436
            ->method('getDatagrid')
3437
            ->willReturn($datagrid);
3438
3439
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3440
3441
        $this->request->setMethod(Request::METHOD_POST);
3442
        $this->request->request->set('action', 'foo');
3443
        $this->request->request->set('idx', ['999']);
3444
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3445
3446
        $result = $controller->batchAction($this->request);
3447
3448
        $this->assertInstanceOf(RedirectResponse::class, $result);
3449
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3450
        $this->assertSame('list', $result->getTargetUrl());
3451
    }
3452
3453
    public function testBatchActionNoItems(): void
3454
    {
3455
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3456
3457
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3458
            ->method('getBatchActions')
3459
            ->willReturn($batchActions);
3460
3461
        $datagrid = $this->createMock(DatagridInterface::class);
3462
3463
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3464
            ->method('getDatagrid')
3465
            ->willReturn($datagrid);
3466
3467
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3468
3469
        $this->request->setMethod(Request::METHOD_POST);
3470
        $this->request->request->set('action', 'delete');
3471
        $this->request->request->set('idx', []);
3472
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3473
3474
        $result = $this->controller->batchAction($this->request);
3475
3476
        $this->assertInstanceOf(RedirectResponse::class, $result);
3477
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3478
        $this->assertSame('list', $result->getTargetUrl());
3479
    }
3480
3481
    public function testBatchActionNoItemsEmptyQuery(): void
3482
    {
3483
        $controller = new BatchAdminController();
3484
        $controller->setContainer($this->container);
3485
3486
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3487
3488
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3489
            ->method('getBatchActions')
3490
            ->willReturn($batchActions);
3491
3492
        $datagrid = $this->createMock(DatagridInterface::class);
3493
3494
        $query = $this->createMock(ProxyQueryInterface::class);
3495
        $datagrid->expects($this->once())
3496
            ->method('getQuery')
3497
            ->willReturn($query);
3498
3499
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3500
            ->method('getDatagrid')
3501
            ->willReturn($datagrid);
3502
3503
        $modelManager = $this->createMock(ModelManagerInterface::class);
3504
3505
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3506
            ->method('getModelManager')
3507
            ->willReturn($modelManager);
3508
3509
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3510
            ->method('getClass')
3511
            ->willReturn('Foo');
3512
3513
        $this->request->setMethod(Request::METHOD_POST);
3514
        $this->request->request->set('action', 'bar');
3515
        $this->request->request->set('idx', []);
3516
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3517
3518
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3519
        $result = $controller->batchAction($this->request);
3520
3521
        $this->assertInstanceOf(Response::class, $result);
3522
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3523
    }
3524
3525
    public function testBatchActionWithRequesData(): void
3526
    {
3527
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3528
3529
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3530
            ->method('getBatchActions')
3531
            ->willReturn($batchActions);
3532
3533
        $datagrid = $this->createMock(DatagridInterface::class);
3534
3535
        $query = $this->createMock(ProxyQueryInterface::class);
3536
        $datagrid->expects($this->once())
3537
            ->method('getQuery')
3538
            ->willReturn($query);
3539
3540
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3541
            ->method('getDatagrid')
3542
            ->willReturn($datagrid);
3543
3544
        $modelManager = $this->createMock(ModelManagerInterface::class);
3545
3546
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3547
            ->method('checkAccess')
3548
            ->with($this->equalTo('batchDelete'));
3549
3550
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3551
            ->method('getModelManager')
3552
            ->willReturn($modelManager);
3553
3554
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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.

Loading history...
3555
            ->method('getClass')
3556
            ->willReturn('Foo');
3557
3558
        $modelManager->expects($this->once())
3559
            ->method('addIdentifiersToQuery')
3560
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3561
            ->willReturn(true);
3562
3563
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3564
3565
        $this->request->setMethod(Request::METHOD_POST);
3566
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3567
        $this->request->request->set('foo', 'bar');
3568
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3569
3570
        $result = $this->controller->batchAction($this->request);
3571
3572
        $this->assertInstanceOf(RedirectResponse::class, $result);
3573
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3574
        $this->assertSame('list', $result->getTargetUrl());
3575
        $this->assertSame('bar', $this->request->request->get('foo'));
3576
    }
3577
3578
    public function getCsrfProvider()
3579
    {
3580
        return $this->csrfProvider;
3581
    }
3582
3583
    public function getToStringValues()
3584
    {
3585
        return [
3586
            ['', ''],
3587
            ['Foo', 'Foo'],
3588
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3589
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3590
        ];
3591
    }
3592
3593
    private function assertLoggerLogsModelManagerException($subject, string $method): void
3594
    {
3595
        $exception = new ModelManagerException(
3596
            $message = 'message',
3597
            1234,
3598
            new \Exception($previousExceptionMessage = 'very useful message')
3599
        );
3600
3601
        $subject->expects($this->once())
3602
            ->method($method)
3603
            ->willReturnCallback(static function () use ($exception): void {
3604
                throw $exception;
3605
            });
3606
3607
        $this->logger->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Psr\Log\LoggerInterface>.

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.

Loading history...
3608
            ->method('error')
3609
            ->with($message, [
3610
                'exception' => $exception,
3611
                'previous_exception_message' => $previousExceptionMessage,
3612
            ]);
3613
    }
3614
3615
    private function expectTranslate(
3616
        string $id,
3617
        array $parameters = [],
3618
        ?string $domain = null,
3619
        ?string $locale = null
3620
    ): void {
3621
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Contracts...on\TranslatorInterface>.

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.

Loading history...
3622
            ->method('trans')
3623
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3624
            ->willReturn($id);
3625
    }
3626
}
3627