Completed
Pull Request — master (#6093)
by Mathieu
02:39
created

CRUDControllerTest::createController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use PHPUnit\Framework\MockObject\MockObject;
17
use PHPUnit\Framework\TestCase;
18
use Psr\Log\LoggerInterface;
19
use Sonata\AdminBundle\Admin\AdminInterface;
20
use Sonata\AdminBundle\Admin\BreadcrumbsBuilder;
21
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
22
use Sonata\AdminBundle\Admin\Pool;
23
use Sonata\AdminBundle\Bridge\Exporter\AdminExporter;
24
use Sonata\AdminBundle\Controller\CRUDController;
25
use Sonata\AdminBundle\Datagrid\DatagridInterface;
26
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
27
use Sonata\AdminBundle\Exception\LockException;
28
use Sonata\AdminBundle\Exception\ModelManagerException;
29
use Sonata\AdminBundle\Model\AuditManagerInterface;
30
use Sonata\AdminBundle\Model\AuditReaderInterface;
31
use Sonata\AdminBundle\Model\ModelManagerInterface;
32
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
33
use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface;
34
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
35
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
36
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
37
use Sonata\AdminBundle\Util\AdminObjectAclData;
38
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
39
use Sonata\Exporter\Exporter;
40
use Sonata\Exporter\Source\SourceIteratorInterface;
41
use Sonata\Exporter\Writer\JsonWriter;
42
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
43
use Symfony\Component\DependencyInjection\Container;
44
use Symfony\Component\DependencyInjection\ContainerInterface;
45
use Symfony\Component\Form\Form;
46
use Symfony\Component\Form\FormError;
47
use Symfony\Component\Form\FormRenderer;
48
use Symfony\Component\Form\FormView;
49
use Symfony\Component\HttpFoundation\JsonResponse;
50
use Symfony\Component\HttpFoundation\RedirectResponse;
51
use Symfony\Component\HttpFoundation\Request;
52
use Symfony\Component\HttpFoundation\RequestStack;
53
use Symfony\Component\HttpFoundation\Response;
54
use Symfony\Component\HttpFoundation\Session\Session;
55
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
56
use Symfony\Component\HttpFoundation\StreamedResponse;
57
use Symfony\Component\HttpKernel\Exception\HttpException;
58
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
59
use Symfony\Component\HttpKernel\KernelInterface;
60
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
61
use Symfony\Component\Security\Csrf\CsrfToken;
62
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
63
use Symfony\Contracts\Translation\TranslatorInterface;
64
use Twig\Environment;
65
66
/**
67
 * Test for CRUDController.
68
 *
69
 * @author Andrej Hudec <[email protected]>
70
 */
71
class CRUDControllerTest extends TestCase
72
{
73
    use ExpectDeprecationTrait;
74
75
    /**
76
     * @var CRUDController
77
     */
78
    private $controller;
79
80
    /**
81
     * @var Request
82
     */
83
    private $request;
84
85
    /**
86
     * @var AdminInterface
87
     */
88
    private $admin;
89
90
    /**
91
     * @var TemplateRegistryInterface
92
     */
93
    private $templateRegistry;
94
95
    /**
96
     * @var Pool
97
     */
98
    private $pool;
99
100
    /**
101
     * @var array
102
     */
103
    private $parameters;
104
105
    /**
106
     * @var Session
107
     */
108
    private $session;
109
110
    /**
111
     * @var AuditManagerInterface
112
     */
113
    private $auditManager;
114
115
    /**
116
     * @var ContainerInterface
117
     */
118
    private $container;
119
120
    /**
121
     * @var AdminObjectAclManipulator
122
     */
123
    private $adminObjectAclManipulator;
124
125
    /**
126
     * @var string
127
     */
128
    private $template;
129
130
    /**
131
     * @var array
132
     */
133
    private $protectedTestedMethods;
134
135
    /**
136
     * @var CsrfTokenManagerInterface
137
     */
138
    private $csrfProvider;
139
140
    /**
141
     * @var KernelInterface
142
     */
143
    private $kernel;
144
145
    /**
146
     * @var TranslatorInterface
147
     */
148
    private $translator;
149
150
    /**
151
     * @var Exporter
152
     */
153
    private $exporter;
154
155
    /**
156
     * @var LoggerInterface|MockObject
157
     */
158
    private $logger;
159
160
    /**
161
     * {@inheritdoc}
162
     */
163
    protected function setUp(): void
164
    {
165
        $this->container = new Container();
166
        $this->request = new Request();
167
        $this->pool = new Pool($this->container, 'title', 'logo.png');
168
        $this->pool->setAdminServiceIds(['foo.admin']);
169
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
170
        $this->admin = $this->createMock(AdminInterface::class);
171
        $this->translator = $this->createMock(TranslatorInterface::class);
172
        $this->parameters = [];
173
        $this->template = '';
174
175
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
176
177
        $this->session = new Session(new MockArraySessionStorage());
178
179
        $this->exporter = new Exporter([new JsonWriter(sys_get_temp_dir().'/sonataadmin/export.json')]);
180
181
        $this->auditManager = $this->createMock(AuditManagerInterface::class);
182
183
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
184
            ->disableOriginalConstructor()
185
            ->getMock();
186
187
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
188
            ->getMock();
189
190
        $this->csrfProvider
191
            ->method('getToken')
192
            ->willReturnCallback(static function (string $intention): CsrfToken {
193
                return new CsrfToken($intention, sprintf('csrf-token-123_%s', $intention));
194
            });
195
196
        $this->csrfProvider
197
            ->method('isTokenValid')
198
            ->willReturnCallback(static function (CsrfToken $token): bool {
199
                return $token->getValue() === sprintf('csrf-token-123_%s', $token->getId());
200
            });
201
202
        $this->logger = $this->createMock(LoggerInterface::class);
203
204
        $requestStack = new RequestStack();
205
        $requestStack->push($this->request);
206
207
        $this->kernel = $this->createMock(KernelInterface::class);
208
209
        $this->container->set('sonata.admin.pool', $this->pool);
210
        $this->container->set('request_stack', $requestStack);
211
        $this->container->set('foo.admin', $this->admin);
212
        $this->container->set('foo.admin.template_registry', $this->templateRegistry->reveal());
213
        $this->container->set('twig', $this->createTwig());
214
        $this->container->set('session', $this->session);
215
        $this->container->set('sonata.exporter.exporter', $this->exporter);
216
        $this->container->set('sonata.admin.audit.manager', $this->auditManager);
217
        $this->container->set('sonata.admin.object.manipulator.acl.admin', $this->adminObjectAclManipulator);
218
        $this->container->set('security.csrf.token_manager', $this->csrfProvider);
219
        $this->container->set('logger', $this->logger);
220
        $this->container->set('kernel', $this->kernel);
221
        $this->container->set('translator', $this->translator);
222
        $this->container->set('sonata.admin.breadcrumbs_builder', new BreadcrumbsBuilder([]));
223
224
        $this->container->setParameter(
225
            'security.role_hierarchy.roles',
226
            ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']]
227
        );
228
        $this->container->setParameter('sonata.admin.security.acl_user_manager', null);
229
230
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
231
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
232
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
233
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
234
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
235
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
236
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
237
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
238
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
239
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
240
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
241
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
242
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
243
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
244
245
        $this->admin
246
            ->method('getIdParameter')
247
            ->willReturn('id');
248
249
        $this->admin
250
            ->method('getAccessMapping')
251
            ->willReturn([]);
252
253
        $this->admin
254
            ->method('generateUrl')
255
            ->willReturnCallback(
256
                static function ($name, array $parameters = []) {
257
                    $result = $name;
258
                    if (!empty($parameters)) {
259
                        $result .= '?'.http_build_query($parameters);
260
                    }
261
262
                    return $result;
263
                }
264
            );
265
266
        $this->admin
267
            ->method('generateObjectUrl')
268
            ->willReturnCallback(
269
                static function (string $name, $object, array $parameters = []): string {
270
                    $result = sprintf('%s_%s', \get_class($object), $name);
271
                    if (!empty($parameters)) {
272
                        $result .= '?'.http_build_query($parameters);
273
                    }
274
275
                    return $result;
276
                }
277
            );
278
279
        $this->admin
280
            ->method('getCode')
281
            ->willReturn('foo.admin');
282
283
        $this->controller = $this->createController();
284
285
        // Make some methods public to test them
286
        $testedMethods = [
287
            'renderJson',
288
            'isXmlHttpRequest',
289
            'configure',
290
            'getBaseTemplate',
291
            'redirectTo',
292
            'addFlash',
293
        ];
294
        foreach ($testedMethods as $testedMethod) {
295
            $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
296
            $method->setAccessible(true);
297
            $this->protectedTestedMethods[$testedMethod] = $method;
298
        }
299
    }
300
301
    public function testRenderJson1(): void
302
    {
303
        $data = ['example' => '123', 'foo' => 'bar'];
304
305
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
306
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
307
308
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
309
        $this->assertSame(json_encode($data), $response->getContent());
310
    }
311
312
    public function testRenderJson2(): void
313
    {
314
        $data = ['example' => '123', 'foo' => 'bar'];
315
316
        $this->request->headers->set('Content-Type', 'multipart/form-data');
317
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
318
319
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
320
        $this->assertSame(json_encode($data), $response->getContent());
321
    }
322
323
    public function testRenderJsonAjax(): void
324
    {
325
        $data = ['example' => '123', 'foo' => 'bar'];
326
327
        $this->request->attributes->set('_xml_http_request', true);
328
        $this->request->headers->set('Content-Type', 'multipart/form-data');
329
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
330
331
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
332
        $this->assertSame(json_encode($data), $response->getContent());
333
    }
334
335
    public function testIsXmlHttpRequest(): void
336
    {
337
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
338
339
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
340
341
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
342
343
        $this->request->headers->remove('X-Requested-With');
344
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
345
346
        $this->request->attributes->set('_xml_http_request', true);
347
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
348
    }
349
350
    public function testConfigure(): void
351
    {
352
        $uniqueId = '';
353
354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
355
            ->method('setUniqid')
356
            ->willReturnCallback(static function (string $uniqid) use (&$uniqueId): void {
357
                $uniqueId = $uniqid;
358
            });
359
360
        $this->request->query->set('uniqid', '123456');
361
        $this->protectedTestedMethods['configure']->invoke($this->controller);
362
363
        $this->assertSame('123456', $uniqueId);
364
    }
365
366
    public function testConfigureChild(): void
367
    {
368
        $uniqueId = '';
369
370
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
377
            ->method('isChild')
378
            ->willReturn(true);
379
380
        $adminParent = $this->getMockBuilder(AdminInterface::class)
381
            ->disableOriginalConstructor()
382
            ->getMock();
383
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
507
            ->method('checkAccess')
508
            ->with($this->equalTo('list'))
509
            ->will($this->throwException(new AccessDeniedException()));
510
511
        $this->controller->listAction($this->request);
512
    }
513
514
    public function testPreList(): void
515
    {
516
        $datagrid = $this->createMock(DatagridInterface::class);
0 ignored issues
show
Unused Code introduced by
$datagrid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
517
518
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
524
            ->method('checkAccess')
525
            ->with($this->equalTo('list'));
526
527
        $controller = $this->createController(PreCRUDController::class);
528
529
        $response = $controller->listAction($this->request);
530
        $this->assertInstanceOf(Response::class, $response);
531
        $this->assertSame('preList called', $response->getContent());
532
    }
533
534
    public function testListAction(): void
535
    {
536
        $datagrid = $this->createMock(DatagridInterface::class);
537
538
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
544
            ->method('checkAccess')
545
            ->with($this->equalTo('list'));
546
547
        $form = $this->getMockBuilder(Form::class)
548
            ->disableOriginalConstructor()
549
            ->getMock();
550
551
        $form->expects($this->once())
552
            ->method('createView')
553
            ->willReturn($this->createMock(FormView::class));
554
555
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
556
            ->method('getDatagrid')
557
            ->willReturn($datagrid);
558
559
        $datagrid->expects($this->once())
560
            ->method('getForm')
561
            ->willReturn($form);
562
563
        $this->parameters = [];
564
        $this->assertInstanceOf(Response::class, $this->controller->listAction($this->request));
565
566
        $this->assertSame($this->admin, $this->parameters['admin']);
567
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
568
569
        $this->assertSame('list', $this->parameters['action']);
570
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
571
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
572
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
573
        $this->assertSame([], $this->session->getFlashBag()->all());
574
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
575
    }
576
577
    public function testBatchActionDeleteAccessDenied(): void
578
    {
579
        $this->expectException(AccessDeniedException::class);
580
581
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
582
            ->method('checkAccess')
583
            ->with($this->equalTo('batchDelete'))
584
            ->will($this->throwException(new AccessDeniedException()));
585
586
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
587
    }
588
589
    public function testBatchActionDelete(): void
590
    {
591
        $modelManager = $this->createMock(ModelManagerInterface::class);
592
593
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
602
            ->method('getFilterParameters')
603
            ->willReturn(['foo' => 'bar']);
604
605
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
606
607
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
608
609
        $this->assertInstanceOf(RedirectResponse::class, $result);
610
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
611
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
612
    }
613
614
    public function testBatchActionDeleteWithModelManagerException(): void
615
    {
616
        $modelManager = $this->createMock(ModelManagerInterface::class);
617
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
618
619
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
648
            ->method('getModelManager')
649
            ->willReturn($modelManager);
650
651
        $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...
652
            ->method('isDebug')
653
            ->willReturn(true);
654
655
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
656
    }
657
658
    public function testShowActionNotFoundException(): void
659
    {
660
        $this->expectException(NotFoundHttpException::class);
661
662
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
663
            ->method('getObject')
664
            ->willReturn(null);
665
666
        $this->controller->showAction($this->request);
667
    }
668
669
    public function testShowActionAccessDenied(): void
670
    {
671
        $this->expectException(AccessDeniedException::class);
672
673
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
678
            ->method('checkAccess')
679
            ->with($this->equalTo('show'))
680
            ->will($this->throwException(new AccessDeniedException()));
681
682
        $this->controller->showAction($this->request);
683
    }
684
685
    public function testPreShow(): void
686
    {
687
        $object = new \stdClass();
688
        $object->foo = 123456;
689
690
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
695
            ->method('checkAccess')
696
            ->with($this->equalTo('show'));
697
698
        $this->container->set('foo.admin', $this->admin);
699
        $controller = $this->createController(PreCRUDController::class);
700
701
        $response = $controller->showAction($this->request);
702
        $this->assertInstanceOf(Response::class, $response);
703
        $this->assertSame('preShow called: 123456', $response->getContent());
704
    }
705
706
    public function testShowAction(): void
707
    {
708
        $object = new \stdClass();
709
710
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
715
            ->method('checkAccess')
716
            ->with($this->equalTo('show'));
717
718
        $show = new FieldDescriptionCollection();
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getShow')
722
            ->willReturn($show);
723
724
        $this->assertInstanceOf(Response::class, $this->controller->showAction($this->request));
725
726
        $this->assertSame($this->admin, $this->parameters['admin']);
727
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
728
729
        $this->assertSame('show', $this->parameters['action']);
730
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
731
        $this->assertSame($object, $this->parameters['object']);
732
733
        $this->assertSame([], $this->session->getFlashBag()->all());
734
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
735
    }
736
737
    /**
738
     * @dataProvider getRedirectToTests
739
     */
740
    public function testRedirectTo(
741
        string $expected,
742
        string $route,
743
        array $queryParams,
744
        array $requestParams,
745
        bool $hasActiveSubclass
746
    ): void {
747
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
748
            ->method('hasActiveSubclass')
749
            ->willReturn($hasActiveSubclass);
750
751
        $object = new \stdClass();
752
753
        foreach ($queryParams as $key => $value) {
754
            $this->request->query->set($key, $value);
755
        }
756
757
        foreach ($requestParams as $key => $value) {
758
            $this->request->request->set($key, $value);
759
        }
760
761
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
767
            ->method('hasAccess')
768
            ->with($this->equalTo($route))
769
            ->willReturn(true);
770
771
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
772
        $this->assertInstanceOf(RedirectResponse::class, $response);
773
        $this->assertSame($expected, $response->getTargetUrl());
774
    }
775
776
    public function testRedirectToWithObject(): void
777
    {
778
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
779
            ->method('hasActiveSubclass')
780
            ->willReturn(false);
781
782
        $object = new \stdClass();
783
784
        $this->admin->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
790
            ->method('hasAccess')
791
            ->with($this->equalTo('edit'), $object)
792
            ->willReturn(false);
793
794
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
795
        $this->assertInstanceOf(RedirectResponse::class, $response);
796
        $this->assertSame('list', $response->getTargetUrl());
797
    }
798
799
    public function getRedirectToTests()
800
    {
801
        return [
802
            ['stdClass_edit', 'edit', [], [], false],
803
            ['list', 'list', ['btn_update_and_list' => true], [], false],
804
            ['list', 'list', ['btn_create_and_list' => true], [], false],
805
            ['create', 'create', ['btn_create_and_create' => true], [], false],
806
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
807
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
808
        ];
809
    }
810
811
    public function testDeleteActionNotFoundException(): void
812
    {
813
        $this->expectException(NotFoundHttpException::class);
814
815
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
816
            ->method('getObject')
817
            ->willReturn(null);
818
819
        $this->controller->deleteAction($this->request);
820
    }
821
822
    public function testDeleteActionAccessDenied(): void
823
    {
824
        $this->expectException(AccessDeniedException::class);
825
826
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
831
            ->method('checkAccess')
832
            ->with($this->equalTo('delete'))
833
            ->will($this->throwException(new AccessDeniedException()));
834
835
        $this->controller->deleteAction($this->request);
836
    }
837
838
    public function testPreDelete(): void
839
    {
840
        $object = new \stdClass();
841
        $object->foo = 123456;
842
843
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
848
            ->method('checkAccess')
849
            ->with($this->equalTo('delete'));
850
851
        $controller = $this->createController(PreCRUDController::class);
852
853
        $response = $controller->deleteAction($this->request);
854
        $this->assertInstanceOf(Response::class, $response);
855
        $this->assertSame('preDelete called: 123456', $response->getContent());
856
    }
857
858
    public function testDeleteAction(): void
859
    {
860
        $object = new \stdClass();
861
862
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
867
            ->method('checkAccess')
868
            ->with($this->equalTo('delete'));
869
870
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
871
872
        $this->assertSame($this->admin, $this->parameters['admin']);
873
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
874
875
        $this->assertSame('delete', $this->parameters['action']);
876
        $this->assertSame($object, $this->parameters['object']);
877
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
878
879
        $this->assertSame([], $this->session->getFlashBag()->all());
880
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
881
    }
882
883
    public function testDeleteActionNoCsrfToken(): void
884
    {
885
        $this->csrfProvider = null;
886
887
        $object = new \stdClass();
888
889
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
921
            ->method('checkAccess')
922
            ->with($this->equalTo('delete'));
923
924
        $this->request->setMethod(Request::METHOD_DELETE);
925
926
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
927
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
928
929
        $response = $this->controller->deleteAction($this->request);
930
931
        $this->assertInstanceOf(Response::class, $response);
932
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
933
        $this->assertSame([], $this->session->getFlashBag()->all());
934
    }
935
936
    public function testDeleteActionAjaxSuccess2(): void
937
    {
938
        $object = new \stdClass();
939
940
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1006
            ->method('delete')
1007
            ->willReturnCallback(static function (): void {
1008
                throw new ModelManagerException();
1009
            });
1010
1011
        $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...
1012
            ->method('isDebug')
1013
            ->willReturn(true);
1014
1015
        $this->request->setMethod(Request::METHOD_DELETE);
1016
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1017
1018
        $this->controller->deleteAction($this->request);
1019
    }
1020
1021
    /**
1022
     * @dataProvider getToStringValues
1023
     */
1024
    public function testDeleteActionSuccess1(string $expectedToStringValue, string $toStringValue): void
1025
    {
1026
        $object = new \stdClass();
1027
1028
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1033
            ->method('toString')
1034
            ->with($this->equalTo($object))
1035
            ->willReturn($toStringValue);
1036
1037
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1038
1039
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1040
            ->method('checkAccess')
1041
            ->with($this->equalTo('delete'));
1042
1043
        $this->request->setMethod(Request::METHOD_DELETE);
1044
1045
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1046
1047
        $response = $this->controller->deleteAction($this->request);
1048
1049
        $this->assertInstanceOf(RedirectResponse::class, $response);
1050
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1051
        $this->assertSame('list', $response->getTargetUrl());
1052
    }
1053
1054
    /**
1055
     * @dataProvider getToStringValues
1056
     */
1057
    public function testDeleteActionSuccess2(string $expectedToStringValue, string $toStringValue): void
1058
    {
1059
        $object = new \stdClass();
1060
1061
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1106
            ->method('toString')
1107
            ->with($this->equalTo($object))
1108
            ->willReturn($toStringValue);
1109
1110
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1111
1112
        $this->request->setMethod(Request::METHOD_POST);
1113
        $this->request->request->set('_method', Request::METHOD_DELETE);
1114
1115
        $this->controller = $this->createController();
1116
        $response = $this->controller->deleteAction($this->request);
1117
1118
        $this->assertInstanceOf(RedirectResponse::class, $response);
1119
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1120
        $this->assertSame('list', $response->getTargetUrl());
1121
    }
1122
1123
    public function testDeleteActionWrongRequestMethod(): void
1124
    {
1125
        $object = new \stdClass();
1126
1127
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1132
            ->method('checkAccess')
1133
            ->with($this->equalTo('delete'));
1134
1135
        //without POST request parameter "_method" should not be used as real REST method
1136
        $this->request->query->set('_method', Request::METHOD_DELETE);
1137
1138
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction($this->request));
1139
1140
        $this->assertSame($this->admin, $this->parameters['admin']);
1141
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1142
1143
        $this->assertSame('delete', $this->parameters['action']);
1144
        $this->assertSame($object, $this->parameters['object']);
1145
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1146
1147
        $this->assertSame([], $this->session->getFlashBag()->all());
1148
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1149
    }
1150
1151
    /**
1152
     * @dataProvider getToStringValues
1153
     */
1154
    public function testDeleteActionError(string $expectedToStringValue, string $toStringValue): void
1155
    {
1156
        $object = new \stdClass();
1157
1158
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1167
            ->method('toString')
1168
            ->with($this->equalTo($object))
1169
            ->willReturn($toStringValue);
1170
1171
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1172
1173
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1174
1175
        $this->request->setMethod(Request::METHOD_DELETE);
1176
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1177
1178
        $response = $this->controller->deleteAction($this->request);
1179
1180
        $this->assertInstanceOf(RedirectResponse::class, $response);
1181
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1182
        $this->assertSame('list', $response->getTargetUrl());
1183
    }
1184
1185
    public function testDeleteActionInvalidCsrfToken(): void
1186
    {
1187
        $object = new \stdClass();
1188
1189
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1194
            ->method('checkAccess')
1195
            ->with($this->equalTo('delete'));
1196
1197
        $this->request->setMethod(Request::METHOD_POST);
1198
        $this->request->request->set('_method', Request::METHOD_DELETE);
1199
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1200
1201
        try {
1202
            $this->controller->deleteAction($this->request);
1203
        } catch (HttpException $e) {
1204
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1205
            $this->assertSame(400, $e->getStatusCode());
1206
        }
1207
    }
1208
1209
    public function testEditActionNotFoundException(): void
1210
    {
1211
        $this->expectException(NotFoundHttpException::class);
1212
1213
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1214
            ->method('getObject')
1215
            ->willReturn(null);
1216
1217
        $this->controller->editAction($this->request);
1218
    }
1219
1220
    public function testEditActionAccessDenied(): void
1221
    {
1222
        $this->expectException(AccessDeniedException::class);
1223
1224
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1229
            ->method('checkAccess')
1230
            ->with($this->equalTo('edit'))
1231
            ->will($this->throwException(new AccessDeniedException()));
1232
1233
        $this->controller->editAction($this->request);
1234
    }
1235
1236
    public function testPreEdit(): void
1237
    {
1238
        $object = new \stdClass();
1239
        $object->foo = 123456;
1240
1241
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1246
            ->method('checkAccess')
1247
            ->with($this->equalTo('edit'));
1248
1249
        $controller = $this->createController(PreCRUDController::class);
1250
1251
        $response = $controller->editAction($this->request);
1252
        $this->assertInstanceOf(Response::class, $response);
1253
        $this->assertSame('preEdit called: 123456', $response->getContent());
1254
    }
1255
1256
    public function testEditAction(): void
1257
    {
1258
        $object = new \stdClass();
1259
1260
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1265
            ->method('checkAccess')
1266
            ->with($this->equalTo('edit'));
1267
1268
        $form = $this->createMock(Form::class);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getForm')
1272
            ->willReturn($form);
1273
1274
        $formView = $this->createMock(FormView::class);
1275
1276
        $form
1277
            ->method('createView')
1278
            ->willReturn($formView);
1279
1280
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1281
1282
        $this->assertSame($this->admin, $this->parameters['admin']);
1283
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1284
1285
        $this->assertSame('edit', $this->parameters['action']);
1286
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1287
        $this->assertSame($object, $this->parameters['object']);
1288
        $this->assertSame([], $this->session->getFlashBag()->all());
1289
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1290
    }
1291
1292
    /**
1293
     * @dataProvider getToStringValues
1294
     */
1295
    public function testEditActionSuccess(string $expectedToStringValue, string $toStringValue): void
1296
    {
1297
        $object = new \stdClass();
1298
1299
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1317
            ->method('hasAccess')
1318
            ->with($this->equalTo('edit'))
1319
            ->willReturn(true);
1320
1321
        $form = $this->createMock(Form::class);
1322
1323
        $form->expects($this->once())
1324
            ->method('getData')
1325
            ->willReturn($object);
1326
1327
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1328
            ->method('getForm')
1329
            ->willReturn($form);
1330
1331
        $form->expects($this->once())
1332
            ->method('isSubmitted')
1333
            ->willReturn(true);
1334
1335
        $form->expects($this->once())
1336
            ->method('isValid')
1337
            ->willReturn(true);
1338
1339
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1340
            ->method('toString')
1341
            ->with($this->equalTo($object))
1342
            ->willReturn($toStringValue);
1343
1344
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1345
1346
        $this->request->setMethod(Request::METHOD_POST);
1347
1348
        $response = $this->controller->editAction($this->request);
1349
1350
        $this->assertInstanceOf(RedirectResponse::class, $response);
1351
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1352
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1353
    }
1354
1355
    /**
1356
     * @dataProvider getToStringValues
1357
     */
1358
    public function testEditActionError(string $expectedToStringValue, string $toStringValue): void
1359
    {
1360
        $object = new \stdClass();
1361
1362
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1367
            ->method('checkAccess')
1368
            ->with($this->equalTo('edit'));
1369
1370
        $form = $this->createMock(Form::class);
1371
1372
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1373
            ->method('getForm')
1374
            ->willReturn($form);
1375
1376
        $form->expects($this->once())
1377
            ->method('isSubmitted')
1378
            ->willReturn(true);
1379
1380
        $form->expects($this->once())
1381
            ->method('isValid')
1382
            ->willReturn(false);
1383
1384
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1385
            ->method('toString')
1386
            ->with($this->equalTo($object))
1387
            ->willReturn($toStringValue);
1388
1389
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1390
1391
        $this->request->setMethod(Request::METHOD_POST);
1392
1393
        $formView = $this->createMock(FormView::class);
1394
1395
        $form
1396
            ->method('createView')
1397
            ->willReturn($formView);
1398
1399
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1400
1401
        $this->assertSame($this->admin, $this->parameters['admin']);
1402
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1403
1404
        $this->assertSame('edit', $this->parameters['action']);
1405
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1406
        $this->assertSame($object, $this->parameters['object']);
1407
1408
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1409
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1410
    }
1411
1412
    public function testEditActionAjaxSuccess(): void
1413
    {
1414
        $object = new \stdClass();
1415
1416
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1425
            ->method('checkAccess')
1426
            ->with($this->equalTo('edit'));
1427
1428
        $form = $this->createMock(Form::class);
1429
1430
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1431
            ->method('getForm')
1432
            ->willReturn($form);
1433
1434
        $form->expects($this->once())
1435
            ->method('isSubmitted')
1436
            ->willReturn(true);
1437
1438
        $form->expects($this->once())
1439
            ->method('isValid')
1440
            ->willReturn(true);
1441
1442
        $form->expects($this->once())
1443
            ->method('getData')
1444
            ->willReturn($object);
1445
1446
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1447
            ->method('getNormalizedIdentifier')
1448
            ->with($this->equalTo($object))
1449
            ->willReturn('foo_normalized');
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->willReturn('foo');
1454
1455
        $this->request->setMethod(Request::METHOD_POST);
1456
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1457
        $this->request->headers->set('Accept', 'application/json');
1458
1459
        $response = $this->controller->editAction($this->request);
1460
1461
        $this->assertInstanceOf(Response::class, $response);
1462
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1463
        $this->assertSame([], $this->session->getFlashBag()->all());
1464
    }
1465
1466
    public function testEditActionAjaxError(): void
1467
    {
1468
        $object = new \stdClass();
1469
1470
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1475
            ->method('checkAccess')
1476
            ->with($this->equalTo('edit'));
1477
1478
        $form = $this->createMock(Form::class);
1479
1480
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1481
            ->method('getForm')
1482
            ->willReturn($form);
1483
1484
        $form->expects($this->once())
1485
            ->method('isSubmitted')
1486
            ->willReturn(true);
1487
1488
        $form->expects($this->once())
1489
            ->method('isValid')
1490
            ->willReturn(false);
1491
1492
        $formError = $this->createMock(FormError::class);
1493
        $formError->expects($this->atLeastOnce())
1494
            ->method('getMessage')
1495
            ->willReturn('Form error message');
1496
1497
        $form->expects($this->once())
1498
            ->method('getErrors')
1499
            ->with(true)
1500
            ->willReturn([$formError]);
1501
1502
        $this->request->setMethod(Request::METHOD_POST);
1503
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1504
        $this->request->headers->set('Accept', 'application/json');
1505
1506
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction($this->request));
1507
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
1508
    }
