Completed
Push — 3.x ( 8a92d8...567b58 )
by Grégoire
04:36
created

testEditActionAjaxErrorWithoutAcceptApplicationJson()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 1
nc 1
nop 0

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\TestCase;
17
use Psr\Log\LoggerInterface;
18
use Sonata\AdminBundle\Admin\AbstractAdmin;
19
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
20
use Sonata\AdminBundle\Admin\Pool;
21
use Sonata\AdminBundle\Controller\CRUDController;
22
use Sonata\AdminBundle\Datagrid\DatagridInterface;
23
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
24
use Sonata\AdminBundle\Exception\LockException;
25
use Sonata\AdminBundle\Exception\ModelManagerException;
26
use Sonata\AdminBundle\Export\Exporter as SonataExporter;
27
use Sonata\AdminBundle\Model\AuditManager;
28
use Sonata\AdminBundle\Model\AuditReaderInterface;
29
use Sonata\AdminBundle\Model\ModelManagerInterface;
30
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
31
use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
32
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
33
use Sonata\AdminBundle\Tests\Fixtures\Admin\PostAdmin;
34
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
35
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
36
use Sonata\AdminBundle\Util\AdminObjectAclData;
37
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
38
use Sonata\Exporter\Exporter;
39
use Sonata\Exporter\Source\SourceIteratorInterface;
40
use Sonata\Exporter\Writer\JsonWriter;
41
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
42
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
43
use Symfony\Component\DependencyInjection\ContainerInterface;
44
use Symfony\Component\Form\Form;
45
use Symfony\Component\Form\FormBuilderInterface;
46
use Symfony\Component\Form\FormError;
47
use Symfony\Component\Form\FormInterface;
48
use Symfony\Component\Form\FormRenderer;
49
use Symfony\Component\Form\FormView;
50
use Symfony\Component\HttpFoundation\JsonResponse;
51
use Symfony\Component\HttpFoundation\RedirectResponse;
52
use Symfony\Component\HttpFoundation\Request;
53
use Symfony\Component\HttpFoundation\RequestStack;
54
use Symfony\Component\HttpFoundation\Response;
55
use Symfony\Component\HttpFoundation\Session\Session;
56
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
57
use Symfony\Component\HttpFoundation\StreamedResponse;
58
use Symfony\Component\HttpKernel\Exception\HttpException;
59
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
60
use Symfony\Component\HttpKernel\KernelInterface;
61
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
62
use Symfony\Component\Security\Csrf\CsrfToken;
63
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
64
use Symfony\Component\Translation\TranslatorInterface;
65
use Twig\Environment;
66
67
/**
68
 * Test for CRUDController.
69
 *
70
 * @author Andrej Hudec <[email protected]>
71
 *
72
 * @group legacy
73
 */
74
class CRUDControllerTest extends TestCase
75
{
76
    /**
77
     * @var CRUDController
78
     */
79
    private $controller;
80
81
    /**
82
     * @var Request
83
     */
84
    private $request;
85
86
    /**
87
     * @var AbstractAdmin
88
     */
89
    private $admin;
90
91
    /**
92
     * @var TemplateRegistryInterface
93
     */
94
    private $templateRegistry;
95
96
    /**
97
     * @var Pool
98
     */
99
    private $pool;
100
101
    /**
102
     * @var array
103
     */
104
    private $parameters;
105
106
    /**
107
     * @var Session
108
     */
109
    private $session;
110
111
    /**
112
     * @var AuditManager
113
     */
114
    private $auditManager;
115
116
    /**
117
     * @var ContainerInterface
118
     */
119
    private $container;
120
121
    /**
122
     * @var AdminObjectAclManipulator
123
     */
124
    private $adminObjectAclManipulator;
125
126
    /**
127
     * @var string
128
     */
129
    private $template;
130
131
    /**
132
     * @var array
133
     */
134
    private $protectedTestedMethods;
135
136
    /**
137
     * @var CsrfTokenManagerInterface
138
     */
139
    private $csrfProvider;
140
141
    /**
142
     * @var KernelInterface
143
     */
144
    private $kernel;
145
146
    /**
147
     * @var TranslatorInterface
148
     */
149
    private $translator;
150
151
    /**
152
     * @var FormBuilderInterface
153
     */
154
    private $formBuilder;
155
156
    /**
157
     * {@inheritdoc}
158
     */
159
    protected function setUp(): void
160
    {
161
        $this->container = $this->createMock(ContainerInterface::class);
162
163
        $this->request = new Request();
164
        $this->pool = new Pool($this->container, 'title', 'logo.png');
165
        $this->pool->setAdminServiceIds(['foo.admin']);
166
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
167
        $this->admin = $this->getMockBuilder(AbstractAdmin::class)
168
            ->disableOriginalConstructor()
169
            ->getMock();
170
        $this->translator = $this->createMock(TranslatorInterface::class);
171
        $this->parameters = [];
172
        $this->template = '';
173
174
        $this->formBuilder = $this->createMock(FormBuilderInterface::class);
175
        $this->admin
176
            ->method('getFormBuilder')
177
            ->willReturn($this->formBuilder);
178
179
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
180
181
        $templating = $this->getMockBuilder(DelegatingEngine::class)
182
            ->setConstructorArgs([$this->container, []])
183
            ->getMock();
184
185
        $templatingRenderReturnCallback = $this->returnCallback(function (
186
            $view,
187
            array $parameters = [],
188
            Response $response = null
189
        ) {
190
            $this->template = $view;
191
192
            if (null === $response) {
193
                $response = new Response();
194
            }
195
196
            $this->parameters = $parameters;
197
198
            return $response;
199
        });
200
201
        $templating
202
            ->method('render')
203
            ->will($templatingRenderReturnCallback);
204
205
        $this->session = new Session(new MockArraySessionStorage());
206
207
        $twig = $this->getMockBuilder(Environment::class)
208
            ->disableOriginalConstructor()
209
            ->getMock();
210
211
        $twig
212
            ->method('getRuntime')
213
            ->willReturn($this->createMock(FormRenderer::class));
214
215
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
216
        if (class_exists(Exporter::class)) {
217
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
218
        } else {
219
            $exporter = $this->createMock(SonataExporter::class);
220
221
            $exporter
222
                ->method('getResponse')
223
                ->willReturn(new StreamedResponse());
224
        }
225
226
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
227
            ->disableOriginalConstructor()
228
            ->getMock();
229
230
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
231
            ->disableOriginalConstructor()
232
            ->getMock();
233
234
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
235
            ->getMock();
236
237
        $this->csrfProvider
238
            ->method('getToken')
239
            ->willReturnCallback(static function (string $intention): CsrfToken {
240
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
241
            });
242
243
        $this->csrfProvider
244
            ->method('isTokenValid')
245
            ->willReturnCallback(static function (CsrfToken $token): bool {
246
                return $token->getValue() === 'csrf-token-123_'.$token->getId();
247
            });
248
249
        $this->logger = $this->createMock(LoggerInterface::class);
250
251
        $requestStack = new RequestStack();
252
        $requestStack->push($this->request);
253
254
        $this->kernel = $this->createMock(KernelInterface::class);
255
256
        $this->container
257
            ->method('get')
258
            ->willReturnCallback(function (string $id) use (
259
                $templating,
260
                $twig,
261
                $exporter,
262
                $requestStack
263
            ) {
264
                switch ($id) {
265
                    case 'sonata.admin.pool':
266
                        return $this->pool;
267
                    case 'request_stack':
268
                        return $requestStack;
269
                    case 'foo.admin':
270
                        return $this->admin;
271
                    case 'foo.admin.template_registry':
272
                        return $this->templateRegistry->reveal();
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundl...plateRegistryInterface>.

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

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

Loading history...
273
                    case 'templating':
274
                        return $templating;
275
                    case 'twig':
276
                        return $twig;
277
                    case 'session':
278
                        return $this->session;
279
                    case 'sonata.admin.exporter':
280
                        return $exporter;
281
                    case 'sonata.admin.audit.manager':
282
                        return $this->auditManager;
283
                    case 'sonata.admin.object.manipulator.acl.admin':
284
                        return $this->adminObjectAclManipulator;
285
                    case 'security.csrf.token_manager':
286
                        return $this->csrfProvider;
287
                    case 'logger':
288
                        return $this->logger;
289
                    case 'kernel':
290
                        return $this->kernel;
291
                    case 'translator':
292
                        return $this->translator;
293
                }
294
            });
295
296
        $this->container
297
            ->method('has')
298
            ->willReturnCallback(function (string $id): bool {
299
                if ('security.csrf.token_manager' === $id && null !== $this->getCsrfProvider()) {
300
                    return true;
301
                }
302
303
                if ('logger' === $id) {
304
                    return true;
305
                }
306
307
                if ('session' === $id) {
308
                    return true;
309
                }
310
311
                if ('templating' === $id) {
312
                    return true;
313
                }
314
315
                if ('translator' === $id) {
316
                    return true;
317
                }
318
319
                return false;
320
            });
321
322
        $this->container
323
            ->method('getParameter')
324
            ->willReturnCallback(static function (string $name): ?array {
325
                switch ($name) {
326
                    case 'security.role_hierarchy.roles':
327
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
328
                    default:
329
                       return null;
330
                }
331
            });
332
333
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
334
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
335
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
336
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
337
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
338
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
339
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
340
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
341
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
342
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
343
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
344
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
345
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
346
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
347
348
        // NEXT_MAJOR: Remove this call
349
        $this->admin->method('getTemplate')->willReturnMap([
350
            ['ajax', '@SonataAdmin/ajax_layout.html.twig'],
351
            ['layout', '@SonataAdmin/standard_layout.html.twig'],
352
            ['show', '@SonataAdmin/CRUD/show.html.twig'],
353
            ['show_compare', '@SonataAdmin/CRUD/show_compare.html.twig'],
354
            ['edit', '@SonataAdmin/CRUD/edit.html.twig'],
355
            ['dashboard', '@SonataAdmin/Core/dashboard.html.twig'],
356
            ['search', '@SonataAdmin/Core/search.html.twig'],
357
            ['list', '@SonataAdmin/CRUD/list.html.twig'],
358
            ['preview', '@SonataAdmin/CRUD/preview.html.twig'],
359
            ['history', '@SonataAdmin/CRUD/history.html.twig'],
360
            ['acl', '@SonataAdmin/CRUD/acl.html.twig'],
361
            ['delete', '@SonataAdmin/CRUD/delete.html.twig'],
362
            ['batch', '@SonataAdmin/CRUD/list__batch.html.twig'],
363
            ['batch_confirmation', '@SonataAdmin/CRUD/batch_confirmation.html.twig'],
364
        ]);
365
366
        $this->admin
367
            ->method('getIdParameter')
368
            ->willReturn('id');
369
370
        $this->admin
371
            ->method('getAccessMapping')
372
            ->willReturn([]);
373
374
        $this->admin
375
            ->method('generateUrl')
376
            ->willReturnCallback(
377
378
                    static function ($name, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
379
                        $result = $name;
380
                        if (!empty($parameters)) {
381
                            $result .= '?'.http_build_query($parameters);
382
                        }
383
384
                        return $result;
385
                    }
386
387
            );
388
389
        $this->admin
390
            ->method('generateObjectUrl')
391
            ->willReturnCallback(
392
393
                    static function (string $name, $object, array $parameters = [], bool $absolute = false): string {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
394
                        $result = \get_class($object).'_'.$name;
395
                        if (!empty($parameters)) {
396
                            $result .= '?'.http_build_query($parameters);
397
                        }
398
399
                        return $result;
400
                    }
401
402
            );
403
404
        $this->admin
405
            ->method('getCode')
406
            ->willReturn('foo.admin');
407
408
        $this->controller = new CRUDController();
409
        $this->controller->setContainer($this->container);
410
411
        // Make some methods public to test them
412
        $testedMethods = [
413
            'renderJson',
414
            'isXmlHttpRequest',
415
            'configure',
416
            'getBaseTemplate',
417
            'redirectTo',
418
            'addFlash',
419
        ];
420
        foreach ($testedMethods as $testedMethod) {
421
            // NEXT_MAJOR: Remove this check and only use CRUDController
422
            if (method_exists(CRUDController::class, $testedMethod)) {
423
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
424
            } else {
425
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
426
            }
427
428
            $method->setAccessible(true);
429
            $this->protectedTestedMethods[$testedMethod] = $method;
430
        }
431
    }
432
433
    public function testRenderJson1(): void
434
    {
435
        $data = ['example' => '123', 'foo' => 'bar'];
436
437
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
438
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
439
440
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
441
        $this->assertSame(json_encode($data), $response->getContent());
442
    }
443
444
    public function testRenderJson2(): void
445
    {
446
        $data = ['example' => '123', 'foo' => 'bar'];
447
448
        $this->request->headers->set('Content-Type', 'multipart/form-data');
449
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
450
451
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
452
        $this->assertSame(json_encode($data), $response->getContent());
453
    }
454
455
    public function testRenderJsonAjax(): void
456
    {
457
        $data = ['example' => '123', 'foo' => 'bar'];
458
459
        $this->request->attributes->set('_xml_http_request', true);
460
        $this->request->headers->set('Content-Type', 'multipart/form-data');
461
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
462
463
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
464
        $this->assertSame(json_encode($data), $response->getContent());
465
    }
466
467
    public function testIsXmlHttpRequest(): void
468
    {
469
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
470
471
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
472
473
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
474
475
        $this->request->headers->remove('X-Requested-With');
476
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
477
478
        $this->request->attributes->set('_xml_http_request', true);
479
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
480
    }
481
482
    public function testConfigure(): void
483
    {
484
        $uniqueId = '';
485
486
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
487
            ->method('setUniqid')
488
            ->willReturnCallback(static function (int $uniqid) use (&$uniqueId): void {
489
                $uniqueId = $uniqid;
490
            });
491
492
        $this->request->query->set('uniqid', 123456);
493
        $this->protectedTestedMethods['configure']->invoke($this->controller);
494
495
        $this->assertSame(123456, $uniqueId);
496
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
497
    }
498
499
    public function testConfigureChild(): void
500
    {
501
        $uniqueId = '';
502
503
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
504
            ->method('setUniqid')
505
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
506
                $uniqueId = $uniqid;
507
            });
508
509
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
510
            ->method('isChild')
511
            ->willReturn(true);
512
513
        $adminParent = $this->getMockBuilder(AbstractAdmin::class)
514
            ->disableOriginalConstructor()
515
            ->getMock();
516
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
517
            ->method('getParent')
