Completed
Push — master ( 651a01...276b19 )
by Grégoire
03:01
created

CRUDControllerTest::testEditActionError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 9.0036
c 0
b 0
f 0
cc 1
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\AuditManager;
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\AclSecurityHandler;
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\Bundle\FrameworkBundle\Controller\Controller;
43
use Symfony\Component\DependencyInjection\Container;
44
use Symfony\Component\DependencyInjection\ContainerInterface;
45
use Symfony\Component\Form\Form;
46
use Symfony\Component\Form\FormError;
47
use Symfony\Component\Form\FormRenderer;
48
use Symfony\Component\Form\FormView;
49
use Symfony\Component\HttpFoundation\JsonResponse;
50
use Symfony\Component\HttpFoundation\RedirectResponse;
51
use Symfony\Component\HttpFoundation\Request;
52
use Symfony\Component\HttpFoundation\RequestStack;
53
use Symfony\Component\HttpFoundation\Response;
54
use Symfony\Component\HttpFoundation\Session\Session;
55
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
56
use Symfony\Component\HttpFoundation\StreamedResponse;
57
use Symfony\Component\HttpKernel\Exception\HttpException;
58
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
59
use Symfony\Component\HttpKernel\KernelInterface;
60
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
61
use Symfony\Component\Security\Csrf\CsrfToken;
62
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
63
use Symfony\Contracts\Translation\TranslatorInterface;
64
use Twig\Environment;
65
66
/**
67
 * Test for CRUDController.
68
 *
69
 * @author Andrej Hudec <[email protected]>
70
 *
71
 * @group legacy
72
 */
73
class CRUDControllerTest extends TestCase
74
{
75
    /**
76
     * @var CRUDController
77
     */
78
    private $controller;
79
80
    /**
81
     * @var Request
82
     */
83
    private $request;
84
85
    /**
86
     * @var AdminInterface
87
     */
88
    private $admin;
89
90
    /**
91
     * @var TemplateRegistryInterface
92
     */
93
    private $templateRegistry;
94
95
    /**
96
     * @var Pool
97
     */
98
    private $pool;
99
100
    /**
101
     * @var array
102
     */
103
    private $parameters;
104
105
    /**
106
     * @var Session
107
     */
108
    private $session;
109
110
    /**
111
     * @var AuditManager
112
     */
113
    private $auditManager;
114
115
    /**
116
     * @var ContainerInterface
117
     */
118
    private $container;
119
120
    /**
121
     * @var AdminObjectAclManipulator
122
     */
123
    private $adminObjectAclManipulator;
124
125
    /**
126
     * @var string
127
     */
128
    private $template;
129
130
    /**
131
     * @var array
132
     */
133
    private $protectedTestedMethods;
134
135
    /**
136
     * @var CsrfTokenManagerInterface
137
     */
138
    private $csrfProvider;
139
140
    /**
141
     * @var KernelInterface
142
     */
143
    private $kernel;
144
145
    /**
146
     * @var TranslatorInterface
147
     */
148
    private $translator;
149
150
    /**
151
     * @var LoggerInterface|MockObject
152
     */
153
    private $logger;
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    protected function setUp(): void
159
    {
160
        $this->container = new Container();
161
        $this->request = new Request();
162
        $this->pool = new Pool($this->container, 'title', 'logo.png');
163
        $this->pool->setAdminServiceIds(['foo.admin']);
164
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
165
        $this->admin = $this->createMock(AdminInterface::class);
166
        $this->translator = $this->createMock(TranslatorInterface::class);
167
        $this->parameters = [];
168
        $this->template = '';
169
170
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
171
172
        $templatingRenderReturnCallback = $this->returnCallback(function (
173
            string $name,
174
            array $context = []
175
        ): string {
176
            $this->template = $name;
177
178
            $this->parameters = $context;
179
180
            return '';
181
        });
182
183
        $this->session = new Session(new MockArraySessionStorage());
184
185
        $twig = $this->getMockBuilder(Environment::class)
186
            ->disableOriginalConstructor()
187
            ->getMock();
188
189
        $twig
190
            ->method('getRuntime')
191
            ->willReturn($this->createMock(FormRenderer::class));
192
193
        $twig
194
            ->method('render')
195
            ->will($templatingRenderReturnCallback);
196
197
        $exporter = new Exporter([new JsonWriter(sys_get_temp_dir().'/sonataadmin/export.json')]);
198
199
        $adminExporter = new AdminExporter($exporter);
200
201
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
202
            ->disableOriginalConstructor()
203
            ->getMock();
204
205
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
206
            ->disableOriginalConstructor()
207
            ->getMock();
208
209
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
210
            ->getMock();
211
212
        $this->csrfProvider
213
            ->method('getToken')
214
            ->willReturnCallback(static function (string $intention): CsrfToken {
215
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
216
            });
217
218
        $this->csrfProvider
219
            ->method('isTokenValid')
220
            ->willReturnCallback(static function (CsrfToken $token): bool {
221
                return $token->getValue() === 'csrf-token-123_'.$token->getId();
222
            });
223
224
        $this->logger = $this->createMock(LoggerInterface::class);
225
226
        $requestStack = new RequestStack();
227
        $requestStack->push($this->request);
228
229
        $this->kernel = $this->createMock(KernelInterface::class);
230
231
        $this->container->set('sonata.admin.pool', $this->pool);
232
        $this->container->set('request_stack', $requestStack);
233
        $this->container->set('foo.admin', $this->admin);
234
        $this->container->set('foo.admin.template_registry', $this->templateRegistry->reveal());
235
        $this->container->set('twig', $twig);
236
        $this->container->set('session', $this->session);
237
        $this->container->set('sonata.exporter.exporter', $exporter);
238
        $this->container->set('sonata.admin.admin_exporter', $adminExporter);
239
        $this->container->set('sonata.admin.audit.manager', $this->auditManager);
240
        $this->container->set('sonata.admin.object.manipulator.acl.admin', $this->adminObjectAclManipulator);
241
        $this->container->set('security.csrf.token_manager', $this->csrfProvider);
242
        $this->container->set('logger', $this->logger);
243
        $this->container->set('kernel', $this->kernel);
244
        $this->container->set('translator', $this->translator);
245
        $this->container->set('sonata.admin.breadcrumbs_builder', new BreadcrumbsBuilder([]));
246
247
        $this->container->setParameter(
248
            'security.role_hierarchy.roles',
249
            ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']]
250
        );
251
        $this->container->setParameter('sonata.admin.security.acl_user_manager', null);
252
253
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
254
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
255
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
256
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
257
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
258
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
259
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
260
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
261
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
262
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
263
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
264
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
265
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
266
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
267
268
        $this->admin
269
            ->method('getIdParameter')
270
            ->willReturn('id');
271
272
        $this->admin
273
            ->method('getAccessMapping')
274
            ->willReturn([]);
275
276
        $this->admin
277
            ->method('generateUrl')
278
            ->willReturnCallback(
279
                static function ($name, array $parameters = []) {
280
                    $result = $name;
281
                    if (!empty($parameters)) {
282
                        $result .= '?'.http_build_query($parameters);
283
                    }
284
285
                    return $result;
286
                }
287
            );
288
289
        $this->admin
290
            ->method('generateObjectUrl')
291
            ->willReturnCallback(
292
                static function (string $name, $object, array $parameters = []): string {
293
                    $result = \get_class($object).'_'.$name;
294
                    if (!empty($parameters)) {
295
                        $result .= '?'.http_build_query($parameters);
296
                    }
297
298
                    return $result;
299
                }
300
            );
301
302
        $this->admin
303
            ->method('getCode')
304
            ->willReturn('foo.admin');
305
306
        $this->controller = new CRUDController();
307
        $this->controller->setContainer($this->container);
308
309
        // Make some methods public to test them
310
        $testedMethods = [
311
            'renderJson',
312
            'isXmlHttpRequest',
313
            'configure',
314
            'getBaseTemplate',
315
            'redirectTo',
316
            'addFlash',
317
        ];
318
        foreach ($testedMethods as $testedMethod) {
319
            // NEXT_MAJOR: Remove this check and only use CRUDController
320
            if (method_exists(CRUDController::class, $testedMethod)) {
321
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
322
            } else {
323
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
324
            }
325
326
            $method->setAccessible(true);
327
            $this->protectedTestedMethods[$testedMethod] = $method;
328
        }
329
    }
330
331
    public function testRenderJson1(): void
332
    {
333
        $data = ['example' => '123', 'foo' => 'bar'];
334
335
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
336
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
337
338
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
339
        $this->assertSame(json_encode($data), $response->getContent());
340
    }
341
342
    public function testRenderJson2(): void
343
    {
344
        $data = ['example' => '123', 'foo' => 'bar'];
345
346
        $this->request->headers->set('Content-Type', 'multipart/form-data');
347
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
348
349
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
350
        $this->assertSame(json_encode($data), $response->getContent());
351
    }
352
353
    public function testRenderJsonAjax(): void
354
    {
355
        $data = ['example' => '123', 'foo' => 'bar'];
356
357
        $this->request->attributes->set('_xml_http_request', true);
358
        $this->request->headers->set('Content-Type', 'multipart/form-data');
359
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
360
361
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
362
        $this->assertSame(json_encode($data), $response->getContent());
363
    }
364
365
    public function testIsXmlHttpRequest(): void
366
    {
367
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
368
369
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
370
371
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
372
373
        $this->request->headers->remove('X-Requested-With');
374
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
375
376
        $this->request->attributes->set('_xml_http_request', true);
377
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
378
    }
379
380
    public function testConfigure(): void
381
    {
382
        $uniqueId = '';
383
384
        $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...
385
            ->method('setUniqid')
386
            ->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void {
387
                $uniqueId = $uniqid;
388
            });
389
390
        $this->request->query->set('uniqid', '123456');
391
        $this->protectedTestedMethods['configure']->invoke($this->controller);
392
393
        $this->assertSame('123456', $uniqueId);
394
    }
395
396
    public function testConfigureChild(): void
397
    {
398
        $uniqueId = '';
399
400
        $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...
401
            ->method('setUniqid')
402
            ->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void {
403
                $uniqueId = $uniqid;
404
            });
405
406
        $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...
407
            ->method('isChild')
408
            ->willReturn(true);
409
410
        $adminParent = $this->getMockBuilder(AdminInterface::class)
411
            ->disableOriginalConstructor()
412
            ->getMock();
413
        $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...
414
            ->method('getParent')
415
            ->willReturn($adminParent);
416
417
        $this->request->query->set('uniqid', '123456');
418
        $this->protectedTestedMethods['configure']->invoke($this->controller);
419
420
        $this->assertSame('123456', $uniqueId);
421
    }
422
423
    public function testConfigureWithException(): void
424
    {
425
        $this->expectException(\RuntimeException::class);
426
        $this->expectExceptionMessage(
427
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
428
        );
429
430
        $this->request->attributes->remove('_sonata_admin');
431
        $this->protectedTestedMethods['configure']->invoke($this->controller);
432
    }
433
434
    public function testConfigureWithException2(): void
435
    {
436
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
437
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
438
439
        $this->expectException(\RuntimeException::class);
440
        $this->expectExceptionMessage('Unable to find the admin class related to the current controller (Sonata\AdminBundle\Controller\CRUDController)');
441
442
        $this->protectedTestedMethods['configure']->invoke($this->controller);
443
    }
444
445
    public function testGetBaseTemplate(): void
446
    {
447
        $this->assertSame(
448
            '@SonataAdmin/standard_layout.html.twig',
449
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
450
        );
451
452
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
453
        $this->assertSame(
454
            '@SonataAdmin/ajax_layout.html.twig',
455
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
456
        );
457
458
        $this->request->headers->remove('X-Requested-With');
459
        $this->assertSame(
460
            '@SonataAdmin/standard_layout.html.twig',
461
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
462
        );
463
464
        $this->request->attributes->set('_xml_http_request', true);
465
        $this->assertSame(
466
            '@SonataAdmin/ajax_layout.html.twig',
467
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
468
        );
469
    }
470
471
    public function testRender(): void
472
    {
473
        $this->parameters = [];
474
        $this->assertInstanceOf(
475
            Response::class,
476
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
477
        );
478
        $this->assertSame($this->admin, $this->parameters['admin']);
479
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
480
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
481
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
482
    }
483
484
    public function testRenderWithResponse(): void
485
    {
486
        $this->parameters = [];
487
        $response = new Response();
488
        $response->headers->set('X-foo', 'bar');
489
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
490
491
        $this->assertSame($response, $responseResult);
492
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
493
        $this->assertSame($this->admin, $this->parameters['admin']);
494
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
495
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
496
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
497
    }