1509
1510
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1511
    {
1512
        $object = new \stdClass();
1513
1514
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1519
            ->method('checkAccess')
1520
            ->with($this->equalTo('edit'));
1521
1522
        $form = $this->createMock(Form::class);
1523
1524
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1525
            ->method('getForm')
1526
            ->willReturn($form);
1527
1528
        $form->expects($this->once())
1529
            ->method('isSubmitted')
1530
            ->willReturn(true);
1531
1532
        $form->expects($this->once())
1533
            ->method('isValid')
1534
            ->willReturn(false);
1535
1536
        $this->request->setMethod(Request::METHOD_POST);
1537
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1538
1539
        $formView = $this->createMock(FormView::class);
1540
        $form
1541
            ->method('createView')
1542
            ->willReturn($formView);
1543
1544
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction($this->request));
1545
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
1546
    }
1547
1548
    /**
1549
     * @dataProvider getToStringValues
1550
     */
1551
    public function testEditActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
1552
    {
1553
        $object = new \stdClass();
1554
1555
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1564
            ->method('getClass')
1565
            ->willReturn(\stdClass::class);
1566
1567
        $form = $this->createMock(Form::class);
1568
1569
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1570
            ->method('getForm')
1571
            ->willReturn($form);
1572
1573
        $form->expects($this->once())
1574
            ->method('isValid')
1575
            ->willReturn(true);
1576
1577
        $form->expects($this->once())
1578
            ->method('getData')
1579
            ->willReturn($object);
1580
1581
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1582
            ->method('toString')
1583
            ->with($this->equalTo($object))
1584
            ->willReturn($toStringValue);
1585
1586
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1587
1588
        $form->expects($this->once())
1589
            ->method('isSubmitted')
1590
            ->willReturn(true);
1591
        $this->request->setMethod(Request::METHOD_POST);
1592
1593
        $formView = $this->createMock(FormView::class);
1594
1595
        $form
1596
            ->method('createView')
1597
            ->willReturn($formView);
1598
1599
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1600
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1601
1602
        $this->assertSame($this->admin, $this->parameters['admin']);
1603
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1604
1605
        $this->assertSame('edit', $this->parameters['action']);
1606
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1607
        $this->assertSame($object, $this->parameters['object']);
1608
1609
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1610
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1611
    }