518
            ->willReturn($adminParent);
519
520
        $this->request->query->set('uniqid', 123456);
521
        $this->protectedTestedMethods['configure']->invoke($this->controller);
522
523
        $this->assertSame(123456, $uniqueId);
524
        $this->assertAttributeInstanceOf(\get_class($adminParent), 'admin', $this->controller);
525
    }
526
527
    public function testConfigureWithException(): void
528
    {
529
        $this->expectException(\RuntimeException::class);
530
        $this->expectExceptionMessage(
531
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
532
        );
533
534
        $this->request->attributes->remove('_sonata_admin');
535
        $this->protectedTestedMethods['configure']->invoke($this->controller);
536
    }
537
538
    public function testConfigureWithException2(): void
539
    {
540
        $this->expectException(\InvalidArgumentException::class);
541
        $this->expectExceptionMessage('Found service "nonexistent.admin" is not a valid admin service');
542
543
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
544
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
545
        $this->protectedTestedMethods['configure']->invoke($this->controller);
546
    }
547
548
    public function testGetBaseTemplate(): void
549
    {
550
        $this->assertSame(
551
            '@SonataAdmin/standard_layout.html.twig',
552
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
553
        );
554
555
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
556
        $this->assertSame(
557
            '@SonataAdmin/ajax_layout.html.twig',
558
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
559
        );
560
561
        $this->request->headers->remove('X-Requested-With');
562
        $this->assertSame(
563
            '@SonataAdmin/standard_layout.html.twig',
564
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
565
        );
566
567
        $this->request->attributes->set('_xml_http_request', true);
568
        $this->assertSame(
569
            '@SonataAdmin/ajax_layout.html.twig',
570
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
571
        );
572
    }
573
574
    public function testRender(): void
575
    {
576
        $this->parameters = [];
577
        $this->assertInstanceOf(
578
            Response::class,
579
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
580
        );
581
        $this->assertSame($this->admin, $this->parameters['admin']);
582
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
583
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
584
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
585
    }
586
587
    public function testRenderWithResponse(): void
588
    {
589
        $this->parameters = [];
590
        $response = new Response();
591
        $response->headers->set('X-foo', 'bar');
592
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
593
594
        $this->assertSame($response, $responseResult);
595
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
596
        $this->assertSame($this->admin, $this->parameters['admin']);
597
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
598
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
599
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
600
    }
601
602
    public function testRenderCustomParams(): void
603
    {
604
        $this->parameters = [];
605
        $this->assertInstanceOf(
606
            Response::class,
607
            $this->controller->renderWithExtraParams(
608
                '@FooAdmin/foo.html.twig',
609
                ['foo' => 'bar'],
610
                null
611
            )
612
        );
613
        $this->assertSame($this->admin, $this->parameters['admin']);
614
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
615
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
616
        $this->assertSame('bar', $this->parameters['foo']);
617
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
618
    }
619
620
    public function testRenderAjax(): void
621
    {
622
        $this->parameters = [];
623
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
624
        $this->assertInstanceOf(
625
            Response::class,
626
            $this->controller->renderWithExtraParams(
627
                '@FooAdmin/foo.html.twig',
628
                ['foo' => 'bar'],
629
                null
630
            )
631
        );
632
        $this->assertSame($this->admin, $this->parameters['admin']);
633
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
634
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
635
        $this->assertSame('bar', $this->parameters['foo']);
636
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
637
    }
638
639
    public function testListActionAccessDenied(): void
640
    {
641
        $this->expectException(AccessDeniedException::class);
642
643
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
644
            ->method('checkAccess')
645
            ->with($this->equalTo('list'))
646
            ->will($this->throwException(new AccessDeniedException()));
647
648
        $this->controller->listAction();
649
    }
650
651
    public function testPreList(): void
652
    {
653
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('hasRoute')
655
            ->with($this->equalTo('list'))
656
            ->willReturn(true);
657
658
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
659
            ->method('checkAccess')
660
            ->with($this->equalTo('list'))
661
            ->willReturn(true);
662
663
        $controller = new PreCRUDController();
664
        $controller->setContainer($this->container);
665
666
        $response = $controller->listAction();
667
        $this->assertInstanceOf(Response::class, $response);
668
        $this->assertSame('preList called', $response->getContent());
669
    }
670
671
    public function testListAction(): void
672
    {
673
        $datagrid = $this->createMock(DatagridInterface::class);
674
675
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
676
            ->method('hasRoute')
677
            ->with($this->equalTo('list'))
678
            ->willReturn(true);
679
680
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
681
            ->method('checkAccess')
682
            ->with($this->equalTo('list'))
683
            ->willReturn(true);
684
685
        $form = $this->getMockBuilder(Form::class)
686
            ->disableOriginalConstructor()
687
            ->getMock();
688
689
        $form->expects($this->once())
690
            ->method('createView')
691
            ->willReturn($this->createMock(FormView::class));
692
693
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
694
            ->method('getDatagrid')
695
            ->willReturn($datagrid);
696
697
        $datagrid->expects($this->once())
698
            ->method('getForm')
699
            ->willReturn($form);
700
701
        $this->parameters = [];
702
        $this->assertInstanceOf(Response::class, $this->controller->listAction());
703
704
        $this->assertSame($this->admin, $this->parameters['admin']);
705
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
706
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
707
708
        $this->assertSame('list', $this->parameters['action']);
709
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
710
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
711
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
712
        $this->assertSame([], $this->session->getFlashBag()->all());
713
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
714
    }
715
716
    public function testBatchActionDeleteAccessDenied(): void
717
    {
718
        $this->expectException(AccessDeniedException::class);
719
720
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
721
            ->method('checkAccess')
722
            ->with($this->equalTo('batchDelete'))
723
            ->will($this->throwException(new AccessDeniedException()));
724
725
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
726
    }
727
728
    public function testBatchActionDelete(): void
729
    {
730
        $modelManager = $this->createMock(ModelManagerInterface::class);
731
732
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
733
            ->method('checkAccess')
734
            ->with($this->equalTo('batchDelete'))
735
            ->willReturn(true);
736
737
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
742
            ->method('getFilterParameters')
743
            ->willReturn(['foo' => 'bar']);
744
745
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
746
747
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
748
749
        $this->assertInstanceOf(RedirectResponse::class, $result);
750
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
751
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
752
    }
753
754
    public function testBatchActionDeleteWithModelManagerException(): void
755
    {
756
        $modelManager = $this->createMock(ModelManagerInterface::class);
757
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
758
759
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
760
            ->method('getModelManager')
761
            ->willReturn($modelManager);
762
763
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
764
            ->method('getFilterParameters')
765
            ->willReturn(['foo' => 'bar']);
766
767
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
768
769
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
770
771
        $this->assertInstanceOf(RedirectResponse::class, $result);
772
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
773
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
774
    }
775
776
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
777
    {
778
        $modelManager = $this->createMock(ModelManagerInterface::class);
779
        $this->expectException(ModelManagerException::class);
780
781
        $modelManager->expects($this->once())
782
            ->method('batchDelete')
783
            ->willReturnCallback(static function (): void {
784
                throw new ModelManagerException();
785
            });
786
787
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
788
            ->method('getModelManager')
789
            ->willReturn($modelManager);
790
791
        $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...
792
            ->method('isDebug')
793
            ->willReturn(true);
794
795
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
796
    }
797
798
    public function testShowActionNotFoundException(): void
799
    {
800
        $this->expectException(NotFoundHttpException::class);
801
802
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
803
            ->method('getObject')
804
            ->willReturn(false);
805
806
        $this->controller->showAction(null);
807
    }
808
809
    public function testShowActionAccessDenied(): void
810
    {
811
        $this->expectException(AccessDeniedException::class);
812
813
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
815
            ->willReturn(new \stdClass());
816
817
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
818
            ->method('checkAccess')
819
            ->with($this->equalTo('show'))
820
            ->will($this->throwException(new AccessDeniedException()));
821
822
        $this->controller->showAction(null);
823
    }
824
825
    /**
826
     * @group legacy
827
     * @expectedDeprecation Calling this method without implementing "configureShowFields" is not supported since sonata-project/admin-bundle 3.40.0 and will no longer be possible in 4.0
828
     */
829
    public function testShowActionDeprecation(): void
830
    {
831
        $object = new \stdClass();
832
833
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
834
            ->method('getObject')
835
            ->willReturn($object);
836
837
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
838
            ->method('checkAccess')
839
            ->with($this->equalTo('show'))
840
            ->willReturn(true);
841
842
        $show = $this->createMock(FieldDescriptionCollection::class);
843
844
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
845
            ->method('getShow')
846
            ->willReturn($show);
847
848
        $show->expects($this->once())
849
            ->method('getElements')
850
            ->willReturn([]);
851
852
        $show->expects($this->once())
853
            ->method('count')
854
            ->willReturn(0);
855
856
        $this->controller->showAction(null);
857
    }
858
859
    public function testPreShow(): void
860
    {
861
        $object = new \stdClass();
862
        $object->foo = 123456;
863
864
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
865
            ->method('getObject')
866
            ->willReturn($object);
867
868
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
869
            ->method('checkAccess')
870
            ->with($this->equalTo('show'))
871
            ->willReturn(true);
872
873
        $controller = new PreCRUDController();
874
        $controller->setContainer($this->container);
875
876
        $response = $controller->showAction(null);
877
        $this->assertInstanceOf(Response::class, $response);
878
        $this->assertSame('preShow called: 123456', $response->getContent());
879
    }
880
881
    public function testShowAction(): void
882
    {
883
        $object = new \stdClass();
884
885
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
886
            ->method('getObject')
887
            ->willReturn($object);
888
889
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
890
            ->method('checkAccess')
891
            ->with($this->equalTo('show'))
892
            ->willReturn(true);
893
894
        $show = $this->createMock(FieldDescriptionCollection::class);
895
896
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
897
            ->method('getShow')
898
            ->willReturn($show);
899
900
        $show->expects($this->once())
901
            ->method('getElements')
902
            ->willReturn(['field' => 'fielddata']);
903
904
        $this->assertInstanceOf(Response::class, $this->controller->showAction(null));
905
906
        $this->assertSame($this->admin, $this->parameters['admin']);
907
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
908
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
909
910
        $this->assertSame('show', $this->parameters['action']);
911
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
912
        $this->assertSame($object, $this->parameters['object']);
913
914
        $this->assertSame([], $this->session->getFlashBag()->all());
915
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
916
    }
917
918
    /**
919
     * @dataProvider getRedirectToTests
920
     */
921
    public function testRedirectTo(
922
        string $expected,
923
        string $route,
924
        array $queryParams,
925
        array $requestParams,
926
        bool $hasActiveSubclass
927
    ): void {
928
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
929
            ->method('hasActiveSubclass')
930
            ->willReturn($hasActiveSubclass);
931
932
        $object = new \stdClass();
933
934
        foreach ($queryParams as $key => $value) {
935
            $this->request->query->set($key, $value);
936
        }
937
938
        foreach ($requestParams as $key => $value) {
939
            $this->request->request->set($key, $value);
940
        }
941
942
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
943
            ->method('hasRoute')
944
            ->with($this->equalTo($route))
945
            ->willReturn(true);
946
947
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
948
            ->method('hasAccess')
949
            ->with($this->equalTo($route))
950
            ->willReturn(true);
951
952
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
953
        $this->assertInstanceOf(RedirectResponse::class, $response);
954
        $this->assertSame($expected, $response->getTargetUrl());
955
    }
956
957
    public function testRedirectToWithObject(): void
958
    {
959
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
960
            ->method('hasActiveSubclass')
961
            ->willReturn(false);
962
963
        $object = new \stdClass();
964
965
        $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\AbstractAdmin>.

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

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

Loading history...
966
            ->method('hasRoute')
967
            ->with($this->equalTo('edit'))
968
            ->willReturn(true);
969
970
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
971
            ->method('hasAccess')
972
            ->with($this->equalTo('edit'), $object)
973
            ->willReturn(false);
974
975
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
976
        $this->assertInstanceOf(RedirectResponse::class, $response);
977
        $this->assertSame('list', $response->getTargetUrl());
978
    }
979
980
    public function getRedirectToTests()
981
    {
982
        return [
983
            ['stdClass_edit', 'edit', [], [], false],
984
            ['list', 'list', ['btn_update_and_list' => true], [], false],
985
            ['list', 'list', ['btn_create_and_list' => true], [], false],
986
            ['create', 'create', ['btn_create_and_create' => true], [], false],
987
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
988
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
989
        ];
990
    }
991
992
    public function testDeleteActionNotFoundException(): void
993
    {
994
        $this->expectException(NotFoundHttpException::class);
995
996
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
997
            ->method('getObject')
998
            ->willReturn(false);
999
1000
        $this->controller->deleteAction(1);
1001
    }
1002
1003
    public function testDeleteActionAccessDenied(): void
1004
    {
1005
        $this->expectException(AccessDeniedException::class);
1006
1007
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1008
            ->method('getObject')
1009
            ->willReturn(new \stdClass());
1010
1011
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1012
            ->method('checkAccess')
1013
            ->with($this->equalTo('delete'))
1014
            ->will($this->throwException(new AccessDeniedException()));
1015
1016
        $this->controller->deleteAction(1);
1017
    }
1018
1019
    public function testPreDelete(): void
1020
    {
1021
        $object = new \stdClass();
1022
        $object->foo = 123456;
1023
1024
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1029
            ->method('checkAccess')
1030
            ->with($this->equalTo('delete'))
1031
            ->willReturn(true);
1032
1033
        $controller = new PreCRUDController();
1034
        $controller->setContainer($this->container);
1035
1036
        $response = $controller->deleteAction(null);
1037
        $this->assertInstanceOf(Response::class, $response);
1038
        $this->assertSame('preDelete called: 123456', $response->getContent());
1039
    }
1040
1041
    public function testDeleteAction(): void
1042
    {
1043
        $object = new \stdClass();
1044
1045
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1046
            ->method('getObject')
1047
            ->willReturn($object);
1048
1049
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1050
            ->method('checkAccess')
1051
            ->with($this->equalTo('delete'))
1052
            ->willReturn(true);
1053
1054
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1));
1055
1056
        $this->assertSame($this->admin, $this->parameters['admin']);
1057
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1058
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1059
1060
        $this->assertSame('delete', $this->parameters['action']);
1061
        $this->assertSame($object, $this->parameters['object']);
1062
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1063
1064
        $this->assertSame([], $this->session->getFlashBag()->all());
1065
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1066
    }
