Completed
Pull Request — master (#6093)
by Mathieu
35:29
created

CRUDControllerTest::createTwig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
509
            ->method('checkAccess')
510
            ->with($this->equalTo('list'))
511
            ->will($this->throwException(new AccessDeniedException()));
512
513
        $this->controller->listAction($this->request);
514
    }
515
516
    public function testPreList(): void
517
    {
518
        $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...
519
520
        $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...
521
            ->method('hasRoute')
522
            ->with($this->equalTo('list'))
523
            ->willReturn(true);
524
525
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
717
            ->method('checkAccess')
718
            ->with($this->equalTo('show'));
719
720
        $show = $this->createMock(FieldDescriptionCollection::class);
721
722
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
723
            ->method('getShow')
724
            ->willReturn($show);
725
726
        $this->assertInstanceOf(Response::class, $this->controller->showAction($this->request));
727
728
        $this->assertSame($this->admin, $this->parameters['admin']);
729
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
730
731
        $this->assertSame('show', $this->parameters['action']);
732
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
733
        $this->assertSame($object, $this->parameters['object']);
734
735
        $this->assertSame([], $this->session->getFlashBag()->all());
736
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
737
    }
738
739
    /**
740
     * @dataProvider getRedirectToTests
741
     */
742
    public function testRedirectTo(
743
        string $expected,
744
        string $route,
745
        array $queryParams,
746
        array $requestParams,
747
        bool $hasActiveSubclass
748
    ): void {
749
        $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...
750
            ->method('hasActiveSubclass')
751
            ->willReturn($hasActiveSubclass);
752
753
        $object = new \stdClass();
754
755
        foreach ($queryParams as $key => $value) {
756
            $this->request->query->set($key, $value);
757
        }
758
759
        foreach ($requestParams as $key => $value) {
760
            $this->request->request->set($key, $value);
761
        }
762
763
        $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...
764
            ->method('hasRoute')
765
            ->with($this->equalTo($route))
766
            ->willReturn(true);
767
768
        $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...
769
            ->method('hasAccess')
770
            ->with($this->equalTo($route))
771
            ->willReturn(true);
772
773
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
774
        $this->assertInstanceOf(RedirectResponse::class, $response);
775
        $this->assertSame($expected, $response->getTargetUrl());
776
    }
777
778
    public function testRedirectToWithObject(): void
779
    {
780
        $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...
781
            ->method('hasActiveSubclass')
782
            ->willReturn(false);
783
784
        $object = new \stdClass();
785
786
        $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...
787
            ->method('hasRoute')
788
            ->with($this->equalTo('edit'))
789
            ->willReturn(true);
790
791
        $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...
792
            ->method('hasAccess')
793
            ->with($this->equalTo('edit'), $object)
794
            ->willReturn(false);
795
796
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
797
        $this->assertInstanceOf(RedirectResponse::class, $response);
798
        $this->assertSame('list', $response->getTargetUrl());
799
    }
800
801
    public function getRedirectToTests()
802
    {
803
        return [
804
            ['stdClass_edit', 'edit', [], [], false],
805
            ['list', 'list', ['btn_update_and_list' => true], [], false],
806
            ['list', 'list', ['btn_create_and_list' => true], [], false],
807
            ['create', 'create', ['btn_create_and_create' => true], [], false],
808
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
809
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
810
        ];
811
    }
812
813
    public function testDeleteActionNotFoundException(): void