498
499
    public function testRenderCustomParams(): void
500
    {
501
        $this->parameters = [];
502
        $this->assertInstanceOf(
503
            Response::class,
504
            $this->controller->renderWithExtraParams(
505
                '@FooAdmin/foo.html.twig',
506
                ['foo' => 'bar'],
507
                null
508
            )
509
        );
510
        $this->assertSame($this->admin, $this->parameters['admin']);
511
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
512
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
513
        $this->assertSame('bar', $this->parameters['foo']);
514
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
515
    }
516
517
    public function testRenderAjax(): void
518
    {
519
        $this->parameters = [];
520
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
521
        $this->assertInstanceOf(
522
            Response::class,
523
            $this->controller->renderWithExtraParams(
524
                '@FooAdmin/foo.html.twig',
525
                ['foo' => 'bar'],
526
                null
527
            )
528
        );
529
        $this->assertSame($this->admin, $this->parameters['admin']);
530
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
531
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
532
        $this->assertSame('bar', $this->parameters['foo']);
533
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
534
    }
535
536
    public function testListActionAccessDenied(): void
537
    {
538
        $this->expectException(AccessDeniedException::class);
539
540
        $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...
541
            ->method('checkAccess')
542
            ->with($this->equalTo('list'))
543
            ->will($this->throwException(new AccessDeniedException()));
544
545
        $this->controller->listAction($this->request);
546
    }
547
548
    public function testPreList(): void
549
    {
550
        $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...
551
            ->method('hasRoute')
552
            ->with($this->equalTo('list'))
553
            ->willReturn(true);
554
555
        $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...
556
            ->method('checkAccess')
557
            ->with($this->equalTo('list'));
558
559
        $controller = new PreCRUDController();
560
        $controller->setContainer($this->container);
561
562
        $response = $controller->listAction($this->request);
563
        $this->assertInstanceOf(Response::class, $response);
564
        $this->assertSame('preList called', $response->getContent());
565
    }
566
567
    public function testListAction(): void
568
    {
569
        $datagrid = $this->createMock(DatagridInterface::class);
570
571
        $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...
572
            ->method('hasRoute')
573
            ->with($this->equalTo('list'))
574
            ->willReturn(true);
575
576
        $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...
577
            ->method('checkAccess')
578
            ->with($this->equalTo('list'));
579
580
        $form = $this->getMockBuilder(Form::class)
581
            ->disableOriginalConstructor()
582
            ->getMock();
583
584
        $form->expects($this->once())
585
            ->method('createView')
586
            ->willReturn($this->createMock(FormView::class));
587
588
        $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...
589
            ->method('getDatagrid')
590
            ->willReturn($datagrid);
591
592
        $datagrid->expects($this->once())
593
            ->method('getForm')
594
            ->willReturn($form);
595
596
        $this->parameters = [];
597
        $this->assertInstanceOf(Response::class, $this->controller->listAction($this->request));
598
599
        $this->assertSame($this->admin, $this->parameters['admin']);
600
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
601
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
602
603
        $this->assertSame('list', $this->parameters['action']);
604
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
605
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
606
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
607
        $this->assertSame([], $this->session->getFlashBag()->all());
608
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
609
    }
610
611
    public function testBatchActionDeleteAccessDenied(): void
612
    {
613
        $this->expectException(AccessDeniedException::class);
614
615
        $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...
616
            ->method('checkAccess')
617
            ->with($this->equalTo('batchDelete'))
618
            ->will($this->throwException(new AccessDeniedException()));
619
620
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
621
    }
622
623
    public function testBatchActionDelete(): void
624
    {
625
        $modelManager = $this->createMock(ModelManagerInterface::class);
626
627
        $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...
628
            ->method('checkAccess')
629
            ->with($this->equalTo('batchDelete'));
630
631
        $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...
632
            ->method('getModelManager')
633
            ->willReturn($modelManager);
634
635
        $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...
636
            ->method('getFilterParameters')
637
            ->willReturn(['foo' => 'bar']);
638
639
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
640
641
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
642
643
        $this->assertInstanceOf(RedirectResponse::class, $result);
644
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
645
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
646
    }
647
648
    public function testBatchActionDeleteWithModelManagerException(): void
649
    {
650
        $modelManager = $this->createMock(ModelManagerInterface::class);
651
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
652
653
        $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...
654
            ->method('getModelManager')
655
            ->willReturn($modelManager);
656
657
        $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...
658
            ->method('getFilterParameters')
659
            ->willReturn(['foo' => 'bar']);
660
661
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
662
663
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
664
665
        $this->assertInstanceOf(RedirectResponse::class, $result);
666
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
667
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
668
    }
669
670
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
671
    {
672
        $modelManager = $this->createMock(ModelManagerInterface::class);
673
        $this->expectException(ModelManagerException::class);
674
675
        $modelManager->expects($this->once())
676
            ->method('batchDelete')
677
            ->willReturnCallback(static function (): void {
678
                throw new ModelManagerException();
679
            });
680
681
        $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...
682
            ->method('getModelManager')
683
            ->willReturn($modelManager);
684
685
        $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...
686
            ->method('isDebug')
687
            ->willReturn(true);
688
689
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
690
    }
691
692
    public function testShowActionNotFoundException(): void
693
    {
694
        $this->expectException(NotFoundHttpException::class);
695
696
        $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...
697
            ->method('getObject')
698
            ->willReturn(null);
699
700
        $this->controller->showAction($this->request);
701
    }
702
703
    public function testShowActionAccessDenied(): void
704
    {
705
        $this->expectException(AccessDeniedException::class);
706
707
        $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...
708
            ->method('getObject')
709
            ->willReturn(new \stdClass());
710
711
        $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...
712
            ->method('checkAccess')
713
            ->with($this->equalTo('show'))
714
            ->will($this->throwException(new AccessDeniedException()));
715
716
        $this->controller->showAction($this->request);
717
    }
718
719
    public function testPreShow(): void
720
    {
721
        $object = new \stdClass();
722
        $object->foo = 123456;
723
724
        $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...
725
            ->method('getObject')
726
            ->willReturn($object);
727
728
        $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...
729
            ->method('checkAccess')
730
            ->with($this->equalTo('show'));
731
732
        $controller = new PreCRUDController();
733
        $controller->setContainer($this->container);
734
735
        $response = $controller->showAction($this->request);
736
        $this->assertInstanceOf(Response::class, $response);
737
        $this->assertSame('preShow called: 123456', $response->getContent());
738
    }
739
740
    public function testShowAction(): void
741
    {
742
        $object = new \stdClass();
743
744
        $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...
745
            ->method('getObject')
746
            ->willReturn($object);
747
748
        $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...
749
            ->method('checkAccess')
750
            ->with($this->equalTo('show'));
751
752
        $show = $this->createMock(FieldDescriptionCollection::class);
753
754
        $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...
755
            ->method('getShow')
756
            ->willReturn($show);
757
758
        $this->assertInstanceOf(Response::class, $this->controller->showAction($this->request));
759
760
        $this->assertSame($this->admin, $this->parameters['admin']);
761
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
762
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
763
764
        $this->assertSame('show', $this->parameters['action']);
765
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
766
        $this->assertSame($object, $this->parameters['object']);
767
768
        $this->assertSame([], $this->session->getFlashBag()->all());
769
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
770
    }
771
772
    /**
773
     * @dataProvider getRedirectToTests
774
     */
775
    public function testRedirectTo(
776
        string $expected,
777
        string $route,
778
        array $queryParams,
779
        array $requestParams,
780
        bool $hasActiveSubclass
781
    ): void {
782
        $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...
783
            ->method('hasActiveSubclass')
784
            ->willReturn($hasActiveSubclass);
785
786
        $object = new \stdClass();
787
788
        foreach ($queryParams as $key => $value) {
789
            $this->request->query->set($key, $value);
790
        }
791
792
        foreach ($requestParams as $key => $value) {
793
            $this->request->request->set($key, $value);
794
        }
795
796
        $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...
797
            ->method('hasRoute')
798
            ->with($this->equalTo($route))
799
            ->willReturn(true);
800
801
        $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...
802
            ->method('hasAccess')
803
            ->with($this->equalTo($route))
804
            ->willReturn(true);
805
806
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
807
        $this->assertInstanceOf(RedirectResponse::class, $response);
808
        $this->assertSame($expected, $response->getTargetUrl());
809
    }
810
811
    public function testRedirectToWithObject(): void
812
    {
813
        $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...
814
            ->method('hasActiveSubclass')
815
            ->willReturn(false);
816
817
        $object = new \stdClass();
818
819
        $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...
820
            ->method('hasRoute')
821
            ->with($this->equalTo('edit'))
822
            ->willReturn(true);
823
824
        $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...
825
            ->method('hasAccess')
826
            ->with($this->equalTo('edit'), $object)
827
            ->willReturn(false);
828
829
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
830
        $this->assertInstanceOf(RedirectResponse::class, $response);
831
        $this->assertSame('list', $response->getTargetUrl());
832
    }
833
834
    public function getRedirectToTests()
835
    {
836
        return [
837
            ['stdClass_edit', 'edit', [], [], false],
838
            ['list', 'list', ['btn_update_and_list' => true], [], false],
839
            ['list', 'list', ['btn_create_and_list' => true], [], false],
840
            ['create', 'create', ['btn_create_and_create' => true], [], false],
841
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
842
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
843
        ];
844
    }
845
846
    public function testDeleteActionNotFoundException(): void
847
    {
848
        $this->expectException(NotFoundHttpException::class);
849
850
        $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...
851
            ->method('getObject')
852
            ->willReturn(null);
853
854
        $this->controller->deleteAction($this->request);
855
    }
856
857
    public function testDeleteActionAccessDenied(): void
858
    {
859
        $this->expectException(AccessDeniedException::class);
860
861
        $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...
862
            ->method('getObject')
863
            ->willReturn(new \stdClass());
864
865
        $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...
866
            ->method('checkAccess')
867
            ->with($this->equalTo('delete'))
868
            ->will($this->throwException(new AccessDeniedException()));
869
870
        $this->controller->deleteAction($this->request);
871
    }
872
873
    public function testPreDelete(): void
874
    {
875
        $object = new \stdClass();
876
        $object->foo = 123456;
877
878
        $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...
879
            ->method('getObject')
880
            ->willReturn($object);
881
882
        $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...
883
            ->method('checkAccess')
884
            ->with($this->equalTo('delete'));
885
886
        $controller = new PreCRUDController();
887
        $controller->setContainer($this->container);
888
889
        $response = $controller->deleteAction($this->request);
890
        $this->assertInstanceOf(Response::class, $response);
891
        $this->assertSame('preDelete called: 123456', $response->getContent());
892
    }
893
894
    public function testDeleteAction(): void
895
    {
896
        $object = new \stdClass();
897
898
        $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...
899
            ->method('getObject')
900
            ->willReturn($object);
901
902
        $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...
903
            ->method('checkAccess')
904
            ->with($this->equalTo('delete'));
905
906
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
907
908
        $this->assertSame($this->admin, $this->parameters['admin']);
909
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
910
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
911
912
        $this->assertSame('delete', $this->parameters['action']);
913
        $this->assertSame($object, $this->parameters['object']);
914
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
915
916
        $this->assertSame([], $this->session->getFlashBag()->all());
917
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
918
    }
919
920
    public function testDeleteActionNoCsrfToken(): void
921
    {
922
        $this->container->set('security.csrf.token_manager', null);
923
924
        $object = new \stdClass();
925
926
        $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...
927
            ->method('getObject')
928
            ->willReturn($object);
929
930
        $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...
931
            ->method('checkAccess')
932
            ->with($this->equalTo('delete'));
933
934
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
935
936
        $this->assertSame($this->admin, $this->parameters['admin']);
937
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
938
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
939
940
        $this->assertSame('delete', $this->parameters['action']);
941
        $this->assertSame($object, $this->parameters['object']);
942
        $this->assertFalse($this->parameters['csrf_token']);
943
944
        $this->assertSame([], $this->session->getFlashBag()->all());
945
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
946
    }
947
948
    public function testDeleteActionAjaxSuccess1(): void
949
    {
950
        $object = new \stdClass();
951
952
        $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...
953
            ->method('getObject')
954
            ->willReturn($object);
955
956
        $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...
957
            ->method('checkAccess')
958
            ->with($this->equalTo('delete'));
959
960
        $this->request->setMethod(Request::METHOD_DELETE);
961
962
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
963
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
964
965
        $response = $this->controller->deleteAction($this->request);
966
967
        $this->assertInstanceOf(Response::class, $response);
968
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
969
        $this->assertSame([], $this->session->getFlashBag()->all());
970
    }