1612
1613
    public function testEditActionWithPreview(): void
1614
    {
1615
        $object = new \stdClass();
1616
1617
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1618
            ->method('getObject')
1619
            ->willReturn($object);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1623
            ->with($this->equalTo('edit'));
1624
1625
        $form = $this->createMock(Form::class);
1626
1627
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1632
            ->method('supportsPreviewMode')
1633
            ->willReturn(true);
1634
1635
        $formView = $this->createMock(FormView::class);
1636
1637
        $form
1638
            ->method('createView')
1639
            ->willReturn($formView);
1640
1641
        $form->expects($this->once())
1642
            ->method('isSubmitted')
1643
            ->willReturn(true);
1644
1645
        $form->expects($this->once())
1646
            ->method('isValid')
1647
            ->willReturn(true);
1648
1649
        $this->request->setMethod(Request::METHOD_POST);
1650
        $this->request->request->set('btn_preview', 'Preview');
1651
1652
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1653
1654
        $this->assertSame($this->admin, $this->parameters['admin']);
1655
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1656
1657
        $this->assertSame('edit', $this->parameters['action']);
1658
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1659
        $this->assertSame($object, $this->parameters['object']);
1660
1661
        $this->assertSame([], $this->session->getFlashBag()->all());
1662
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1663
    }