814
    {
815
        $this->expectException(NotFoundHttpException::class);
816
817
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1267
            ->method('checkAccess')
1268
            ->with($this->equalTo('edit'));
1269
1270
        $form = $this->createMock(Form::class);
1271
1272
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1433
            ->method('getForm')
1434
            ->willReturn($form);
1435
1436
        $form->expects($this->once())
1437
            ->method('isSubmitted')
1438
            ->willReturn(true);
1439
1440
        $form->expects($this->once())
1441
            ->method('isValid')
1442
            ->willReturn(true);
1443
1444
        $form->expects($this->once())
1445
            ->method('getData')
1446
            ->willReturn($object);
1447
1448
        $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...
1449
            ->method('getNormalizedIdentifier')
1450
            ->with($this->equalTo($object))
1451
            ->willReturn('foo_normalized');
1452
1453
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1634
            ->method('supportsPreviewMode')
1635
            ->willReturn(true);
1636
1637
        $formView = $this->createMock(FormView::class);
1638
1639
        $form
1640
            ->method('createView')
1641
            ->willReturn($formView);
1642
1643
        $form->expects($this->once())
1644
            ->method('isSubmitted')
1645
            ->willReturn(true);
1646
1647
        $form->expects($this->once())
1648
            ->method('isValid')
1649
            ->willReturn(true);
1650
1651
        $this->request->setMethod(Request::METHOD_POST);
1652
        $this->request->request->set('btn_preview', 'Preview');
1653
1654
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1655
1656
        $this->assertSame($this->admin, $this->parameters['admin']);
1657
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1658
1659
        $this->assertSame('edit', $this->parameters['action']);
1660
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1661
        $this->assertSame($object, $this->parameters['object']);
1662
1663
        $this->assertSame([], $this->session->getFlashBag()->all());
1664
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1665
    }
1666
1667
    public function testEditActionWithLockException(): void
1668
    {
1669
        $object = new \stdClass();
1670
        $class = \get_class($object);
1671
1672
        $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...
1673
            ->method('getObject')
1674
            ->willReturn($object);
1675
1676
        $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...
1677
            ->method('checkAccess')
1678
            ->with($this->equalTo('edit'));
1679
1680
        $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...
1681
            ->method('getClass')
1682
            ->willReturn($class);
1683
1684
        $form = $this->createMock(Form::class);
1685
1686
        $form
1687
            ->method('isValid')
1688
            ->willReturn(true);
1689
1690
        $form->expects($this->once())
1691
            ->method('getData')
1692
            ->willReturn($object);
1693
1694
        $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...
1695
            ->method('getForm')
1696
            ->willReturn($form);
1697
1698
        $form
1699
            ->method('isSubmitted')
1700
            ->willReturn(true);
1701
        $this->request->setMethod(Request::METHOD_POST);
1702
1703
        $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...
1704
            ->method('update')
1705
            ->will($this->throwException(new LockException()));
1706
1707
        $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...
1708
            ->method('toString')
1709
            ->with($this->equalTo($object))
1710
            ->willReturn($class);
1711
1712
        $formView = $this->createMock(FormView::class);
1713
1714
        $form
1715
            ->method('createView')
1716
            ->willReturn($formView);
1717
1718
        $this->expectTranslate('flash_lock_error', [
1719
            '%name%' => $class,
1720
            '%link_start%' => '<a href="stdClass_edit">',
1721
            '%link_end%' => '</a>',
1722
        ], 'SonataAdminBundle');
1723
1724
        $this->assertInstanceOf(Response::class, $this->controller->editAction($this->request));
1725
    }
1726
1727
    public function testCreateActionAccessDenied(): void
1728
    {
1729
        $this->expectException(AccessDeniedException::class);
1730
1731
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1745
            ->method('checkAccess')
1746
            ->with($this->equalTo('create'));
1747
1748
        $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...
1749
            ->method('getClass')
1750
            ->willReturn(\stdClass::class);
1751
1752
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1766
            ->method('checkAccess')
1767
            ->with($this->equalTo('create'));
1768
1769
        $object = new \stdClass();
1770
1771
        $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...
1772
            ->method('getClass')
1773
            ->willReturn(\stdClass::class);
1774
1775
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1782
            ->method('getForm')
1783
            ->willReturn($form);
1784
1785
        $formView = $this->createMock(FormView::class);
1786
1787
        $form
1788
            ->method('createView')
1789
            ->willReturn($formView);
1790
1791
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
1792
1793
        $this->assertSame($this->admin, $this->parameters['admin']);
1794
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1795
1796
        $this->assertSame('create', $this->parameters['action']);
1797
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1798
        $this->assertSame($object, $this->parameters['object']);
1799
1800
        $this->assertSame([], $this->session->getFlashBag()->all());
1801
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1802
    }