971
972
    public function testDeleteActionAjaxSuccess2(): void
973
    {
974
        $object = new \stdClass();
975
976
        $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...
977
            ->method('getObject')
978
            ->willReturn($object);
979
980
        $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...
981
            ->method('checkAccess')
982
            ->with($this->equalTo('delete'));
983
984
        $this->request->setMethod(Request::METHOD_POST);
985
        $this->request->request->set('_method', Request::METHOD_DELETE);
986
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
987
988
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
989
990
        $response = $this->controller->deleteAction($this->request);
991
992
        $this->assertInstanceOf(Response::class, $response);
993
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
994
        $this->assertSame([], $this->session->getFlashBag()->all());
995
    }
996
997
    public function testDeleteActionAjaxError(): void
998
    {
999
        $object = new \stdClass();
1000
1001
        $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...
1002
            ->method('getObject')
1003
            ->willReturn($object);
1004
1005
        $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...
1006
            ->method('checkAccess')
1007
            ->with($this->equalTo('delete'));
1008
1009
        $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...
1010
            ->method('getClass')
1011
            ->willReturn(\stdClass::class);
1012
1013
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1014
1015
        $this->request->setMethod(Request::METHOD_DELETE);
1016
1017
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1018
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1019
1020
        $response = $this->controller->deleteAction($this->request);
1021
1022
        $this->assertInstanceOf(Response::class, $response);
1023
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1024
        $this->assertSame([], $this->session->getFlashBag()->all());
1025
    }
1026
1027
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1028
    {
1029
        $this->expectException(ModelManagerException::class);
1030
1031
        $object = new \stdClass();
1032
1033
        $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...
1034
            ->method('getObject')
1035
            ->willReturn($object);
1036
1037
        $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...
1038
            ->method('checkAccess')
1039
            ->with($this->equalTo('delete'));
1040
1041
        $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...
1042
            ->method('delete')
1043
            ->willReturnCallback(static function (): void {
1044
                throw new ModelManagerException();
1045
            });
1046
1047
        $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...
1048
            ->method('isDebug')
1049
            ->willReturn(true);
1050
1051
        $this->request->setMethod(Request::METHOD_DELETE);
1052
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1053
1054
        $this->controller->deleteAction($this->request);
1055
    }
1056
1057
    /**
1058
     * @dataProvider getToStringValues
1059
     */
1060
    public function testDeleteActionSuccess1(string $expectedToStringValue, string $toStringValue): void
1061
    {
1062
        $object = new \stdClass();
1063
1064
        $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...
1065
            ->method('getObject')
1066
            ->willReturn($object);
1067
1068
        $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...
1069
            ->method('toString')
1070
            ->with($this->equalTo($object))
1071
            ->willReturn($toStringValue);
1072
1073
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1074
1075
        $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...
1076
            ->method('checkAccess')
1077
            ->with($this->equalTo('delete'));
1078
1079
        $this->request->setMethod(Request::METHOD_DELETE);
1080
1081
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1082
1083
        $response = $this->controller->deleteAction($this->request);
1084
1085
        $this->assertInstanceOf(RedirectResponse::class, $response);
1086
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1087
        $this->assertSame('list', $response->getTargetUrl());
1088
    }
1089
1090
    /**
1091
     * @dataProvider getToStringValues
1092
     */
1093
    public function testDeleteActionSuccess2(string $expectedToStringValue, string $toStringValue): void
1094
    {
1095
        $object = new \stdClass();
1096
1097
        $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...
1098
            ->method('getObject')
1099
            ->willReturn($object);
1100
1101
        $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...
1102
            ->method('checkAccess')
1103
            ->with($this->equalTo('delete'));
1104
1105
        $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...
1106
            ->method('toString')
1107
            ->with($this->equalTo($object))
1108
            ->willReturn($toStringValue);
1109
1110
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1111
1112
        $this->request->setMethod(Request::METHOD_POST);
1113
        $this->request->request->set('_method', Request::METHOD_DELETE);
1114
1115
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1116
1117
        $response = $this->controller->deleteAction($this->request);
1118
1119
        $this->assertInstanceOf(RedirectResponse::class, $response);
1120
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1121
        $this->assertSame('list', $response->getTargetUrl());
1122
    }
1123
1124
    /**
1125
     * @dataProvider getToStringValues
1126
     */
1127
    public function testDeleteActionSuccessNoCsrfTokenProvider(string $expectedToStringValue, string $toStringValue): void
1128
    {
1129
        $this->container->set('security.csrf.token_manager', null);
1130
1131
        $object = new \stdClass();
1132
1133
        $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...
1134
            ->method('getObject')
1135
            ->willReturn($object);
1136
1137
        $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...
1138
            ->method('checkAccess')
1139
            ->with($this->equalTo('delete'));
1140
1141
        $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...
1142
            ->method('toString')
1143
            ->with($this->equalTo($object))
1144
            ->willReturn($toStringValue);
1145
1146
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1147
1148
        $this->request->setMethod(Request::METHOD_POST);
1149
        $this->request->request->set('_method', Request::METHOD_DELETE);
1150
1151
        $response = $this->controller->deleteAction($this->request);
1152
1153
        $this->assertInstanceOf(RedirectResponse::class, $response);
1154
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1155
        $this->assertSame('list', $response->getTargetUrl());
1156
    }
1157
1158
    public function testDeleteActionWrongRequestMethod(): void
1159
    {
1160
        $object = new \stdClass();
1161
1162
        $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...
1163
            ->method('getObject')
1164
            ->willReturn($object);
1165
1166
        $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...
1167
            ->method('checkAccess')
1168
            ->with($this->equalTo('delete'));
1169
1170
        //without POST request parameter "_method" should not be used as real REST method
1171
        $this->request->query->set('_method', Request::METHOD_DELETE);
1172
1173
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
1174
1175
        $this->assertSame($this->admin, $this->parameters['admin']);
1176
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1177
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1178
1179
        $this->assertSame('delete', $this->parameters['action']);
1180
        $this->assertSame($object, $this->parameters['object']);
1181
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1182
1183
        $this->assertSame([], $this->session->getFlashBag()->all());
1184
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1185
    }
1186
1187
    /**
1188
     * @dataProvider getToStringValues
1189
     */
1190
    public function testDeleteActionError(string $expectedToStringValue, string $toStringValue): void
1191
    {
1192
        $object = new \stdClass();
1193
1194
        $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...
1195
            ->method('getObject')
1196
            ->willReturn($object);
1197
1198
        $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...
1199
            ->method('checkAccess')
1200
            ->with($this->equalTo('delete'));
1201
1202
        $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...
1203
            ->method('toString')
1204
            ->with($this->equalTo($object))
1205
            ->willReturn($toStringValue);
1206
1207
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1208
1209
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1210
1211
        $this->request->setMethod(Request::METHOD_DELETE);
1212
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1213
1214
        $response = $this->controller->deleteAction($this->request);
1215
1216
        $this->assertInstanceOf(RedirectResponse::class, $response);
1217
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1218
        $this->assertSame('list', $response->getTargetUrl());
1219
    }
1220
1221
    public function testDeleteActionInvalidCsrfToken(): void
1222
    {
1223
        $object = new \stdClass();
1224
1225
        $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...
1226
            ->method('getObject')
1227
            ->willReturn($object);
1228
1229
        $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...
1230
            ->method('checkAccess')
1231
            ->with($this->equalTo('delete'));
1232
1233
        $this->request->setMethod(Request::METHOD_POST);
1234
        $this->request->request->set('_method', Request::METHOD_DELETE);
1235
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1236
1237
        try {
1238
            $this->controller->deleteAction($this->request);
1239
        } catch (HttpException $e) {
1240
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1241
            $this->assertSame(400, $e->getStatusCode());
1242
        }
1243
    }
1244
1245
    public function testEditActionNotFoundException(): void
1246
    {
1247
        $this->expectException(NotFoundHttpException::class);
1248
1249
        $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...
1250
            ->method('getObject')
1251
            ->willReturn(null);
1252
1253
        $this->controller->editAction($this->request);
1254
    }
1255
1256
    public function testEditActionAccessDenied(): void
1257
    {
1258
        $this->expectException(AccessDeniedException::class);
1259
1260
        $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...
1261
            ->method('getObject')
1262
            ->willReturn(new \stdClass());
1263
1264
        $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...
1265
            ->method('checkAccess')
1266
            ->with($this->equalTo('edit'))
1267
            ->will($this->throwException(new AccessDeniedException()));
1268
1269
        $this->controller->editAction($this->request);
1270
    }
1271
1272
    public function testPreEdit(): void
1273
    {
1274
        $object = new \stdClass();
1275
        $object->foo = 123456;
1276
1277
        $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...
1278
            ->method('getObject')
1279
            ->willReturn($object);
1280
1281
        $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...
1282
            ->method('checkAccess')
1283
            ->with($this->equalTo('edit'));
1284
1285
        $controller = new PreCRUDController();
1286
        $controller->setContainer($this->container);
1287
1288
        $response = $controller->editAction($this->request);
1289
        $this->assertInstanceOf(Response::class, $response);
1290
        $this->assertSame('preEdit called: 123456', $response->getContent());
1291
    }
1292
1293
    public function testEditAction(): void
1294
    {
1295
        $object = new \stdClass();
1296
1297
        $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...
1298
            ->method('getObject')
1299
            ->willReturn($object);
1300
1301
        $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...
1302
            ->method('checkAccess')
1303
            ->with($this->equalTo('edit'));
1304
1305
        $form = $this->createMock(Form::class);
1306
1307
        $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...
1308
            ->method('getForm')
1309
            ->willReturn($form);
1310
1311
        $formView = $this->createMock(FormView::class);
1312
1313
        $form
1314
            ->method('createView')
1315
            ->willReturn($formView);
1316
1317
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1318
1319
        $this->assertSame($this->admin, $this->parameters['admin']);
1320
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1321
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1322
1323
        $this->assertSame('edit', $this->parameters['action']);
1324
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1325
        $this->assertSame($object, $this->parameters['object']);
1326
        $this->assertSame([], $this->session->getFlashBag()->all());
1327
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1328
    }
1329
1330
    /**
1331
     * @dataProvider getToStringValues
1332
     */
1333
    public function testEditActionSuccess(string $expectedToStringValue, string $toStringValue): void
1334
    {
1335
        $object = new \stdClass();
1336
1337
        $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...
1338
            ->method('getObject')
1339
            ->willReturn($object);
1340
1341
        $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...
1342
            ->method('update')
1343
            ->willReturnArgument(0);
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('checkAccess')
1347
            ->with($this->equalTo('edit'));
1348
1349
        $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...
1350
            ->method('hasRoute')
1351
            ->with($this->equalTo('edit'))
1352
            ->willReturn(true);
1353
1354
        $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...
1355
            ->method('hasAccess')
1356
            ->with($this->equalTo('edit'))
1357
            ->willReturn(true);
1358
1359
        $form = $this->createMock(Form::class);
1360
1361
        $form->expects($this->once())
1362
            ->method('getData')
1363
            ->willReturn($object);
1364
1365
        $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...
1366
            ->method('getForm')
1367
            ->willReturn($form);
1368
1369
        $form->expects($this->once())
1370
            ->method('isSubmitted')
1371
            ->willReturn(true);
1372
1373
        $form->expects($this->once())
1374
            ->method('isValid')
1375
            ->willReturn(true);
1376
1377
        $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...
1378
            ->method('toString')
1379
            ->with($this->equalTo($object))
1380
            ->willReturn($toStringValue);
1381
1382
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1383
1384
        $this->request->setMethod(Request::METHOD_POST);
1385
1386
        $response = $this->controller->editAction($this->request);
1387
1388
        $this->assertInstanceOf(RedirectResponse::class, $response);
1389
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1390
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1391
    }
1392
1393
    /**
1394
     * @dataProvider getToStringValues
1395
     */
1396
    public function testEditActionError(string $expectedToStringValue, string $toStringValue): void