1664
1665
    public function testEditActionWithLockException(): void
1666
    {
1667
        $object = new \stdClass();
1668
        $class = \get_class($object);
1669
1670
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1679
            ->method('getClass')
1680
            ->willReturn($class);
1681
1682
        $form = $this->createMock(Form::class);
1683
1684
        $form
1685
            ->method('isValid')
1686
            ->willReturn(true);
1687
1688
        $form->expects($this->once())
1689
            ->method('getData')
1690
            ->willReturn($object);
1691
1692
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1693
            ->method('getForm')
1694
            ->willReturn($form);
1695
1696
        $form
1697
            ->method('isSubmitted')
1698
            ->willReturn(true);
1699
        $this->request->setMethod(Request::METHOD_POST);
1700
1701
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1706
            ->method('toString')
1707
            ->with($this->equalTo($object))
1708
            ->willReturn($class);
1709
1710
        $formView = $this->createMock(FormView::class);
1711
1712
        $form
1713
            ->method('createView')
1714
            ->willReturn($formView);
1715
1716
        $this->expectTranslate('flash_lock_error', [
1717
            '%name%' => $class,
1718
            '%link_start%' => '<a href="stdClass_edit">',
1719
            '%link_end%' => '</a>',
1720
        ], 'SonataAdminBundle');
1721
1722
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1723
    }
1724
1725
    public function testCreateActionAccessDenied(): void
1726
    {
1727
        $this->expectException(AccessDeniedException::class);
1728
1729
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1730
            ->method('checkAccess')
1731
            ->with($this->equalTo('create'))
1732
            ->will($this->throwException(new AccessDeniedException()));
1733
1734
        $this->controller->createAction($this->request);
1735
    }
1736
1737
    public function testPreCreate(): void
1738
    {
1739
        $object = new \stdClass();
1740
        $object->foo = 123456;
1741
1742
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1751
            ->method('getNewInstance')
1752
            ->willReturn($object);
1753
1754
        $controller = $this->createController(PreCRUDController::class);
1755
1756
        $response = $controller->createAction($this->request);
1757
        $this->assertInstanceOf(Response::class, $response);
1758
        $this->assertSame('preCreate called: 123456', $response->getContent());
1759
    }
1760
1761
    public function testCreateAction(): void
1762
    {
1763
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1764
            ->method('checkAccess')
1765
            ->with($this->equalTo('create'));
1766
1767
        $object = new \stdClass();
1768
1769
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1774
            ->method('getNewInstance')
1775
            ->willReturn($object);
1776
1777
        $form = $this->createMock(Form::class);
1778
1779
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1780
            ->method('getForm')
1781
            ->willReturn($form);
1782
1783
        $formView = $this->createMock(FormView::class);
1784
1785
        $form
1786
            ->method('createView')
1787
            ->willReturn($formView);
1788
1789
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
1790
1791
        $this->assertSame($this->admin, $this->parameters['admin']);
1792
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1793
1794
        $this->assertSame('create', $this->parameters['action']);
1795
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1796
        $this->assertSame($object, $this->parameters['object']);
1797
1798
        $this->assertSame([], $this->session->getFlashBag()->all());
1799
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1800
    }
1801
1802
    /**
1803
     * @dataProvider getToStringValues
1804
     */
1805
    public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void
1806
    {
1807
        $object = new \stdClass();
1808
1809
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1810
            ->method('checkAccess')
1811
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
1812
                if ('edit' === $name) {
1813
                    return;
1814
                }
1815
1816
                if ('create' !== $name) {
1817
                    throw new AccessDeniedException();
1818
                }
1819
1820
                if (null === $objectIn) {
1821
                    return;
1822
                }
1823
1824
                if ($objectIn !== $object) {
1825
                    throw new AccessDeniedException();
1826
                }
1827
            });
1828
1829
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1844
            ->method('create')
1845
            ->willReturnArgument(0);
1846
1847
        $form = $this->createMock(Form::class);
1848
1849
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1854
            ->method('getForm')
1855
            ->willReturn($form);
1856
1857
        $form->expects($this->once())
1858
            ->method('isSubmitted')
1859
            ->willReturn(true);
1860
1861
        $form->expects($this->once())
1862
            ->method('isValid')
1863
            ->willReturn(true);
1864
1865
        $form->expects($this->once())
1866
            ->method('getData')
1867
            ->willReturn($object);
1868
1869
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1870
            ->method('toString')
1871
            ->with($this->equalTo($object))
1872
            ->willReturn($toStringValue);
1873
1874
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1875
1876
        $this->request->setMethod(Request::METHOD_POST);
1877
1878
        $response = $this->controller->createAction($this->request);
1879
1880
        $this->assertInstanceOf(RedirectResponse::class, $response);
1881
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1882
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1883
    }
1884
1885
    public function testCreateActionAccessDenied2(): void
1886
    {
1887
        $this->expectException(AccessDeniedException::class);
1888
1889
        $object = new \stdClass();
1890
1891
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1892
            ->method('checkAccess')
1893
            ->willReturnCallback(static function (string $name, $object = null): void {
1894
                if ('create' !== $name) {
1895
                    throw new AccessDeniedException();
1896
                }
1897
                if (null === $object) {
1898
                    return;
1899
                }
1900
1901
                throw new AccessDeniedException();
1902
            });
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getNewInstance')
1906
            ->willReturn($object);
1907
1908
        $form = $this->createMock(Form::class);
1909
1910
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1915
            ->method('getForm')
1916
            ->willReturn($form);
1917
1918
        $form->expects($this->once())
1919
            ->method('isSubmitted')
1920
            ->willReturn(true);
1921
1922
        $form->expects($this->once())
1923
            ->method('getData')
1924
            ->willReturn($object);
1925
1926
        $form->expects($this->once())
1927
            ->method('isValid')
1928
            ->willReturn(true);
1929
1930
        $this->request->setMethod(Request::METHOD_POST);
1931
1932
        $this->controller->createAction($this->request);
1933
    }
1934
1935
    /**
1936
     * @dataProvider getToStringValues
1937
     */
1938
    public function testCreateActionError(string $expectedToStringValue, string $toStringValue): void