1803
1804
    /**
1805
     * @dataProvider getToStringValues
1806
     */
1807
    public function testCreateActionSuccess(string $expectedToStringValue, string $toStringValue): void
1808
    {
1809
        $object = new \stdClass();
1810
1811
        $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...
1812
            ->method('checkAccess')
1813
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
1814
                if ('edit' === $name) {
1815
                    return;
1816
                }
1817
1818
                if ('create' !== $name) {
1819
                    throw new AccessDeniedException();
1820
                }
1821
1822
                if (null === $objectIn) {
1823
                    return;
1824
                }
1825
1826
                if ($objectIn !== $object) {
1827
                    throw new AccessDeniedException();
1828
                }
1829
            });
1830
1831
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1846
            ->method('create')
1847
            ->willReturnArgument(0);
1848
1849
        $form = $this->createMock(Form::class);
1850
1851
        $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...
1852
            ->method('getClass')
1853
            ->willReturn(\stdClass::class);
1854
1855
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1872
            ->method('toString')
1873
            ->with($this->equalTo($object))
1874
            ->willReturn($toStringValue);
1875
1876
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1877
1878
        $this->request->setMethod(Request::METHOD_POST);
1879
1880
        $response = $this->controller->createAction($this->request);
1881
1882
        $this->assertInstanceOf(RedirectResponse::class, $response);
1883
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1884
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1885
    }
1886
1887
    public function testCreateActionAccessDenied2(): void
1888
    {
1889
        $this->expectException(AccessDeniedException::class);
1890
1891
        $object = new \stdClass();
1892
1893
        $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...
1894
            ->method('checkAccess')
1895
            ->willReturnCallback(static function (string $name, $object = null): void {
1896
                if ('create' !== $name) {
1897
                    throw new AccessDeniedException();
1898
                }
1899
                if (null === $object) {
1900
                    return;
1901
                }
1902
1903
                throw new AccessDeniedException();
1904
            });
1905
1906
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1907
            ->method('getNewInstance')
1908
            ->willReturn($object);
1909
1910
        $form = $this->createMock(Form::class);
1911
1912
        $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...
1913
            ->method('getClass')
1914
            ->willReturn(\stdClass::class);
1915
1916
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1943
            ->method('checkAccess')
1944
            ->with($this->equalTo('create'));
1945
1946
        $object = new \stdClass();
1947
1948
        $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...
1949
            ->method('getClass')
1950
            ->willReturn(\stdClass::class);
1951
1952
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2028
            ->method('toString')
2029
            ->with($this->equalTo($object))
2030
            ->willReturn($toStringValue);
2031
2032
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2033
2034
        $form->expects($this->once())
2035
            ->method('isSubmitted')
2036
            ->willReturn(true);
2037
2038
        $form->expects($this->once())
2039
            ->method('getData')
2040
            ->willReturn($object);
2041
2042
        $this->request->setMethod(Request::METHOD_POST);
2043
2044
        $formView = $this->createMock(FormView::class);
2045
2046
        $form
2047
            ->method('createView')
2048
            ->willReturn($formView);
2049
2050
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2051
2052
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
2053
2054
        $this->assertSame($this->admin, $this->parameters['admin']);
2055
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2056
2057
        $this->assertSame('create', $this->parameters['action']);
2058
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2059
        $this->assertSame($object, $this->parameters['object']);
2060
2061
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2062
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2063
    }
2064
2065
    public function testCreateActionAjaxSuccess(): void