1397
    {
1398
        $object = new \stdClass();
1399
1400
        $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...
1401
            ->method('getObject')
1402
            ->willReturn($object);
1403
1404
        $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...
1405
            ->method('checkAccess')
1406
            ->with($this->equalTo('edit'));
1407
1408
        $form = $this->createMock(Form::class);
1409
1410
        $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...
1411
            ->method('getForm')
1412
            ->willReturn($form);
1413
1414
        $form->expects($this->once())
1415
            ->method('isSubmitted')
1416
            ->willReturn(true);
1417
1418
        $form->expects($this->once())
1419
            ->method('isValid')
1420
            ->willReturn(false);
1421
1422
        $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...
1423
            ->method('toString')
1424
            ->with($this->equalTo($object))
1425
            ->willReturn($toStringValue);
1426
1427
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1428
1429
        $this->request->setMethod(Request::METHOD_POST);
1430
1431
        $formView = $this->createMock(FormView::class);
1432
1433
        $form
1434
            ->method('createView')
1435
            ->willReturn($formView);
1436
1437
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1438
1439
        $this->assertSame($this->admin, $this->parameters['admin']);
1440
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1441
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1442
1443
        $this->assertSame('edit', $this->parameters['action']);
1444
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1445
        $this->assertSame($object, $this->parameters['object']);
1446
1447
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1448
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1449
    }
1450
1451
    public function testEditActionAjaxSuccess(): void
1452
    {
1453
        $object = new \stdClass();
1454
1455
        $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...
1456
            ->method('getObject')
1457
            ->willReturn($object);
1458
1459
        $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...
1460
            ->method('update')
1461
            ->willReturnArgument(0);
1462
1463
        $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...
1464
            ->method('checkAccess')
1465
            ->with($this->equalTo('edit'));
1466
1467
        $form = $this->createMock(Form::class);
1468
1469
        $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...
1470
            ->method('getForm')
1471
            ->willReturn($form);
1472
1473
        $form->expects($this->once())
1474
            ->method('isSubmitted')
1475
            ->willReturn(true);
1476
1477
        $form->expects($this->once())
1478
            ->method('isValid')
1479
            ->willReturn(true);
1480
1481
        $form->expects($this->once())
1482
            ->method('getData')
1483
            ->willReturn($object);
1484
1485
        $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...
1486
            ->method('getNormalizedIdentifier')
1487
            ->with($this->equalTo($object))
1488
            ->willReturn('foo_normalized');
1489
1490
        $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...
1491
            ->method('toString')
1492
            ->willReturn('foo');
1493
1494
        $this->request->setMethod(Request::METHOD_POST);
1495
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1496
        $this->request->headers->set('Accept', 'application/json');
1497
1498
        $response = $this->controller->editAction($this->request);
1499
1500
        $this->assertInstanceOf(Response::class, $response);
1501
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1502
        $this->assertSame([], $this->session->getFlashBag()->all());
1503
    }
1504
1505
    public function testEditActionAjaxError(): void
1506
    {
1507
        $object = new \stdClass();
1508
1509
        $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...
1510
            ->method('getObject')
1511
            ->willReturn($object);
1512
1513
        $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...
1514
            ->method('checkAccess')
1515
            ->with($this->equalTo('edit'));
1516
1517
        $form = $this->createMock(Form::class);
1518
1519
        $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...
1520
            ->method('getForm')
1521
            ->willReturn($form);
1522
1523
        $form->expects($this->once())
1524
            ->method('isSubmitted')
1525
            ->willReturn(true);
1526
1527
        $form->expects($this->once())
1528
            ->method('isValid')
1529
            ->willReturn(false);
1530
1531
        $formError = $this->createMock(FormError::class);
1532
        $formError->expects($this->atLeastOnce())
1533
            ->method('getMessage')
1534
            ->willReturn('Form error message');
1535
1536
        $form->expects($this->once())
1537
            ->method('getErrors')
1538
            ->with(true)
1539
            ->willReturn([$formError]);
1540
1541
        $this->request->setMethod(Request::METHOD_POST);
1542
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1543
        $this->request->headers->set('Accept', 'application/json');
1544
1545
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction($this->request));
1546
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
1547
    }
1548
1549
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1550
    {
1551
        $object = new \stdClass();
1552
1553
        $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...
1554
            ->method('getObject')
1555
            ->willReturn($object);
1556
1557
        $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...
1558
            ->method('checkAccess')
1559
            ->with($this->equalTo('edit'));
1560
1561
        $form = $this->createMock(Form::class);
1562
1563
        $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...
1564
            ->method('getForm')
1565
            ->willReturn($form);
1566
1567
        $form->expects($this->once())
1568
            ->method('isSubmitted')
1569
            ->willReturn(true);
1570
1571
        $form->expects($this->once())
1572
            ->method('isValid')
1573
            ->willReturn(false);
1574
1575
        $this->request->setMethod(Request::METHOD_POST);
1576
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1577
1578
        $formView = $this->createMock(FormView::class);
1579
        $form
1580
            ->method('createView')
1581
            ->willReturn($formView);
1582
1583
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction($this->request));
1584
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
1585
    }
1586
1587
    /**
1588
     * @dataProvider getToStringValues
1589
     */
1590
    public function testEditActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
1591
    {
1592
        $object = new \stdClass();
1593
1594
        $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...
1595
            ->method('getObject')
1596
            ->willReturn($object);
1597
1598
        $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...
1599
            ->method('checkAccess')
1600
            ->with($this->equalTo('edit'));
1601
1602
        $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...
1603
            ->method('getClass')
1604
            ->willReturn(\stdClass::class);
1605
1606
        $form = $this->createMock(Form::class);
1607
1608
        $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...
1609
            ->method('getForm')
1610
            ->willReturn($form);
1611
1612
        $form->expects($this->once())
1613
            ->method('isValid')
1614
            ->willReturn(true);
1615
1616
        $form->expects($this->once())
1617
            ->method('getData')
1618
            ->willReturn($object);
1619
1620
        $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...
1621
            ->method('toString')
1622
            ->with($this->equalTo($object))
1623
            ->willReturn($toStringValue);
1624
1625
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1626
1627
        $form->expects($this->once())
1628
            ->method('isSubmitted')
1629
            ->willReturn(true);
1630
        $this->request->setMethod(Request::METHOD_POST);
1631
1632
        $formView = $this->createMock(FormView::class);
1633
1634
        $form
1635
            ->method('createView')
1636
            ->willReturn($formView);
1637
1638
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1639
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1640
1641
        $this->assertSame($this->admin, $this->parameters['admin']);
1642
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1643
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1644
1645
        $this->assertSame('edit', $this->parameters['action']);
1646
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1647
        $this->assertSame($object, $this->parameters['object']);
1648
1649
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1650
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1651
    }
1652
1653
    public function testEditActionWithPreview(): void
1654
    {
1655
        $object = new \stdClass();
1656
1657
        $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...
1658
            ->method('getObject')
1659
            ->willReturn($object);
1660
1661
        $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...
1662
            ->method('checkAccess')
1663
            ->with($this->equalTo('edit'));
1664
1665
        $form = $this->createMock(Form::class);
1666
1667
        $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...
1668
            ->method('getForm')
1669
            ->willReturn($form);
1670
1671
        $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...
1672
            ->method('supportsPreviewMode')
1673
            ->willReturn(true);
1674
1675
        $formView = $this->createMock(FormView::class);
1676
1677
        $form
1678
            ->method('createView')
1679
            ->willReturn($formView);
1680
1681
        $form->expects($this->once())
1682
            ->method('isSubmitted')
1683
            ->willReturn(true);
1684
1685
        $form->expects($this->once())
1686
            ->method('isValid')
1687
            ->willReturn(true);
1688
1689
        $this->request->setMethod(Request::METHOD_POST);
1690
        $this->request->request->set('btn_preview', 'Preview');
1691
1692
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1693
1694
        $this->assertSame($this->admin, $this->parameters['admin']);
1695
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1696
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1697
1698
        $this->assertSame('edit', $this->parameters['action']);
1699
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1700
        $this->assertSame($object, $this->parameters['object']);
1701
1702
        $this->assertSame([], $this->session->getFlashBag()->all());
1703
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1704
    }
1705
1706
    public function testEditActionWithLockException(): void
1707
    {
1708
        $object = new \stdClass();
1709
        $class = \get_class($object);
1710
1711
        $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...
1712
            ->method('getObject')
1713
            ->willReturn($object);
1714
1715
        $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...
1716
            ->method('checkAccess')
1717
            ->with($this->equalTo('edit'));
1718
1719
        $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...
1720
            ->method('getClass')
1721
            ->willReturn($class);
1722
1723
        $form = $this->createMock(Form::class);
1724
1725
        $form
1726
            ->method('isValid')
1727
            ->willReturn(true);
1728
1729
        $form->expects($this->once())
1730
            ->method('getData')
1731
            ->willReturn($object);
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('getForm')
1735
            ->willReturn($form);
1736
1737
        $form
1738
            ->method('isSubmitted')
1739
            ->willReturn(true);
1740
        $this->request->setMethod(Request::METHOD_POST);
1741
1742
        $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...
1743
            ->method('update')
1744
            ->will($this->throwException(new LockException()));
1745
1746
        $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...
1747
            ->method('toString')
1748
            ->with($this->equalTo($object))
1749
            ->willReturn($class);
1750
1751
        $formView = $this->createMock(FormView::class);
1752
1753
        $form
1754
            ->method('createView')
1755
            ->willReturn($formView);
1756
1757
        $this->expectTranslate('flash_lock_error', [
1758
            '%name%' => $class,
1759
            '%link_start%' => '<a href="stdClass_edit">',
1760
            '%link_end%' => '</a>',
1761
        ], 'SonataAdminBundle');
1762
1763
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1764
    }
1765
1766
    public function testCreateActionAccessDenied(): void
1767
    {
1768
        $this->expectException(AccessDeniedException::class);
1769
1770
        $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...
1771
            ->method('checkAccess')
1772
            ->with($this->equalTo('create'))
1773
            ->will($this->throwException(new AccessDeniedException()));
1774
1775
        $this->controller->createAction($this->request);
1776
    }
1777
1778
    public function testPreCreate(): void
1779
    {
1780
        $object = new \stdClass();
1781
        $object->foo = 123456;
1782
1783
        $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...
1784
            ->method('checkAccess')
1785
            ->with($this->equalTo('create'));
1786
1787
        $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...
1788
            ->method('getClass')
1789
            ->willReturn(\stdClass::class);
1790
1791
        $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...
1792
            ->method('getNewInstance')
1793
            ->willReturn($object);
1794
1795
        $controller = new PreCRUDController();
1796
        $controller->setContainer($this->container);
1797
1798
        $response = $controller->createAction($this->request);
1799
        $this->assertInstanceOf(Response::class, $response);
1800
        $this->assertSame('preCreate called: 123456', $response->getContent());
1801
    }
1802
1803
    public function testCreateAction(): void
1804
    {
1805
        $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...
1806
            ->method('checkAccess')
1807
            ->with($this->equalTo('create'));
1808
1809
        $object = new \stdClass();
1810
1811
        $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...
1812
            ->method('getClass')
1813
            ->willReturn(\stdClass::class);
1814
1815
        $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...
1816
            ->method('getNewInstance')
1817
            ->willReturn($object);
1818
1819
        $form = $this->createMock(Form::class);
1820
1821
        $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...
1822
            ->method('getForm')
1823
            ->willReturn($form);
1824
1825
        $formView = $this->createMock(FormView::class);
1826
1827
        $form
1828
            ->method('createView')
1829
            ->willReturn($formView);
1830
1831
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
1832
1833
        $this->assertSame($this->admin, $this->parameters['admin']);
1834
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1835
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1836
1837
        $this->assertSame('create', $this->parameters['action']);
1838
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1839
        $this->assertSame($object, $this->parameters['object']);
1840
1841
        $this->assertSame([], $this->session->getFlashBag()->all());
1842
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1843
    }
1844
1845
    /**
1846
     * @dataProvider getToStringValues
1847
     */
1848
    public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void
1849
    {
1850
        $object = new \stdClass();
1851
1852
        $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...
1853
            ->method('checkAccess')
1854
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
1855
                if ('edit' === $name) {
1856
                    return;
1857
                }
1858
1859
                if ('create' !== $name) {
1860
                    throw new AccessDeniedException();
1861
                }
1862
1863
                if (null === $objectIn) {
1864
                    return;
1865
                }
1866
1867
                if ($objectIn !== $object) {
1868
                    throw new AccessDeniedException();
1869
                }
1870
            });
1871
1872
        $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...
1873
            ->method('hasRoute')
1874
            ->with($this->equalTo('edit'))
1875
            ->willReturn(true);
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('hasAccess')
1879
            ->with($this->equalTo('edit'))
1880
            ->willReturn(true);