1067
1068
    /**
1069
     * @group legacy
1070
     * @expectedDeprecation Accessing a child that isn't connected to a given parent is deprecated since sonata-project/admin-bundle 3.34 and won't be allowed in 4.0.
1071
     */
1072
    public function testDeleteActionChildDeprecation(): void
1073
    {
1074
        $object = new \stdClass();
1075
        $object->parent = 'test';
1076
1077
        $object2 = new \stdClass();
1078
1079
        $admin = $this->createMock(PostAdmin::class);
1080
1081
        $admin->expects($this->once())
1082
            ->method('getObject')
1083
            ->willReturn($object2);
1084
1085
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1090
            ->method('getParent')
1091
            ->willReturn($admin);
1092
1093
        $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\AbstractAdmin>.

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

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

Loading history...
1094
            ->method('getParentAssociationMapping')
1095
            ->willReturn('parent');
1096
1097
        $this->controller->deleteAction(1);
1098
    }
1099
1100
    public function testDeleteActionNoParentMappings(): void
1101
    {
1102
        $object = new \stdClass();
1103
1104
        $admin = $this->createMock(PostAdmin::class);
1105
1106
        $admin->expects($this->never())
1107
            ->method('getObject');
1108
1109
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1110
            ->method('getObject')
1111
            ->willReturn($object);
1112
1113
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1114
            ->method('getParent')
1115
            ->willReturn($admin);
1116
1117
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1118
            ->method('getParentAssociationMapping')
1119
            ->willReturn(false);
1120
1121
        $this->controller->deleteAction(1);
1122
    }
1123
1124
    public function testDeleteActionNoCsrfToken(): void
1125
    {
1126
        $this->csrfProvider = null;
1127
1128
        $object = new \stdClass();
1129
1130
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1131
            ->method('getObject')
1132
            ->willReturn($object);
1133
1134
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1135
            ->method('checkAccess')
1136
            ->with($this->equalTo('delete'))
1137
            ->willReturn(true);
1138
1139
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1));
1140
1141
        $this->assertSame($this->admin, $this->parameters['admin']);
1142
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1143
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1144
1145
        $this->assertSame('delete', $this->parameters['action']);
1146
        $this->assertSame($object, $this->parameters['object']);
1147
        $this->assertFalse($this->parameters['csrf_token']);
1148
1149
        $this->assertSame([], $this->session->getFlashBag()->all());
1150
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1151
    }
1152
1153
    public function testDeleteActionAjaxSuccess1(): void
1154
    {
1155
        $object = new \stdClass();
1156
1157
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1158
            ->method('getObject')
1159
            ->willReturn($object);
1160
1161
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1162
            ->method('checkAccess')
1163
            ->with($this->equalTo('delete'))
1164
            ->willReturn(true);
1165
1166
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getOption')
1168
            ->with('csrf_protection')
1169
            ->willReturn(true);
1170
1171
        $this->request->setMethod(Request::METHOD_DELETE);
1172
1173
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1174
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1175
1176
        $response = $this->controller->deleteAction(1);
1177
1178
        $this->assertInstanceOf(Response::class, $response);
1179
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1180
        $this->assertSame([], $this->session->getFlashBag()->all());
1181
    }
1182
1183
    public function testDeleteActionAjaxSuccess2(): void
1184
    {
1185
        $object = new \stdClass();
1186
1187
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1192
            ->method('checkAccess')
1193
            ->with($this->equalTo('delete'))
1194
            ->willReturn(true);
1195
1196
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1197
            ->method('getOption')
1198
            ->with('csrf_protection')
1199
            ->willReturn(true);
1200
1201
        $this->request->setMethod(Request::METHOD_POST);
1202
        $this->request->request->set('_method', Request::METHOD_DELETE);
1203
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1204
1205
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1206
1207
        $response = $this->controller->deleteAction(1);
1208
1209
        $this->assertInstanceOf(Response::class, $response);
1210
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1211
        $this->assertSame([], $this->session->getFlashBag()->all());
1212
    }
1213
1214
    public function testDeleteActionAjaxError(): void
1215
    {
1216
        $object = new \stdClass();
1217
1218
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1223
            ->method('checkAccess')
1224
            ->with($this->equalTo('delete'))
1225
            ->willReturn(true);
1226
1227
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1228
            ->method('getClass')
1229
            ->willReturn('stdClass');
1230
1231
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1232
            ->method('getOption')
1233
            ->with('csrf_protection')
1234
            ->willReturn(true);
1235
1236
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1237
1238
        $this->request->setMethod(Request::METHOD_DELETE);
1239
1240
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1241
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1242
1243
        $response = $this->controller->deleteAction(1);
1244
1245
        $this->assertInstanceOf(Response::class, $response);
1246
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1247
        $this->assertSame([], $this->session->getFlashBag()->all());
1248
    }
1249
1250
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1251
    {
1252
        $this->expectException(ModelManagerException::class);
1253
1254
        $object = new \stdClass();
1255
1256
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1257
            ->method('getObject')
1258
            ->willReturn($object);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1262
            ->with($this->equalTo('delete'))
1263
            ->willReturn(true);
1264
1265
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1266
            ->method('getOption')
1267
            ->with('csrf_protection')
1268
            ->willReturn(true);
1269
1270
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1271
            ->method('delete')
1272
            ->willReturnCallback(static function (): void {
1273
                throw new ModelManagerException();
1274
            });
1275
1276
        $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...
1277
            ->method('isDebug')
1278
            ->willReturn(true);
1279
1280
        $this->request->setMethod(Request::METHOD_DELETE);
1281
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1282
1283
        $this->controller->deleteAction(1);
1284
    }
1285
1286
    /**
1287
     * @dataProvider getToStringValues
1288
     */
1289
    public function testDeleteActionSuccess1(string $expectedToStringValue, string $toStringValue): void
1290
    {
1291
        $object = new \stdClass();
1292
1293
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1294
            ->method('getObject')
1295
            ->willReturn($object);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('toString')
1299
            ->with($this->equalTo($object))
1300
            ->willReturn($toStringValue);
1301
1302
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1303
1304
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1305
            ->method('checkAccess')
1306
            ->with($this->equalTo('delete'))
1307
            ->willReturn(true);
1308
1309
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1310
            ->method('getOption')
1311
            ->with('csrf_protection')
1312
            ->willReturn(true);
1313
1314
        $this->request->setMethod(Request::METHOD_DELETE);
1315
1316
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1317
1318
        $response = $this->controller->deleteAction(1);
1319
1320
        $this->assertInstanceOf(RedirectResponse::class, $response);
1321
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1322
        $this->assertSame('list', $response->getTargetUrl());
1323
    }
1324
1325
    /**
1326
     * @dataProvider getToStringValues
1327
     */
1328
    public function testDeleteActionSuccess2(string $expectedToStringValue, string $toStringValue): void
1329
    {
1330
        $object = new \stdClass();
1331
1332
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1337
            ->method('checkAccess')
1338
            ->with($this->equalTo('delete'))
1339
            ->willReturn(true);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('toString')
1343
            ->with($this->equalTo($object))
1344
            ->willReturn($toStringValue);
1345
1346
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1347
1348
        $this->request->setMethod(Request::METHOD_POST);
1349
        $this->request->request->set('_method', Request::METHOD_DELETE);
1350
1351
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1352
1353
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1354
            ->method('getOption')
1355
            ->with('csrf_protection')
1356
            ->willReturn(true);
1357
1358
        $response = $this->controller->deleteAction(1);
1359
1360
        $this->assertInstanceOf(RedirectResponse::class, $response);
1361
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1362
        $this->assertSame('list', $response->getTargetUrl());
1363
    }
1364
1365
    /**
1366
     * @dataProvider getToStringValues
1367
     */
1368
    public function testDeleteActionSuccessNoCsrfTokenProvider(string $expectedToStringValue, string $toStringValue): void
1369
    {
1370
        $this->csrfProvider = null;
1371
1372
        $object = new \stdClass();
1373
1374
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1375
            ->method('getObject')
1376
            ->willReturn($object);
1377
1378
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1379
            ->method('checkAccess')
1380
            ->with($this->equalTo('delete'))
1381
            ->willReturn(true);
1382
1383
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1384
            ->method('toString')
1385
            ->with($this->equalTo($object))
1386
            ->willReturn($toStringValue);
1387
1388
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1389
1390
        $this->request->setMethod(Request::METHOD_POST);
1391
        $this->request->request->set('_method', Request::METHOD_DELETE);
1392
1393
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1394
            ->method('getOption')
1395
            ->with('csrf_protection')
1396
            ->willReturn(true);
1397
1398
        $response = $this->controller->deleteAction(1);
1399
1400
        $this->assertInstanceOf(RedirectResponse::class, $response);
1401
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1402
        $this->assertSame('list', $response->getTargetUrl());
1403
    }
1404
1405
    public function testDeleteActionWrongRequestMethod(): void
1406
    {
1407
        $object = new \stdClass();
1408
1409
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1410
            ->method('getObject')
1411
            ->willReturn($object);
1412
1413
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1414
            ->method('checkAccess')
1415
            ->with($this->equalTo('delete'))
1416
            ->willReturn(true);
1417
1418
        //without POST request parameter "_method" should not be used as real REST method
1419
        $this->request->query->set('_method', Request::METHOD_DELETE);
1420
1421
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1));
1422
1423
        $this->assertSame($this->admin, $this->parameters['admin']);
1424
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1425
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1426
1427
        $this->assertSame('delete', $this->parameters['action']);
1428
        $this->assertSame($object, $this->parameters['object']);
1429
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1430
1431
        $this->assertSame([], $this->session->getFlashBag()->all());
1432
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1433
    }
1434
1435
    /**
1436
     * @dataProvider getToStringValues
1437
     */
1438
    public function testDeleteActionError(string $expectedToStringValue, string $toStringValue): void
1439
    {
1440
        $object = new \stdClass();
1441
1442
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1443
            ->method('getObject')
1444
            ->willReturn($object);
1445
1446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1452
            ->method('toString')
1453
            ->with($this->equalTo($object))
1454
            ->willReturn($toStringValue);
1455
1456
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1457
1458
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1459
1460
        $this->request->setMethod(Request::METHOD_DELETE);
1461
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1462
1463
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getOption')
1465
            ->with('csrf_protection')
1466
            ->willReturn(true);
1467
1468
        $response = $this->controller->deleteAction(1);
1469
1470
        $this->assertInstanceOf(RedirectResponse::class, $response);
1471
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1472
        $this->assertSame('list', $response->getTargetUrl());
1473
    }
1474
1475
    public function testDeleteActionInvalidCsrfToken(): void
1476
    {
1477
        $object = new \stdClass();
1478
1479
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1480
            ->method('getObject')
1481
            ->willReturn($object);
1482
1483
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1484
            ->method('checkAccess')
1485
            ->with($this->equalTo('delete'))
1486
            ->willReturn(true);
1487
1488
        $this->request->setMethod(Request::METHOD_POST);
1489
        $this->request->request->set('_method', Request::METHOD_DELETE);
1490
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1491
1492
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1493
            ->method('getOption')
1494
            ->with('csrf_protection')
1495
            ->willReturn(true);
1496
1497
        try {
1498
            $this->controller->deleteAction(1);
1499
        } catch (HttpException $e) {
1500
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1501
            $this->assertSame(400, $e->getStatusCode());
1502
        }
1503
    }
1504
1505
    public function testDeleteActionWithDisabledCsrfProtection(): 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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('delete'))
1516
            ->willReturn(true);
1517
1518
        $this->request->setMethod(Request::METHOD_POST);
1519
        $this->request->request->set('_method', Request::METHOD_DELETE);
1520
1521
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1522
            ->method('getOption')
1523
            ->with('csrf_protection')
1524
            ->willReturn(false);
1525
1526
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1527
            ->method('toString')
1528
            ->with($object)
1529
            ->willReturn(\stdClass::class);
1530
1531
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...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...
1532
            ->method('trans')
1533
            ->willReturn('flash message');
1534
1535
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1536
            ->method('delete')
1537
            ->with($object);
1538
1539
        $this->controller->deleteAction(1);
1540
    }
1541
1542
    public function testEditActionNotFoundException(): void
1543
    {
1544
        $this->expectException(NotFoundHttpException::class);
1545
1546
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1547
            ->method('getObject')
1548
            ->willReturn(false);
1549
1550
        $this->controller->editAction(null);
1551
    }
1552
1553
    public function testEditActionRuntimeException(): void
1554
    {
1555
        $this->expectException(\RuntimeException::class);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
1559
            ->willReturn(new \stdClass());
1560
1561
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1562
            ->method('checkAccess')
1563
            ->with($this->equalTo('edit'))
1564
            ->willReturn(true);
1565
1566
        $form = $this->createMock(Form::class);
1567
1568
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1569
            ->method('getForm')
1570
            ->willReturn($form);
1571
1572
        $form->expects($this->once())
1573
            ->method('all')
1574
            ->willReturn([]);
1575
1576
        $this->controller->editAction(null);
1577
    }
1578
1579
    public function testEditActionAccessDenied(): void
1580
    {
1581
        $this->expectException(AccessDeniedException::class);
1582
1583
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1588
            ->method('checkAccess')
1589
            ->with($this->equalTo('edit'))
1590
            ->will($this->throwException(new AccessDeniedException()));
1591
1592
        $this->controller->editAction(null);
1593
    }
1594
1595
    public function testPreEdit(): void
1596
    {
1597
        $object = new \stdClass();
1598
        $object->foo = 123456;
1599
1600
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1601
            ->method('getObject')
1602
            ->willReturn($object);
1603
1604
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1605
            ->method('checkAccess')
1606
            ->with($this->equalTo('edit'))
1607
            ->willReturn(true);
1608
1609
        $controller = new PreCRUDController();
1610
        $controller->setContainer($this->container);
1611
1612
        $response = $controller->editAction(null);
1613
        $this->assertInstanceOf(Response::class, $response);
1614
        $this->assertSame('preEdit called: 123456', $response->getContent());
1615
    }
1616
1617
    public function testEditAction(): void
1618
    {
1619
        $object = new \stdClass();
1620
1621
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1622
            ->method('getObject')
1623
            ->willReturn($object);
1624
1625
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1626
            ->method('checkAccess')
1627
            ->with($this->equalTo('edit'))
1628
            ->willReturn(true);
1629
1630
        $form = $this->createMock(Form::class);
1631
1632
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1633
            ->method('getForm')
1634
            ->willReturn($form);
1635
1636
        $formView = $this->createMock(FormView::class);
1637
1638
        $form
1639
            ->method('createView')
1640
            ->willReturn($formView);
1641
1642
        $form->expects($this->once())
1643
            ->method('all')
1644
            ->willReturn(['field' => 'fielddata']);
1645
1646
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null));
1647
1648
        $this->assertSame($this->admin, $this->parameters['admin']);