2066
    {
2067
        $object = new \stdClass();
2068
2069
        $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...
2070
            ->method('checkAccess')
2071
            ->willReturnCallback(static function (string $name, $objectIn = null) use ($object): void {
2072
                if ('create' !== $name) {
2073
                    throw new AccessDeniedException();
2074
                }
2075
2076
                if (null === $objectIn) {
2077
                    return;
2078
                }
2079
2080
                if ($objectIn !== $object) {
2081
                    throw new AccessDeniedException();
2082
                }
2083
            });
2084
2085
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2096
            ->method('getForm')
2097
            ->willReturn($form);
2098
2099
        $form->expects($this->once())
2100
            ->method('isSubmitted')
2101
            ->willReturn(true);
2102
2103
        $form->expects($this->once())
2104
            ->method('isValid')
2105
            ->willReturn(true);
2106
2107
        $form->expects($this->once())
2108
            ->method('getData')
2109
            ->willReturn($object);
2110
2111
        $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...
2112
            ->method('getClass')
2113
            ->willReturn(\stdClass::class);
2114
2115
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2144
            ->method('getNewInstance')
2145
            ->willReturn($object);
2146
2147
        $form = $this->createMock(Form::class);
2148
2149
        $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...
2150
            ->method('getClass')
2151
            ->willReturn(\stdClass::class);
2152
2153
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2192
            ->method('getNewInstance')
2193
            ->willReturn($object);
2194
2195
        $form = $this->createMock(Form::class);
2196
2197
        $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...
2198
            ->method('getClass')
2199
            ->willReturn(\stdClass::class);
2200
2201
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2228
            ->method('checkAccess')
2229
            ->with($this->equalTo('create'));
2230
2231
        $object = new \stdClass();
2232
2233
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2234
            ->method('getNewInstance')
2235
            ->willReturn($object);
2236
2237
        $form = $this->createMock(Form::class);
2238
2239
        $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...
2240
            ->method('getClass')
2241
            ->willReturn(\stdClass::class);
2242
2243
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2386
            ->method('getObject')
2387
            ->willReturn($object);
2388
2389
        $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...
2390
            ->method('getClass')
2391
            ->willReturn('Foo');
2392
2393
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

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

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

Loading history...
2412
            ->method('getObject')
2413
            ->willReturn($object);
2414
2415
        $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...
2416
            ->method('getClass')
2417
            ->willReturn('Foo');
2418
2419
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2505
            ->method('getObject')
2506
            ->willReturn($object);
2507
2508
        $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...
2509
            ->expects($this->once())
2510
            ->method('checkAccess');
2511
2512
        $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...
2513
            ->method('getSecurityInformation')
2514
            ->willReturn([]);
2515
2516
        $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...
2517
            ->method('getMaskBuilderClass')
2518
            ->willReturn(AdminPermissionMap::class);
2519
2520
        $aclUsersForm = $this->getMockBuilder(Form::class)
2521
            ->disableOriginalConstructor()
2522
            ->getMock();
2523
2524
        $aclUsersForm->expects($this->once())
2525
            ->method('createView')
2526
            ->willReturn($this->createMock(FormView::class));
2527
2528
        $aclRolesForm = $this->getMockBuilder(Form::class)
2529
            ->disableOriginalConstructor()
2530
            ->getMock();
2531
2532
        $aclRolesForm->expects($this->once())
2533
            ->method('createView')
2534
            ->willReturn($this->createMock(FormView::class));
2535
2536
        $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...
2537
            ->method('createAclUsersForm')
2538
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2539
            ->willReturn($aclUsersForm);
2540
2541
        $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...
2542
            ->method('createAclRolesForm')
2543
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2544
            ->willReturn($aclRolesForm);
2545
2546
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2547
            ->disableOriginalConstructor()
2548
            ->getMock();
2549
2550
        $aclSecurityHandler
2551
            ->method('getObjectPermissions')
2552
            ->willReturn([]);
2553
2554
        $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...
2555
            ->method('getSecurityHandler')
2556
            ->willReturn($aclSecurityHandler);
2557
2558
        $controller = $this->createController();
2559
2560
        $this->assertInstanceOf(Response::class, $controller->aclAction($this->request));
2561
2562
        $this->assertSame($this->admin, $this->parameters['admin']);
2563
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2564
2565
        $this->assertSame('acl', $this->parameters['action']);
2566
        $this->assertSame([], $this->parameters['permissions']);
2567
        $this->assertSame($object, $this->parameters['object']);
2568
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2569
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2570
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2571
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2572
2573
        $this->assertSame([], $this->session->getFlashBag()->all());
2574
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2575
    }