1881
1882
        $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...
1883
            ->method('getNewInstance')
1884
            ->willReturn($object);
1885
1886
        $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...
1887
            ->method('create')
1888
            ->willReturnArgument(0);
1889
1890
        $form = $this->createMock(Form::class);
1891
1892
        $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...
1893
            ->method('getClass')
1894
            ->willReturn(\stdClass::class);
1895
1896
        $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...
1897
            ->method('getForm')
1898
            ->willReturn($form);
1899
1900
        $form->expects($this->once())
1901
            ->method('isSubmitted')
1902
            ->willReturn(true);
1903
1904
        $form->expects($this->once())
1905
            ->method('isValid')
1906
            ->willReturn(true);
1907
1908
        $form->expects($this->once())
1909
            ->method('getData')
1910
            ->willReturn($object);
1911
1912
        $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...
1913
            ->method('toString')
1914
            ->with($this->equalTo($object))
1915
            ->willReturn($toStringValue);
1916
1917
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1918
1919
        $this->request->setMethod(Request::METHOD_POST);
1920
1921
        $response = $this->controller->createAction($this->request);
1922
1923
        $this->assertInstanceOf(RedirectResponse::class, $response);
1924
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1925
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1926
    }
1927
1928
    public function testCreateActionAccessDenied2(): void
1929
    {
1930
        $this->expectException(AccessDeniedException::class);
1931
1932
        $object = new \stdClass();
1933
1934
        $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...
1935
            ->method('checkAccess')
1936
            ->willReturnCallback(static function (string $name, $object = null): void {
1937
                if ('create' !== $name) {
1938
                    throw new AccessDeniedException();
1939
                }
1940
                if (null === $object) {
1941
                    return;
1942
                }
1943
1944
                throw new AccessDeniedException();
1945
            });
1946
1947
        $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...
1948
            ->method('getNewInstance')
1949
            ->willReturn($object);
1950
1951
        $form = $this->createMock(Form::class);
1952
1953
        $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...
1954
            ->method('getClass')
1955
            ->willReturn(\stdClass::class);
1956
1957
        $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...
1958
            ->method('getForm')
1959
            ->willReturn($form);
1960
1961
        $form->expects($this->once())
1962
            ->method('isSubmitted')
1963
            ->willReturn(true);
1964
1965
        $form->expects($this->once())
1966
            ->method('getData')
1967
            ->willReturn($object);
1968
1969
        $form->expects($this->once())
1970
            ->method('isValid')
1971
            ->willReturn(true);
1972
1973
        $this->request->setMethod(Request::METHOD_POST);
1974
1975
        $this->controller->createAction($this->request);
1976
    }
1977
1978
    /**
1979
     * @dataProvider getToStringValues
1980
     */
1981
    public function testCreateActionError(string $expectedToStringValue, string $toStringValue): void
1982
    {
1983
        $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...
1984
            ->method('checkAccess')
1985
            ->with($this->equalTo('create'));
1986
1987
        $object = new \stdClass();
1988
1989
        $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...
1990
            ->method('getClass')
1991
            ->willReturn(\stdClass::class);
1992
1993
        $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...
1994
            ->method('getNewInstance')
1995
            ->willReturn($object);
1996
1997
        $form = $this->createMock(Form::class);
1998
1999
        $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...
2000
            ->method('getForm')
2001
            ->willReturn($form);
2002
2003
        $form->expects($this->once())
2004
            ->method('isSubmitted')
2005
            ->willReturn(true);
2006
2007
        $form->expects($this->once())
2008
            ->method('isValid')
2009
            ->willReturn(false);
2010
2011
        $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...
2012
            ->method('toString')
2013
            ->with($this->equalTo($object))
2014
            ->willReturn($toStringValue);
2015
2016
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2017
2018
        $this->request->setMethod(Request::METHOD_POST);
2019
2020
        $formView = $this->createMock(FormView::class);
2021
2022
        $form
2023
            ->method('createView')
2024
            ->willReturn($formView);
2025
2026
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2027
2028
        $this->assertSame($this->admin, $this->parameters['admin']);
2029
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2030
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2031
2032
        $this->assertSame('create', $this->parameters['action']);
2033
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2034
        $this->assertSame($object, $this->parameters['object']);
2035
2036
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2037
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2038
    }
2039
2040
    /**
2041
     * @dataProvider getToStringValues
2042
     */
2043
    public function testCreateActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
2044
    {
2045
        $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...
2046
            ->method('checkAccess')
2047
            ->with($this->equalTo('create'));
2048
2049
        $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...
2050
            ->method('getClass')
2051
            ->willReturn(\stdClass::class);
2052
2053
        $object = new \stdClass();
2054
2055
        $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...
2056
            ->method('getNewInstance')
2057
            ->willReturn($object);
2058
2059
        $form = $this->createMock(Form::class);
2060
2061
        $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...
2062
            ->method('getForm')
2063
            ->willReturn($form);
2064
2065
        $form->expects($this->once())
2066
            ->method('isValid')
2067
            ->willReturn(true);
2068
2069
        $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...
2070
            ->method('toString')
2071
            ->with($this->equalTo($object))
2072
            ->willReturn($toStringValue);
2073
2074
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2075
2076
        $form->expects($this->once())
2077
            ->method('isSubmitted')
2078
            ->willReturn(true);
2079
2080
        $form->expects($this->once())
2081
            ->method('getData')
2082
            ->willReturn($object);
2083
2084
        $this->request->setMethod(Request::METHOD_POST);
2085
2086
        $formView = $this->createMock(FormView::class);
2087
2088
        $form
2089
            ->method('createView')
2090
            ->willReturn($formView);
2091
2092
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2093
2094
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2095
2096
        $this->assertSame($this->admin, $this->parameters['admin']);
2097
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2098
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2099
2100
        $this->assertSame('create', $this->parameters['action']);
2101
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2102
        $this->assertSame($object, $this->parameters['object']);
2103
2104
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2105
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2106
    }
2107
2108
    public function testCreateActionAjaxSuccess(): void
2109
    {
2110
        $object = new \stdClass();
2111
2112
        $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...
2113
            ->method('checkAccess')
2114
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
2115
                if ('create' !== $name) {
2116
                    throw new AccessDeniedException();
2117
                }
2118
2119
                if (null === $objectIn) {
2120
                    return;
2121
                }
2122
2123
                if ($objectIn !== $object) {
2124
                    throw new AccessDeniedException();
2125
                }
2126
            });
2127
2128
        $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...
2129
            ->method('getNewInstance')
2130
            ->willReturn($object);
2131
2132
        $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...
2133
            ->method('create')
2134
            ->willReturnArgument(0);
2135
2136
        $form = $this->createMock(Form::class);
2137
2138
        $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...
2139
            ->method('getForm')
2140
            ->willReturn($form);
2141
2142
        $form->expects($this->once())
2143
            ->method('isSubmitted')
2144
            ->willReturn(true);
2145
2146
        $form->expects($this->once())
2147
            ->method('isValid')
2148
            ->willReturn(true);
2149
2150
        $form->expects($this->once())
2151
            ->method('getData')
2152
            ->willReturn($object);
2153
2154
        $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...
2155
            ->method('getClass')
2156
            ->willReturn(\stdClass::class);
2157
2158
        $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...
2159
            ->method('getNormalizedIdentifier')
2160
            ->with($this->equalTo($object))
2161
            ->willReturn('foo_normalized');
2162
2163
        $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...
2164
            ->method('toString')
2165
            ->willReturn('foo');
2166
2167
        $this->request->setMethod(Request::METHOD_POST);
2168
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2169
        $this->request->headers->set('Accept', 'application/json');
2170
2171
        $response = $this->controller->createAction($this->request);
2172
2173
        $this->assertInstanceOf(Response::class, $response);
2174
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2175
        $this->assertSame([], $this->session->getFlashBag()->all());
2176
    }
2177
2178
    public function testCreateActionAjaxError(): void
2179
    {
2180
        $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...
2181
            ->method('checkAccess')
2182
            ->with($this->equalTo('create'));
2183
2184
        $object = new \stdClass();
2185
2186
        $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...
2187
            ->method('getNewInstance')
2188
            ->willReturn($object);
2189
2190
        $form = $this->createMock(Form::class);
2191
2192
        $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...
2193
            ->method('getClass')
2194
            ->willReturn(\stdClass::class);
2195
2196
        $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...
2197
            ->method('getForm')
2198
            ->willReturn($form);
2199
2200
        $form->expects($this->once())
2201
            ->method('isSubmitted')
2202
            ->willReturn(true);
2203
2204
        $form->expects($this->once())
2205
            ->method('isValid')
2206
            ->willReturn(false);
2207
2208
        $formError = $this->createMock(FormError::class);
2209
        $formError->expects($this->atLeastOnce())
2210
            ->method('getMessage')
2211
            ->willReturn('Form error message');
2212
2213
        $form->expects($this->once())
2214
            ->method('getErrors')
2215
            ->with(true)
2216
            ->willReturn([$formError]);
2217
2218
        $this->request->setMethod(Request::METHOD_POST);
2219
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2220
        $this->request->headers->set('Accept', 'application/json');
2221
2222
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request));
2223
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
2224
    }
2225
2226
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2227
    {
2228
        $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...
2229
            ->method('checkAccess')
2230
            ->with($this->equalTo('create'));
2231
2232
        $object = new \stdClass();
2233
2234
        $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...
2235
            ->method('getNewInstance')
2236
            ->willReturn($object);
2237
2238
        $form = $this->createMock(Form::class);
2239
2240
        $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...
2241
            ->method('getClass')
2242
            ->willReturn(\stdClass::class);
2243
2244
        $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...
2245
            ->method('getForm')
2246
            ->willReturn($form);
2247
2248
        $form->expects($this->once())
2249
            ->method('isSubmitted')
2250
            ->willReturn(true);
2251
2252
        $form->expects($this->once())
2253
            ->method('isValid')
2254
            ->willReturn(false);
2255
2256
        $this->request->setMethod(Request::METHOD_POST);
2257
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2258
2259
        $formView = $this->createMock(FormView::class);
2260
        $form
2261
            ->method('createView')
2262
            ->willReturn($formView);
2263
2264
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request));
2265
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
2266
    }
2267
2268
    public function testCreateActionWithPreview(): void
2269
    {
2270
        $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...
2271
            ->method('checkAccess')
2272
            ->with($this->equalTo('create'));
2273
2274
        $object = new \stdClass();
2275
2276
        $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...
2277
            ->method('getNewInstance')
2278
            ->willReturn($object);
2279
2280
        $form = $this->createMock(Form::class);
2281
2282
        $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...
2283
            ->method('getClass')
2284
            ->willReturn(\stdClass::class);
2285
2286
        $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...
2287
            ->method('getForm')
2288
            ->willReturn($form);
2289
2290
        $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...
2291
            ->method('supportsPreviewMode')
2292
            ->willReturn(true);
2293
2294
        $formView = $this->createMock(FormView::class);
2295
2296
        $form
2297
            ->method('createView')
2298
            ->willReturn($formView);
2299
2300
        $form->expects($this->once())
2301
            ->method('isSubmitted')
2302
            ->willReturn(true);
2303
2304
        $form->expects($this->once())
2305
            ->method('isValid')
2306
            ->willReturn(true);
2307
2308
        $this->request->setMethod(Request::METHOD_POST);
2309
        $this->request->request->set('btn_preview', 'Preview');
2310
2311
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2312
2313
        $this->assertSame($this->admin, $this->parameters['admin']);
2314
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2315
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2316
2317
        $this->assertSame('create', $this->parameters['action']);
2318
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2319
        $this->assertSame($object, $this->parameters['object']);
2320
2321
        $this->assertSame([], $this->session->getFlashBag()->all());
2322
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2323
    }
2324
2325
    public function testExportActionAccessDenied(): void
2326
    {
2327
        $this->expectException(AccessDeniedException::class);
2328
2329
        $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...
2330
            ->method('checkAccess')
2331
            ->with($this->equalTo('export'))
2332
            ->will($this->throwException(new AccessDeniedException()));
2333
2334
        $this->controller->exportAction($this->request);
2335
    }
2336
2337
    public function testExportActionWrongFormat(): void
2338
    {
2339
        $this->expectException(\RuntimeException::class);
2340
        $this->expectExceptionMessage(
2341
            'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`'
2342
        );
2343
2344
        $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...
2345
            ->method('checkAccess')
2346
            ->with($this->equalTo('export'));
2347
2348
        $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...
2349
            ->method('getExportFormats')
2350
            ->willReturn(['json']);
2351
2352
        $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...
2353
            ->method('getClass')
2354
            ->willReturn('Foo');
2355
2356
        $this->request->query->set('format', 'csv');
2357
2358
        $this->controller->exportAction($this->request);
2359
    }