1649
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1650
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1651
1652
        $this->assertSame('edit', $this->parameters['action']);
1653
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1654
        $this->assertSame($object, $this->parameters['object']);
1655
        $this->assertSame([], $this->session->getFlashBag()->all());
1656
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1657
    }
1658
1659
    /**
1660
     * @dataProvider getToStringValues
1661
     */
1662
    public function testEditActionSuccess(string $expectedToStringValue, string $toStringValue): void
1663
    {
1664
        $object = new \stdClass();
1665
1666
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1667
            ->method('getObject')
1668
            ->willReturn($object);
1669
1670
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1671
            ->method('update')
1672
            ->willReturnArgument(0);
1673
1674
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1675
            ->method('checkAccess')
1676
            ->with($this->equalTo('edit'));
1677
1678
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1679
            ->method('hasRoute')
1680
            ->with($this->equalTo('edit'))
1681
            ->willReturn(true);
1682
1683
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1684
            ->method('hasAccess')
1685
            ->with($this->equalTo('edit'))
1686
            ->willReturn(true);
1687
1688
        $form = $this->createMock(Form::class);
1689
1690
        $form->expects($this->once())
1691
            ->method('getData')
1692
            ->willReturn($object);
1693
1694
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1695
            ->method('getForm')
1696
            ->willReturn($form);
1697
1698
        $form->expects($this->once())
1699
            ->method('isSubmitted')
1700
            ->willReturn(true);
1701
1702
        $form->expects($this->once())
1703
            ->method('isValid')
1704
            ->willReturn(true);
1705
1706
        $form->expects($this->once())
1707
            ->method('all')
1708
            ->willReturn(['field' => 'fielddata']);
1709
1710
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1711
            ->method('toString')
1712
            ->with($this->equalTo($object))
1713
            ->willReturn($toStringValue);
1714
1715
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1716
1717
        $this->request->setMethod(Request::METHOD_POST);
1718
1719
        $response = $this->controller->editAction(null);
1720
1721
        $this->assertInstanceOf(RedirectResponse::class, $response);
1722
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1723
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1724
    }
1725
1726
    /**
1727
     * @dataProvider getToStringValues
1728
     */
1729
    public function testEditActionError(string $expectedToStringValue, string $toStringValue): void
1730
    {
1731
        $object = new \stdClass();
1732
1733
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
1735
            ->willReturn($object);
1736
1737
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1738
            ->method('checkAccess')
1739
            ->with($this->equalTo('edit'))
1740
            ->willReturn(true);
1741
1742
        $form = $this->createMock(Form::class);
1743
1744
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1745
            ->method('getForm')
1746
            ->willReturn($form);
1747
1748
        $form->expects($this->once())
1749
            ->method('isSubmitted')
1750
            ->willReturn(true);
1751
1752
        $form->expects($this->once())
1753
            ->method('isValid')
1754
            ->willReturn(false);
1755
1756
        $form->expects($this->once())
1757
            ->method('all')
1758
            ->willReturn(['field' => 'fielddata']);
1759
1760
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1761
            ->method('toString')
1762
            ->with($this->equalTo($object))
1763
            ->willReturn($toStringValue);
1764
1765
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1766
1767
        $this->request->setMethod(Request::METHOD_POST);
1768
1769
        $formView = $this->createMock(FormView::class);
1770
1771
        $form
1772
            ->method('createView')
1773
            ->willReturn($formView);
1774
1775
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null));
1776
1777
        $this->assertSame($this->admin, $this->parameters['admin']);
1778
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1779
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1780
1781
        $this->assertSame('edit', $this->parameters['action']);
1782
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1783
        $this->assertSame($object, $this->parameters['object']);
1784
1785
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1786
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1787
    }
1788
1789
    public function testEditActionAjaxSuccess(): void
1790
    {
1791
        $object = new \stdClass();
1792
1793
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1794
            ->method('getObject')
1795
            ->willReturn($object);
1796
1797
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1798
            ->method('update')
1799
            ->willReturnArgument(0);
1800
1801
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1802
            ->method('checkAccess')
1803
            ->with($this->equalTo('edit'))
1804
            ->willReturn(true);
1805
1806
        $form = $this->createMock(Form::class);
1807
1808
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1809
            ->method('getForm')
1810
            ->willReturn($form);
1811
1812
        $form->expects($this->once())
1813
            ->method('isSubmitted')
1814
            ->willReturn(true);
1815
1816
        $form->expects($this->once())
1817
            ->method('isValid')
1818
            ->willReturn(true);
1819
1820
        $form->expects($this->once())
1821
            ->method('getData')
1822
            ->willReturn($object);
1823
1824
        $form->expects($this->once())
1825
            ->method('all')
1826
            ->willReturn(['field' => 'fielddata']);
1827
1828
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1829
            ->method('getNormalizedIdentifier')
1830
            ->with($this->equalTo($object))
1831
            ->willReturn('foo_normalized');
1832
1833
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1834
            ->method('toString')
1835
            ->willReturn('foo');
1836
1837
        $this->request->setMethod(Request::METHOD_POST);
1838
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1839
1840
        $response = $this->controller->editAction(null);
1841
1842
        $this->assertInstanceOf(Response::class, $response);
1843
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1844
        $this->assertSame([], $this->session->getFlashBag()->all());
1845
    }
1846
1847
    public function testEditActionAjaxError(): void
1848
    {
1849
        $object = new \stdClass();
1850
1851
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1852
            ->method('getObject')
1853
            ->willReturn($object);
1854
1855
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1856
            ->method('checkAccess')
1857
            ->with($this->equalTo('edit'))
1858
            ->willReturn(true);
1859
1860
        $form = $this->createMock(Form::class);
1861
1862
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1863
            ->method('getForm')
1864
            ->willReturn($form);
1865
1866
        $form->expects($this->once())
1867
            ->method('isSubmitted')
1868
            ->willReturn(true);
1869
1870
        $form->expects($this->once())
1871
            ->method('isValid')
1872
            ->willReturn(false);
1873
1874
        $form->expects($this->once())
1875
            ->method('all')
1876
            ->willReturn(['field' => 'fielddata']);
1877
1878
        $formError = $this->createMock(FormError::class);
1879
        $formError->expects($this->atLeastOnce())
1880
            ->method('getMessage')
1881
            ->willReturn('Form error message');
1882
1883
        $form->expects($this->once())
1884
            ->method('getErrors')
1885
            ->with(true)
1886
            ->willReturn([$formError]);
1887
1888
        $this->request->setMethod(Request::METHOD_POST);
1889
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1890
        $this->request->headers->set('Accept', 'application/json');
1891
1892
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction(null));
1893
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
1894
    }
1895
1896
    /**
1897
     * @legacy
1898
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
1899
     */
1900
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1901
    {
1902
        $object = new \stdClass();
1903
1904
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1905
            ->method('getObject')
1906
            ->willReturn($object);
1907
1908
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1909
            ->method('checkAccess')
1910
            ->with($this->equalTo('edit'))
1911
            ->willReturn(true);
1912
1913
        $form = $this->createMock(Form::class);
1914
1915
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1916
            ->method('getForm')
1917
            ->willReturn($form);
1918
1919
        $form->expects($this->once())
1920
            ->method('isSubmitted')
1921
            ->willReturn(true);
1922
1923
        $form->expects($this->once())
1924
            ->method('isValid')
1925
            ->willReturn(false);
1926
1927
        $form->expects($this->once())
1928
            ->method('all')
1929
            ->willReturn(['field' => 'fielddata']);
1930
1931
        $this->request->setMethod(Request::METHOD_POST);
1932
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1933
1934
        $formView = $this->createMock(FormView::class);
1935
        $form
1936
            ->method('createView')
1937
            ->willReturn($formView);
1938
1939
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...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...
1940
            ->method('trans')
1941
            ->willReturn('flash message');
1942
1943
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction(null));
1944
        $this->assertSame($this->admin, $this->parameters['admin']);
1945
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1946
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1947
        $this->assertSame('edit', $this->parameters['action']);
1948
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1949
        $this->assertSame($object, $this->parameters['object']);
1950
        $this->assertSame([
1951
            'sonata_flash_error' => [0 => 'flash message'],
1952
        ], $this->session->getFlashBag()->all());
1953
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1954
    }
1955
1956
    /**
1957
     * @dataProvider getToStringValues
1958
     */
1959
    public function testEditActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
1960
    {
1961
        $object = new \stdClass();
1962
1963
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1964
            ->method('getObject')
1965
            ->willReturn($object);
1966
1967
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1968
            ->method('checkAccess')
1969
            ->with($this->equalTo('edit'))
1970
            ->willReturn(true);
1971
1972
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1973
            ->method('getClass')
1974
            ->willReturn('stdClass');
1975
1976
        $form = $this->createMock(Form::class);
1977
1978
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1979
            ->method('getForm')
1980
            ->willReturn($form);
1981
1982
        $form->expects($this->once())
1983
            ->method('isValid')
1984
            ->willReturn(true);
1985
1986
        $form->expects($this->once())
1987
            ->method('getData')
1988
            ->willReturn($object);
1989
1990
        $form->expects($this->once())
1991
            ->method('all')
1992
            ->willReturn(['field' => 'fielddata']);
1993
1994
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1995
            ->method('toString')
1996
            ->with($this->equalTo($object))
1997
            ->willReturn($toStringValue);
1998
1999
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2000
2001
        $form->expects($this->once())
2002
            ->method('isSubmitted')
2003
            ->willReturn(true);
2004
        $this->request->setMethod(Request::METHOD_POST);
2005
2006
        $formView = $this->createMock(FormView::class);
2007
2008
        $form
2009
            ->method('createView')
2010
            ->willReturn($formView);
2011
2012
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
2013
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null));
2014
2015
        $this->assertSame($this->admin, $this->parameters['admin']);
2016
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2017
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2018
2019
        $this->assertSame('edit', $this->parameters['action']);
2020
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2021
        $this->assertSame($object, $this->parameters['object']);
2022
2023
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
2024
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2025
    }
2026
2027
    public function testEditActionWithPreview(): void
2028
    {
2029
        $object = new \stdClass();
2030
2031
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2032
            ->method('getObject')
2033
            ->willReturn($object);
2034
2035
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2036
            ->method('checkAccess')
2037
            ->with($this->equalTo('edit'))
2038
            ->willReturn(true);
2039
2040
        $form = $this->createMock(Form::class);
2041
2042
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2043
            ->method('getForm')
2044
            ->willReturn($form);
2045
2046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2047
            ->method('supportsPreviewMode')
2048
            ->willReturn(true);
2049
2050
        $formView = $this->createMock(FormView::class);
2051
2052
        $form
2053
            ->method('createView')
2054
            ->willReturn($formView);
2055
2056
        $form->expects($this->once())
2057
            ->method('isSubmitted')
2058
            ->willReturn(true);
2059
2060
        $form->expects($this->once())
2061
            ->method('isValid')
2062
            ->willReturn(true);
2063
2064
        $form->expects($this->once())
2065
            ->method('all')
2066
            ->willReturn(['field' => 'fielddata']);
2067
2068
        $this->request->setMethod(Request::METHOD_POST);
2069
        $this->request->request->set('btn_preview', 'Preview');
2070
2071
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null));
2072
2073
        $this->assertSame($this->admin, $this->parameters['admin']);
2074
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2075
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2076
2077
        $this->assertSame('edit', $this->parameters['action']);
2078
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2079
        $this->assertSame($object, $this->parameters['object']);
2080
2081
        $this->assertSame([], $this->session->getFlashBag()->all());
2082
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2083
    }
2084
2085
    public function testEditActionWithLockException(): void
2086
    {
2087
        $object = new \stdClass();
2088
        $class = \get_class($object);
2089
2090
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2091
            ->method('getObject')
2092
            ->willReturn($object);
2093
2094
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2095
            ->method('checkAccess')
2096
            ->with($this->equalTo('edit'))
2097
            ->willReturn(true);
2098
2099
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2100
            ->method('getClass')
2101
            ->willReturn($class);
2102
2103
        $form = $this->createMock(Form::class);
2104
2105
        $form
2106
            ->method('isValid')
2107
            ->willReturn(true);
2108
2109
        $form->expects($this->once())
2110
            ->method('getData')
2111
            ->willReturn($object);
2112
2113
        $form->expects($this->once())
2114
            ->method('all')
2115
            ->willReturn(['field' => 'fielddata']);
2116
2117
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2118
            ->method('getForm')
2119
            ->willReturn($form);
2120
2121
        $form
2122
            ->method('isSubmitted')
2123
            ->willReturn(true);
2124
        $this->request->setMethod(Request::METHOD_POST);
2125
2126
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2127
            ->method('update')
2128
            ->will($this->throwException(new LockException()));
2129
2130
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2131
            ->method('toString')
2132
            ->with($this->equalTo($object))
2133
            ->willReturn($class);
2134
2135
        $formView = $this->createMock(FormView::class);
2136
2137
        $form
2138
            ->method('createView')
2139
            ->willReturn($formView);
2140
2141
        $this->expectTranslate('flash_lock_error', [
2142
            '%name%' => $class,
2143
            '%link_start%' => '<a href="stdClass_edit">',
2144
            '%link_end%' => '</a>',
2145
        ], 'SonataAdminBundle');
2146
2147
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null));
2148
    }
2149
2150
    public function testCreateActionAccessDenied(): void
2151
    {
2152
        $this->expectException(AccessDeniedException::class);
2153
2154
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2156
            ->with($this->equalTo('create'))
2157
            ->will($this->throwException(new AccessDeniedException()));
2158
2159
        $this->controller->createAction();
2160
    }
2161
2162
    public function testCreateActionRuntimeException(): void
2163
    {
2164
        $this->expectException(\RuntimeException::class);
2165
2166
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2167
            ->method('checkAccess')
2168
            ->with($this->equalTo('create'))
2169
            ->willReturn(true);
2170
2171
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2172
            ->method('getClass')
2173
            ->willReturn('stdClass');
2174
2175
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2182
            ->method('getForm')
2183
            ->willReturn($form);
2184
2185
        $form->expects($this->once())
2186
            ->method('all')
2187
            ->willReturn([]);
2188
2189
        $this->controller->createAction();
2190
    }