1939
    {
1940
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1941
            ->method('checkAccess')
1942
            ->with($this->equalTo('create'));
1943
1944
        $object = new \stdClass();
1945
1946
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1951
            ->method('getNewInstance')
1952
            ->willReturn($object);
1953
1954
        $form = $this->createMock(Form::class);
1955
1956
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1957
            ->method('getForm')
1958
            ->willReturn($form);
1959
1960
        $form->expects($this->once())
1961
            ->method('isSubmitted')
1962
            ->willReturn(true);
1963
1964
        $form->expects($this->once())
1965
            ->method('isValid')
1966
            ->willReturn(false);
1967
1968
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1969
            ->method('toString')
1970
            ->with($this->equalTo($object))
1971
            ->willReturn($toStringValue);
1972
1973
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1974
1975
        $this->request->setMethod(Request::METHOD_POST);
1976
1977
        $formView = $this->createMock(FormView::class);
1978
1979
        $form
1980
            ->method('createView')
1981
            ->willReturn($formView);
1982
1983
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
1984
1985
        $this->assertSame($this->admin, $this->parameters['admin']);
1986
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1987
1988
        $this->assertSame('create', $this->parameters['action']);
1989
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1990
        $this->assertSame($object, $this->parameters['object']);
1991
1992
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
1993
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1994
    }
1995
1996
    /**
1997
     * @dataProvider getToStringValues
1998
     */
1999
    public function testCreateActionWithModelManagerException(string $expectedToStringValue, string $toStringValue): void
2000
    {
2001
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2006
            ->method('getClass')
2007
            ->willReturn(\stdClass::class);
2008
2009
        $object = new \stdClass();
2010
2011
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2012
            ->method('getNewInstance')
2013
            ->willReturn($object);
2014
2015
        $form = $this->createMock(Form::class);
2016
2017
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2018
            ->method('getForm')
2019
            ->willReturn($form);
2020
2021
        $form->expects($this->once())
2022
            ->method('isValid')
2023
            ->willReturn(true);
2024
2025
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2026
            ->method('toString')
2027
            ->with($this->equalTo($object))
2028
            ->willReturn($toStringValue);
2029
2030
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2031
2032
        $form->expects($this->once())
2033
            ->method('isSubmitted')
2034
            ->willReturn(true);
2035
2036
        $form->expects($this->once())
2037
            ->method('getData')
2038
            ->willReturn($object);
2039
2040
        $this->request->setMethod(Request::METHOD_POST);
2041
2042
        $formView = $this->createMock(FormView::class);
2043
2044
        $form
2045
            ->method('createView')
2046
            ->willReturn($formView);
2047
2048
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2049
2050
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2051
2052
        $this->assertSame($this->admin, $this->parameters['admin']);
2053
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2054
2055
        $this->assertSame('create', $this->parameters['action']);
2056
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2057
        $this->assertSame($object, $this->parameters['object']);
2058
2059
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2060
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2061
    }
2062
2063
    public function testCreateActionAjaxSuccess(): void
2064
    {
2065
        $object = new \stdClass();
2066
2067
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2068
            ->method('checkAccess')
2069
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
2070
                if ('create' !== $name) {
2071
                    throw new AccessDeniedException();
2072
                }
2073
2074
                if (null === $objectIn) {
2075
                    return;
2076
                }
2077
2078
                if ($objectIn !== $object) {
2079
                    throw new AccessDeniedException();
2080
                }
2081
            });
2082
2083
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2088
            ->method('create')
2089
            ->willReturnArgument(0);
2090
2091
        $form = $this->createMock(Form::class);
2092
2093
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2094
            ->method('getForm')
2095
            ->willReturn($form);
2096
2097
        $form->expects($this->once())
2098
            ->method('isSubmitted')
2099
            ->willReturn(true);
2100
2101
        $form->expects($this->once())
2102
            ->method('isValid')
2103
            ->willReturn(true);
2104
2105
        $form->expects($this->once())
2106
            ->method('getData')
2107
            ->willReturn($object);
2108
2109
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2119
            ->method('toString')
2120
            ->willReturn('foo');
2121
2122
        $this->request->setMethod(Request::METHOD_POST);
2123
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2124
        $this->request->headers->set('Accept', 'application/json');
2125
2126
        $response = $this->controller->createAction($this->request);
2127
2128
        $this->assertInstanceOf(Response::class, $response);
2129
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2130
        $this->assertSame([], $this->session->getFlashBag()->all());
2131
    }
2132
2133
    public function testCreateActionAjaxError(): void
2134
    {
2135
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2136
            ->method('checkAccess')
2137
            ->with($this->equalTo('create'));
2138
2139
        $object = new \stdClass();
2140
2141
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2142
            ->method('getNewInstance')
2143
            ->willReturn($object);
2144
2145
        $form = $this->createMock(Form::class);
2146
2147
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2152
            ->method('getForm')
2153
            ->willReturn($form);
2154
2155
        $form->expects($this->once())
2156
            ->method('isSubmitted')
2157
            ->willReturn(true);
2158
2159
        $form->expects($this->once())
2160
            ->method('isValid')
2161
            ->willReturn(false);
2162
2163
        $formError = $this->createMock(FormError::class);
2164
        $formError->expects($this->atLeastOnce())
2165
            ->method('getMessage')
2166
            ->willReturn('Form error message');
2167
2168
        $form->expects($this->once())
2169
            ->method('getErrors')
2170
            ->with(true)
2171
            ->willReturn([$formError]);
2172
2173
        $this->request->setMethod(Request::METHOD_POST);
2174
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2175
        $this->request->headers->set('Accept', 'application/json');
2176
2177
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request));
2178
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
2179
    }
2180
2181
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2182
    {
2183
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2184
            ->method('checkAccess')
2185
            ->with($this->equalTo('create'));
2186
2187
        $object = new \stdClass();
2188
2189
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2190
            ->method('getNewInstance')
2191
            ->willReturn($object);
2192
2193
        $form = $this->createMock(Form::class);
2194
2195
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2200
            ->method('getForm')
2201
            ->willReturn($form);
2202
2203
        $form->expects($this->once())
2204
            ->method('isSubmitted')
2205
            ->willReturn(true);
2206
2207
        $form->expects($this->once())
2208
            ->method('isValid')
2209
            ->willReturn(false);
2210
2211
        $this->request->setMethod(Request::METHOD_POST);
2212
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2213
2214
        $formView = $this->createMock(FormView::class);
2215
        $form
2216
            ->method('createView')
2217
            ->willReturn($formView);
2218
2219
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request));
2220
        $this->assertSame(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode());
2221
    }
2222
2223
    public function testCreateActionWithPreview(): void
2224
    {
2225
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2226
            ->method('checkAccess')
2227
            ->with($this->equalTo('create'));
2228
2229
        $object = new \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\AdminInterface>.

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

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

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

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

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

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

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

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

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

Loading history...
2246
            ->method('supportsPreviewMode')
2247
            ->willReturn(true);
2248
2249
        $formView = $this->createMock(FormView::class);
2250
2251
        $form
2252
            ->method('createView')
2253
            ->willReturn($formView);
2254
2255
        $form->expects($this->once())
2256
            ->method('isSubmitted')
2257
            ->willReturn(true);
2258
2259
        $form->expects($this->once())
2260
            ->method('isValid')
2261
            ->willReturn(true);
2262
2263
        $this->request->setMethod(Request::METHOD_POST);
2264
        $this->request->request->set('btn_preview', 'Preview');
2265
2266
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2267
2268
        $this->assertSame($this->admin, $this->parameters['admin']);
2269
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2270
2271
        $this->assertSame('create', $this->parameters['action']);
2272
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2273
        $this->assertSame($object, $this->parameters['object']);
2274
2275
        $this->assertSame([], $this->session->getFlashBag()->all());
2276
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2277
    }
2278
2279
    public function testExportActionAccessDenied(): void
2280
    {
2281
        $this->expectException(AccessDeniedException::class);
2282
2283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2284
            ->method('checkAccess')
2285
            ->with($this->equalTo('export'))
2286
            ->will($this->throwException(new AccessDeniedException()));
2287
2288
        $this->controller->exportAction($this->request);
2289
    }
2290
2291
    public function testExportActionWrongFormat(): void
2292
    {
2293
        $this->expectException(\RuntimeException::class);
2294
        $this->expectExceptionMessage(
2295
            'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`'
2296
        );
2297
2298
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2307
            ->method('getClass')
2308
            ->willReturn('Foo');
2309
2310
        $this->request->query->set('format', 'csv');
2311
2312
        $this->controller->exportAction($this->request);
2313
    }
2314
2315
    public function testExportAction(): void
2316
    {
2317
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2326
            ->method('getClass')
2327
            ->willReturn(\stdClass::class);
2328
2329
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2330
2331
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2332
            ->method('getDataSourceIterator')
2333
            ->willReturn($dataSourceIterator);
2334
2335
        $this->request->query->set('format', 'json');
2336
2337
        $response = $this->controller->exportAction($this->request);
2338
        $this->assertInstanceOf(StreamedResponse::class, $response);
2339
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
2340
        $this->assertSame([], $this->session->getFlashBag()->all());
2341
    }
2342
2343
    public function testHistoryActionAccessDenied(): void
2344
    {
2345
        $this->expectException(AccessDeniedException::class);
2346
2347
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2352
            ->method('checkAccess')
2353
            ->with($this->equalTo('history'))
2354
            ->will($this->throwException(new AccessDeniedException()));
2355
2356
        $this->controller->historyAction($this->request);
2357
    }
2358
2359
    public function testHistoryActionNotFoundException(): void
2360
    {
2361
        $this->expectException(NotFoundHttpException::class);
2362
2363
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2364
            ->method('getObject')
2365
            ->willReturn(null);
2366
2367
        $this->controller->historyAction($this->request);
2368
    }
2369
2370
    public function testHistoryActionNoReader(): void
2371
    {
2372
        $this->expectException(NotFoundHttpException::class);
2373
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2374
2375
        $this->request->query->set('id', 123);
2376
2377
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2378
            ->method('checkAccess')
2379
            ->with($this->equalTo('history'));
2380
2381
        $object = new \stdClass();
2382
2383
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2392
            ->method('hasReader')
2393
            ->with($this->equalTo('Foo'))
2394
            ->willReturn(false);
2395
2396
        $this->controller->historyAction($this->request);
2397
    }