2360
2361
    public function testExportAction(): void
2362
    {
2363
        $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...
2364
            ->method('checkAccess')
2365
            ->with($this->equalTo('export'));
2366
2367
        $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...
2368
            ->method('getExportFormats')
2369
            ->willReturn(['json']);
2370
2371
        $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...
2372
            ->method('getClass')
2373
            ->willReturn(\stdClass::class);
2374
2375
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2376
2377
        $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...
2378
            ->method('getDataSourceIterator')
2379
            ->willReturn($dataSourceIterator);
2380
2381
        $this->request->query->set('format', 'json');
2382
2383
        $response = $this->controller->exportAction($this->request);
2384
        $this->assertInstanceOf(StreamedResponse::class, $response);
2385
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
2386
        $this->assertSame([], $this->session->getFlashBag()->all());
2387
    }
2388
2389
    public function testHistoryActionAccessDenied(): void
2390
    {
2391
        $this->expectException(AccessDeniedException::class);
2392
2393
        $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...
2394
            ->method('getObject')
2395
            ->willReturn(new \stdClass());
2396
2397
        $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...
2398
            ->method('checkAccess')
2399
            ->with($this->equalTo('history'))
2400
            ->will($this->throwException(new AccessDeniedException()));
2401
2402
        $this->controller->historyAction($this->request);
2403
    }
2404
2405
    public function testHistoryActionNotFoundException(): void
2406
    {
2407
        $this->expectException(NotFoundHttpException::class);
2408
2409
        $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...
2410
            ->method('getObject')
2411
            ->willReturn(null);
2412
2413
        $this->controller->historyAction($this->request);
2414
    }
2415
2416
    public function testHistoryActionNoReader(): void
2417
    {
2418
        $this->expectException(NotFoundHttpException::class);
2419
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2420
2421
        $this->request->query->set('id', 123);
2422
2423
        $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...
2424
            ->method('checkAccess')
2425
            ->with($this->equalTo('history'));
2426
2427
        $object = new \stdClass();
2428
2429
        $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...
2430
            ->method('getObject')
2431
            ->willReturn($object);
2432
2433
        $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...
2434
            ->method('getClass')
2435
            ->willReturn('Foo');
2436
2437
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2438
            ->method('hasReader')
2439
            ->with($this->equalTo('Foo'))
2440
            ->willReturn(false);
2441
2442
        $this->controller->historyAction($this->request);
2443
    }
2444
2445
    public function testHistoryAction(): void
2446
    {
2447
        $this->request->query->set('id', 123);
2448
2449
        $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...
2450
            ->method('checkAccess')
2451
            ->with($this->equalTo('history'));
2452
2453
        $object = new \stdClass();
2454
2455
        $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...
2456
            ->method('getObject')
2457
            ->willReturn($object);
2458
2459
        $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...
2460
            ->method('getClass')
2461
            ->willReturn('Foo');
2462
2463
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2464
            ->method('hasReader')
2465
            ->with($this->equalTo('Foo'))
2466
            ->willReturn(true);
2467
2468
        $reader = $this->createMock(AuditReaderInterface::class);
2469
2470
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2471
            ->method('getReader')
2472
            ->with($this->equalTo('Foo'))
2473
            ->willReturn($reader);
2474
2475
        $reader->expects($this->once())
2476
            ->method('findRevisions')
2477
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2478
            ->willReturn([]);
2479
2480
        $this->assertInstanceOf(Response::class, $this->controller->historyAction($this->request));
2481
2482
        $this->assertSame($this->admin, $this->parameters['admin']);
2483
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2484
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2485
2486
        $this->assertSame('history', $this->parameters['action']);
2487
        $this->assertSame([], $this->parameters['revisions']);
2488
        $this->assertSame($object, $this->parameters['object']);
2489
2490
        $this->assertSame([], $this->session->getFlashBag()->all());
2491
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2492
    }
2493
2494
    public function testAclActionAclNotEnabled(): void
2495
    {
2496
        $this->expectException(NotFoundHttpException::class);
2497
        $this->expectExceptionMessage('ACL are not enabled for this admin');
2498
2499
        $this->controller->aclAction($this->request);
2500
    }
2501
2502
    public function testAclActionNotFoundException(): void
2503
    {
2504
        $this->expectException(NotFoundHttpException::class);
2505
2506
        $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...
2507
            ->method('isAclEnabled')
2508
            ->willReturn(true);
2509
2510
        $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...
2511
            ->method('getObject')
2512
            ->willReturn(null);
2513
2514
        $this->controller->aclAction($this->request);
2515
    }
2516
2517
    public function testAclActionAccessDenied(): void
2518
    {
2519
        $this->expectException(AccessDeniedException::class);
2520
2521
        $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...
2522
            ->method('isAclEnabled')
2523
            ->willReturn(true);
2524
2525
        $object = new \stdClass();
2526
2527
        $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...
2528
            ->method('getObject')
2529
            ->willReturn($object);
2530
2531
        $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...
2532
            ->method('checkAccess')
2533
            ->with($this->equalTo('acl'), $this->equalTo($object))
2534
            ->will($this->throwException(new AccessDeniedException()));
2535
2536
        $this->controller->aclAction($this->request);
2537
    }
2538
2539
    public function testAclAction(): void
2540
    {
2541
        $this->request->query->set('id', 123);
2542
2543
        $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...
2544
            ->method('isAclEnabled')
2545
            ->willReturn(true);
2546
2547
        $object = new \stdClass();
2548
2549
        $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...
2550
            ->method('getObject')
2551
            ->willReturn($object);
2552
2553
        $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...
2554
            ->expects($this->once())
2555
            ->method('checkAccess');
2556
2557
        $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...
2558
            ->method('getSecurityInformation')
2559
            ->willReturn([]);
2560
2561
        $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...
2562
            ->method('getMaskBuilderClass')
2563
            ->willReturn(AdminPermissionMap::class);
2564
2565
        $aclUsersForm = $this->getMockBuilder(Form::class)
2566
            ->disableOriginalConstructor()
2567
            ->getMock();
2568
2569
        $aclUsersForm->expects($this->once())
2570
            ->method('createView')
2571
            ->willReturn($this->createMock(FormView::class));
2572
2573
        $aclRolesForm = $this->getMockBuilder(Form::class)
2574
            ->disableOriginalConstructor()
2575
            ->getMock();
2576
2577
        $aclRolesForm->expects($this->once())
2578
            ->method('createView')
2579
            ->willReturn($this->createMock(FormView::class));
2580
2581
        $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...
2582
            ->method('createAclUsersForm')
2583
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2584
            ->willReturn($aclUsersForm);
2585
2586
        $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...
2587
            ->method('createAclRolesForm')
2588
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2589
            ->willReturn($aclRolesForm);
2590
2591
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2592
            ->disableOriginalConstructor()
2593
            ->getMock();
2594
2595
        $aclSecurityHandler
2596
            ->method('getObjectPermissions')
2597
            ->willReturn([]);
2598
2599
        $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...
2600
            ->method('getSecurityHandler')
2601
            ->willReturn($aclSecurityHandler);
2602
2603
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2604
2605
        $this->assertSame($this->admin, $this->parameters['admin']);
2606
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2607
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2608
2609
        $this->assertSame('acl', $this->parameters['action']);
2610
        $this->assertSame([], $this->parameters['permissions']);
2611
        $this->assertSame($object, $this->parameters['object']);
2612
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2613
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2614
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2615
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2616
2617
        $this->assertSame([], $this->session->getFlashBag()->all());
2618
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2619
    }
2620
2621
    public function testAclActionInvalidUpdate(): void
2622
    {
2623
        $this->request->query->set('id', 123);
2624
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2625
2626
        $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...
2627
            ->method('isAclEnabled')
2628
            ->willReturn(true);
2629
2630
        $object = new \stdClass();
2631
2632
        $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...
2633
            ->method('getObject')
2634
            ->willReturn($object);
2635
2636
        $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...
2637
            ->expects($this->once())
2638
            ->method('checkAccess');
2639
2640
        $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...
2641
            ->method('getSecurityInformation')
2642
            ->willReturn([]);
2643
2644
        $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...
2645
            ->method('getMaskBuilderClass')
2646
            ->willReturn(AdminPermissionMap::class);
2647
2648
        $aclUsersForm = $this->getMockBuilder(Form::class)
2649
            ->disableOriginalConstructor()
2650
            ->getMock();
2651
2652
        $aclUsersForm->expects($this->once())
2653
            ->method('isValid')
2654
            ->willReturn(false);
2655
2656
        $aclUsersForm->expects($this->once())
2657
            ->method('createView')
2658
            ->willReturn($this->createMock(FormView::class));
2659
2660
        $aclRolesForm = $this->getMockBuilder(Form::class)
2661
            ->disableOriginalConstructor()
2662
            ->getMock();
2663
2664
        $aclRolesForm->expects($this->once())
2665
            ->method('createView')
2666
            ->willReturn($this->createMock(FormView::class));
2667
2668
        $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...
2669
            ->method('createAclUsersForm')
2670
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2671
            ->willReturn($aclUsersForm);
2672
2673
        $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...
2674
            ->method('createAclRolesForm')
2675
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2676
            ->willReturn($aclRolesForm);
2677
2678
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2679
            ->disableOriginalConstructor()
2680
            ->getMock();
2681
2682
        $aclSecurityHandler
2683
            ->method('getObjectPermissions')
2684
            ->willReturn([]);
2685
2686
        $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...
2687
            ->method('getSecurityHandler')
2688
            ->willReturn($aclSecurityHandler);
2689
2690
        $this->request->setMethod(Request::METHOD_POST);
2691
2692
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2693
2694
        $this->assertSame($this->admin, $this->parameters['admin']);
2695
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2696
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2697
2698
        $this->assertSame('acl', $this->parameters['action']);
2699
        $this->assertSame([], $this->parameters['permissions']);
2700
        $this->assertSame($object, $this->parameters['object']);
2701
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2702
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2703
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2704
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2705
2706
        $this->assertSame([], $this->session->getFlashBag()->all());
2707
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2708
    }
2709
2710
    public function testAclActionSuccessfulUpdate(): void
2711
    {
2712
        $this->request->query->set('id', 123);
2713
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2714
2715
        $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...
2716
            ->method('isAclEnabled')
2717
            ->willReturn(true);
2718
2719
        $object = new \stdClass();
2720
2721
        $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...
2722
            ->method('getObject')
2723
            ->willReturn($object);
2724
2725
        $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...
2726
            ->expects($this->once())
2727
            ->method('checkAccess');
2728
2729
        $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...
2730
            ->method('getSecurityInformation')
2731
            ->willReturn([]);
2732
2733
        $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...
2734
            ->method('getMaskBuilderClass')
2735
            ->willReturn(AdminPermissionMap::class);
2736
2737
        $aclUsersForm = $this->getMockBuilder(Form::class)
2738
            ->disableOriginalConstructor()
2739
            ->getMock();
2740
2741
        $aclUsersForm
2742
            ->method('createView')
2743
            ->willReturn($this->createMock(FormView::class));
2744
2745
        $aclRolesForm = $this->getMockBuilder(Form::class)
2746
            ->disableOriginalConstructor()
2747
            ->getMock();
2748
2749
        $aclRolesForm
2750
            ->method('createView')
2751
            ->willReturn($this->createMock(FormView::class));
2752
2753
        $aclRolesForm->expects($this->once())
2754
            ->method('isValid')
2755
            ->willReturn(true);
2756
2757
        $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...
2758
            ->method('createAclUsersForm')
2759
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2760
            ->willReturn($aclUsersForm);
2761
2762
        $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...
2763
            ->method('createAclRolesForm')
2764
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2765
            ->willReturn($aclRolesForm);
2766
2767
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2768
            ->disableOriginalConstructor()
2769
            ->getMock();
2770
2771
        $aclSecurityHandler
2772
            ->method('getObjectPermissions')
2773
            ->willReturn([]);
2774
2775
        $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...
2776
            ->method('getSecurityHandler')
2777
            ->willReturn($aclSecurityHandler);
2778
2779
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2780
2781
        $this->request->setMethod(Request::METHOD_POST);
2782
2783
        $response = $this->controller->aclAction($this->request);
2784
2785
        $this->assertInstanceOf(RedirectResponse::class, $response);
2786
2787
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2788
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2789
    }