2576
2577
    public function testAclActionInvalidUpdate(): void
2578
    {
2579
        $this->request->query->set('id', 123);
2580
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2581
2582
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2589
            ->method('getObject')
2590
            ->willReturn($object);
2591
2592
        $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...
2593
            ->expects($this->once())
2594
            ->method('checkAccess');
2595
2596
        $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...
2597
            ->method('getSecurityInformation')
2598
            ->willReturn([]);
2599
2600
        $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...
2601
            ->method('getMaskBuilderClass')
2602
            ->willReturn(AdminPermissionMap::class);
2603
2604
        $aclUsersForm = $this->getMockBuilder(Form::class)
2605
            ->disableOriginalConstructor()
2606
            ->getMock();
2607
2608
        $aclUsersForm->expects($this->once())
2609
            ->method('isValid')
2610
            ->willReturn(false);
2611
2612
        $aclUsersForm->expects($this->once())
2613
            ->method('createView')
2614
            ->willReturn($this->createMock(FormView::class));
2615
2616
        $aclRolesForm = $this->getMockBuilder(Form::class)
2617
            ->disableOriginalConstructor()
2618
            ->getMock();
2619
2620
        $aclRolesForm->expects($this->once())
2621
            ->method('createView')
2622
            ->willReturn($this->createMock(FormView::class));
2623
2624
        $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...
2625
            ->method('createAclUsersForm')
2626
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2627
            ->willReturn($aclUsersForm);
2628
2629
        $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...
2630
            ->method('createAclRolesForm')
2631
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2632
            ->willReturn($aclRolesForm);
2633
2634
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2635
            ->disableOriginalConstructor()
2636
            ->getMock();
2637
2638
        $aclSecurityHandler
2639
            ->method('getObjectPermissions')
2640
            ->willReturn([]);
2641
2642
        $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...
2643
            ->method('getSecurityHandler')
2644
            ->willReturn($aclSecurityHandler);
2645
2646
        $this->request->setMethod(Request::METHOD_POST);
2647
2648
        $this->assertInstanceOf(Response::class, $this->controller->aclAction($this->request));
2649
2650
        $this->assertSame($this->admin, $this->parameters['admin']);
2651
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2652
2653
        $this->assertSame('acl', $this->parameters['action']);
2654
        $this->assertSame([], $this->parameters['permissions']);
2655
        $this->assertSame($object, $this->parameters['object']);
2656
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2657
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2658
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2659
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2660
2661
        $this->assertSame([], $this->session->getFlashBag()->all());
2662
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2663
    }
2664
2665
    public function testAclActionSuccessfulUpdate(): void