2191
2192
    public function testPreCreate(): void
2193
    {
2194
        $object = new \stdClass();
2195
        $object->foo = 123456;
2196
2197
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2198
            ->method('checkAccess')
2199
            ->with($this->equalTo('create'))
2200
            ->willReturn(true);
2201
2202
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2203
            ->method('getClass')
2204
            ->willReturn('stdClass');
2205
2206
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2207
            ->method('getNewInstance')
2208
            ->willReturn($object);
2209
2210
        $controller = new PreCRUDController();
2211
        $controller->setContainer($this->container);
2212
2213
        $response = $controller->createAction();
2214
        $this->assertInstanceOf(Response::class, $response);
2215
        $this->assertSame('preCreate called: 123456', $response->getContent());
2216
    }
2217
2218
    public function testCreateAction(): void
2219
    {
2220
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2228
            ->method('getClass')
2229
            ->willReturn('stdClass');
2230
2231
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2232
            ->method('getNewInstance')
2233
            ->willReturn($object);
2234
2235
        $form = $this->createMock(Form::class);
2236
2237
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2238
            ->method('getForm')
2239
            ->willReturn($form);
2240
2241
        $form->expects($this->once())
2242
            ->method('all')
2243
            ->willReturn(['field' => 'fielddata']);
2244
2245
        $formView = $this->createMock(FormView::class);
2246
2247
        $form
2248
            ->method('createView')
2249
            ->willReturn($formView);
2250
2251
        $this->assertInstanceOf(Response::class, $this->controller->createAction());
2252
2253
        $this->assertSame($this->admin, $this->parameters['admin']);
2254
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2255
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2256
2257
        $this->assertSame('create', $this->parameters['action']);
2258
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2259
        $this->assertSame($object, $this->parameters['object']);
2260
2261
        $this->assertSame([], $this->session->getFlashBag()->all());
2262
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2263
    }
2264
2265
    /**
2266
     * @dataProvider getToStringValues
2267
     */
2268
    public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void
2269
    {
2270
        $object = new \stdClass();
2271
2272
        $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\AbstractAdmin>.

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

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

Loading history...
2273
            ->method('checkAccess')
2274
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): bool {
2275
                if ('edit' === $name) {
2276
                    return true;
2277
                }
2278
2279
                if ('create' !== $name) {
2280
                    return false;
2281
                }
2282
2283
                if (null === $objectIn) {
2284
                    return true;
2285
                }
2286
2287
                return $objectIn === $object;
2288
            });
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('hasRoute')
2292
            ->with($this->equalTo('edit'))
2293
            ->willReturn(true);
2294
2295
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2296
            ->method('hasAccess')
2297
            ->with($this->equalTo('edit'))
2298
            ->willReturn(true);
2299
2300
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2301
            ->method('getNewInstance')
2302
            ->willReturn($object);
2303
2304
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2305
            ->method('create')
2306
            ->willReturnArgument(0);
2307
2308
        $form = $this->createMock(Form::class);
2309
2310
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2311
            ->method('getClass')
2312
            ->willReturn('stdClass');
2313
2314
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2315
            ->method('getForm')
2316
            ->willReturn($form);
2317
2318
        $form->expects($this->once())
2319
            ->method('all')
2320
            ->willReturn(['field' => 'fielddata']);
2321
2322
        $form->expects($this->once())
2323
            ->method('isSubmitted')
2324
            ->willReturn(true);
2325
2326
        $form->expects($this->once())
2327
            ->method('isValid')
2328
            ->willReturn(true);
2329
2330
        $form->expects($this->once())
2331
            ->method('getData')
2332
            ->willReturn($object);
2333
2334
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2335
            ->method('toString')
2336
            ->with($this->equalTo($object))
2337
            ->willReturn($toStringValue);
2338
2339
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2340
2341
        $this->request->setMethod(Request::METHOD_POST);
2342
2343
        $response = $this->controller->createAction();
2344
2345
        $this->assertInstanceOf(RedirectResponse::class, $response);
2346
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2347
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2348
    }
2349
2350
    public function testCreateActionAccessDenied2(): void
2351
    {
2352
        $this->expectException(AccessDeniedException::class);
2353
2354
        $object = new \stdClass();
2355
2356
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2357
            ->method('checkAccess')
2358
            ->willReturnCallback(static function (string $name, $object = null): bool {
2359
                if ('create' !== $name) {
2360
                    throw new AccessDeniedException();
2361
                }
2362
                if (null === $object) {
2363
                    return true;
2364
                }
2365
2366
                throw new AccessDeniedException();
2367
            });
2368
2369
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2370
            ->method('getNewInstance')
2371
            ->willReturn($object);
2372
2373
        $form = $this->createMock(Form::class);
2374
2375
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2376
            ->method('getClass')
2377
            ->willReturn('stdClass');
2378
2379
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2380
            ->method('getForm')
2381
            ->willReturn($form);
2382
2383
        $form->expects($this->once())
2384
            ->method('all')
2385
            ->willReturn(['field' => 'fielddata']);
2386
2387
        $form->expects($this->once())
2388
            ->method('isSubmitted')
2389
            ->willReturn(true);
2390
2391
        $form->expects($this->once())
2392
            ->method('getData')
2393
            ->willReturn($object);
2394
2395
        $form->expects($this->once())
2396
            ->method('isValid')
2397
            ->willReturn(true);
2398
2399
        $this->request->setMethod(Request::METHOD_POST);
2400
2401
        $this->controller->createAction();
2402
    }
2403
2404
    /**
2405
     * @dataProvider getToStringValues
2406
     */
2407
    public function testCreateActionError(string $expectedToStringValue, string $toStringValue): void
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2411
            ->with($this->equalTo('create'))
2412
            ->willReturn(true);
2413
2414
        $object = new \stdClass();
2415
2416
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2417
            ->method('getClass')
2418
            ->willReturn('stdClass');
2419
2420
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2421
            ->method('getNewInstance')
2422
            ->willReturn($object);
2423
2424
        $form = $this->createMock(Form::class);
2425
2426
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2427
            ->method('getForm')
2428
            ->willReturn($form);
2429
2430
        $form->expects($this->once())
2431
            ->method('all')
2432
            ->willReturn(['field' => 'fielddata']);
2433
2434
        $form->expects($this->once())
2435
            ->method('isSubmitted')
2436
            ->willReturn(true);
2437
2438
        $form->expects($this->once())
2439
            ->method('isValid')
2440
            ->willReturn(false);
2441
2442
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2443
            ->method('toString')
2444
            ->with($this->equalTo($object))
2445
            ->willReturn($toStringValue);
2446
2447
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2448
2449
        $this->request->setMethod(Request::METHOD_POST);
2450
2451
        $formView = $this->createMock(FormView::class);
2452
2453
        $form
2454
            ->method('createView')
2455
            ->willReturn($formView);
2456
2457
        $this->assertInstanceOf(Response::class, $this->controller->createAction());
2458
2459
        $this->assertSame($this->admin, $this->parameters['admin']);
2460
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2461
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2462
2463
        $this->assertSame('create', $this->parameters['action']);
2464
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2465
        $this->assertSame($object, $this->parameters['object']);
2466
2467
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2468
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2469
    }
2470
2471
    /**
2472
     * @dataProvider getToStringValues
2473
     */
2474
    public function testCreateActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
2475
    {
2476
        $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\AbstractAdmin>.

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

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

Loading history...
2477
            ->method('checkAccess')
2478
            ->with($this->equalTo('create'))
2479
            ->willReturn(true);
2480
2481
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2482
            ->method('getClass')
2483
            ->willReturn('stdClass');
2484
2485
        $object = new \stdClass();
2486
2487
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2488
            ->method('getNewInstance')
2489
            ->willReturn($object);
2490
2491
        $form = $this->createMock(Form::class);
2492
2493
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2494
            ->method('getForm')
2495
            ->willReturn($form);
2496
2497
        $form->expects($this->once())
2498
            ->method('all')
2499
            ->willReturn(['field' => 'fielddata']);
2500
2501
        $form->expects($this->once())
2502
            ->method('isValid')
2503
            ->willReturn(true);
2504
2505
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2506
            ->method('toString')
2507
            ->with($this->equalTo($object))
2508
            ->willReturn($toStringValue);
2509
2510
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2511
2512
        $form->expects($this->once())
2513
            ->method('isSubmitted')
2514
            ->willReturn(true);
2515
2516
        $form->expects($this->once())
2517
            ->method('getData')
2518
            ->willReturn($object);
2519
2520
        $this->request->setMethod(Request::METHOD_POST);
2521
2522
        $formView = $this->createMock(FormView::class);
2523
2524
        $form
2525
            ->method('createView')
2526
            ->willReturn($formView);
2527
2528
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2529
2530
        $this->assertInstanceOf(Response::class, $this->controller->createAction());
2531
2532
        $this->assertSame($this->admin, $this->parameters['admin']);
2533
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2534
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2535
2536
        $this->assertSame('create', $this->parameters['action']);
2537
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2538
        $this->assertSame($object, $this->parameters['object']);
2539
2540
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2541
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2542
    }
2543
2544
    public function testCreateActionAjaxSuccess(): void
2545
    {
2546
        $object = new \stdClass();
2547
2548
        $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\AbstractAdmin>.

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

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

Loading history...
2549
            ->method('checkAccess')
2550
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): bool {
2551
                if ('create' !== $name) {
2552
                    return false;
2553
                }
2554
2555
                if (null === $objectIn) {
2556
                    return true;
2557
                }
2558
2559
                return $objectIn === $object;
2560
            });
2561
2562
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2563
            ->method('getNewInstance')
2564
            ->willReturn($object);
2565
2566
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2567
            ->method('create')
2568
            ->willReturnArgument(0);
2569
2570
        $form = $this->createMock(Form::class);
2571
2572
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2573
            ->method('getForm')
2574
            ->willReturn($form);
2575
2576
        $form->expects($this->once())
2577
            ->method('all')
2578
            ->willReturn(['field' => 'fielddata']);
2579
2580
        $form->expects($this->once())
2581
            ->method('isSubmitted')
2582
            ->willReturn(true);
2583
2584
        $form->expects($this->once())
2585
            ->method('isValid')
2586
            ->willReturn(true);
2587
2588
        $form->expects($this->once())
2589
            ->method('getData')
2590
            ->willReturn($object);
2591
2592
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2593
            ->method('getClass')
2594
            ->willReturn('stdClass');
2595
2596
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2597
            ->method('getNormalizedIdentifier')
2598
            ->with($this->equalTo($object))
2599
            ->willReturn('foo_normalized');
2600
2601
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2602
            ->method('toString')
2603
            ->willReturn('foo');
2604
2605
        $this->request->setMethod(Request::METHOD_POST);
2606
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2607
2608
        $response = $this->controller->createAction();
2609
2610
        $this->assertInstanceOf(Response::class, $response);
2611
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2612
        $this->assertSame([], $this->session->getFlashBag()->all());
2613
    }
2614
2615
    public function testCreateActionAjaxError(): void
2616
    {
2617
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2618
            ->method('checkAccess')
2619
            ->with($this->equalTo('create'))
2620
            ->willReturn(true);
2621
2622
        $object = new \stdClass();
2623
2624
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2625
            ->method('getNewInstance')
2626
            ->willReturn($object);
2627
2628
        $form = $this->createMock(Form::class);
2629
2630
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2631
            ->method('getClass')
2632
            ->willReturn('stdClass');
2633
2634
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2635
            ->method('getForm')
2636
            ->willReturn($form);
2637
2638
        $form->expects($this->once())
2639
            ->method('all')
2640
            ->willReturn(['field' => 'fielddata']);
2641
2642
        $form->expects($this->once())
2643
            ->method('isSubmitted')
2644
            ->willReturn(true);
2645
2646
        $form->expects($this->once())
2647
            ->method('isValid')
2648
            ->willReturn(false);
2649
2650
        $formError = $this->createMock(FormError::class);
2651
        $formError->expects($this->atLeastOnce())
2652
            ->method('getMessage')
2653
            ->willReturn('Form error message');
2654
2655
        $form->expects($this->once())
2656
            ->method('getErrors')
2657
            ->with(true)
2658
            ->willReturn([$formError]);
2659
2660
        $this->request->setMethod(Request::METHOD_POST);
2661
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2662
        $this->request->headers->set('Accept', 'application/json');
2663
2664
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction());
2665
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
2666
    }
2667
2668
    /**
2669
     * @legacy
2670
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
2671
     */
2672
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2673
    {
2674
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2675
            ->method('checkAccess')
2676
            ->with($this->equalTo('create'))
2677
            ->willReturn(true);
2678
2679
        $object = new \stdClass();
2680
2681
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2682
            ->method('getNewInstance')
2683
            ->willReturn($object);
2684
2685
        $form = $this->createMock(Form::class);
2686
2687
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2688
            ->method('getClass')
2689
            ->willReturn('stdClass');
2690
2691
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2692
            ->method('getForm')
2693
            ->willReturn($form);
2694
2695
        $form->expects($this->once())
2696
            ->method('all')
2697
            ->willReturn(['field' => 'fielddata']);
2698
2699
        $form->expects($this->once())
2700
            ->method('isSubmitted')
2701
            ->willReturn(true);
2702
2703
        $form->expects($this->once())
2704
            ->method('isValid')
2705
            ->willReturn(false);
2706
2707
        $this->request->setMethod(Request::METHOD_POST);
2708
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2709
2710
        $formView = $this->createMock(FormView::class);
2711
        $form
2712
            ->method('createView')
2713
            ->willReturn($formView);
2714
2715
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...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...
2716
            ->method('trans')
2717
            ->willReturn('flash message');
2718
2719
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction());
2720
        $this->assertSame($this->admin, $this->parameters['admin']);
2721
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2722
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2723
        $this->assertSame('create', $this->parameters['action']);
2724
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2725
        $this->assertSame($object, $this->parameters['object']);
2726
        $this->assertSame([
2727
            'sonata_flash_error' => [0 => 'flash message'],
2728
        ], $this->session->getFlashBag()->all());
2729
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2730
    }
2731
2732
    public function testCreateActionWithPreview(): void