2398
2399
    public function testHistoryAction(): void
2400
    {
2401
        $this->request->query->set('id', 123);
2402
2403
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2404
            ->method('checkAccess')
2405
            ->with($this->equalTo('history'));
2406
2407
        $object = new \stdClass();
2408
2409
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2418
            ->method('hasReader')
2419
            ->with($this->equalTo('Foo'))
2420
            ->willReturn(true);
2421
2422
        $reader = $this->createMock(AuditReaderInterface::class);
2423
2424
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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

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

Loading history...
2425
            ->method('getReader')
2426
            ->with($this->equalTo('Foo'))
2427
            ->willReturn($reader);
2428
2429
        $reader->expects($this->once())
2430
            ->method('findRevisions')
2431
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2432
            ->willReturn([]);
2433
2434
        $this->assertInstanceOf(Response::class, $this->controller->historyAction($this->request));
2435
2436
        $this->assertSame($this->admin, $this->parameters['admin']);
2437
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2438
2439
        $this->assertSame('history', $this->parameters['action']);
2440
        $this->assertSame([], $this->parameters['revisions']);
2441
        $this->assertSame($object, $this->parameters['object']);
2442
2443
        $this->assertSame([], $this->session->getFlashBag()->all());
2444
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2445
    }
2446
2447
    public function testAclActionAclNotEnabled(): void
2448
    {
2449
        $this->expectException(NotFoundHttpException::class);
2450
        $this->expectExceptionMessage('ACL are not enabled for this admin');
2451
2452
        $this->controller->aclAction($this->request);
2453
    }
2454
2455
    public function testAclActionNotFoundException(): void
2456
    {
2457
        $this->expectException(NotFoundHttpException::class);
2458
2459
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2464
            ->method('getObject')
2465
            ->willReturn(null);
2466
2467
        $this->controller->aclAction($this->request);
2468
    }
2469
2470
    public function testAclActionAccessDenied(): void
2471
    {
2472
        $this->expectException(AccessDeniedException::class);
2473
2474
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2475
            ->method('isAclEnabled')
2476
            ->willReturn(true);
2477
2478
        $object = new \stdClass();
2479
2480
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2485
            ->method('checkAccess')
2486
            ->with($this->equalTo('acl'), $this->equalTo($object))
2487
            ->will($this->throwException(new AccessDeniedException()));
2488
2489
        $this->controller->aclAction($this->request);
2490
    }
2491
2492
    public function testAclAction(): void
2493
    {
2494
        $this->request->query->set('id', 123);
2495
2496
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2511
            ->method('getSecurityInformation')
2512
            ->willReturn([]);
2513
2514
        $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...
2515
            ->method('getMaskBuilderClass')
2516
            ->willReturn(AdminPermissionMap::class);
2517
2518
        $aclUsersForm = $this->getMockBuilder(Form::class)
2519
            ->disableOriginalConstructor()
2520
            ->getMock();
2521
2522
        $aclUsersForm->expects($this->once())
2523
            ->method('createView')
2524
            ->willReturn($this->createMock(FormView::class));
2525
2526
        $aclRolesForm = $this->getMockBuilder(Form::class)
2527
            ->disableOriginalConstructor()
2528
            ->getMock();
2529
2530
        $aclRolesForm->expects($this->once())
2531
            ->method('createView')
2532
            ->willReturn($this->createMock(FormView::class));
2533
2534
        $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...
2535
            ->method('createAclUsersForm')
2536
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2537
            ->willReturn($aclUsersForm);
2538
2539
        $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...
2540
            ->method('createAclRolesForm')
2541
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2542
            ->willReturn($aclRolesForm);
2543
2544
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2545
2546
        $aclSecurityHandler
2547
            ->method('getObjectPermissions')
2548
            ->willReturn([]);
2549
2550
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2551
            ->method('getSecurityHandler')
2552
            ->willReturn($aclSecurityHandler);
2553
2554
        $controller = $this->createController();
2555
2556
        $this->assertInstanceOf(Response::class, $controller->aclAction($this->request));
2557
2558
        $this->assertSame($this->admin, $this->parameters['admin']);
2559
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2560
2561
        $this->assertSame('acl', $this->parameters['action']);
2562
        $this->assertSame([], $this->parameters['permissions']);
2563
        $this->assertSame($object, $this->parameters['object']);
2564
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2565
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2566
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2567
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2568
2569
        $this->assertSame([], $this->session->getFlashBag()->all());
2570
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2571
    }
2572
2573
    public function testAclActionInvalidUpdate(): void
2574
    {
2575
        $this->request->query->set('id', 123);
2576
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2577
2578
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2579
            ->method('isAclEnabled')
2580
            ->willReturn(true);
2581
2582
        $object = new \stdClass();
2583
2584
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2593
            ->method('getSecurityInformation')
2594
            ->willReturn([]);
2595
2596
        $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...
2597
            ->method('getMaskBuilderClass')
2598
            ->willReturn(AdminPermissionMap::class);
2599
2600
        $aclUsersForm = $this->getMockBuilder(Form::class)
2601
            ->disableOriginalConstructor()
2602
            ->getMock();
2603
2604
        $aclUsersForm->expects($this->once())
2605
            ->method('isValid')
2606
            ->willReturn(false);
2607
2608
        $aclUsersForm->expects($this->once())
2609
            ->method('createView')
2610
            ->willReturn($this->createMock(FormView::class));
2611
2612
        $aclRolesForm = $this->getMockBuilder(Form::class)
2613
            ->disableOriginalConstructor()
2614
            ->getMock();
2615
2616
        $aclRolesForm->expects($this->once())
2617
            ->method('createView')
2618
            ->willReturn($this->createMock(FormView::class));
2619
2620
        $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...
2621
            ->method('createAclUsersForm')
2622
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2623
            ->willReturn($aclUsersForm);
2624
2625
        $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...
2626
            ->method('createAclRolesForm')
2627
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2628
            ->willReturn($aclRolesForm);
2629
2630
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2631
2632
        $aclSecurityHandler
2633
            ->method('getObjectPermissions')
2634
            ->willReturn([]);
2635
2636
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2637
            ->method('getSecurityHandler')
2638
            ->willReturn($aclSecurityHandler);
2639
2640
        $this->request->setMethod(Request::METHOD_POST);
2641
2642
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2643
2644
        $this->assertSame($this->admin, $this->parameters['admin']);
2645
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2646
2647
        $this->assertSame('acl', $this->parameters['action']);
2648
        $this->assertSame([], $this->parameters['permissions']);
2649
        $this->assertSame($object, $this->parameters['object']);
2650
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2651
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2652
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2653
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2654
2655
        $this->assertSame([], $this->session->getFlashBag()->all());
2656
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2657
    }
2658
2659
    public function testAclActionSuccessfulUpdate(): void
2660
    {
2661
        $this->request->query->set('id', 123);
2662
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2663
2664
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2665
            ->method('isAclEnabled')
2666
            ->willReturn(true);
2667
2668
        $object = new \stdClass();
2669
2670
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2679
            ->method('getSecurityInformation')
2680
            ->willReturn([]);
2681
2682
        $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...
2683
            ->method('getMaskBuilderClass')
2684
            ->willReturn(AdminPermissionMap::class);
2685
2686
        $aclUsersForm = $this->getMockBuilder(Form::class)
2687
            ->disableOriginalConstructor()
2688
            ->getMock();
2689
2690
        $aclUsersForm
2691
            ->method('createView')
2692
            ->willReturn($this->createMock(FormView::class));
2693
2694
        $aclRolesForm = $this->getMockBuilder(Form::class)
2695
            ->disableOriginalConstructor()
2696
            ->getMock();
2697
2698
        $aclRolesForm
2699
            ->method('createView')
2700
            ->willReturn($this->createMock(FormView::class));
2701
2702
        $aclRolesForm->expects($this->once())
2703
            ->method('isValid')
2704
            ->willReturn(true);
2705
2706
        $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...
2707
            ->method('createAclUsersForm')
2708
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2709
            ->willReturn($aclUsersForm);
2710
2711
        $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...
2712
            ->method('createAclRolesForm')
2713
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2714
            ->willReturn($aclRolesForm);
2715
2716
        $aclSecurityHandler = $this->createMock(AclSecurityHandlerInterface::class);
2717
2718
        $aclSecurityHandler
2719
            ->method('getObjectPermissions')
2720
            ->willReturn([]);
2721
2722
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2723
            ->method('getSecurityHandler')
2724
            ->willReturn($aclSecurityHandler);
2725
2726
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2727
2728
        $this->request->setMethod(Request::METHOD_POST);
2729
2730
        $controller = $this->createController();
2731
        $response = $controller->aclAction($this->request);
2732
2733
        $this->assertInstanceOf(RedirectResponse::class, $response);
2734
2735
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2736
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2737
    }
2738
2739
    public function testHistoryViewRevisionActionAccessDenied(): void
2740
    {
2741
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2746
            ->method('checkAccess')
2747
            ->with($this->equalTo('historyViewRevision'))
2748
            ->will($this->throwException(new AccessDeniedException()));
2749
2750
        $this->expectException(AccessDeniedException::class);
2751
2752
        $this->controller->historyViewRevisionAction($this->request, null);
2753
    }
2754
2755
    public function testHistoryViewRevisionActionNotFoundException(): void
2756
    {
2757
        $this->request->query->set('id', 123);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2761
            ->willReturn(null);
2762
2763
        $this->expectException(NotFoundHttpException::class);
2764
        $this->expectExceptionMessage('unable to find the object with id: 123');
2765
2766
        $this->controller->historyViewRevisionAction($this->request, null);
2767
    }
2768
2769
    public function testHistoryViewRevisionActionNoReader(): void
2770
    {
2771
        $this->expectException(NotFoundHttpException::class);
2772
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2773
2774
        $this->request->query->set('id', 123);
2775
2776
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2791
            ->method('hasReader')
2792
            ->with($this->equalTo('Foo'))
2793
            ->willReturn(false);
2794
2795
        $this->controller->historyViewRevisionAction($this->request, null);
2796
    }
2797
2798
    public function testHistoryViewRevisionActionNotFoundRevision(): void