2666
    {
2667
        $this->request->query->set('id', 123);
2668
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
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('isAclEnabled')
2672
            ->willReturn(true);
2673
2674
        $object = new \stdClass();
2675
2676
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2677
            ->method('getObject')
2678
            ->willReturn($object);
2679
2680
        $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...
2681
            ->expects($this->once())
2682
            ->method('checkAccess');
2683
2684
        $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...
2685
            ->method('getSecurityInformation')
2686
            ->willReturn([]);
2687
2688
        $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...
2689
            ->method('getMaskBuilderClass')
2690
            ->willReturn(AdminPermissionMap::class);
2691
2692
        $aclUsersForm = $this->getMockBuilder(Form::class)
2693
            ->disableOriginalConstructor()
2694
            ->getMock();
2695
2696
        $aclUsersForm
2697
            ->method('createView')
2698
            ->willReturn($this->createMock(FormView::class));
2699
2700
        $aclRolesForm = $this->getMockBuilder(Form::class)
2701
            ->disableOriginalConstructor()
2702
            ->getMock();
2703
2704
        $aclRolesForm
2705
            ->method('createView')
2706
            ->willReturn($this->createMock(FormView::class));
2707
2708
        $aclRolesForm->expects($this->once())
2709
            ->method('isValid')
2710
            ->willReturn(true);
2711
2712
        $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...
2713
            ->method('createAclUsersForm')
2714
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2715
            ->willReturn($aclUsersForm);
2716
2717
        $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...
2718
            ->method('createAclRolesForm')
2719
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2720
            ->willReturn($aclRolesForm);
2721
2722
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2723
            ->disableOriginalConstructor()
2724
            ->getMock();
2725
2726
        $aclSecurityHandler
2727
            ->method('getObjectPermissions')
2728
            ->willReturn([]);
2729
2730
        $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...
2731
            ->method('getSecurityHandler')
2732
            ->willReturn($aclSecurityHandler);
2733
2734
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2735
2736
        $this->request->setMethod(Request::METHOD_POST);
2737
2738
        $controller = $this->createController();
2739
        $response = $controller->aclAction($this->request);
2740
2741
        $this->assertInstanceOf(RedirectResponse::class, $response);
2742
2743
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2744
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2745
    }
2746
2747
    public function testHistoryViewRevisionActionAccessDenied(): void
2748
    {
2749
        $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...
2750
            ->method('getObject')
2751
            ->willReturn(new \stdClass());
2752
2753
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2754
            ->method('checkAccess')
2755
            ->with($this->equalTo('historyViewRevision'))
2756
            ->will($this->throwException(new AccessDeniedException()));
2757
2758
        $this->expectException(AccessDeniedException::class);
2759
2760
        $this->controller->historyViewRevisionAction($this->request, null);
2761
    }
2762
2763
    public function testHistoryViewRevisionActionNotFoundException(): void
2764
    {
2765
        $this->request->query->set('id', 123);
2766
2767
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2768
            ->method('getObject')
2769
            ->willReturn(null);
2770
2771
        $this->expectException(NotFoundHttpException::class);
2772
        $this->expectExceptionMessage('unable to find the object with id: 123');
2773
2774
        $this->controller->historyViewRevisionAction($this->request, null);
2775
    }
2776
2777
    public function testHistoryViewRevisionActionNoReader(): void
2778
    {
2779
        $this->expectException(NotFoundHttpException::class);
2780
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2781
2782
        $this->request->query->set('id', 123);
2783
2784
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2785
            ->method('checkAccess')
2786
            ->with($this->equalTo('historyViewRevision'));
2787
2788
        $object = new \stdClass();
2789
2790
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2792
            ->willReturn($object);
2793
2794
        $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...
2795
            ->method('getClass')
2796
            ->willReturn('Foo');
2797
2798
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2823
            ->willReturn($object);
2824
2825
        $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...
2826
            ->method('getClass')
2827
            ->willReturn('Foo');
2828
2829
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

Loading history...
2830
            ->method('hasReader')
2831
            ->with($this->equalTo('Foo'))
2832
            ->willReturn(true);
2833
2834
        $reader = $this->createMock(AuditReaderInterface::class);
2835
2836
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

Loading history...
2854
            ->method('checkAccess')
2855
            ->with($this->equalTo('historyViewRevision'));
2856
2857
        $object = new \stdClass();
2858
2859
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2860
            ->method('getObject')
2861
            ->willReturn($object);
2862
2863
        $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...
2864
            ->method('getClass')
2865
            ->willReturn('Foo');
2866
2867
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

Loading history...
2875
            ->method('getReader')
2876
            ->with($this->equalTo('Foo'))
2877
            ->willReturn($reader);
2878
2879
        $objectRevision = new \stdClass();
2880
        $objectRevision->revision = 456;
2881
2882
        $reader->expects($this->once())
2883
            ->method('find')
2884
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2885
            ->willReturn($objectRevision);
2886
2887
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2914
            ->method('checkAccess')
2915
            ->with($this->equalTo('historyCompareRevisions'))
2916
            ->will($this->throwException(new AccessDeniedException()));
2917
2918
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2919
    }