2733
    {
2734
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2735
            ->method('checkAccess')
2736
            ->with($this->equalTo('create'))
2737
            ->willReturn(true);
2738
2739
        $object = new \stdClass();
2740
2741
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2742
            ->method('getNewInstance')
2743
            ->willReturn($object);
2744
2745
        $form = $this->createMock(Form::class);
2746
2747
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2748
            ->method('getClass')
2749
            ->willReturn('stdClass');
2750
2751
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2752
            ->method('getForm')
2753
            ->willReturn($form);
2754
2755
        $form->expects($this->once())
2756
            ->method('all')
2757
            ->willReturn(['field' => 'fielddata']);
2758
2759
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2760
            ->method('supportsPreviewMode')
2761
            ->willReturn(true);
2762
2763
        $formView = $this->createMock(FormView::class);
2764
2765
        $form
2766
            ->method('createView')
2767
            ->willReturn($formView);
2768
2769
        $form->expects($this->once())
2770
            ->method('isSubmitted')
2771
            ->willReturn(true);
2772
2773
        $form->expects($this->once())
2774
            ->method('isValid')
2775
            ->willReturn(true);
2776
2777
        $this->request->setMethod(Request::METHOD_POST);
2778
        $this->request->request->set('btn_preview', 'Preview');
2779
2780
        $this->assertInstanceOf(Response::class, $this->controller->createAction());
2781
2782
        $this->assertSame($this->admin, $this->parameters['admin']);
2783
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2784
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2785
2786
        $this->assertSame('create', $this->parameters['action']);
2787
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2788
        $this->assertSame($object, $this->parameters['object']);
2789
2790
        $this->assertSame([], $this->session->getFlashBag()->all());
2791
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2792
    }
2793
2794
    public function testExportActionAccessDenied(): void
2795
    {
2796
        $this->expectException(AccessDeniedException::class);
2797
2798
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2799
            ->method('checkAccess')
2800
            ->with($this->equalTo('export'))
2801
            ->will($this->throwException(new AccessDeniedException()));
2802
2803
        $this->controller->exportAction($this->request);
2804
    }
2805
2806
    public function testExportActionWrongFormat(): void
2807
    {
2808
        $this->expectException(\RuntimeException::class);
2809
        $this->expectExceptionMessage(
2810
            'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`'
2811
        );
2812
2813
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
2823
            ->method('getClass')
2824
            ->willReturn('Foo');
2825
2826
        $this->request->query->set('format', 'csv');
2827
2828
        $this->controller->exportAction($this->request);
2829
    }
2830
2831
    public function testExportAction(): void
2832
    {
2833
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2834
            ->method('checkAccess')
2835
            ->with($this->equalTo('export'))
2836
            ->willReturn(true);
2837
2838
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getExportFormats')
2840
            ->willReturn(['json']);
2841
2842
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2843
2844
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2845
            ->method('getDataSourceIterator')
2846
            ->willReturn($dataSourceIterator);
2847
2848
        $this->request->query->set('format', 'json');
2849
2850
        $response = $this->controller->exportAction($this->request);
2851
        $this->assertInstanceOf(StreamedResponse::class, $response);
2852
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
2853
        $this->assertSame([], $this->session->getFlashBag()->all());
2854
    }
2855
2856
    public function testHistoryActionAccessDenied(): void
2857
    {
2858
        $this->expectException(AccessDeniedException::class);
2859
2860
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2861
            ->method('getObject')
2862
            ->willReturn(new \stdClass());
2863
2864
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2865
            ->method('checkAccess')
2866
            ->with($this->equalTo('history'))
2867
            ->will($this->throwException(new AccessDeniedException()));
2868
2869
        $this->controller->historyAction(null);
2870
    }
2871
2872
    public function testHistoryActionNotFoundException(): void
2873
    {
2874
        $this->expectException(NotFoundHttpException::class);
2875
2876
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2877
            ->method('getObject')
2878
            ->willReturn(false);
2879
2880
        $this->controller->historyAction(null);
2881
    }
2882
2883
    public function testHistoryActionNoReader(): void
2884
    {
2885
        $this->expectException(NotFoundHttpException::class);
2886
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2887
2888
        $this->request->query->set('id', 123);
2889
2890
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2891
            ->method('checkAccess')
2892
            ->with($this->equalTo('history'))
2893
            ->willReturn(true);
2894
2895
        $object = new \stdClass();
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2899
            ->willReturn($object);
2900
2901
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2902
            ->method('getClass')
2903
            ->willReturn('Foo');
2904
2905
        $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...
2906
            ->method('hasReader')
2907
            ->with($this->equalTo('Foo'))
2908
            ->willReturn(false);
2909
2910
        $this->controller->historyAction(null);
2911
    }
2912
2913
    public function testHistoryAction(): void
2914
    {
2915
        $this->request->query->set('id', 123);
2916
2917
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2918
            ->method('checkAccess')
2919
            ->with($this->equalTo('history'))
2920
            ->willReturn(true);
2921
2922
        $object = new \stdClass();
2923
2924
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2925
            ->method('getObject')
2926
            ->willReturn($object);
2927
2928
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2929
            ->method('getClass')
2930
            ->willReturn('Foo');
2931
2932
        $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...
2933
            ->method('hasReader')
2934
            ->with($this->equalTo('Foo'))
2935
            ->willReturn(true);
2936
2937
        $reader = $this->createMock(AuditReaderInterface::class);
2938
2939
        $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...
2940
            ->method('getReader')
2941
            ->with($this->equalTo('Foo'))
2942
            ->willReturn($reader);
2943
2944
        $reader->expects($this->once())
2945
            ->method('findRevisions')
2946
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2947
            ->willReturn([]);
2948
2949
        $this->assertInstanceOf(Response::class, $this->controller->historyAction(null));
2950
2951
        $this->assertSame($this->admin, $this->parameters['admin']);
2952
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2953
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2954
2955
        $this->assertSame('history', $this->parameters['action']);
2956
        $this->assertSame([], $this->parameters['revisions']);
2957
        $this->assertSame($object, $this->parameters['object']);
2958
2959
        $this->assertSame([], $this->session->getFlashBag()->all());
2960
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2961
    }
2962
2963
    public function testAclActionAclNotEnabled(): void
2964
    {
2965
        $this->expectException(NotFoundHttpException::class);
2966
        $this->expectExceptionMessage('ACL are not enabled for this admin');
2967
2968
        $this->controller->aclAction(null);
2969
    }
2970
2971
    public function testAclActionNotFoundException(): void
2972
    {
2973
        $this->expectException(NotFoundHttpException::class);
2974
2975
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2976
            ->method('isAclEnabled')
2977
            ->willReturn(true);
2978
2979
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2980
            ->method('getObject')
2981
            ->willReturn(false);
2982
2983
        $this->controller->aclAction(null);
2984
    }
2985
2986
    public function testAclActionAccessDenied(): void
2987
    {
2988
        $this->expectException(AccessDeniedException::class);
2989
2990
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2991
            ->method('isAclEnabled')
2992
            ->willReturn(true);
2993
2994
        $object = new \stdClass();
2995
2996
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2997
            ->method('getObject')
2998
            ->willReturn($object);
2999
3000
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3001
            ->method('checkAccess')
3002
            ->with($this->equalTo('acl'), $this->equalTo($object))
3003
            ->will($this->throwException(new AccessDeniedException()));
3004
3005
        $this->controller->aclAction(null);
3006
    }
3007
3008
    public function testAclAction(): void
3009
    {
3010
        $this->request->query->set('id', 123);
3011
3012
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3013
            ->method('isAclEnabled')
3014
            ->willReturn(true);
3015
3016
        $object = new \stdClass();
3017
3018
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3019
            ->method('getObject')
3020
            ->willReturn($object);
3021
3022
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->willReturn(true);
3025
3026
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3027
            ->method('getSecurityInformation')
3028
            ->willReturn([]);
3029
3030
        $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...
3031
            ->method('getMaskBuilderClass')
3032
            ->willReturn(AdminPermissionMap::class);
3033
3034
        $aclUsersForm = $this->getMockBuilder(Form::class)
3035
            ->disableOriginalConstructor()
3036
            ->getMock();
3037
3038
        $aclUsersForm->expects($this->once())
3039
            ->method('createView')
3040
            ->willReturn($this->createMock(FormView::class));
3041
3042
        $aclRolesForm = $this->getMockBuilder(Form::class)
3043
            ->disableOriginalConstructor()
3044
            ->getMock();
3045
3046
        $aclRolesForm->expects($this->once())
3047
            ->method('createView')
3048
            ->willReturn($this->createMock(FormView::class));
3049
3050
        $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...
3051
            ->method('createAclUsersForm')
3052
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3053
            ->willReturn($aclUsersForm);
3054
3055
        $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...
3056
            ->method('createAclRolesForm')
3057
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3058
            ->willReturn($aclRolesForm);
3059
3060
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3061
            ->disableOriginalConstructor()
3062
            ->getMock();
3063
3064
        $aclSecurityHandler
3065
            ->method('getObjectPermissions')
3066
            ->willReturn([]);
3067
3068
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3069
            ->method('getSecurityHandler')
3070
            ->willReturn($aclSecurityHandler);
3071
3072
        $this->assertInstanceOf(Response::class, $this->controller->aclAction(null));
3073
3074
        $this->assertSame($this->admin, $this->parameters['admin']);
3075
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3076
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3077
3078
        $this->assertSame('acl', $this->parameters['action']);
3079
        $this->assertSame([], $this->parameters['permissions']);
3080
        $this->assertSame($object, $this->parameters['object']);
3081
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3082
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3083
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3084
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3085
3086
        $this->assertSame([], $this->session->getFlashBag()->all());
3087
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3088
    }
3089
3090
    public function testAclActionInvalidUpdate(): void
3091
    {
3092
        $this->request->query->set('id', 123);
3093
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
3094
3095
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3096
            ->method('isAclEnabled')
3097
            ->willReturn(true);
3098
3099
        $object = new \stdClass();
3100
3101
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
3110
            ->method('getSecurityInformation')
3111
            ->willReturn([]);
3112
3113
        $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...
3114
            ->method('getMaskBuilderClass')
3115
            ->willReturn(AdminPermissionMap::class);
3116
3117
        $aclUsersForm = $this->getMockBuilder(Form::class)
3118
            ->disableOriginalConstructor()
3119
            ->getMock();
3120
3121
        $aclUsersForm->expects($this->once())
3122
            ->method('isValid')
3123
            ->willReturn(false);
3124
3125
        $aclUsersForm->expects($this->once())
3126
            ->method('createView')
3127
            ->willReturn($this->createMock(FormView::class));
3128
3129
        $aclRolesForm = $this->getMockBuilder(Form::class)
3130
            ->disableOriginalConstructor()
3131
            ->getMock();
3132
3133
        $aclRolesForm->expects($this->once())
3134
            ->method('createView')
3135
            ->willReturn($this->createMock(FormView::class));
3136
3137
        $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...
3138
            ->method('createAclUsersForm')
3139
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3140
            ->willReturn($aclUsersForm);
3141
3142
        $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...
3143
            ->method('createAclRolesForm')
3144
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3145
            ->willReturn($aclRolesForm);
3146
3147
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3148
            ->disableOriginalConstructor()
3149
            ->getMock();
3150
3151
        $aclSecurityHandler
3152
            ->method('getObjectPermissions')
3153
            ->willReturn([]);
3154
3155
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getSecurityHandler')
3157
            ->willReturn($aclSecurityHandler);
3158
3159
        $this->request->setMethod(Request::METHOD_POST);
3160
3161
        $this->assertInstanceOf(Response::class, $this->controller->aclAction(null));
3162
3163
        $this->assertSame($this->admin, $this->parameters['admin']);
3164
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3165
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3166
3167
        $this->assertSame('acl', $this->parameters['action']);
3168
        $this->assertSame([], $this->parameters['permissions']);
3169
        $this->assertSame($object, $this->parameters['object']);
3170
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3171
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3172
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3173
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3174
3175
        $this->assertSame([], $this->session->getFlashBag()->all());
3176
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3177
    }
3178
3179
    public function testAclActionSuccessfulUpdate(): void
3180
    {
3181
        $this->request->query->set('id', 123);
3182
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
3183
3184
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3185
            ->method('isAclEnabled')
3186
            ->willReturn(true);
3187
3188
        $object = new \stdClass();
3189
3190
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3191
            ->method('getObject')
3192
            ->willReturn($object);
3193
3194
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
3196
            ->willReturn(true);
3197
3198
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3199
            ->method('getSecurityInformation')
3200
            ->willReturn([]);
3201
3202
        $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...
3203
            ->method('getMaskBuilderClass')
3204
            ->willReturn(AdminPermissionMap::class);
3205
3206
        $aclUsersForm = $this->getMockBuilder(Form::class)
3207
            ->disableOriginalConstructor()
3208
            ->getMock();
3209
3210
        $aclUsersForm
3211
            ->method('createView')
3212
            ->willReturn($this->createMock(FormView::class));
3213
3214
        $aclRolesForm = $this->getMockBuilder(Form::class)
3215
            ->disableOriginalConstructor()
3216
            ->getMock();
3217
3218
        $aclRolesForm
3219
            ->method('createView')
3220
            ->willReturn($this->createMock(FormView::class));
3221
3222
        $aclRolesForm->expects($this->once())
3223
            ->method('isValid')
3224
            ->willReturn(true);
3225
3226
        $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...
3227
            ->method('createAclUsersForm')
3228
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3229
            ->willReturn($aclUsersForm);
3230
3231
        $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...
3232
            ->method('createAclRolesForm')
3233
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3234
            ->willReturn($aclRolesForm);
3235
3236
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3237
            ->disableOriginalConstructor()
3238
            ->getMock();
3239
3240
        $aclSecurityHandler
3241
            ->method('getObjectPermissions')
3242
            ->willReturn([]);
3243
3244
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3245
            ->method('getSecurityHandler')
3246
            ->willReturn($aclSecurityHandler);
3247
3248
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
3249
3250
        $this->request->setMethod(Request::METHOD_POST);
3251
3252
        $response = $this->controller->aclAction(null);
3253
3254
        $this->assertInstanceOf(RedirectResponse::class, $response);
3255
3256
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3257
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3258
    }
3259
3260
    public function testHistoryViewRevisionActionAccessDenied(): void
3261
    {
3262
        $this->expectException(AccessDeniedException::class);
3263
3264
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
3266
            ->willReturn(new \stdClass());
3267
3268
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3269
            ->method('checkAccess')
3270
            ->with($this->equalTo('historyViewRevision'))
3271
            ->will($this->throwException(new AccessDeniedException()));
3272
3273
        $this->controller->historyViewRevisionAction(null, null);
3274
    }
3275
3276
    public function testHistoryViewRevisionActionNotFoundException(): void