2790
2791
    public function testHistoryViewRevisionActionAccessDenied(): void
2792
    {
2793
        $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...
2794
            ->method('getObject')
2795
            ->willReturn(new \stdClass());
2796
2797
        $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...
2798
            ->method('checkAccess')
2799
            ->with($this->equalTo('historyViewRevision'))
2800
            ->will($this->throwException(new AccessDeniedException()));
2801
2802
        $this->expectException(AccessDeniedException::class);
2803
2804
        $this->controller->historyViewRevisionAction($this->request, null);
2805
    }
2806
2807
    public function testHistoryViewRevisionActionNotFoundException(): void
2808
    {
2809
        $this->request->query->set('id', 123);
2810
2811
        $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...
2812
            ->method('getObject')
2813
            ->willReturn(null);
2814
2815
        $this->expectException(NotFoundHttpException::class);
2816
        $this->expectExceptionMessage('unable to find the object with id: 123');
2817
2818
        $this->controller->historyViewRevisionAction($this->request, null);
2819
    }
2820
2821
    public function testHistoryViewRevisionActionNoReader(): void
2822
    {
2823
        $this->expectException(NotFoundHttpException::class);
2824
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2825
2826
        $this->request->query->set('id', 123);
2827
2828
        $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...
2829
            ->method('checkAccess')
2830
            ->with($this->equalTo('historyViewRevision'));
2831
2832
        $object = new \stdClass();
2833
2834
        $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...
2835
            ->method('getObject')
2836
            ->willReturn($object);
2837
2838
        $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...
2839
            ->method('getClass')
2840
            ->willReturn('Foo');
2841
2842
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2843
            ->method('hasReader')
2844
            ->with($this->equalTo('Foo'))
2845
            ->willReturn(false);
2846
2847
        $this->controller->historyViewRevisionAction($this->request, null);
2848
    }
2849
2850
    public function testHistoryViewRevisionActionNotFoundRevision(): void
2851
    {
2852
        $this->expectException(NotFoundHttpException::class);
2853
        $this->expectExceptionMessage(
2854
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
2855
        );
2856
2857
        $this->request->query->set('id', 123);
2858
2859
        $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...
2860
            ->method('checkAccess')
2861
            ->with($this->equalTo('historyViewRevision'));
2862
2863
        $object = new \stdClass();
2864
2865
        $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...
2866
            ->method('getObject')
2867
            ->willReturn($object);
2868
2869
        $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...
2870
            ->method('getClass')
2871
            ->willReturn('Foo');
2872
2873
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2874
            ->method('hasReader')
2875
            ->with($this->equalTo('Foo'))
2876
            ->willReturn(true);
2877
2878
        $reader = $this->createMock(AuditReaderInterface::class);
2879
2880
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2881
            ->method('getReader')
2882
            ->with($this->equalTo('Foo'))
2883
            ->willReturn($reader);
2884
2885
        $reader->expects($this->once())
2886
            ->method('find')
2887
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2888
            ->willReturn(null);
2889
2890
        $this->controller->historyViewRevisionAction($this->request, 456);
2891
    }
2892
2893
    public function testHistoryViewRevisionAction(): void
2894
    {
2895
        $this->request->query->set('id', 123);
2896
2897
        $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...
2898
            ->method('checkAccess')
2899
            ->with($this->equalTo('historyViewRevision'));
2900
2901
        $object = new \stdClass();
2902
2903
        $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...
2904
            ->method('getObject')
2905
            ->willReturn($object);
2906
2907
        $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...
2908
            ->method('getClass')
2909
            ->willReturn('Foo');
2910
2911
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2912
            ->method('hasReader')
2913
            ->with($this->equalTo('Foo'))
2914
            ->willReturn(true);
2915
2916
        $reader = $this->createMock(AuditReaderInterface::class);
2917
2918
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2919
            ->method('getReader')
2920
            ->with($this->equalTo('Foo'))
2921
            ->willReturn($reader);
2922
2923
        $objectRevision = new \stdClass();
2924
        $objectRevision->revision = 456;
2925
2926
        $reader->expects($this->once())
2927
            ->method('find')
2928
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2929
            ->willReturn($objectRevision);
2930
2931
        $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...
2932
            ->method('setSubject')
2933
            ->with($this->equalTo($objectRevision));
2934
2935
        $fieldDescriptionCollection = new FieldDescriptionCollection();
2936
        $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...
2937
            ->method('getShow')
2938
            ->willReturn($fieldDescriptionCollection);
2939
2940
        $this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction($this->request, 456));
2941
2942
        $this->assertSame($this->admin, $this->parameters['admin']);
2943
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2944
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2945
2946
        $this->assertSame('show', $this->parameters['action']);
2947
        $this->assertSame($objectRevision, $this->parameters['object']);
2948
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
2949
2950
        $this->assertSame([], $this->session->getFlashBag()->all());
2951
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
2952
    }
2953
2954
    public function testHistoryCompareRevisionsActionAccessDenied(): void
2955
    {
2956
        $this->expectException(AccessDeniedException::class);
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
            ->will($this->throwException(new AccessDeniedException()));
2962
2963
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2964
    }
2965
2966
    public function testHistoryCompareRevisionsActionNotFoundException(): void
2967
    {
2968
        $this->expectException(NotFoundHttpException::class);
2969
        $this->expectExceptionMessage('unable to find the object with id: 123');
2970
2971
        $this->request->query->set('id', 123);
2972
2973
        $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...
2974
            ->method('checkAccess')
2975
            ->with($this->equalTo('historyCompareRevisions'));
2976
2977
        $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...
2978
            ->method('getObject')
2979
            ->willReturn(null);
2980
2981
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2982
    }
2983
2984
    public function testHistoryCompareRevisionsActionNoReader(): void
2985
    {
2986
        $this->expectException(NotFoundHttpException::class);
2987
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2988
2989
        $this->request->query->set('id', 123);
2990
2991
        $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...
2992
            ->method('checkAccess')
2993
            ->with($this->equalTo('historyCompareRevisions'));
2994
2995
        $object = new \stdClass();
2996
2997
        $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...
2998
            ->method('getObject')
2999
            ->willReturn($object);
3000
3001
        $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...
3002
            ->method('getClass')
3003
            ->willReturn('Foo');
3004
3005
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3006
            ->method('hasReader')
3007
            ->with($this->equalTo('Foo'))
3008
            ->willReturn(false);
3009
3010
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
3011
    }
3012
3013
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3014
    {
3015
        $this->expectException(NotFoundHttpException::class);
3016
        $this->expectExceptionMessage(
3017
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
3018
        );
3019
3020
        $this->request->query->set('id', 123);
3021
3022
        $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...
3023
            ->method('checkAccess')
3024
            ->with($this->equalTo('historyCompareRevisions'));
3025
3026
        $object = new \stdClass();
3027
3028
        $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...
3029
            ->method('getObject')
3030
            ->willReturn($object);
3031
3032
        $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...
3033
            ->method('getClass')
3034
            ->willReturn('Foo');
3035
3036
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3037
            ->method('hasReader')
3038
            ->with($this->equalTo('Foo'))
3039
            ->willReturn(true);
3040
3041
        $reader = $this->createMock(AuditReaderInterface::class);
3042
3043
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3044
            ->method('getReader')
3045
            ->with($this->equalTo('Foo'))
3046
            ->willReturn($reader);
3047
3048
        // once because it will not be found and therefore the second call won't be executed
3049
        $reader->expects($this->once())
3050
            ->method('find')
3051
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3052
            ->willReturn(null);
3053
3054
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3055
    }
3056
3057
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3058
    {
3059
        $this->expectException(NotFoundHttpException::class);
3060
        $this->expectExceptionMessage(
3061
            'unable to find the targeted object `123` from the revision `789` with classname : `Foo`'
3062
        );
3063
3064
        $this->request->query->set('id', 123);
3065
3066
        $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...
3067
            ->method('checkAccess')
3068
            ->with($this->equalTo('historyCompareRevisions'));
3069
3070
        $object = new \stdClass();
3071
3072
        $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...
3073
            ->method('getObject')
3074
            ->willReturn($object);
3075
3076
        $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...
3077
            ->method('getClass')
3078
            ->willReturn('Foo');
3079
3080
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3081
            ->method('hasReader')
3082
            ->with($this->equalTo('Foo'))
3083
            ->willReturn(true);
3084
3085
        $reader = $this->createMock(AuditReaderInterface::class);
3086
3087
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3088
            ->method('getReader')
3089
            ->with($this->equalTo('Foo'))
3090
            ->willReturn($reader);
3091
3092
        $objectRevision = new \stdClass();
3093
        $objectRevision->revision = 456;
3094
3095
        // first call should return, so the second call will throw an exception
3096
        $reader->expects($this->at(0))
3097
            ->method('find')
3098
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3099
            ->willReturn($objectRevision);
3100
3101
        $reader->expects($this->at(1))
3102
            ->method('find')
3103
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3104
            ->willReturn(null);
3105
3106
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3107
    }
3108
3109
    public function testHistoryCompareRevisionsActionAction(): void
3110
    {
3111
        $this->request->query->set('id', 123);
3112
3113
        $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...
3114
            ->method('checkAccess')
3115
            ->with($this->equalTo('historyCompareRevisions'));
3116
3117
        $object = new \stdClass();
3118
3119
        $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...
3120
            ->method('getObject')
3121
            ->willReturn($object);
3122
3123
        $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...
3124
            ->method('getClass')
3125
            ->willReturn('Foo');
3126
3127
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3128
            ->method('hasReader')
3129
            ->with($this->equalTo('Foo'))
3130
            ->willReturn(true);
3131
3132
        $reader = $this->createMock(AuditReaderInterface::class);
3133
3134
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
3135
            ->method('getReader')
3136
            ->with($this->equalTo('Foo'))
3137
            ->willReturn($reader);
3138
3139
        $objectRevision = new \stdClass();
3140
        $objectRevision->revision = 456;
3141
3142
        $compareObjectRevision = new \stdClass();
3143
        $compareObjectRevision->revision = 789;
3144
3145
        $reader->expects($this->at(0))
3146
            ->method('find')
3147
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3148
            ->willReturn($objectRevision);
3149
3150
        $reader->expects($this->at(1))
3151
            ->method('find')
3152
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3153
            ->willReturn($compareObjectRevision);
3154
3155
        $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...
3156
            ->method('setSubject')
3157
            ->with($this->equalTo($objectRevision));
3158
3159
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3160
        $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...
3161
            ->method('getShow')
3162
            ->willReturn($fieldDescriptionCollection);
3163
3164
        $this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction($this->request, 456, 789));
3165
3166
        $this->assertSame($this->admin, $this->parameters['admin']);
3167
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3168
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3169
3170
        $this->assertSame('show', $this->parameters['action']);
3171
        $this->assertSame($objectRevision, $this->parameters['object']);
3172
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3173
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3174
3175
        $this->assertSame([], $this->session->getFlashBag()->all());
3176
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3177
    }
3178
3179
    public function testBatchActionWrongMethod(): void
3180
    {
3181
        $this->expectException(NotFoundHttpException::class);
3182
        $this->expectExceptionMessage('Invalid request method given "GET", POST expected');
3183
3184
        $this->controller->batchAction($this->request);
3185
    }
3186
3187
    public function testBatchActionActionNotDefined(): void
3188
    {
3189
        $this->expectException(\RuntimeException::class);
3190
        $this->expectExceptionMessage('The `foo` batch action is not defined');
3191
3192
        $batchActions = [];
3193
3194
        $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...
3195
            ->method('getBatchActions')
3196
            ->willReturn($batchActions);
3197
3198
        $this->request->setMethod(Request::METHOD_POST);
3199
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3200
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3201
3202
        $this->controller->batchAction($this->request);
3203
    }
3204
3205
    public function testBatchActionActionInvalidCsrfToken(): void
3206
    {
3207
        $this->request->setMethod(Request::METHOD_POST);
3208
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3209
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3210
3211
        try {
3212
            $this->controller->batchAction($this->request);
3213
        } catch (HttpException $e) {
3214
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3215
            $this->assertSame(400, $e->getStatusCode());
3216
        }
3217
    }
3218
3219
    /**
3220
     * NEXT_MAJOR: Remove this legacy group.
3221
     *
3222
     * @group legacy
3223
     */
3224
    public function testBatchActionMethodNotExist(): void