2920
2921
    public function testHistoryCompareRevisionsActionNotFoundException(): void
2922
    {
2923
        $this->expectException(NotFoundHttpException::class);
2924
        $this->expectExceptionMessage('unable to find the object with id: 123');
2925
2926
        $this->request->query->set('id', 123);
2927
2928
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2933
            ->method('getObject')
2934
            ->willReturn(null);
2935
2936
        $this->controller->historyCompareRevisionsAction($this->request, null, null);
2937
    }
2938
2939
    public function testHistoryCompareRevisionsActionNoReader(): void
2940
    {
2941
        $this->expectException(NotFoundHttpException::class);
2942
        $this->expectExceptionMessage('unable to find the audit reader for class : Foo');
2943
2944
        $this->request->query->set('id', 123);
2945
2946
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2947
            ->method('checkAccess')
2948
            ->with($this->equalTo('historyCompareRevisions'));
2949
2950
        $object = new \stdClass();
2951
2952
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2954
            ->willReturn($object);
2955
2956
        $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...
2957
            ->method('getClass')
2958
            ->willReturn('Foo');
2959
2960
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2985
            ->willReturn($object);
2986
2987
        $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...
2988
            ->method('getClass')
2989
            ->willReturn('Foo');
2990
2991
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

Loading history...
2992
            ->method('hasReader')
2993
            ->with($this->equalTo('Foo'))
2994
            ->willReturn(true);
2995
2996
        $reader = $this->createMock(AuditReaderInterface::class);
2997
2998
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

Loading history...
3022
            ->method('checkAccess')
3023
            ->with($this->equalTo('historyCompareRevisions'));
3024
3025
        $object = new \stdClass();
3026
3027
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
3029
            ->willReturn($object);
3030
3031
        $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...
3032
            ->method('getClass')
3033
            ->willReturn('Foo');
3034
3035
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

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

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

Loading history...
3069
            ->method('checkAccess')
3070
            ->with($this->equalTo('historyCompareRevisions'));
3071
3072
        $object = new \stdClass();
3073
3074
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
3076
            ->willReturn($object);
3077
3078
        $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...
3079
            ->method('getClass')
3080
            ->willReturn('Foo');
3081
3082
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
3193
            ->method('getDatagrid')
3194
            ->willReturn($datagrid);
3195
3196
        $this->request->setMethod(Request::METHOD_POST);
3197
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3198
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3199
3200
        $this->controller->batchAction($this->request);
3201
    }
3202
3203
    public function testBatchActionWithoutConfirmation(): void
3204
    {
3205
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3206
3207
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
3495
            ->method('getDatagrid')
3496
            ->willReturn($datagrid);
3497
3498
        $modelManager = $this->createMock(ModelManagerInterface::class);
3499
3500
        $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...
3501
            ->method('getModelManager')
3502
            ->willReturn($modelManager);
3503
3504
        $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...
3505
            ->method('getClass')
3506
            ->willReturn('Foo');
3507
3508
        $this->request->setMethod(Request::METHOD_POST);
3509
        $this->request->request->set('action', 'bar');
3510
        $this->request->request->set('idx', []);
3511
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3512
3513
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3514
        $result = $controller->batchAction($this->request);
3515
3516
        $this->assertInstanceOf(Response::class, $result);
3517
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3518
    }
3519
3520
    public function testBatchActionWithRequesData(): void