3277
    {
3278
        $this->expectException(NotFoundHttpException::class);
3279
        $this->expectExceptionMessage('unable to find the object with id: 123');
3280
3281
        $this->request->query->set('id', 123);
3282
3283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3284
            ->method('getObject')
3285
            ->willReturn(false);
3286
3287
        $this->controller->historyViewRevisionAction(null, null);
3288
    }
3289
3290
    public function testHistoryViewRevisionActionNoReader(): void
3291
    {
3292
        $this->expectException(NotFoundHttpException::class);
3293
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
3294
3295
        $this->request->query->set('id', 123);
3296
3297
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3298
            ->method('checkAccess')
3299
            ->with($this->equalTo('historyViewRevision'))
3300
            ->willReturn(true);
3301
3302
        $object = new \stdClass();
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
3306
            ->willReturn($object);
3307
3308
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3309
            ->method('getClass')
3310
            ->willReturn('Foo');
3311
3312
        $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...
3313
            ->method('hasReader')
3314
            ->with($this->equalTo('Foo'))
3315
            ->willReturn(false);
3316
3317
        $this->controller->historyViewRevisionAction(null, null);
3318
    }
3319
3320
    public function testHistoryViewRevisionActionNotFoundRevision(): void
3321
    {
3322
        $this->expectException(NotFoundHttpException::class);
3323
        $this->expectExceptionMessage(
3324
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
3325
        );
3326
3327
        $this->request->query->set('id', 123);
3328
3329
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
3331
            ->with($this->equalTo('historyViewRevision'))
3332
            ->willReturn(true);
3333
3334
        $object = new \stdClass();
3335
3336
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3337
            ->method('getObject')
3338
            ->willReturn($object);
3339
3340
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3341
            ->method('getClass')
3342
            ->willReturn('Foo');
3343
3344
        $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...
3345
            ->method('hasReader')
3346
            ->with($this->equalTo('Foo'))
3347
            ->willReturn(true);
3348
3349
        $reader = $this->createMock(AuditReaderInterface::class);
3350
3351
        $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...
3352
            ->method('getReader')
3353
            ->with($this->equalTo('Foo'))
3354
            ->willReturn($reader);
3355
3356
        $reader->expects($this->once())
3357
            ->method('find')
3358
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3359
            ->willReturn(null);
3360
3361
        $this->controller->historyViewRevisionAction(123, 456);
3362
    }
3363
3364
    public function testHistoryViewRevisionAction(): void
3365
    {
3366
        $this->request->query->set('id', 123);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
3370
            ->with($this->equalTo('historyViewRevision'))
3371
            ->willReturn(true);
3372
3373
        $object = new \stdClass();
3374
3375
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3376
            ->method('getObject')
3377
            ->willReturn($object);
3378
3379
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3380
            ->method('getClass')
3381
            ->willReturn('Foo');
3382
3383
        $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...
3384
            ->method('hasReader')
3385
            ->with($this->equalTo('Foo'))
3386
            ->willReturn(true);
3387
3388
        $reader = $this->createMock(AuditReaderInterface::class);
3389
3390
        $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...
3391
            ->method('getReader')
3392
            ->with($this->equalTo('Foo'))
3393
            ->willReturn($reader);
3394
3395
        $objectRevision = new \stdClass();
3396
        $objectRevision->revision = 456;
3397
3398
        $reader->expects($this->once())
3399
            ->method('find')
3400
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3401
            ->willReturn($objectRevision);
3402
3403
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3404
            ->method('setSubject')
3405
            ->with($this->equalTo($objectRevision))
3406
            ->willReturn(null);
3407
3408
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3409
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3410
            ->method('getShow')
3411
            ->willReturn($fieldDescriptionCollection);
3412
3413
        $this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction(123, 456));
3414
3415
        $this->assertSame($this->admin, $this->parameters['admin']);
3416
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3417
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3418
3419
        $this->assertSame('show', $this->parameters['action']);
3420
        $this->assertSame($objectRevision, $this->parameters['object']);
3421
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3422
3423
        $this->assertSame([], $this->session->getFlashBag()->all());
3424
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3425
    }
3426
3427
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3428
    {
3429
        $this->expectException(AccessDeniedException::class);
3430
3431
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3432
            ->method('checkAccess')
3433
            ->with($this->equalTo('historyCompareRevisions'))
3434
            ->will($this->throwException(new AccessDeniedException()));
3435
3436
        $this->controller->historyCompareRevisionsAction(null, null, null);
3437
    }
3438
3439
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3440
    {
3441
        $this->expectException(NotFoundHttpException::class);
3442
        $this->expectExceptionMessage('unable to find the object with id: 123');
3443
3444
        $this->request->query->set('id', 123);
3445
3446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3447
            ->method('checkAccess')
3448
            ->with($this->equalTo('historyCompareRevisions'))
3449
            ->willReturn(true);
3450
3451
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3452
            ->method('getObject')
3453
            ->willReturn(false);
3454
3455
        $this->controller->historyCompareRevisionsAction(null, null, null);
3456
    }
3457
3458
    public function testHistoryCompareRevisionsActionNoReader(): void
3459
    {
3460
        $this->expectException(NotFoundHttpException::class);
3461
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
3462
3463
        $this->request->query->set('id', 123);
3464
3465
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3466
            ->method('checkAccess')
3467
            ->with($this->equalTo('historyCompareRevisions'))
3468
            ->willReturn(true);
3469
3470
        $object = new \stdClass();
3471
3472
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3473
            ->method('getObject')
3474
            ->willReturn($object);
3475
3476
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3477
            ->method('getClass')
3478
            ->willReturn('Foo');
3479
3480
        $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...
3481
            ->method('hasReader')
3482
            ->with($this->equalTo('Foo'))
3483
            ->willReturn(false);
3484
3485
        $this->controller->historyCompareRevisionsAction(null, null, null);
3486
    }
3487
3488
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3489
    {
3490
        $this->expectException(NotFoundHttpException::class);
3491
        $this->expectExceptionMessage(
3492
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
3493
        );
3494
3495
        $this->request->query->set('id', 123);
3496
3497
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3498
            ->method('checkAccess')
3499
            ->with($this->equalTo('historyCompareRevisions'))
3500
            ->willReturn(true);
3501
3502
        $object = new \stdClass();
3503
3504
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getClass')
3510
            ->willReturn('Foo');
3511
3512
        $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...
3513
            ->method('hasReader')
3514
            ->with($this->equalTo('Foo'))
3515
            ->willReturn(true);
3516
3517
        $reader = $this->createMock(AuditReaderInterface::class);
3518
3519
        $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...
3520
            ->method('getReader')
3521
            ->with($this->equalTo('Foo'))
3522
            ->willReturn($reader);
3523
3524
        // once because it will not be found and therefore the second call won't be executed
3525
        $reader->expects($this->once())
3526
            ->method('find')
3527
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3528
            ->willReturn(null);
3529
3530
        $this->controller->historyCompareRevisionsAction(123, 456, 789);
3531
    }
3532
3533
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3534
    {
3535
        $this->expectException(NotFoundHttpException::class);
3536
        $this->expectExceptionMessage(
3537
            'unable to find the targeted object `123` from the revision `789` with classname : `Foo`'
3538
        );
3539
3540
        $this->request->query->set('id', 123);
3541
3542
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3543
            ->method('checkAccess')
3544
            ->with($this->equalTo('historyCompareRevisions'))
3545
            ->willReturn(true);
3546
3547
        $object = new \stdClass();
3548
3549
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3554
            ->method('getClass')
3555
            ->willReturn('Foo');
3556
3557
        $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...
3558
            ->method('hasReader')
3559
            ->with($this->equalTo('Foo'))
3560
            ->willReturn(true);
3561
3562
        $reader = $this->createMock(AuditReaderInterface::class);
3563
3564
        $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...
3565
            ->method('getReader')
3566
            ->with($this->equalTo('Foo'))
3567
            ->willReturn($reader);
3568
3569
        $objectRevision = new \stdClass();
3570
        $objectRevision->revision = 456;
3571
3572
        // first call should return, so the second call will throw an exception
3573
        $reader->expects($this->at(0))
3574
            ->method('find')
3575
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3576
            ->willReturn($objectRevision);
3577
3578
        $reader->expects($this->at(1))
3579
            ->method('find')
3580
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3581
            ->willReturn(null);
3582
3583
        $this->controller->historyCompareRevisionsAction(123, 456, 789);
3584
    }
3585
3586
    public function testHistoryCompareRevisionsActionAction(): void
3587
    {
3588
        $this->request->query->set('id', 123);
3589
3590
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3591
            ->method('checkAccess')
3592
            ->with($this->equalTo('historyCompareRevisions'))
3593
            ->willReturn(true);
3594
3595
        $object = new \stdClass();
3596
3597
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3598
            ->method('getObject')
3599
            ->willReturn($object);
3600
3601
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3602
            ->method('getClass')
3603
            ->willReturn('Foo');
3604
3605
        $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...
3606
            ->method('hasReader')
3607
            ->with($this->equalTo('Foo'))
3608
            ->willReturn(true);
3609
3610
        $reader = $this->createMock(AuditReaderInterface::class);
3611
3612
        $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...
3613
            ->method('getReader')
3614
            ->with($this->equalTo('Foo'))
3615
            ->willReturn($reader);
3616
3617
        $objectRevision = new \stdClass();
3618
        $objectRevision->revision = 456;
3619
3620
        $compareObjectRevision = new \stdClass();
3621
        $compareObjectRevision->revision = 789;
3622
3623
        $reader->expects($this->at(0))
3624
            ->method('find')
3625
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3626
            ->willReturn($objectRevision);
3627
3628
        $reader->expects($this->at(1))
3629
            ->method('find')
3630
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3631
            ->willReturn($compareObjectRevision);
3632
3633
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3634
            ->method('setSubject')
3635
            ->with($this->equalTo($objectRevision))
3636
            ->willReturn(null);
3637
3638
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3639
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3640
            ->method('getShow')
3641
            ->willReturn($fieldDescriptionCollection);
3642
3643
        $this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction(123, 456, 789));
3644
3645
        $this->assertSame($this->admin, $this->parameters['admin']);
3646
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3647
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3648
3649
        $this->assertSame('show', $this->parameters['action']);
3650
        $this->assertSame($objectRevision, $this->parameters['object']);
3651
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3652
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3653
3654
        $this->assertSame([], $this->session->getFlashBag()->all());
3655
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3656
    }
3657
3658
    public function testBatchActionWrongMethod(): void
3659
    {
3660
        $this->expectException(NotFoundHttpException::class);
3661
        $this->expectExceptionMessage('Invalid request method given "GET", POST expected');
3662
3663
        $this->controller->batchAction();
3664
    }
3665
3666
    /**
3667
     * NEXT_MAJOR: Remove this legacy group.
3668
     *
3669
     * @group legacy
3670
     */
3671
    public function testBatchActionActionNotDefined(): void
3672
    {
3673
        $this->expectException(\RuntimeException::class);
3674
        $this->expectExceptionMessage('The `foo` batch action is not defined');
3675
3676
        $batchActions = [];
3677
3678
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3679
            ->method('getBatchActions')
3680
            ->willReturn($batchActions);
3681
3682
        $this->request->setMethod(Request::METHOD_POST);
3683
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3684
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3685
3686
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3687
            ->method('getOption')
3688
            ->with('csrf_protection')
3689
            ->willReturn(true);
3690
3691
        $this->controller->batchAction();
3692
    }
3693
3694
    public function testBatchActionActionInvalidCsrfToken(): void
3695
    {
3696
        $this->request->setMethod(Request::METHOD_POST);
3697
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3698
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3699
3700
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3701
            ->method('getOption')
3702
            ->with('csrf_protection')
3703
            ->willReturn(true);
3704
3705
        try {
3706
            $this->controller->batchAction();
3707
        } catch (HttpException $e) {
3708
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3709
            $this->assertSame(400, $e->getStatusCode());
3710
        }
3711
    }
3712
3713
    public function testBatchActionActionWithDisabledCsrfProtection(): void
3714
    {
3715
        $this->request->setMethod(Request::METHOD_POST);
3716
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3717
3718
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3719
            ->method('getOption')
3720
            ->with('csrf_protection')
3721
            ->willReturn(false);
3722
3723
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3724
            ->method('getBatchActions')
3725
            ->willReturn(['foo' => ['label' => 'foo']]);
3726
3727
        $datagrid = $this->createMock(DatagridInterface::class);
3728
3729
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3730
            ->method('getDatagrid')
3731
            ->willReturn($datagrid);
3732
3733
        $datagrid->expects($this->once())
3734
            ->method('buildPager');
3735
3736
        $form = $this->createMock(FormInterface::class);
3737
3738
        $datagrid->expects($this->once())
3739
            ->method('getForm')
3740
            ->willReturn($form);
3741
3742
        $formView = $this->createMock(FormView::class);
3743
3744
        $form->expects($this->once())
3745
            ->method('createView')
3746
            ->willReturn($formView);
3747
3748
        $this->controller->batchAction();
3749
    }
3750
3751
    /**
3752
     * NEXT_MAJOR: Remove this legacy group.
3753
     *
3754
     * @group legacy
3755
     */
3756
    public function testBatchActionMethodNotExist(): void
3757
    {
3758
        $this->expectException(\RuntimeException::class);
3759
        $this->expectExceptionMessage(
3760
            'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable'
3761
        );
3762
3763
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3764
3765
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3766
            ->method('getBatchActions')
3767
            ->willReturn($batchActions);
3768
3769
        $datagrid = $this->createMock(DatagridInterface::class);
3770
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3771
            ->method('getDatagrid')
3772
            ->willReturn($datagrid);
3773
3774
        $this->request->setMethod(Request::METHOD_POST);
3775
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3776
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3777
3778
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3779
            ->method('getOption')
3780
            ->with('csrf_protection')
3781
            ->willReturn(true);
3782
3783
        $this->controller->batchAction();
3784
    }
3785
3786
    /**
3787
     * NEXT_MAJOR: Remove this legacy group.
3788
     *
3789
     * @group legacy
3790
     */
3791
    public function testBatchActionWithoutConfirmation(): void