2799
    {
2800
        $this->expectException(NotFoundHttpException::class);
2801
        $this->expectExceptionMessage(
2802
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
2803
        );
2804
2805
        $this->request->query->set('id', 123);
2806
2807
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2808
            ->method('checkAccess')
2809
            ->with($this->equalTo('historyViewRevision'));
2810
2811
        $object = new \stdClass();
2812
2813
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2822
            ->method('hasReader')
2823
            ->with($this->equalTo('Foo'))
2824
            ->willReturn(true);
2825
2826
        $reader = $this->createMock(AuditReaderInterface::class);
2827
2828
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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

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

Loading history...
2829
            ->method('getReader')
2830
            ->with($this->equalTo('Foo'))
2831
            ->willReturn($reader);
2832
2833
        $reader->expects($this->once())
2834
            ->method('find')
2835
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2836
            ->willReturn(null);
2837
2838
        $this->controller->historyViewRevisionAction($this->request, 456);
2839
    }
2840
2841
    public function testHistoryViewRevisionAction(): void
2842
    {
2843
        $this->request->query->set('id', 123);
2844
2845
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2867
            ->method('getReader')
2868
            ->with($this->equalTo('Foo'))
2869
            ->willReturn($reader);
2870
2871
        $objectRevision = new \stdClass();
2872
        $objectRevision->revision = 456;
2873
2874
        $reader->expects($this->once())
2875
            ->method('find')
2876
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2877
            ->willReturn($objectRevision);
2878
2879
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2885
            ->method('getShow')
2886
            ->willReturn($fieldDescriptionCollection);
2887
2888
        $this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction($this->request, 456));
2889
2890
        $this->assertSame($this->admin, $this->parameters['admin']);
2891
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2892
2893
        $this->assertSame('show', $this->parameters['action']);
2894
        $this->assertSame($objectRevision, $this->parameters['object']);
2895
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
2896
2897
        $this->assertSame([], $this->session->getFlashBag()->all());
2898
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
2899
    }
2900
2901
    public function testHistoryCompareRevisionsActionAccessDenied(): void
2902
    {
2903
        $this->expectException(AccessDeniedException::class);
2904
2905
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2907
            ->with($this->equalTo('historyCompareRevisions'))
2908
            ->will($this->throwException(new AccessDeniedException()));
2909
2910
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2911
    }
2912
2913
    public function testHistoryCompareRevisionsActionNotFoundException(): void
2914
    {
2915
        $this->expectException(NotFoundHttpException::class);
2916
        $this->expectExceptionMessage('unable to find the object with id: 123');
2917
2918
        $this->request->query->set('id', 123);
2919
2920
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2921
            ->method('checkAccess')
2922
            ->with($this->equalTo('historyCompareRevisions'));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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(null);
2927
2928
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2929
    }
2930
2931
    public function testHistoryCompareRevisionsActionNoReader(): void
2932
    {
2933
        $this->expectException(NotFoundHttpException::class);
2934
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2935
2936
        $this->request->query->set('id', 123);
2937
2938
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2939
            ->method('checkAccess')
2940
            ->with($this->equalTo('historyCompareRevisions'));
2941
2942
        $object = new \stdClass();
2943
2944
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2953
            ->method('hasReader')
2954
            ->with($this->equalTo('Foo'))
2955
            ->willReturn(false);
2956
2957
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2958
    }
2959
2960
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
2961
    {
2962
        $this->expectException(NotFoundHttpException::class);
2963
        $this->expectExceptionMessage(
2964
            'unable to find the targeted object `123` from the revision `456` with classname : `Foo`'
2965
        );
2966
2967
        $this->request->query->set('id', 123);
2968
2969
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2970
            ->method('checkAccess')
2971
            ->with($this->equalTo('historyCompareRevisions'));
2972
2973
        $object = new \stdClass();
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\AdminInterface>.

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

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

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

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

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

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

Loading history...
2984
            ->method('hasReader')
2985
            ->with($this->equalTo('Foo'))
2986
            ->willReturn(true);
2987
2988
        $reader = $this->createMock(AuditReaderInterface::class);
2989
2990
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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

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

Loading history...
2991
            ->method('getReader')
2992
            ->with($this->equalTo('Foo'))
2993
            ->willReturn($reader);
2994
2995
        // once because it will not be found and therefore the second call won't be executed
2996
        $reader->expects($this->once())
2997
            ->method('find')
2998
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2999
            ->willReturn(null);
3000
3001
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3002
    }
3003
3004
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3005
    {
3006
        $this->expectException(NotFoundHttpException::class);
3007
        $this->expectExceptionMessage(
3008
            'unable to find the targeted object `123` from the revision `789` with classname : `Foo`'
3009
        );
3010
3011
        $this->request->query->set('id', 123);
3012
3013
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3014
            ->method('checkAccess')
3015
            ->with($this->equalTo('historyCompareRevisions'));
3016
3017
        $object = new \stdClass();
3018
3019
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
3035
            ->method('getReader')
3036
            ->with($this->equalTo('Foo'))
3037
            ->willReturn($reader);
3038
3039
        $objectRevision = new \stdClass();
3040
        $objectRevision->revision = 456;
3041
3042
        // first call should return, so the second call will throw an exception
3043
        $reader->expects($this->at(0))
3044
            ->method('find')
3045
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3046
            ->willReturn($objectRevision);
3047
3048
        $reader->expects($this->at(1))
3049
            ->method('find')
3050
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3051
            ->willReturn(null);
3052
3053
        $this->controller->historyCompareRevisionsAction($this->request, 456, 789);
3054
    }
3055
3056
    public function testHistoryCompareRevisionsActionAction(): void
3057
    {
3058
        $this->request->query->set('id', 123);
3059
3060
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3061
            ->method('checkAccess')
3062
            ->with($this->equalTo('historyCompareRevisions'));
3063
3064
        $object = new \stdClass();
3065
3066
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
3075
            ->method('hasReader')
3076
            ->with($this->equalTo('Foo'))
3077
            ->willReturn(true);
3078
3079
        $reader = $this->createMock(AuditReaderInterface::class);
3080
3081
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...\AuditManagerInterface>.

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

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

Loading history...
3082
            ->method('getReader')
3083
            ->with($this->equalTo('Foo'))
3084
            ->willReturn($reader);
3085
3086
        $objectRevision = new \stdClass();
3087
        $objectRevision->revision = 456;
3088
3089
        $compareObjectRevision = new \stdClass();
3090
        $compareObjectRevision->revision = 789;
3091
3092
        $reader->expects($this->at(0))
3093
            ->method('find')
3094
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3095
            ->willReturn($objectRevision);
3096
3097
        $reader->expects($this->at(1))
3098
            ->method('find')
3099
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3100
            ->willReturn($compareObjectRevision);
3101
3102
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3108
            ->method('getShow')
3109
            ->willReturn($fieldDescriptionCollection);
3110
3111
        $this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction($this->request, 456, 789));
3112
3113
        $this->assertSame($this->admin, $this->parameters['admin']);
3114
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3115
3116
        $this->assertSame('show', $this->parameters['action']);
3117
        $this->assertSame($objectRevision, $this->parameters['object']);
3118
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3119
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3120
3121
        $this->assertSame([], $this->session->getFlashBag()->all());
3122
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3123
    }
3124
3125
    public function testBatchActionWrongMethod(): void
3126
    {
3127
        $this->expectException(NotFoundHttpException::class);
3128
        $this->expectExceptionMessage('Invalid request method given "GET", POST expected');
3129
3130
        $this->controller->batchAction($this->request);
3131
    }
3132
3133
    public function testBatchActionActionNotDefined(): void
3134
    {
3135
        $this->expectException(\RuntimeException::class);
3136
        $this->expectExceptionMessage('The `foo` batch action is not defined');
3137
3138
        $batchActions = [];
3139
3140
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3141
            ->method('getBatchActions')
3142
            ->willReturn($batchActions);
3143
3144
        $this->request->setMethod(Request::METHOD_POST);
3145
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3146
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3147
3148
        $this->controller->batchAction($this->request);
3149
    }
3150
3151
    public function testBatchActionActionInvalidCsrfToken(): void
3152
    {
3153
        $this->request->setMethod(Request::METHOD_POST);
3154
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3155
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3156
3157
        try {
3158
            $this->controller->batchAction($this->request);
3159
        } catch (HttpException $e) {
3160
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3161
            $this->assertSame(400, $e->getStatusCode());
3162
        }
3163
    }
3164
3165
    public function testBatchActionMethodNotExist(): void
3166
    {
3167
        $this->expectException(\RuntimeException::class);
3168
        $this->expectExceptionMessage(
3169
            'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable'
3170
        );
3171
3172
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3173
3174
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3180
            ->method('getDatagrid')
3181
            ->willReturn($datagrid);
3182
3183
        $this->request->setMethod(Request::METHOD_POST);
3184
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3185
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3186
3187
        $this->controller->batchAction($this->request);
3188
    }
3189
3190
    public function testBatchActionWithoutConfirmation(): void
3191
    {
3192
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3193
3194
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3195
            ->method('getBatchActions')
3196
            ->willReturn($batchActions);
3197
3198
        $datagrid = $this->createMock(DatagridInterface::class);
3199
3200
        $query = $this->createMock(ProxyQueryInterface::class);
3201
        $datagrid->expects($this->once())
3202
            ->method('getQuery')
3203
            ->willReturn($query);
3204
3205
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3206
            ->method('getDatagrid')
3207
            ->willReturn($datagrid);
3208
3209
        $modelManager = $this->createMock(ModelManagerInterface::class);
3210
3211
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
3220
            ->method('getClass')
3221
            ->willReturn('Foo');
3222
3223
        $modelManager->expects($this->once())
3224
            ->method('addIdentifiersToQuery')
3225
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3226
            ->willReturn(true);
3227
3228
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3229
3230
        $this->request->setMethod(Request::METHOD_POST);
3231
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3232
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3233
3234
        $result = $this->controller->batchAction($this->request);
3235
3236
        $this->assertInstanceOf(RedirectResponse::class, $result);
3237
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3238
        $this->assertSame('list', $result->getTargetUrl());
3239
    }