3521
    {
3522
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3523
3524
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
3542
            ->method('checkAccess')
3543
            ->with($this->equalTo('batchDelete'));
3544
3545
        $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...
3546
            ->method('getModelManager')
3547
            ->willReturn($modelManager);
3548
3549
        $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...
3550
            ->method('getClass')
3551
            ->willReturn('Foo');
3552
3553
        $modelManager->expects($this->once())
3554
            ->method('addIdentifiersToQuery')
3555
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3556
            ->willReturn(true);
3557
3558
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3559
3560
        $this->request->setMethod(Request::METHOD_POST);
3561
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3562
        $this->request->request->set('foo', 'bar');
3563
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3564
3565
        $result = $this->controller->batchAction($this->request);
3566
3567
        $this->assertInstanceOf(RedirectResponse::class, $result);
3568
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3569
        $this->assertSame('list', $result->getTargetUrl());
3570
        $this->assertSame('bar', $this->request->request->get('foo'));
3571
    }
3572
3573
    public function getCsrfProvider()
3574
    {
3575
        return $this->csrfProvider;
3576
    }
3577
3578
    public function getToStringValues()
3579
    {
3580
        return [
3581
            ['', ''],
3582
            ['Foo', 'Foo'],
3583
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3584
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3585
        ];
3586
    }
3587
3588
    private function assertLoggerLogsModelManagerException($subject, string $method): void
3589
    {
3590
        $exception = new ModelManagerException(
3591
            $message = 'message',
3592
            1234,
3593
            new \Exception($previousExceptionMessage = 'very useful message')
3594
        );
3595
3596
        $subject->expects($this->once())
3597
            ->method($method)
3598
            ->willReturnCallback(static function () use ($exception): void {
3599
                throw $exception;
3600
            });
3601
3602
        $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...
3603
            ->method('error')
3604
            ->with($message, [
3605
                'exception' => $exception,
3606
                'previous_exception_message' => $previousExceptionMessage,
3607
            ]);
3608
    }
3609
3610
    private function expectTranslate(
3611
        string $id,
3612
        array $parameters = [],
3613
        ?string $domain = null,
3614
        ?string $locale = null
3615
    ): void {
3616
        $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...
3617
            ->method('trans')
3618
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3619
            ->willReturn($id);
3620
    }
3621
3622
    private function createTwig(): Environment
3623
    {
3624
        $templatingRenderReturnCallback = $this->returnCallback(function (
3625
            string $name,
3626
            array $context = []
3627
        ): string {
3628
            $this->template = $name;
3629
3630
            $this->parameters = $context;
3631
3632
            return '';
3633
        });
3634
3635
        $twig = $this->getMockBuilder(Environment::class)
3636
            ->disableOriginalConstructor()
3637
            ->getMock();
3638
3639
        $twig
3640
            ->method('getRuntime')
3641
            ->willReturn($this->createMock(FormRenderer::class));
3642
3643
        $twig
3644
            ->method('render')
3645
            ->will($templatingRenderReturnCallback);
3646
3647
        return $twig;
3648
    }
3649
3650
    private function createController(string $classname = CRUDController::class): CRUDController
3651
    {
3652
        $requestStack = new RequestStack();
3653
        $requestStack->push($this->request);
3654
3655
        $pool = new Pool($this->container, 'title', 'logo.png');
3656
        $pool->setAdminServiceIds(['foo.admin']);
3657
3658
        return new $classname(
3659
            $requestStack,
3660
            $pool,
3661
            $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...
3662
            new BreadcrumbsBuilder([]),
3663
            $this->createTwig(),
3664
            $this->translator,
3665
            $this->session,
3666
            $this->kernel,
3667
            $this->auditManager,
3668
            $this->exporter,
3669
            new AdminExporter($this->exporter),
3670
            $this->csrfProvider,
3671
            $this->logger,
3672
            $this->adminObjectAclManipulator
3673
        );
3674
    }
3675
}
3676