3225
    {
3226
        $this->expectException(\RuntimeException::class);
3227
        $this->expectExceptionMessage(
3228
            'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable'
3229
        );
3230
3231
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3232
3233
        $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...
3234
            ->method('getBatchActions')
3235
            ->willReturn($batchActions);
3236
3237
        $datagrid = $this->createMock(DatagridInterface::class);
3238
        $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...
3239
            ->method('getDatagrid')
3240
            ->willReturn($datagrid);
3241
3242
        $this->request->setMethod(Request::METHOD_POST);
3243
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3244
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3245
3246
        $this->controller->batchAction($this->request);
3247
    }
3248
3249
    public function testBatchActionWithoutConfirmation(): void
3250
    {
3251
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3252
3253
        $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...
3254
            ->method('getBatchActions')
3255
            ->willReturn($batchActions);
3256
3257
        $datagrid = $this->createMock(DatagridInterface::class);
3258
3259
        $query = $this->createMock(ProxyQueryInterface::class);
3260
        $datagrid->expects($this->once())
3261
            ->method('getQuery')
3262
            ->willReturn($query);
3263
3264
        $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...
3265
            ->method('getDatagrid')
3266
            ->willReturn($datagrid);
3267
3268
        $modelManager = $this->createMock(ModelManagerInterface::class);
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('checkAccess')
3272
            ->with($this->equalTo('batchDelete'));
3273
3274
        $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...
3275
            ->method('getModelManager')
3276
            ->willReturn($modelManager);
3277
3278
        $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...
3279
            ->method('getClass')
3280
            ->willReturn('Foo');
3281
3282
        $modelManager->expects($this->once())
3283
            ->method('addIdentifiersToQuery')
3284
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3285
            ->willReturn(true);
3286
3287
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3288
3289
        $this->request->setMethod(Request::METHOD_POST);
3290
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3291
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3292
3293
        $result = $this->controller->batchAction($this->request);
3294
3295
        $this->assertInstanceOf(RedirectResponse::class, $result);
3296
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3297
        $this->assertSame('list', $result->getTargetUrl());
3298
    }
3299
3300
    public function testBatchActionWithoutConfirmation2(): void
3301
    {
3302
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3303
3304
        $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...
3305
            ->method('getBatchActions')
3306
            ->willReturn($batchActions);
3307
3308
        $datagrid = $this->createMock(DatagridInterface::class);
3309
3310
        $query = $this->createMock(ProxyQueryInterface::class);
3311
        $datagrid->expects($this->once())
3312
            ->method('getQuery')
3313
            ->willReturn($query);
3314
3315
        $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...
3316
            ->method('getDatagrid')
3317
            ->willReturn($datagrid);
3318
3319
        $modelManager = $this->createMock(ModelManagerInterface::class);
3320
3321
        $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...
3322
            ->method('checkAccess')
3323
            ->with($this->equalTo('batchDelete'));
3324
3325
        $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...
3326
            ->method('getModelManager')
3327
            ->willReturn($modelManager);
3328
3329
        $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...
3330
            ->method('getClass')
3331
            ->willReturn('Foo');
3332
3333
        $modelManager->expects($this->once())
3334
            ->method('addIdentifiersToQuery')
3335
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3336
            ->willReturn(true);
3337
3338
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3339
3340
        $this->request->setMethod(Request::METHOD_POST);
3341
        $this->request->request->set('action', 'delete');
3342
        $this->request->request->set('idx', ['123', '456']);
3343
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3344
3345
        $result = $this->controller->batchAction($this->request);
3346
3347
        $this->assertInstanceOf(RedirectResponse::class, $result);
3348
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3349
        $this->assertSame('list', $result->getTargetUrl());
3350
    }
3351
3352
    public function testBatchActionWithConfirmation(): void
3353
    {
3354
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3355
3356
        $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...
3357
            ->method('getBatchActions')
3358
            ->willReturn($batchActions);
3359
3360
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3361
3362
        $this->request->setMethod(Request::METHOD_POST);
3363
        $this->request->request->set('data', json_encode($data));
3364
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3365
3366
        $datagrid = $this->createMock(DatagridInterface::class);
3367
3368
        $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...
3369
            ->method('getDatagrid')
3370
            ->willReturn($datagrid);
3371
3372
        $form = $this->getMockBuilder(Form::class)
3373
            ->disableOriginalConstructor()
3374
            ->getMock();
3375
3376
        $form->expects($this->once())
3377
            ->method('createView')
3378
            ->willReturn($this->createMock(FormView::class));
3379
3380
        $datagrid->expects($this->once())
3381
            ->method('getForm')
3382
            ->willReturn($form);
3383
3384
        $this->assertInstanceOf(Response::class, $this->controller->batchAction($this->request));
3385
3386
        $this->assertSame($this->admin, $this->parameters['admin']);
3387
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3388
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3389
3390
        $this->assertSame('list', $this->parameters['action']);
3391
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3392
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3393
        $this->assertSame($data, $this->parameters['data']);
3394
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3395
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3396
3397
        $this->assertSame([], $this->session->getFlashBag()->all());
3398
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3399
    }
3400
3401
    public function testBatchActionNonRelevantAction(): void
3402
    {
3403
        $controller = new BatchAdminController();
3404
        $controller->setContainer($this->container);
3405
3406
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3407
3408
        $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...
3409
            ->method('getBatchActions')
3410
            ->willReturn($batchActions);
3411
3412
        $datagrid = $this->createMock(DatagridInterface::class);
3413
3414
        $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...
3415
            ->method('getDatagrid')
3416
            ->willReturn($datagrid);
3417
3418
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3419
3420
        $this->request->setMethod(Request::METHOD_POST);
3421
        $this->request->request->set('action', 'foo');
3422
        $this->request->request->set('idx', ['789']);
3423
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3424
3425
        $result = $controller->batchAction($this->request);
3426
3427
        $this->assertInstanceOf(RedirectResponse::class, $result);
3428
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3429
        $this->assertSame('list', $result->getTargetUrl());
3430
    }
3431
3432
    public function testBatchActionWithCustomConfirmationTemplate(): void
3433
    {
3434
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3435
3436
        $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...
3437
            ->method('getBatchActions')
3438
            ->willReturn($batchActions);
3439
3440
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3441
3442
        $this->request->setMethod(Request::METHOD_POST);
3443
        $this->request->request->set('data', json_encode($data));
3444
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3445
3446
        $datagrid = $this->createMock(DatagridInterface::class);
3447
3448
        $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...
3449
            ->method('getDatagrid')
3450
            ->willReturn($datagrid);
3451
3452
        $form = $this->createMock(Form::class);
3453
3454
        $form->expects($this->once())
3455
            ->method('createView')
3456
            ->willReturn($this->createMock(FormView::class));
3457
3458
        $datagrid->expects($this->once())
3459
            ->method('getForm')
3460
            ->willReturn($form);
3461
3462
        $this->controller->batchAction($this->request);
3463
3464
        $this->assertSame('custom_template.html.twig', $this->template);
3465
    }
3466
3467
    public function testBatchActionNonRelevantAction2(): void
3468
    {
3469
        $controller = new BatchAdminController();
3470
        $controller->setContainer($this->container);
3471
3472
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3473
3474
        $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...
3475
            ->method('getBatchActions')
3476
            ->willReturn($batchActions);
3477
3478
        $datagrid = $this->createMock(DatagridInterface::class);
3479
3480
        $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...
3481
            ->method('getDatagrid')
3482
            ->willReturn($datagrid);
3483
3484
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3485
3486
        $this->request->setMethod(Request::METHOD_POST);
3487
        $this->request->request->set('action', 'foo');
3488
        $this->request->request->set('idx', ['999']);
3489
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3490
3491
        $result = $controller->batchAction($this->request);
3492
3493
        $this->assertInstanceOf(RedirectResponse::class, $result);
3494
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3495
        $this->assertSame('list', $result->getTargetUrl());
3496
    }
3497
3498
    public function testBatchActionNoItems(): void
3499
    {
3500
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3501
3502
        $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...
3503
            ->method('getBatchActions')
3504
            ->willReturn($batchActions);
3505
3506
        $datagrid = $this->createMock(DatagridInterface::class);
3507
3508
        $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...
3509
            ->method('getDatagrid')
3510
            ->willReturn($datagrid);
3511
3512
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3513
3514
        $this->request->setMethod(Request::METHOD_POST);
3515
        $this->request->request->set('action', 'delete');
3516
        $this->request->request->set('idx', []);
3517
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3518
3519
        $result = $this->controller->batchAction($this->request);
3520
3521
        $this->assertInstanceOf(RedirectResponse::class, $result);
3522
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3523
        $this->assertSame('list', $result->getTargetUrl());
3524
    }
3525
3526
    public function testBatchActionNoItemsEmptyQuery(): void
3527
    {
3528
        $controller = new BatchAdminController();
3529
        $controller->setContainer($this->container);
3530
3531
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3532
3533
        $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...
3534
            ->method('getBatchActions')
3535
            ->willReturn($batchActions);
3536
3537
        $datagrid = $this->createMock(DatagridInterface::class);
3538
3539
        $query = $this->createMock(ProxyQueryInterface::class);
3540
        $datagrid->expects($this->once())
3541
            ->method('getQuery')
3542
            ->willReturn($query);
3543
3544
        $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...
3545
            ->method('getDatagrid')
3546
            ->willReturn($datagrid);
3547
3548
        $modelManager = $this->createMock(ModelManagerInterface::class);
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
        $this->request->setMethod(Request::METHOD_POST);
3559
        $this->request->request->set('action', 'bar');
3560
        $this->request->request->set('idx', []);
3561
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3562
3563
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3564
        $result = $controller->batchAction($this->request);
3565
3566
        $this->assertInstanceOf(Response::class, $result);
3567
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3568
    }
3569
3570
    public function testBatchActionWithRequesData(): void
3571
    {
3572
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3573
3574
        $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...
3575
            ->method('getBatchActions')
3576
            ->willReturn($batchActions);
3577
3578
        $datagrid = $this->createMock(DatagridInterface::class);
3579
3580
        $query = $this->createMock(ProxyQueryInterface::class);
3581
        $datagrid->expects($this->once())
3582
            ->method('getQuery')
3583
            ->willReturn($query);
3584
3585
        $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...
3586
            ->method('getDatagrid')
3587
            ->willReturn($datagrid);
3588
3589
        $modelManager = $this->createMock(ModelManagerInterface::class);
3590
3591
        $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...
3592
            ->method('checkAccess')
3593
            ->with($this->equalTo('batchDelete'));
3594
3595
        $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...
3596
            ->method('getModelManager')
3597
            ->willReturn($modelManager);
3598
3599
        $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...
3600
            ->method('getClass')
3601
            ->willReturn('Foo');
3602
3603
        $modelManager->expects($this->once())
3604
            ->method('addIdentifiersToQuery')
3605
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3606
            ->willReturn(true);
3607
3608
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3609
3610
        $this->request->setMethod(Request::METHOD_POST);
3611
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3612
        $this->request->request->set('foo', 'bar');
3613
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3614
3615
        $result = $this->controller->batchAction($this->request);
3616
3617
        $this->assertInstanceOf(RedirectResponse::class, $result);
3618
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3619
        $this->assertSame('list', $result->getTargetUrl());
3620
        $this->assertSame('bar', $this->request->request->get('foo'));
3621
    }
3622
3623
    public function getCsrfProvider()
3624
    {
3625
        return $this->csrfProvider;
3626
    }
3627
3628
    public function getToStringValues()
3629
    {
3630
        return [
3631
            ['', ''],
3632
            ['Foo', 'Foo'],
3633
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3634
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3635
        ];
3636
    }
3637
3638
    private function assertLoggerLogsModelManagerException($subject, string $method): void
3639
    {
3640
        $exception = new ModelManagerException(
3641
            $message = 'message',
3642
            1234,
3643
            new \Exception($previousExceptionMessage = 'very useful message')
3644
        );
3645
3646
        $subject->expects($this->once())
3647
            ->method($method)
3648
            ->willReturnCallback(static function () use ($exception): void {
3649
                throw $exception;
3650
            });
3651
3652
        $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...
3653
            ->method('error')
3654
            ->with($message, [
3655
                'exception' => $exception,
3656
                'previous_exception_message' => $previousExceptionMessage,
3657
            ]);
3658
    }
3659
3660
    private function expectTranslate(
3661
        string $id,
3662
        array $parameters = [],
3663
        ?string $domain = null,
3664
        ?string $locale = null
3665
    ): void {
3666
        $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...
3667
            ->method('trans')
3668
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3669
            ->willReturn($id);
3670
    }
3671
}
3672