3792
    {
3793
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3794
3795
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3796
            ->method('getBatchActions')
3797
            ->willReturn($batchActions);
3798
3799
        $datagrid = $this->createMock(DatagridInterface::class);
3800
3801
        $query = $this->createMock(ProxyQueryInterface::class);
3802
        $datagrid->expects($this->once())
3803
            ->method('getQuery')
3804
            ->willReturn($query);
3805
3806
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3807
            ->method('getDatagrid')
3808
            ->willReturn($datagrid);
3809
3810
        $modelManager = $this->createMock(ModelManagerInterface::class);
3811
3812
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3813
            ->method('checkAccess')
3814
            ->with($this->equalTo('batchDelete'))
3815
            ->willReturn(true);
3816
3817
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3818
            ->method('getModelManager')
3819
            ->willReturn($modelManager);
3820
3821
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3822
            ->method('getClass')
3823
            ->willReturn('Foo');
3824
3825
        $modelManager->expects($this->once())
3826
            ->method('addIdentifiersToQuery')
3827
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3828
            ->willReturn(true);
3829
3830
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3831
3832
        $this->request->setMethod(Request::METHOD_POST);
3833
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3834
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3835
3836
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3837
            ->method('getOption')
3838
            ->with('csrf_protection')
3839
            ->willReturn(true);
3840
3841
        $result = $this->controller->batchAction();
3842
3843
        $this->assertInstanceOf(RedirectResponse::class, $result);
3844
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3845
        $this->assertSame('list', $result->getTargetUrl());
3846
    }
3847
3848
    /**
3849
     * NEXT_MAJOR: Remove this legacy group.
3850
     *
3851
     * @group legacy
3852
     */
3853
    public function testBatchActionWithoutConfirmation2(): void
3854
    {
3855
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3856
3857
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3858
            ->method('getBatchActions')
3859
            ->willReturn($batchActions);
3860
3861
        $datagrid = $this->createMock(DatagridInterface::class);
3862
3863
        $query = $this->createMock(ProxyQueryInterface::class);
3864
        $datagrid->expects($this->once())
3865
            ->method('getQuery')
3866
            ->willReturn($query);
3867
3868
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3869
            ->method('getDatagrid')
3870
            ->willReturn($datagrid);
3871
3872
        $modelManager = $this->createMock(ModelManagerInterface::class);
3873
3874
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3875
            ->method('checkAccess')
3876
            ->with($this->equalTo('batchDelete'))
3877
            ->willReturn(true);
3878
3879
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3880
            ->method('getModelManager')
3881
            ->willReturn($modelManager);
3882
3883
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3884
            ->method('getClass')
3885
            ->willReturn('Foo');
3886
3887
        $modelManager->expects($this->once())
3888
            ->method('addIdentifiersToQuery')
3889
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3890
            ->willReturn(true);
3891
3892
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3893
3894
        $this->request->setMethod(Request::METHOD_POST);
3895
        $this->request->request->set('action', 'delete');
3896
        $this->request->request->set('idx', ['123', '456']);
3897
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3898
3899
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3900
            ->method('getOption')
3901
            ->with('csrf_protection')
3902
            ->willReturn(true);
3903
3904
        $result = $this->controller->batchAction();
3905
3906
        $this->assertInstanceOf(RedirectResponse::class, $result);
3907
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3908
        $this->assertSame('list', $result->getTargetUrl());
3909
    }
3910
3911
    /**
3912
     * NEXT_MAJOR: Remove this legacy group.
3913
     *
3914
     * @group legacy
3915
     */
3916
    public function testBatchActionWithConfirmation(): void
3917
    {
3918
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3919
3920
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3921
            ->method('getBatchActions')
3922
            ->willReturn($batchActions);
3923
3924
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3925
3926
        $this->request->setMethod(Request::METHOD_POST);
3927
        $this->request->request->set('data', json_encode($data));
3928
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3929
3930
        $datagrid = $this->createMock(DatagridInterface::class);
3931
3932
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3933
            ->method('getDatagrid')
3934
            ->willReturn($datagrid);
3935
3936
        $form = $this->getMockBuilder(Form::class)
3937
            ->disableOriginalConstructor()
3938
            ->getMock();
3939
3940
        $form->expects($this->once())
3941
            ->method('createView')
3942
            ->willReturn($this->createMock(FormView::class));
3943
3944
        $datagrid->expects($this->once())
3945
            ->method('getForm')
3946
            ->willReturn($form);
3947
3948
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3949
            ->method('getOption')
3950
            ->with('csrf_protection')
3951
            ->willReturn(true);
3952
3953
        $this->assertInstanceOf(Response::class, $this->controller->batchAction());
3954
3955
        $this->assertSame($this->admin, $this->parameters['admin']);
3956
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3957
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3958
3959
        $this->assertSame('list', $this->parameters['action']);
3960
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3961
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3962
        $this->assertSame($data, $this->parameters['data']);
3963
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3964
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3965
3966
        $this->assertSame([], $this->session->getFlashBag()->all());
3967
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3968
    }
3969
3970
    /**
3971
     * NEXT_MAJOR: Remove this legacy group.
3972
     *
3973
     * @group legacy
3974
     */
3975
    public function testBatchActionNonRelevantAction(): void
3976
    {
3977
        $controller = new BatchAdminController();
3978
        $controller->setContainer($this->container);
3979
3980
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3981
3982
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3983
            ->method('getBatchActions')
3984
            ->willReturn($batchActions);
3985
3986
        $datagrid = $this->createMock(DatagridInterface::class);
3987
3988
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3989
            ->method('getDatagrid')
3990
            ->willReturn($datagrid);
3991
3992
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3993
3994
        $this->request->setMethod(Request::METHOD_POST);
3995
        $this->request->request->set('action', 'foo');
3996
        $this->request->request->set('idx', ['789']);
3997
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3998
3999
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4000
            ->method('getOption')
4001
            ->with('csrf_protection')
4002
            ->willReturn(true);
4003
4004
        $result = $controller->batchAction();
4005
4006
        $this->assertInstanceOf(RedirectResponse::class, $result);
4007
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
4008
        $this->assertSame('list', $result->getTargetUrl());
4009
    }
4010
4011
    public function testBatchActionWithCustomConfirmationTemplate(): void
4012
    {
4013
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
4014
4015
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4016
            ->method('getBatchActions')
4017
            ->willReturn($batchActions);
4018
4019
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
4020
4021
        $this->request->setMethod(Request::METHOD_POST);
4022
        $this->request->request->set('data', json_encode($data));
4023
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4024
4025
        $datagrid = $this->createMock(DatagridInterface::class);
4026
4027
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4028
            ->method('getDatagrid')
4029
            ->willReturn($datagrid);
4030
4031
        $form = $this->createMock(Form::class);
4032
4033
        $form->expects($this->once())
4034
            ->method('createView')
4035
            ->willReturn($this->createMock(FormView::class));
4036
4037
        $datagrid->expects($this->once())
4038
            ->method('getForm')
4039
            ->willReturn($form);
4040
4041
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4042
            ->method('getOption')
4043
            ->with('csrf_protection')
4044
            ->willReturn(true);
4045
4046
        $this->controller->batchAction();
4047
4048
        $this->assertSame('custom_template.html.twig', $this->template);
4049
    }
4050
4051
    /**
4052
     * NEXT_MAJOR: Remove this legacy group.
4053
     *
4054
     * @group legacy
4055
     */
4056
    public function testBatchActionNonRelevantAction2(): void
4057
    {
4058
        $controller = new BatchAdminController();
4059
        $controller->setContainer($this->container);
4060
4061
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4062
4063
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4064
            ->method('getBatchActions')
4065
            ->willReturn($batchActions);
4066
4067
        $datagrid = $this->createMock(DatagridInterface::class);
4068
4069
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4070
            ->method('getDatagrid')
4071
            ->willReturn($datagrid);
4072
4073
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
4074
4075
        $this->request->setMethod(Request::METHOD_POST);
4076
        $this->request->request->set('action', 'foo');
4077
        $this->request->request->set('idx', ['999']);
4078
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4079
4080
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4081
            ->method('getOption')
4082
            ->with('csrf_protection')
4083
            ->willReturn(true);
4084
4085
        $result = $controller->batchAction();
4086
4087
        $this->assertInstanceOf(RedirectResponse::class, $result);
4088
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
4089
        $this->assertSame('list', $result->getTargetUrl());
4090
    }
4091
4092
    /**
4093
     * NEXT_MAJOR: Remove this legacy group.
4094
     *
4095
     * @group legacy
4096
     */
4097
    public function testBatchActionNoItems(): void
4098
    {
4099
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
4100
4101
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4102
            ->method('getBatchActions')
4103
            ->willReturn($batchActions);
4104
4105
        $datagrid = $this->createMock(DatagridInterface::class);
4106
4107
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4108
            ->method('getDatagrid')
4109
            ->willReturn($datagrid);
4110
4111
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
4112
4113
        $this->request->setMethod(Request::METHOD_POST);
4114
        $this->request->request->set('action', 'delete');
4115
        $this->request->request->set('idx', []);
4116
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4117
4118
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4119
            ->method('getOption')
4120
            ->with('csrf_protection')
4121
            ->willReturn(true);
4122
4123
        $result = $this->controller->batchAction();
4124
4125
        $this->assertInstanceOf(RedirectResponse::class, $result);
4126
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
4127
        $this->assertSame('list', $result->getTargetUrl());
4128
    }
4129
4130
    /**
4131
     * NEXT_MAJOR: Remove this legacy group.
4132
     *
4133
     * @group legacy
4134
     */
4135
    public function testBatchActionNoItemsEmptyQuery(): void
4136
    {
4137
        $controller = new BatchAdminController();
4138
        $controller->setContainer($this->container);
4139
4140
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4141
4142
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4143
            ->method('getBatchActions')
4144
            ->willReturn($batchActions);
4145
4146
        $datagrid = $this->createMock(DatagridInterface::class);
4147
4148
        $query = $this->createMock(ProxyQueryInterface::class);
4149
        $datagrid->expects($this->once())
4150
            ->method('getQuery')
4151
            ->willReturn($query);
4152
4153
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4154
            ->method('getDatagrid')
4155
            ->willReturn($datagrid);
4156
4157
        $modelManager = $this->createMock(ModelManagerInterface::class);
4158
4159
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4160
            ->method('getModelManager')
4161
            ->willReturn($modelManager);
4162
4163
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4164
            ->method('getClass')
4165
            ->willReturn('Foo');
4166
4167
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4168
            ->method('getOption')
4169
            ->with('csrf_protection')
4170
            ->willReturn(true);
4171
4172
        $this->request->setMethod(Request::METHOD_POST);
4173
        $this->request->request->set('action', 'bar');
4174
        $this->request->request->set('idx', []);
4175
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4176
4177
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
4178
        $result = $controller->batchAction();
4179
4180
        $this->assertInstanceOf(Response::class, $result);
4181
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
4182
    }
4183
4184
    /**
4185
     * NEXT_MAJOR: Remove this legacy group.
4186
     *
4187
     * @group legacy
4188
     */
4189
    public function testBatchActionWithRequesData(): void
4190
    {
4191
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4192
4193
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4194
            ->method('getBatchActions')
4195
            ->willReturn($batchActions);
4196
4197
        $datagrid = $this->createMock(DatagridInterface::class);
4198
4199
        $query = $this->createMock(ProxyQueryInterface::class);
4200
        $datagrid->expects($this->once())
4201
            ->method('getQuery')
4202
            ->willReturn($query);
4203
4204
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4205
            ->method('getDatagrid')
4206
            ->willReturn($datagrid);
4207
4208
        $modelManager = $this->createMock(ModelManagerInterface::class);
4209
4210
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4211
            ->method('checkAccess')
4212
            ->with($this->equalTo('batchDelete'))
4213
            ->willReturn(true);
4214
4215
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4216
            ->method('getModelManager')
4217
            ->willReturn($modelManager);
4218
4219
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
4220
            ->method('getClass')
4221
            ->willReturn('Foo');
4222
4223
        $modelManager->expects($this->once())
4224
            ->method('addIdentifiersToQuery')
4225
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
4226
            ->willReturn(true);
4227
4228
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
4229
4230
        $this->request->setMethod(Request::METHOD_POST);
4231
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
4232
        $this->request->request->set('foo', 'bar');
4233
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4234
4235
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4236
            ->method('getOption')
4237
            ->with('csrf_protection')
4238
            ->willReturn(true);
4239
4240
        $result = $this->controller->batchAction();
4241
4242
        $this->assertInstanceOf(RedirectResponse::class, $result);
4243
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
4244
        $this->assertSame('list', $result->getTargetUrl());
4245
        $this->assertSame('bar', $this->request->request->get('foo'));
4246
    }
4247
4248
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
4249
    {
4250
        $this->expectException(
4251
            \LogicException::class
4252
        );
4253
        $this->expectExceptionMessage(
4254
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
4255
        );
4256
        $this->controller->doesNotExist();
0 ignored issues
show
Documentation Bug introduced by
The method doesNotExist does not exist on object<Sonata\AdminBundl...troller\CRUDController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
4257
    }
4258
4259
    /**
4260
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
4261
     */
4262
    public function testRenderIsDeprecated(): void
4263
    {
4264
        $this->controller->render('toto.html.twig');
0 ignored issues
show
Deprecated Code introduced by
The method Sonata\AdminBundle\Contr...RUDController::render() has been deprecated with message: since sonata-project/admin-bundle 3.27, to be removed in 4.0. Use Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
4265
    }
4266
4267
    public function getCsrfProvider()
4268
    {
4269
        return $this->csrfProvider;
4270
    }
4271
4272
    public function getToStringValues()
4273
    {
4274
        return [
4275
            ['', ''],
4276
            ['Foo', 'Foo'],
4277
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
4278
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
4279
        ];
4280
    }
4281
4282
    private function assertLoggerLogsModelManagerException($subject, string $method): void
4283
    {
4284
        $exception = new ModelManagerException(
4285
            $message = 'message',
4286
            1234,
4287
            new \Exception($previousExceptionMessage = 'very useful message')
4288
        );
4289
4290
        $subject->expects($this->once())
4291
            ->method($method)
4292
            ->willReturnCallback(static function () use ($exception): void {
4293
                throw $exception;
4294
            });
4295
4296
        $this->logger->expects($this->once())
4297
            ->method('error')
4298
            ->with($message, [
4299
                'exception' => $exception,
4300
                'previous_exception_message' => $previousExceptionMessage,
4301
            ]);
4302
    }
4303
4304
    private function expectTranslate(
4305
        string $id,
4306
        array $parameters = [],
4307
        ?string $domain = null,
4308
        ?string $locale = null
4309
    ): void {
4310
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...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...
4311
            ->method('trans')
4312
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
4313
            ->willReturn($id);
4314
    }
4315
}
4316