3240
3241
    public function testBatchActionWithoutConfirmation2(): void
3242
    {
3243
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3244
3245
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3246
            ->method('getBatchActions')
3247
            ->willReturn($batchActions);
3248
3249
        $datagrid = $this->createMock(DatagridInterface::class);
3250
3251
        $query = $this->createMock(ProxyQueryInterface::class);
3252
        $datagrid->expects($this->once())
3253
            ->method('getQuery')
3254
            ->willReturn($query);
3255
3256
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3257
            ->method('getDatagrid')
3258
            ->willReturn($datagrid);
3259
3260
        $modelManager = $this->createMock(ModelManagerInterface::class);
3261
3262
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
3271
            ->method('getClass')
3272
            ->willReturn('Foo');
3273
3274
        $modelManager->expects($this->once())
3275
            ->method('addIdentifiersToQuery')
3276
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3277
            ->willReturn(true);
3278
3279
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3280
3281
        $this->request->setMethod(Request::METHOD_POST);
3282
        $this->request->request->set('action', 'delete');
3283
        $this->request->request->set('idx', ['123', '456']);
3284
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3285
3286
        $result = $this->controller->batchAction($this->request);
3287
3288
        $this->assertInstanceOf(RedirectResponse::class, $result);
3289
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3290
        $this->assertSame('list', $result->getTargetUrl());
3291
    }
3292
3293
    public function testBatchActionWithConfirmation(): void
3294
    {
3295
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getBatchActions')
3299
            ->willReturn($batchActions);
3300
3301
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3302
3303
        $this->request->setMethod(Request::METHOD_POST);
3304
        $this->request->request->set('data', json_encode($data));
3305
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3306
3307
        $datagrid = $this->createMock(DatagridInterface::class);
3308
3309
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3310
            ->method('getDatagrid')
3311
            ->willReturn($datagrid);
3312
3313
        $form = $this->getMockBuilder(Form::class)
3314
            ->disableOriginalConstructor()
3315
            ->getMock();
3316
3317
        $form->expects($this->once())
3318
            ->method('createView')
3319
            ->willReturn($this->createMock(FormView::class));
3320
3321
        $datagrid->expects($this->once())
3322
            ->method('getForm')
3323
            ->willReturn($form);
3324
3325
        $this->assertInstanceOf(Response::class, $this->controller->batchAction($this->request));
3326
3327
        $this->assertSame($this->admin, $this->parameters['admin']);
3328
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3329
3330
        $this->assertSame('list', $this->parameters['action']);
3331
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3332
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3333
        $this->assertSame($data, $this->parameters['data']);
3334
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3335
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3336
3337
        $this->assertSame([], $this->session->getFlashBag()->all());
3338
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3339
    }
3340
3341
    public function testBatchActionNonRelevantAction(): void
3342
    {
3343
        $controller = $this->createController(BatchAdminController::class);
3344
3345
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3346
3347
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3348
            ->method('getBatchActions')
3349
            ->willReturn($batchActions);
3350
3351
        $datagrid = $this->createMock(DatagridInterface::class);
3352
3353
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3354
            ->method('getDatagrid')
3355
            ->willReturn($datagrid);
3356
3357
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3358
3359
        $this->request->setMethod(Request::METHOD_POST);
3360
        $this->request->request->set('action', 'foo');
3361
        $this->request->request->set('idx', ['789']);
3362
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3363
3364
        $result = $controller->batchAction($this->request);
3365
3366
        $this->assertInstanceOf(RedirectResponse::class, $result);
3367
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3368
        $this->assertSame('list', $result->getTargetUrl());
3369
    }
3370
3371
    public function testBatchActionWithCustomConfirmationTemplate(): void
3372
    {
3373
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getBatchActions')
3377
            ->willReturn($batchActions);
3378
3379
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3380
3381
        $this->request->setMethod(Request::METHOD_POST);
3382
        $this->request->request->set('data', json_encode($data));
3383
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3384
3385
        $datagrid = $this->createMock(DatagridInterface::class);
3386
3387
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3388
            ->method('getDatagrid')
3389
            ->willReturn($datagrid);
3390
3391
        $form = $this->createMock(Form::class);
3392
3393
        $form->expects($this->once())
3394
            ->method('createView')
3395
            ->willReturn($this->createMock(FormView::class));
3396
3397
        $datagrid->expects($this->once())
3398
            ->method('getForm')
3399
            ->willReturn($form);
3400
3401
        $this->controller->batchAction($this->request);
3402
3403
        $this->assertSame('custom_template.html.twig', $this->template);
3404
    }
3405
3406
    public function testBatchActionNonRelevantAction2(): void
3407
    {
3408
        $controller = $this->createController(BatchAdminController::class);
3409
3410
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3411
3412
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3413
            ->method('getBatchActions')
3414
            ->willReturn($batchActions);
3415
3416
        $datagrid = $this->createMock(DatagridInterface::class);
3417
3418
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3419
            ->method('getDatagrid')
3420
            ->willReturn($datagrid);
3421
3422
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3423
3424
        $this->request->setMethod(Request::METHOD_POST);
3425
        $this->request->request->set('action', 'foo');
3426
        $this->request->request->set('idx', ['999']);
3427
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3428
3429
        $result = $controller->batchAction($this->request);
3430
3431
        $this->assertInstanceOf(RedirectResponse::class, $result);
3432
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3433
        $this->assertSame('list', $result->getTargetUrl());
3434
    }
3435
3436
    public function testBatchActionNoItems(): void
3437
    {
3438
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3439
3440
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3441
            ->method('getBatchActions')
3442
            ->willReturn($batchActions);
3443
3444
        $datagrid = $this->createMock(DatagridInterface::class);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getDatagrid')
3448
            ->willReturn($datagrid);
3449
3450
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3451
3452
        $this->request->setMethod(Request::METHOD_POST);
3453
        $this->request->request->set('action', 'delete');
3454
        $this->request->request->set('idx', []);
3455
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3456
3457
        $result = $this->controller->batchAction($this->request);
3458
3459
        $this->assertInstanceOf(RedirectResponse::class, $result);
3460
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3461
        $this->assertSame('list', $result->getTargetUrl());
3462
    }
3463
3464
    public function testBatchActionNoItemsEmptyQuery(): void
3465
    {
3466
        $controller = $this->createController(BatchAdminController::class);
3467
3468
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3469
3470
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3471
            ->method('getBatchActions')
3472
            ->willReturn($batchActions);
3473
3474
        $datagrid = $this->createMock(DatagridInterface::class);
3475
3476
        $query = $this->createMock(ProxyQueryInterface::class);
3477
        $datagrid->expects($this->once())
3478
            ->method('getQuery')
3479
            ->willReturn($query);
3480
3481
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3482
            ->method('getDatagrid')
3483
            ->willReturn($datagrid);
3484
3485
        $modelManager = $this->createMock(ModelManagerInterface::class);
3486
3487
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3492
            ->method('getClass')
3493
            ->willReturn('Foo');
3494
3495
        $this->request->setMethod(Request::METHOD_POST);
3496
        $this->request->request->set('action', 'bar');
3497
        $this->request->request->set('idx', []);
3498
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3499
3500
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3501
        $result = $controller->batchAction($this->request);
3502
3503
        $this->assertInstanceOf(Response::class, $result);
3504
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3505
    }
3506
3507
    public function testBatchActionWithRequesData(): void
3508
    {
3509
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3510
3511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3512
            ->method('getBatchActions')
3513
            ->willReturn($batchActions);
3514
3515
        $datagrid = $this->createMock(DatagridInterface::class);
3516
3517
        $query = $this->createMock(ProxyQueryInterface::class);
3518
        $datagrid->expects($this->once())
3519
            ->method('getQuery')
3520
            ->willReturn($query);
3521
3522
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3523
            ->method('getDatagrid')
3524
            ->willReturn($datagrid);
3525
3526
        $modelManager = $this->createMock(ModelManagerInterface::class);
3527
3528
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
3590
            ->method('error')
3591
            ->with($message, [
3592
                'exception' => $exception,
3593
                'previous_exception_message' => $previousExceptionMessage,
3594
            ]);
3595
    }
3596
3597
    private function expectTranslate(
3598
        string $id,
3599
        array $parameters = [],
3600
        ?string $domain = null,
3601
        ?string $locale = null
3602
    ): void {
3603
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Contracts...on\TranslatorInterface>.

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

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

Loading history...
3604
            ->method('trans')
3605
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3606
            ->willReturn($id);
3607
    }
3608
3609
    private function createTwig(): Environment
3610
    {
3611
        $templatingRenderReturnCallback = $this->returnCallback(function (
3612
            string $name,
3613
            array $context = []
3614
        ): string {
3615
            $this->template = $name;
3616
3617
            $this->parameters = $context;
3618
3619
            return '';
3620
        });
3621
3622
        $twig = $this->getMockBuilder(Environment::class)
3623
            ->disableOriginalConstructor()
3624
            ->getMock();
3625
3626
        $twig
3627
            ->method('getRuntime')
3628
            ->willReturn($this->createMock(FormRenderer::class));
3629
3630
        $twig
3631
            ->method('render')
3632
            ->will($templatingRenderReturnCallback);
3633
3634
        return $twig;
3635
    }
3636
3637
    private function createController(string $classname = CRUDController::class): CRUDController
3638
    {
3639
        $requestStack = new RequestStack();
3640
        $requestStack->push($this->request);
3641
3642
        $pool = new Pool($this->container, 'title', 'logo.png');
3643
        $pool->setAdminServiceIds(['foo.admin']);
3644
3645
        return new $classname(
3646
            $requestStack,
3647
            $pool,
3648
            $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...
3649
            new BreadcrumbsBuilder([]),
3650
            $this->createTwig(),
3651
            $this->translator,
3652
            $this->session,
3653
            $this->kernel,
3654
            $this->auditManager,
3655
            $this->exporter,
3656
            new AdminExporter($this->exporter),
3657
            $this->csrfProvider,
3658
            $this->logger,
3659
            $this->adminObjectAclManipulator
3660
        );
3661
    }
3662
}
3663