Completed
Push — master ( bb4cb5...14823a )
by Grégoire
15s
created

testBatchActionNonRelevantAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\AdminBundle\Tests\Controller;
13
14
use Exporter\Exporter;
15
use Exporter\Writer\JsonWriter;
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Admin\AbstractAdmin;
18
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
19
use Sonata\AdminBundle\Admin\Pool;
20
use Sonata\AdminBundle\Controller\CRUDController;
21
use Sonata\AdminBundle\Exception\LockException;
22
use Sonata\AdminBundle\Exception\ModelManagerException;
23
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
24
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
25
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
26
use Symfony\Bridge\Twig\Extension\FormExtension;
27
use Symfony\Component\DependencyInjection\ContainerInterface;
28
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\HttpFoundation\RequestStack;
31
use Symfony\Component\HttpFoundation\Response;
32
use Symfony\Component\HttpFoundation\Session\Session;
33
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
34
use Symfony\Component\HttpFoundation\StreamedResponse;
35
use Symfony\Component\HttpKernel\Exception\HttpException;
36
use Symfony\Component\HttpKernel\Kernel;
37
use Symfony\Component\HttpKernel\KernelInterface;
38
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
39
use Symfony\Component\Security\Csrf\CsrfToken;
40
41
/**
42
 * Test for CRUDController.
43
 *
44
 * @author Andrej Hudec <[email protected]>
45
 *
46
 * @group legacy
47
 */
48
class CRUDControllerTest extends TestCase
49
{
50
    /**
51
     * @var CRUDController
52
     */
53
    private $controller;
54
55
    /**
56
     * @var Request
57
     */
58
    private $request;
59
60
    /**
61
     * @var AbstractAdmin
62
     */
63
    private $admin;
64
65
    /**
66
     * @var Pool
67
     */
68
    private $pool;
69
70
    /**
71
     * @var array
72
     */
73
    private $parameters;
74
75
    /**
76
     * @var Session
77
     */
78
    private $session;
79
80
    /**
81
     * @var \Sonata\AdminBundle\Model\AuditManager
82
     */
83
    private $auditManager;
84
85
    /**
86
     * @var ContainerInterface
87
     */
88
    private $container;
89
90
    /**
91
     * @var AdminObjectAclManipulator
92
     */
93
    private $adminObjectAclManipulator;
94
95
    /**
96
     * @var string
97
     */
98
    private $template;
99
100
    /**
101
     * @var array
102
     */
103
    private $protectedTestedMethods;
104
105
    /**
106
     * @var CsrfProviderInterface
107
     */
108
    private $csrfProvider;
109
110
    /**
111
     * @var KernelInterface
112
     */
113
    private $kernel;
114
115
    /**
116
     * @var TranslatorInterface
117
     */
118
    private $translator;
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    protected function setUp()
124
    {
125
        $this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
126
127
        $this->request = new Request();
128
        $this->pool = new Pool($this->container, 'title', 'logo.png');
129
        $this->pool->setAdminServiceIds(['foo.admin']);
130
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
131
        $this->admin = $this->getMockBuilder('Sonata\AdminBundle\Admin\AdminInterface')
132
            ->getMock();
133
        $this->translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
134
        $this->parameters = [];
135
        $this->template = '';
136
137
        // php 5.3 BC
138
        $params = &$this->parameters;
139
        $template = &$this->template;
140
141
        $templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine')
142
            ->setConstructorArgs([$this->container, []])
143
            ->getMock();
144
145
        $templatingRenderReturnCallback = $this->returnCallback(function (
146
            $view,
147
            array $parameters = [],
148
            Response $response = null
149
        ) use (
150
            &$params,
151
            &$template
152
        ) {
153
            $template = $view;
154
155
            if (null === $response) {
156
                $response = new Response();
157
            }
158
159
            $params = $parameters;
160
161
            return $response;
162
        });
163
164
        // SF < 3.3.10 BC
165
        $templating->expects($this->any())
166
            ->method('renderResponse')
167
            ->will($templatingRenderReturnCallback);
168
169
        $templating->expects($this->any())
170
            ->method('render')
171
            ->will($templatingRenderReturnCallback);
172
173
        $this->session = new Session(new MockArraySessionStorage());
174
175
        // php 5.3 BC
176
        $pool = $this->pool;
177
        $request = $this->request;
0 ignored issues
show
Unused Code introduced by
$request 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...
178
        $admin = $this->admin;
179
        $session = $this->session;
180
        $translator = $this->translator;
181
182
        $twig = $this->getMockBuilder('Twig_Environment')
183
            ->disableOriginalConstructor()
184
            ->getMock();
185
186
        $twigRenderer = $this->createMock('Symfony\Bridge\Twig\Form\TwigRendererInterface');
187
188
        $formExtension = new FormExtension($twigRenderer);
189
190
        $twig->expects($this->any())
191
            ->method('getExtension')
192
            ->will($this->returnCallback(function ($name) use ($formExtension) {
193
                switch ($name) {
194
                    case 'Symfony\Bridge\Twig\Extension\FormExtension':
195
                        return $formExtension;
196
                }
197
            }));
198
199
        $twig->expects($this->any())
200
            ->method('getRuntime')
201
            ->will($this->returnCallback(function ($name) use ($twigRenderer) {
202
                switch ($name) {
203
                    case 'Symfony\Bridge\Twig\Form\TwigRenderer':
204
                        if (method_exists('Symfony\Bridge\Twig\AppVariable', 'getToken')) {
205
                            return $twigRenderer;
206
                        }
207
208
                        throw new \Twig_Error_Runtime('This runtime exists when Symony >= 3.2.');
209
                }
210
            }));
211
212
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
213
        if (class_exists('Exporter\Exporter')) {
214
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
215
        } else {
216
            $exporter = $this->createMock('Sonata\AdminBundle\Export\Exporter');
217
218
            $exporter->expects($this->any())
219
                ->method('getResponse')
220
                ->will($this->returnValue(new StreamedResponse()));
221
        }
222
223
        $this->auditManager = $this->getMockBuilder('Sonata\AdminBundle\Model\AuditManager')
224
            ->disableOriginalConstructor()
225
            ->getMock();
226
227
        $this->adminObjectAclManipulator = $this->getMockBuilder('Sonata\AdminBundle\Util\AdminObjectAclManipulator')
228
            ->disableOriginalConstructor()
229
            ->getMock();
230
231
        // php 5.3 BC
232
        $request = $this->request;
233
        $auditManager = $this->auditManager;
234
        $adminObjectAclManipulator = $this->adminObjectAclManipulator;
235
236
        // Prefer Symfony 2.x interfaces
237
        if (interface_exists('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface')) {
238
            $this->csrfProvider = $this->getMockBuilder(
239
                'Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'
240
            )
241
                ->getMock();
242
243
            $this->csrfProvider->expects($this->any())
244
                ->method('generateCsrfToken')
245
                ->will($this->returnCallback(function ($intention) {
246
                    return 'csrf-token-123_'.$intention;
247
                }));
248
249
            $this->csrfProvider->expects($this->any())
250
                ->method('isCsrfTokenValid')
251
                ->will($this->returnCallback(function ($intention, $token) {
252
                    if ($token == 'csrf-token-123_'.$intention) {
253
                        return true;
254
                    }
255
256
                    return false;
257
                }));
258
        } else {
259
            $this->csrfProvider = $this->getMockBuilder(
260
                'Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'
261
            )
262
                ->getMock();
263
264
            $this->csrfProvider->expects($this->any())
265
                ->method('getToken')
266
                ->will($this->returnCallback(function ($intention) {
267
                    return new CsrfToken($intention, 'csrf-token-123_'.$intention);
268
                }));
269
270
            $this->csrfProvider->expects($this->any())
271
                ->method('isTokenValid')
272
                ->will($this->returnCallback(function (CsrfToken $token) {
273
                    if ($token->getValue() == 'csrf-token-123_'.$token->getId()) {
274
                        return true;
275
                    }
276
277
                    return false;
278
                }));
279
        }
280
281
        // php 5.3 BC
282
        $csrfProvider = $this->csrfProvider;
283
284
        $this->logger = $this->createMock('Psr\Log\LoggerInterface');
285
        $logger = $this->logger; // php 5.3 BC
286
287
        $requestStack = null;
288
        if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
289
            $requestStack = new RequestStack();
290
            $requestStack->push($request);
291
        }
292
293
        $this->kernel = $this->createMock('Symfony\Component\HttpKernel\KernelInterface');
294
        $kernel = $this->kernel; // php 5.3 BC
295
296
        $this->container->expects($this->any())
297
            ->method('get')
298
            ->will($this->returnCallback(function ($id) use (
299
                $pool,
300
                $admin,
301
                $request,
302
                $templating,
303
                $twig,
304
                $session,
305
                $exporter,
306
                $auditManager,
307
                $adminObjectAclManipulator,
308
                $requestStack,
309
                $csrfProvider,
310
                $logger,
311
                $kernel,
312
                $translator
313
            ) {
314
                switch ($id) {
315
                    case 'sonata.admin.pool':
316
                        return $pool;
317
                    case 'request':
318
                        return $request;
319
                    case 'request_stack':
320
                        return $requestStack;
321
                    case 'foo.admin':
322
                        return $admin;
323
                    case 'templating':
324
                        return $templating;
325
                    case 'twig':
326
                        return $twig;
327
                    case 'session':
328
                        return $session;
329
                    case 'sonata.admin.exporter':
330
                        return $exporter;
331
                    case 'sonata.admin.audit.manager':
332
                        return $auditManager;
333
                    case 'sonata.admin.object.manipulator.acl.admin':
334
                        return $adminObjectAclManipulator;
335
                    case 'form.csrf_provider':
336
                    case 'security.csrf.token_manager':
337
                        return $csrfProvider;
338
                    case 'logger':
339
                        return $logger;
340
                    case 'kernel':
341
                        return $kernel;
342
                    case 'translator':
343
                        return $translator;
344
                }
345
            }));
346
347
        // php 5.3
348
        $tthis = $this;
349
350
        $this->container->expects($this->any())
351
            ->method('has')
352
            ->will($this->returnCallback(function ($id) use ($tthis) {
353
                if ($id == 'form.csrf_provider' && Kernel::MAJOR_VERSION == 2 && $tthis->getCsrfProvider() !== null) {
354
                    return true;
355
                }
356
357
                if ($id == 'security.csrf.token_manager' && Kernel::MAJOR_VERSION >= 3 && $tthis->getCsrfProvider() !== null) {
358
                    return true;
359
                }
360
361
                if ($id == 'logger') {
362
                    return true;
363
                }
364
365
                if ($id == 'session') {
366
                    return true;
367
                }
368
369
                if ($id == 'templating') {
370
                    return true;
371
                }
372
373
                if ($id == 'translator') {
374
                    return true;
375
                }
376
377
                return false;
378
            }));
379
380
        $this->container->expects($this->any())
381
            ->method('getParameter')
382
            ->will($this->returnCallback(function ($name) {
383
                switch ($name) {
384
                    case 'security.role_hierarchy.roles':
385
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
386
                }
387
            }));
388
389
        $this->admin->expects($this->any())
390
            ->method('getTemplate')
391
            ->will($this->returnCallback(function ($name) {
392
                switch ($name) {
393
                    case 'ajax':
394
                        return 'SonataAdminBundle::ajax_layout.html.twig';
395
                    case 'layout':
396
                        return 'SonataAdminBundle::standard_layout.html.twig';
397
                    case 'show':
398
                        return 'SonataAdminBundle:CRUD:show.html.twig';
399
                    case 'show_compare':
400
                        return 'SonataAdminBundle:CRUD:show_compare.html.twig';
401
                    case 'edit':
402
                        return 'SonataAdminBundle:CRUD:edit.html.twig';
403
                    case 'dashboard':
404
                        return 'SonataAdminBundle:Core:dashboard.html.twig';
405
                    case 'search':
406
                        return 'SonataAdminBundle:Core:search.html.twig';
407
                    case 'list':
408
                        return 'SonataAdminBundle:CRUD:list.html.twig';
409
                    case 'preview':
410
                        return 'SonataAdminBundle:CRUD:preview.html.twig';
411
                    case 'history':
412
                        return 'SonataAdminBundle:CRUD:history.html.twig';
413
                    case 'acl':
414
                        return 'SonataAdminBundle:CRUD:acl.html.twig';
415
                    case 'delete':
416
                        return 'SonataAdminBundle:CRUD:delete.html.twig';
417
                    case 'batch':
418
                        return 'SonataAdminBundle:CRUD:list__batch.html.twig';
419
                    case 'batch_confirmation':
420
                        return 'SonataAdminBundle:CRUD:batch_confirmation.html.twig';
421
                }
422
            }));
423
424
        $this->admin->expects($this->any())
425
            ->method('getIdParameter')
426
            ->will($this->returnValue('id'));
427
428
        $this->admin->expects($this->any())
429
            ->method('getAccessMapping')
430
            ->will($this->returnValue([]));
431
432
        $this->admin->expects($this->any())
433
            ->method('generateUrl')
434
            ->will(
435
                $this->returnCallback(
436
                    function ($name, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

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

Loading history...
437
                        $result = $name;
438
                        if (!empty($parameters)) {
439
                            $result .= '?'.http_build_query($parameters);
440
                        }
441
442
                        return $result;
443
                    }
444
                )
445
            );
446
447
        $this->admin->expects($this->any())
448
            ->method('generateObjectUrl')
449
            ->will(
450
                $this->returnCallback(
451
                    function ($name, $object, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

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

Loading history...
452
                        $result = get_class($object).'_'.$name;
453
                        if (!empty($parameters)) {
454
                            $result .= '?'.http_build_query($parameters);
455
                        }
456
457
                        return $result;
458
                    }
459
                )
460
            );
461
462
        $this->controller = new CRUDController();
463
        $this->controller->setContainer($this->container);
464
465
        // Make some methods public to test them
466
        $testedMethods = [
467
            'renderJson',
468
            'isXmlHttpRequest',
469
            'configure',
470
            'getBaseTemplate',
471
            'redirectTo',
472
            'addFlash',
473
        ];
474
        foreach ($testedMethods as $testedMethod) {
475
            $method = new \ReflectionMethod('Sonata\\AdminBundle\\Controller\\CRUDController', $testedMethod);
476
            $method->setAccessible(true);
477
            $this->protectedTestedMethods[$testedMethod] = $method;
478
        }
479
    }
480
481
    public function testRenderJson1()
482
    {
483
        $data = ['example' => '123', 'foo' => 'bar'];
484
485
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
486
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
487
488
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
489
        $this->assertSame(json_encode($data), $response->getContent());
490
    }
491
492
    public function testRenderJson2()
493
    {
494
        $data = ['example' => '123', 'foo' => 'bar'];
495
496
        $this->request->headers->set('Content-Type', 'multipart/form-data');
497
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
498
499
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
500
        $this->assertSame(json_encode($data), $response->getContent());
501
    }
502
503
    public function testRenderJsonAjax()
504
    {
505
        $data = ['example' => '123', 'foo' => 'bar'];
506
507
        $this->request->attributes->set('_xml_http_request', true);
508
        $this->request->headers->set('Content-Type', 'multipart/form-data');
509
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
510
511
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
512
        $this->assertSame(json_encode($data), $response->getContent());
513
    }
514
515
    public function testIsXmlHttpRequest()
516
    {
517
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
518
519
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
520
521
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
522
523
        $this->request->headers->remove('X-Requested-With');
524
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
525
526
        $this->request->attributes->set('_xml_http_request', true);
527
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
528
    }
529
530
    public function testConfigure()
531
    {
532
        $uniqueId = '';
533
534
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
535
            ->method('setUniqid')
536
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId) {
537
                $uniqueId = $uniqid;
538
            }));
539
540
        $this->request->query->set('uniqid', 123456);
541
        $this->protectedTestedMethods['configure']->invoke($this->controller);
542
543
        $this->assertSame(123456, $uniqueId);
544
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
545
    }
546
547
    public function testConfigureChild()
548
    {
549
        $uniqueId = '';
550
551
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
552
            ->method('setUniqid')
553
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId) {
554
                $uniqueId = $uniqid;
555
            }));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('isChild')
559
            ->will($this->returnValue(true));
560
561
        $adminParent = $this->getMockBuilder('Sonata\AdminBundle\Admin\AdminInterface')
562
            ->disableOriginalConstructor()
563
            ->getMock();
564
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
565
            ->method('getParent')
566
            ->will($this->returnValue($adminParent));
567
568
        $this->request->query->set('uniqid', 123456);
569
        $this->protectedTestedMethods['configure']->invoke($this->controller);
570
571
        $this->assertSame(123456, $uniqueId);
572
        $this->assertAttributeInstanceOf(get_class($adminParent), 'admin', $this->controller);
573
    }
574
575
    public function testConfigureWithException()
576
    {
577
        $this->expectException(
578
            'RuntimeException',
579
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
580
        );
581
582
        $this->request->attributes->remove('_sonata_admin');
583
        $this->protectedTestedMethods['configure']->invoke($this->controller);
584
    }
585
586
    public function testConfigureWithException2()
587
    {
588
        $this->expectException(
589
            'RuntimeException',
590
            'Unable to find the admin class related to the current controller '.
591
            '(Sonata\AdminBundle\Controller\CRUDController)'
592
        );
593
594
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
595
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
596
        $this->protectedTestedMethods['configure']->invoke($this->controller);
597
    }
598
599
    public function testGetBaseTemplate()
600
    {
601
        $this->assertSame(
602
            'SonataAdminBundle::standard_layout.html.twig',
603
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
604
        );
605
606
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
607
        $this->assertSame(
608
            'SonataAdminBundle::ajax_layout.html.twig',
609
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
610
        );
611
612
        $this->request->headers->remove('X-Requested-With');
613
        $this->assertSame(
614
            'SonataAdminBundle::standard_layout.html.twig',
615
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
616
        );
617
618
        $this->request->attributes->set('_xml_http_request', true);
619
        $this->assertSame(
620
            'SonataAdminBundle::ajax_layout.html.twig',
621
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
622
        );
623
    }
624
625
    public function testRender()
626
    {
627
        $this->parameters = [];
628
        $this->assertInstanceOf(
629
            'Symfony\Component\HttpFoundation\Response',
630
            $this->controller->render('FooAdminBundle::foo.html.twig', [], null, $this->request)
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::render() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
631
        );
632
        $this->assertSame($this->admin, $this->parameters['admin']);
633
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
634
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
635
        $this->assertSame('FooAdminBundle::foo.html.twig', $this->template);
636
    }
637
638
    public function testRenderWithResponse()
639
    {
640
        $this->parameters = [];
641
        $response = $response = new Response();
642
        $response->headers->set('X-foo', 'bar');
643
        $responseResult = $this->controller->render('FooAdminBundle::foo.html.twig', [], $response, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::render() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
644
645
        $this->assertSame($response, $responseResult);
646
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
647
        $this->assertSame($this->admin, $this->parameters['admin']);
648
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
649
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
650
        $this->assertSame('FooAdminBundle::foo.html.twig', $this->template);
651
    }
652
653
    public function testRenderCustomParams()
654
    {
655
        $this->parameters = [];
656
        $this->assertInstanceOf(
657
            'Symfony\Component\HttpFoundation\Response',
658
            $this->controller->render('FooAdminBundle::foo.html.twig',
659
            ['foo' => 'bar'], null, $this->request)
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::render() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
660
        );
661
        $this->assertSame($this->admin, $this->parameters['admin']);
662
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
663
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
664
        $this->assertSame('bar', $this->parameters['foo']);
665
        $this->assertSame('FooAdminBundle::foo.html.twig', $this->template);
666
    }
667
668
    public function testRenderAjax()
669
    {
670
        $this->parameters = [];
671
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
672
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->render('FooAdminBundle::foo.html.twig', ['foo' => 'bar'], null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::render() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
673
        $this->assertSame($this->admin, $this->parameters['admin']);
674
        $this->assertSame('SonataAdminBundle::ajax_layout.html.twig', $this->parameters['base_template']);
675
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
676
        $this->assertSame('bar', $this->parameters['foo']);
677
        $this->assertSame('FooAdminBundle::foo.html.twig', $this->template);
678
    }
679
680
    public function testListActionAccessDenied()
681
    {
682
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
683
684
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
685
            ->method('checkAccess')
686
            ->with($this->equalTo('list'))
687
            ->will($this->throwException(new AccessDeniedException()));
688
689
        $this->controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
690
    }
691
692
    public function testPreList()
693
    {
694
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
695
            ->method('hasRoute')
696
            ->with($this->equalTo('list'))
697
            ->will($this->returnValue(true));
698
699
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
700
            ->method('checkAccess')
701
            ->with($this->equalTo('list'))
702
            ->will($this->returnValue(true));
703
704
        $controller = new PreCRUDController();
705
        $controller->setContainer($this->container);
706
707
        $response = $controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
708
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
709
        $this->assertSame('preList called', $response->getContent());
710
    }
711
712
    public function testListAction()
713
    {
714
        $datagrid = $this->createMock('Sonata\AdminBundle\Datagrid\DatagridInterface');
715
716
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
717
            ->method('hasRoute')
718
            ->with($this->equalTo('list'))
719
            ->will($this->returnValue(true));
720
721
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
722
            ->method('checkAccess')
723
            ->with($this->equalTo('list'))
724
            ->will($this->returnValue(true));
725
726
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
727
            ->disableOriginalConstructor()
728
            ->getMock();
729
730
        $form->expects($this->once())
731
            ->method('createView')
732
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
733
734
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
735
            ->method('getDatagrid')
736
            ->will($this->returnValue($datagrid));
737
738
        $datagrid->expects($this->once())
739
            ->method('getForm')
740
            ->will($this->returnValue($form));
741
742
        $this->parameters = [];
743
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->listAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
744
745
        $this->assertSame($this->admin, $this->parameters['admin']);
746
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
747
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
748
749
        $this->assertSame('list', $this->parameters['action']);
750
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
751
        $this->assertInstanceOf('Sonata\AdminBundle\Datagrid\DatagridInterface', $this->parameters['datagrid']);
752
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
753
        $this->assertSame([], $this->session->getFlashBag()->all());
754
        $this->assertSame('SonataAdminBundle:CRUD:list.html.twig', $this->template);
755
    }
756
757
    public function testBatchActionDeleteAccessDenied()
758
    {
759
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
760
761
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
762
            ->method('checkAccess')
763
            ->with($this->equalTo('batchDelete'))
764
            ->will($this->throwException(new AccessDeniedException()));
765
766
        $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
767
    }
768
769
    public function testBatchActionDelete()
770
    {
771
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
772
773
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
774
            ->method('checkAccess')
775
            ->with($this->equalTo('batchDelete'))
776
            ->will($this->returnValue(true));
777
778
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
779
            ->method('getModelManager')
780
            ->will($this->returnValue($modelManager));
781
782
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
783
            ->method('getFilterParameters')
784
            ->will($this->returnValue(['foo' => 'bar']));
785
786
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
787
788
        $result = $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
789
790
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
791
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
792
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
793
    }
794
795
    public function testBatchActionDeleteWithModelManagerException()
796
    {
797
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
798
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
799
800
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
801
            ->method('getModelManager')
802
            ->will($this->returnValue($modelManager));
803
804
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
805
            ->method('getFilterParameters')
806
            ->will($this->returnValue(['foo' => 'bar']));
807
808
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
809
810
        $result = $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
811
812
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
813
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
814
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
815
    }
816
817
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode()
818
    {
819
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
820
        $this->expectException('Sonata\AdminBundle\Exception\ModelManagerException');
821
822
        $modelManager->expects($this->once())
823
            ->method('batchDelete')
824
            ->will($this->returnCallback(function () {
825
                throw new ModelManagerException();
826
            }));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getModelManager')
830
            ->will($this->returnValue($modelManager));
831
832
        $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...
833
            ->method('isDebug')
834
            ->will($this->returnValue(true));
835
836
        $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
837
    }
838
839
    public function testShowActionNotFoundException()
840
    {
841
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
842
843
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
844
            ->method('getObject')
845
            ->will($this->returnValue(false));
846
847
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
848
    }
849
850
    public function testShowActionAccessDenied()
851
    {
852
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
853
854
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
859
            ->method('checkAccess')
860
            ->with($this->equalTo('show'))
861
            ->will($this->throwException(new AccessDeniedException()));
862
863
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
864
    }
865
866
    public function testPreShow()
867
    {
868
        $object = new \stdClass();
869
        $object->foo = 123456;
870
871
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
876
            ->method('checkAccess')
877
            ->with($this->equalTo('show'))
878
            ->will($this->returnValue(true));
879
880
        $controller = new PreCRUDController();
881
        $controller->setContainer($this->container);
882
883
        $response = $controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
884
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
885
        $this->assertSame('preShow called: 123456', $response->getContent());
886
    }
887
888
    public function testShowAction()
889
    {
890
        $object = new \stdClass();
891
892
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
897
            ->method('checkAccess')
898
            ->with($this->equalTo('show'))
899
            ->will($this->returnValue(true));
900
901
        $show = $this->createMock('Sonata\AdminBundle\Admin\FieldDescriptionCollection');
902
903
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
904
            ->method('getShow')
905
            ->will($this->returnValue($show));
906
907
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->showAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
908
909
        $this->assertSame($this->admin, $this->parameters['admin']);
910
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
911
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
912
913
        $this->assertSame('show', $this->parameters['action']);
914
        $this->assertInstanceOf('Sonata\AdminBundle\Admin\FieldDescriptionCollection', $this->parameters['elements']);
915
        $this->assertSame($object, $this->parameters['object']);
916
917
        $this->assertSame([], $this->session->getFlashBag()->all());
918
        $this->assertSame('SonataAdminBundle:CRUD:show.html.twig', $this->template);
919
    }
920
921
    /**
922
     * @dataProvider getRedirectToTests
923
     */
924
    public function testRedirectTo($expected, $route, $queryParams, $hasActiveSubclass)
925
    {
926
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
937
            ->method('hasRoute')
938
            ->with($this->equalTo($route))
939
            ->will($this->returnValue(true));
940
941
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
942
            ->method('hasAccess')
943
            ->with($this->equalTo($route))
944
            ->will($this->returnValue(true));
945
946
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
947
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
948
        $this->assertSame($expected, $response->getTargetUrl());
949
    }
950
951
    public function testRedirectToWithObject()
952
    {
953
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
954
            ->method('hasActiveSubclass')
955
            ->will($this->returnValue(false));
956
957
        $object = new \stdClass();
958
959
        $this->admin->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
960
            ->method('hasRoute')
961
            ->with($this->equalTo('edit'))
962
            ->will($this->returnValue(true));
963
964
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
965
            ->method('hasAccess')
966
            ->with($this->equalTo('edit'), $object)
967
            ->will($this->returnValue(false));
968
969
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
970
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
971
        $this->assertSame('list', $response->getTargetUrl());
972
    }
973
974
    public function getRedirectToTests()
975
    {
976
        return [
977
            ['stdClass_edit', 'edit', [], false],
978
            ['list', 'list', ['btn_update_and_list' => true], false],
979
            ['list', 'list', ['btn_create_and_list' => true], false],
980
            ['create', 'create', ['btn_create_and_create' => true], false],
981
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], true],
982
        ];
983
    }
984
985
    public function testAddFlash()
986
    {
987
        $this->protectedTestedMethods['addFlash']->invoke($this->controller, 'foo', 'bar');
988
        $this->assertSame(['bar'], $this->session->getFlashBag()->get('foo'));
989
    }
990
991
    public function testDeleteActionNotFoundException()
992
    {
993
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
994
995
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
996
            ->method('getObject')
997
            ->will($this->returnValue(false));
998
999
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1000
    }
1001
1002
    public function testDeleteActionAccessDenied()
1003
    {
1004
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
1005
1006
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1011
            ->method('checkAccess')
1012
            ->with($this->equalTo('delete'))
1013
            ->will($this->throwException(new AccessDeniedException()));
1014
1015
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1016
    }
1017
1018
    public function testPreDelete()
1019
    {
1020
        $object = new \stdClass();
1021
        $object->foo = 123456;
1022
1023
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1028
            ->method('checkAccess')
1029
            ->with($this->equalTo('delete'))
1030
            ->will($this->returnValue(true));
1031
1032
        $controller = new PreCRUDController();
1033
        $controller->setContainer($this->container);
1034
1035
        $response = $controller->deleteAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1036
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1037
        $this->assertSame('preDelete called: 123456', $response->getContent());
1038
    }
1039
1040
    public function testDeleteAction()
1041
    {
1042
        $object = new \stdClass();
1043
1044
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1049
            ->method('checkAccess')
1050
            ->with($this->equalTo('delete'))
1051
            ->will($this->returnValue(true));
1052
1053
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1054
1055
        $this->assertSame($this->admin, $this->parameters['admin']);
1056
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1057
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1058
1059
        $this->assertSame('delete', $this->parameters['action']);
1060
        $this->assertSame($object, $this->parameters['object']);
1061
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1062
1063
        $this->assertSame([], $this->session->getFlashBag()->all());
1064
        $this->assertSame('SonataAdminBundle:CRUD:delete.html.twig', $this->template);
1065
    }
1066
1067
    public function testDeleteActionNoCsrfToken()
1068
    {
1069
        $this->csrfProvider = null;
1070
1071
        $object = new \stdClass();
1072
1073
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1074
            ->method('getObject')
1075
            ->will($this->returnValue($object));
1076
1077
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1078
            ->method('checkAccess')
1079
            ->with($this->equalTo('delete'))
1080
            ->will($this->returnValue(true));
1081
1082
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1083
1084
        $this->assertSame($this->admin, $this->parameters['admin']);
1085
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1086
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1087
1088
        $this->assertSame('delete', $this->parameters['action']);
1089
        $this->assertSame($object, $this->parameters['object']);
1090
        $this->assertSame(false, $this->parameters['csrf_token']);
1091
1092
        $this->assertSame([], $this->session->getFlashBag()->all());
1093
        $this->assertSame('SonataAdminBundle:CRUD:delete.html.twig', $this->template);
1094
    }
1095
1096
    public function testDeleteActionAjaxSuccess1()
1097
    {
1098
        $object = new \stdClass();
1099
1100
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1105
            ->method('checkAccess')
1106
            ->with($this->equalTo('delete'))
1107
            ->will($this->returnValue(true));
1108
1109
        $this->request->setMethod('DELETE');
1110
1111
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1112
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1113
1114
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1115
1116
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1117
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1118
        $this->assertSame([], $this->session->getFlashBag()->all());
1119
    }
1120
1121
    public function testDeleteActionAjaxSuccess2()
1122
    {
1123
        $object = new \stdClass();
1124
1125
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1126
            ->method('getObject')
1127
            ->will($this->returnValue($object));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1131
            ->with($this->equalTo('delete'))
1132
            ->will($this->returnValue(true));
1133
1134
        $this->request->setMethod('POST');
1135
        $this->request->request->set('_method', 'DELETE');
1136
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1137
1138
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1139
1140
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1141
1142
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1143
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1144
        $this->assertSame([], $this->session->getFlashBag()->all());
1145
    }
1146
1147
    public function testDeleteActionAjaxError()
1148
    {
1149
        $object = new \stdClass();
1150
1151
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1156
            ->method('checkAccess')
1157
            ->with($this->equalTo('delete'))
1158
            ->will($this->returnValue(true));
1159
1160
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1161
            ->method('getClass')
1162
            ->will($this->returnValue('stdClass'));
1163
1164
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1165
1166
        $this->request->setMethod('DELETE');
1167
1168
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1169
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1170
1171
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1172
1173
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1174
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1175
        $this->assertSame([], $this->session->getFlashBag()->all());
1176
    }
1177
1178
    public function testDeleteActionWithModelManagerExceptionInDebugMode()
1179
    {
1180
        $this->expectException('Sonata\AdminBundle\Exception\ModelManagerException');
1181
1182
        $object = new \stdClass();
1183
1184
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
1194
            ->method('delete')
1195
            ->will($this->returnCallback(function () {
1196
                throw new ModelManagerException();
1197
            }));
1198
1199
        $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...
1200
            ->method('isDebug')
1201
            ->will($this->returnValue(true));
1202
1203
        $this->request->setMethod('DELETE');
1204
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1205
1206
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1207
    }
1208
1209
    /**
1210
     * @dataProvider getToStringValues
1211
     */
1212
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue)
1213
    {
1214
        $object = new \stdClass();
1215
1216
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1221
            ->method('toString')
1222
            ->with($this->equalTo($object))
1223
            ->will($this->returnValue($toStringValue));
1224
1225
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1226
1227
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1228
            ->method('checkAccess')
1229
            ->with($this->equalTo('delete'))
1230
            ->will($this->returnValue(true));
1231
1232
        $this->request->setMethod('DELETE');
1233
1234
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1235
1236
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1237
1238
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1239
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1240
        $this->assertSame('list', $response->getTargetUrl());
1241
    }
1242
1243
    /**
1244
     * @dataProvider getToStringValues
1245
     */
1246
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue)
1247
    {
1248
        $object = new \stdClass();
1249
1250
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1255
            ->method('checkAccess')
1256
            ->with($this->equalTo('delete'))
1257
            ->will($this->returnValue(true));
1258
1259
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1260
            ->method('toString')
1261
            ->with($this->equalTo($object))
1262
            ->will($this->returnValue($toStringValue));
1263
1264
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1265
1266
        $this->request->setMethod('POST');
1267
        $this->request->request->set('_method', 'DELETE');
1268
1269
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1270
1271
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1272
1273
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1274
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1275
        $this->assertSame('list', $response->getTargetUrl());
1276
    }
1277
1278
    /**
1279
     * @dataProvider getToStringValues
1280
     */
1281
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue)
1282
    {
1283
        $this->csrfProvider = null;
1284
1285
        $object = new \stdClass();
1286
1287
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1292
            ->method('checkAccess')
1293
            ->with($this->equalTo('delete'))
1294
            ->will($this->returnValue(true));
1295
1296
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1297
            ->method('toString')
1298
            ->with($this->equalTo($object))
1299
            ->will($this->returnValue($toStringValue));
1300
1301
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1302
1303
        $this->request->setMethod('POST');
1304
        $this->request->request->set('_method', 'DELETE');
1305
1306
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1307
1308
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1309
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1310
        $this->assertSame('list', $response->getTargetUrl());
1311
    }
1312
1313
    public function testDeleteActionWrongRequestMethod()
1314
    {
1315
        $object = new \stdClass();
1316
1317
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1318
            ->method('getObject')
1319
            ->will($this->returnValue($object));
1320
1321
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1322
            ->method('checkAccess')
1323
            ->with($this->equalTo('delete'))
1324
            ->will($this->returnValue(true));
1325
1326
        //without POST request parameter "_method" should not be used as real REST method
1327
        $this->request->query->set('_method', 'DELETE');
1328
1329
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1330
1331
        $this->assertSame($this->admin, $this->parameters['admin']);
1332
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1333
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1334
1335
        $this->assertSame('delete', $this->parameters['action']);
1336
        $this->assertSame($object, $this->parameters['object']);
1337
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1338
1339
        $this->assertSame([], $this->session->getFlashBag()->all());
1340
        $this->assertSame('SonataAdminBundle:CRUD:delete.html.twig', $this->template);
1341
    }
1342
1343
    /**
1344
     * @dataProvider getToStringValues
1345
     */
1346
    public function testDeleteActionError($expectedToStringValue, $toStringValue)
1347
    {
1348
        $object = new \stdClass();
1349
1350
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1351
            ->method('getObject')
1352
            ->will($this->returnValue($object));
1353
1354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1355
            ->method('checkAccess')
1356
            ->with($this->equalTo('delete'))
1357
            ->will($this->returnValue(true));
1358
1359
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1360
            ->method('toString')
1361
            ->with($this->equalTo($object))
1362
            ->will($this->returnValue($toStringValue));
1363
1364
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1365
1366
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1367
1368
        $this->request->setMethod('DELETE');
1369
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1370
1371
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1372
1373
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1374
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1375
        $this->assertSame('list', $response->getTargetUrl());
1376
    }
1377
1378
    public function testDeleteActionInvalidCsrfToken()
1379
    {
1380
        $object = new \stdClass();
1381
1382
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1383
            ->method('getObject')
1384
            ->will($this->returnValue($object));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1388
            ->with($this->equalTo('delete'))
1389
            ->will($this->returnValue(true));
1390
1391
        $this->request->setMethod('POST');
1392
        $this->request->request->set('_method', 'DELETE');
1393
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1394
1395
        try {
1396
            $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1397
        } catch (HttpException $e) {
1398
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1399
            $this->assertSame(400, $e->getStatusCode());
1400
        }
1401
    }
1402
1403
    public function testEditActionNotFoundException()
1404
    {
1405
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
1406
1407
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1408
            ->method('getObject')
1409
            ->will($this->returnValue(false));
1410
1411
        $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1412
    }
1413
1414
    public function testEditActionAccessDenied()
1415
    {
1416
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(new \stdClass()));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1424
            ->with($this->equalTo('edit'))
1425
            ->will($this->throwException(new AccessDeniedException()));
1426
1427
        $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1428
    }
1429
1430
    public function testPreEdit()
1431
    {
1432
        $object = new \stdClass();
1433
        $object->foo = 123456;
1434
1435
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1436
            ->method('getObject')
1437
            ->will($this->returnValue($object));
1438
1439
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1440
            ->method('checkAccess')
1441
            ->with($this->equalTo('edit'))
1442
            ->will($this->returnValue(true));
1443
1444
        $controller = new PreCRUDController();
1445
        $controller->setContainer($this->container);
1446
1447
        $response = $controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1448
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1449
        $this->assertSame('preEdit called: 123456', $response->getContent());
1450
    }
1451
1452
    public function testEditAction()
1453
    {
1454
        $object = new \stdClass();
1455
1456
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1457
            ->method('getObject')
1458
            ->will($this->returnValue($object));
1459
1460
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1461
            ->method('checkAccess')
1462
            ->with($this->equalTo('edit'))
1463
            ->will($this->returnValue(true));
1464
1465
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1466
            ->disableOriginalConstructor()
1467
            ->getMock();
1468
1469
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1470
            ->method('getForm')
1471
            ->will($this->returnValue($form));
1472
1473
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1474
1475
        $form->expects($this->any())
1476
            ->method('createView')
1477
            ->will($this->returnValue($formView));
1478
1479
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1480
1481
        $this->assertSame($this->admin, $this->parameters['admin']);
1482
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1483
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1484
1485
        $this->assertSame('edit', $this->parameters['action']);
1486
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1487
        $this->assertSame($object, $this->parameters['object']);
1488
        $this->assertSame([], $this->session->getFlashBag()->all());
1489
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1490
    }
1491
1492
    /**
1493
     * @dataProvider getToStringValues
1494
     */
1495
    public function testEditActionSuccess($expectedToStringValue, $toStringValue)
1496
    {
1497
        $object = new \stdClass();
1498
1499
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1504
            ->method('update')
1505
            ->will($this->returnArgument(0));
1506
1507
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1512
            ->method('hasRoute')
1513
            ->with($this->equalTo('edit'))
1514
            ->will($this->returnValue(true));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('hasAccess')
1518
            ->with($this->equalTo('edit'))
1519
            ->will($this->returnValue(true));
1520
1521
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1522
            ->disableOriginalConstructor()
1523
            ->getMock();
1524
1525
        $form->expects($this->once())
1526
            ->method('getData')
1527
            ->will($this->returnValue($object));
1528
1529
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1530
            ->method('getForm')
1531
            ->will($this->returnValue($form));
1532
1533
        $form->expects($this->once())
1534
            ->method('isSubmitted')
1535
            ->will($this->returnValue(true));
1536
1537
        $form->expects($this->once())
1538
            ->method('isValid')
1539
            ->will($this->returnValue(true));
1540
1541
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1542
            ->method('toString')
1543
            ->with($this->equalTo($object))
1544
            ->will($this->returnValue($toStringValue));
1545
1546
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1547
1548
        $this->request->setMethod('POST');
1549
1550
        $response = $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1551
1552
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1553
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1554
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1555
    }
1556
1557
    /**
1558
     * @dataProvider getToStringValues
1559
     */
1560
    public function testEditActionError($expectedToStringValue, $toStringValue)
1561
    {
1562
        $object = new \stdClass();
1563
1564
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1565
            ->method('getObject')
1566
            ->will($this->returnValue($object));
1567
1568
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1569
            ->method('checkAccess')
1570
            ->with($this->equalTo('edit'))
1571
            ->will($this->returnValue(true));
1572
1573
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1574
            ->disableOriginalConstructor()
1575
            ->getMock();
1576
1577
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1578
            ->method('getForm')
1579
            ->will($this->returnValue($form));
1580
1581
        $form->expects($this->once())
1582
            ->method('isSubmitted')
1583
            ->will($this->returnValue(true));
1584
1585
        $form->expects($this->once())
1586
            ->method('isValid')
1587
            ->will($this->returnValue(false));
1588
1589
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1590
            ->method('toString')
1591
            ->with($this->equalTo($object))
1592
            ->will($this->returnValue($toStringValue));
1593
1594
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1595
1596
        $this->request->setMethod('POST');
1597
1598
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1599
1600
        $form->expects($this->any())
1601
            ->method('createView')
1602
            ->will($this->returnValue($formView));
1603
1604
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1605
1606
        $this->assertSame($this->admin, $this->parameters['admin']);
1607
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1608
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1609
1610
        $this->assertSame('edit', $this->parameters['action']);
1611
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1612
        $this->assertSame($object, $this->parameters['object']);
1613
1614
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1615
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1616
    }
1617
1618
    public function testEditActionAjaxSuccess()
1619
    {
1620
        $object = new \stdClass();
1621
1622
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1627
            ->method('update')
1628
            ->will($this->returnArgument(0));
1629
1630
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1631
            ->method('checkAccess')
1632
            ->with($this->equalTo('edit'))
1633
            ->will($this->returnValue(true));
1634
1635
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1636
            ->disableOriginalConstructor()
1637
            ->getMock();
1638
1639
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1640
            ->method('getForm')
1641
            ->will($this->returnValue($form));
1642
1643
        $form->expects($this->once())
1644
            ->method('isSubmitted')
1645
            ->will($this->returnValue(true));
1646
1647
        $form->expects($this->once())
1648
            ->method('isValid')
1649
            ->will($this->returnValue(true));
1650
1651
        $form->expects($this->once())
1652
            ->method('getData')
1653
            ->will($this->returnValue($object));
1654
1655
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1656
            ->method('getNormalizedIdentifier')
1657
            ->with($this->equalTo($object))
1658
            ->will($this->returnValue('foo_normalized'));
1659
1660
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1661
            ->method('toString')
1662
            ->will($this->returnValue('foo'));
1663
1664
        $this->request->setMethod('POST');
1665
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1666
1667
        $response = $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1668
1669
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1670
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1671
        $this->assertSame([], $this->session->getFlashBag()->all());
1672
    }
1673
1674
    public function testEditActionAjaxError()
1675
    {
1676
        $object = new \stdClass();
1677
1678
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1683
            ->method('checkAccess')
1684
            ->with($this->equalTo('edit'))
1685
            ->will($this->returnValue(true));
1686
1687
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1688
            ->disableOriginalConstructor()
1689
            ->getMock();
1690
1691
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1692
            ->method('getForm')
1693
            ->will($this->returnValue($form));
1694
1695
        $form->expects($this->once())
1696
            ->method('isSubmitted')
1697
            ->will($this->returnValue(true));
1698
1699
        $form->expects($this->once())
1700
            ->method('isValid')
1701
            ->will($this->returnValue(false));
1702
1703
        $this->request->setMethod('POST');
1704
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1705
1706
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1707
1708
        $form->expects($this->any())
1709
            ->method('createView')
1710
            ->will($this->returnValue($formView));
1711
1712
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1713
1714
        $this->assertSame($this->admin, $this->parameters['admin']);
1715
        $this->assertSame('SonataAdminBundle::ajax_layout.html.twig', $this->parameters['base_template']);
1716
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1717
1718
        $this->assertSame('edit', $this->parameters['action']);
1719
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1720
        $this->assertSame($object, $this->parameters['object']);
1721
1722
        $this->assertSame([], $this->session->getFlashBag()->all());
1723
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1724
    }
1725
1726
    /**
1727
     * @dataProvider getToStringValues
1728
     */
1729
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue)
1730
    {
1731
        $object = new \stdClass();
1732
1733
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1734
            ->method('getObject')
1735
            ->will($this->returnValue($object));
1736
1737
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1738
            ->method('checkAccess')
1739
            ->with($this->equalTo('edit'))
1740
            ->will($this->returnValue(true));
1741
1742
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1743
            ->method('getClass')
1744
            ->will($this->returnValue('stdClass'));
1745
1746
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1747
            ->disableOriginalConstructor()
1748
            ->getMock();
1749
1750
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1751
            ->method('getForm')
1752
            ->will($this->returnValue($form));
1753
1754
        $form->expects($this->once())
1755
            ->method('isValid')
1756
            ->will($this->returnValue(true));
1757
1758
        $form->expects($this->once())
1759
            ->method('getData')
1760
            ->will($this->returnValue($object));
1761
1762
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1763
            ->method('toString')
1764
            ->with($this->equalTo($object))
1765
            ->will($this->returnValue($toStringValue));
1766
1767
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1768
1769
        $form->expects($this->once())
1770
            ->method('isSubmitted')
1771
            ->will($this->returnValue(true));
1772
        $this->request->setMethod('POST');
1773
1774
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1775
1776
        $form->expects($this->any())
1777
            ->method('createView')
1778
            ->will($this->returnValue($formView));
1779
1780
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1781
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1782
1783
        $this->assertSame($this->admin, $this->parameters['admin']);
1784
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1785
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1786
1787
        $this->assertSame('edit', $this->parameters['action']);
1788
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1789
        $this->assertSame($object, $this->parameters['object']);
1790
1791
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1792
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1793
    }
1794
1795
    public function testEditActionWithPreview()
1796
    {
1797
        $object = new \stdClass();
1798
1799
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1804
            ->method('checkAccess')
1805
            ->with($this->equalTo('edit'))
1806
            ->will($this->returnValue(true));
1807
1808
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1809
            ->disableOriginalConstructor()
1810
            ->getMock();
1811
1812
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1813
            ->method('getForm')
1814
            ->will($this->returnValue($form));
1815
1816
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1817
            ->method('supportsPreviewMode')
1818
            ->will($this->returnValue(true));
1819
1820
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1821
1822
        $form->expects($this->any())
1823
            ->method('createView')
1824
            ->will($this->returnValue($formView));
1825
1826
        $form->expects($this->once())
1827
            ->method('isSubmitted')
1828
            ->will($this->returnValue(true));
1829
1830
        $form->expects($this->once())
1831
            ->method('isValid')
1832
            ->will($this->returnValue(true));
1833
1834
        $this->request->setMethod('POST');
1835
        $this->request->request->set('btn_preview', 'Preview');
1836
1837
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1838
1839
        $this->assertSame($this->admin, $this->parameters['admin']);
1840
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1841
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1842
1843
        $this->assertSame('edit', $this->parameters['action']);
1844
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1845
        $this->assertSame($object, $this->parameters['object']);
1846
1847
        $this->assertSame([], $this->session->getFlashBag()->all());
1848
        $this->assertSame('SonataAdminBundle:CRUD:preview.html.twig', $this->template);
1849
    }
1850
1851
    public function testEditActionWithLockException()
1852
    {
1853
        $object = new \stdClass();
1854
        $class = get_class($object);
1855
1856
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1857
            ->method('getObject')
1858
            ->will($this->returnValue($object));
1859
1860
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1861
            ->method('checkAccess')
1862
            ->with($this->equalTo('edit'))
1863
            ->will($this->returnValue(true));
1864
1865
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1866
            ->method('getClass')
1867
            ->will($this->returnValue($class));
1868
1869
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1870
            ->disableOriginalConstructor()
1871
            ->getMock();
1872
1873
        $form->expects($this->any())
1874
            ->method('isValid')
1875
            ->will($this->returnValue(true));
1876
1877
        $form->expects($this->once())
1878
            ->method('getData')
1879
            ->will($this->returnValue($object));
1880
1881
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1882
            ->method('getForm')
1883
            ->will($this->returnValue($form));
1884
1885
        $form->expects($this->any())
1886
            ->method('isSubmitted')
1887
            ->will($this->returnValue(true));
1888
        $this->request->setMethod('POST');
1889
1890
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1891
            ->method('update')
1892
            ->will($this->throwException(new LockException()));
1893
1894
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1895
            ->method('toString')
1896
            ->with($this->equalTo($object))
1897
            ->will($this->returnValue($class));
1898
1899
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1900
1901
        $form->expects($this->any())
1902
            ->method('createView')
1903
            ->will($this->returnValue($formView));
1904
1905
        $this->expectTranslate('flash_lock_error', [
1906
            '%name%' => $class,
1907
            '%link_start%' => '<a href="stdClass_edit">',
1908
            '%link_end%' => '</a>',
1909
        ], 'SonataAdminBundle');
1910
1911
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1912
    }
1913
1914
    public function testCreateActionAccessDenied()
1915
    {
1916
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
1917
1918
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1919
            ->method('checkAccess')
1920
            ->with($this->equalTo('create'))
1921
            ->will($this->throwException(new AccessDeniedException()));
1922
1923
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1924
    }
1925
1926
    public function testPreCreate()
1927
    {
1928
        $object = new \stdClass();
1929
        $object->foo = 123456;
1930
1931
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1932
            ->method('checkAccess')
1933
            ->with($this->equalTo('create'))
1934
            ->will($this->returnValue(true));
1935
1936
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1937
            ->method('getClass')
1938
            ->will($this->returnValue('stdClass'));
1939
1940
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1941
            ->method('getNewInstance')
1942
            ->will($this->returnValue($object));
1943
1944
        $controller = new PreCRUDController();
1945
        $controller->setContainer($this->container);
1946
1947
        $response = $controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1948
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1949
        $this->assertSame('preCreate called: 123456', $response->getContent());
1950
    }
1951
1952
    public function testCreateAction()
1953
    {
1954
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1955
            ->method('checkAccess')
1956
            ->with($this->equalTo('create'))
1957
            ->will($this->returnValue(true));
1958
1959
        $object = new \stdClass();
1960
1961
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1962
            ->method('getClass')
1963
            ->will($this->returnValue('stdClass'));
1964
1965
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1966
            ->method('getNewInstance')
1967
            ->will($this->returnValue($object));
1968
1969
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1970
            ->disableOriginalConstructor()
1971
            ->getMock();
1972
1973
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1974
            ->method('getForm')
1975
            ->will($this->returnValue($form));
1976
1977
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1978
1979
        $form->expects($this->any())
1980
            ->method('createView')
1981
            ->will($this->returnValue($formView));
1982
1983
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1984
1985
        $this->assertSame($this->admin, $this->parameters['admin']);
1986
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1987
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1988
1989
        $this->assertSame('create', $this->parameters['action']);
1990
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1991
        $this->assertSame($object, $this->parameters['object']);
1992
1993
        $this->assertSame([], $this->session->getFlashBag()->all());
1994
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1995
    }
1996
1997
    /**
1998
     * @dataProvider getToStringValues
1999
     */
2000
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue)
2001
    {
2002
        $object = new \stdClass();
2003
2004
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2005
            ->method('checkAccess')
2006
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2007
                if ($name == 'edit') {
2008
                    return true;
2009
                }
2010
2011
                if ($name != 'create') {
2012
                    return false;
2013
                }
2014
2015
                if ($objectIn === null) {
2016
                    return true;
2017
                }
2018
2019
                return $objectIn === $object;
2020
            }));
2021
2022
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2023
            ->method('hasRoute')
2024
            ->with($this->equalTo('edit'))
2025
            ->will($this->returnValue(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\AbstractAdmin>.

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

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

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

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

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

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

Loading history...
2037
            ->method('create')
2038
            ->will($this->returnArgument(0));
2039
2040
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2041
            ->disableOriginalConstructor()
2042
            ->getMock();
2043
2044
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2045
            ->method('getClass')
2046
            ->will($this->returnValue('stdClass'));
2047
2048
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2049
            ->method('getForm')
2050
            ->will($this->returnValue($form));
2051
2052
        $form->expects($this->once())
2053
            ->method('isSubmitted')
2054
            ->will($this->returnValue(true));
2055
2056
        $form->expects($this->once())
2057
            ->method('isValid')
2058
            ->will($this->returnValue(true));
2059
2060
        $form->expects($this->once())
2061
            ->method('getData')
2062
            ->will($this->returnValue($object));
2063
2064
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2065
            ->method('toString')
2066
            ->with($this->equalTo($object))
2067
            ->will($this->returnValue($toStringValue));
2068
2069
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2070
2071
        $this->request->setMethod('POST');
2072
2073
        $response = $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2074
2075
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
2076
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2077
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2078
    }
2079
2080
    public function testCreateActionAccessDenied2()
2081
    {
2082
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2083
2084
        $object = new \stdClass();
2085
2086
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2087
            ->method('checkAccess')
2088
            ->will($this->returnCallback(function ($name, $object = null) {
2089
                if ($name != 'create') {
2090
                    throw new AccessDeniedException();
2091
                }
2092
                if ($object === null) {
2093
                    return true;
2094
                }
2095
2096
                throw new AccessDeniedException();
2097
            }));
2098
2099
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2100
            ->method('getNewInstance')
2101
            ->will($this->returnValue($object));
2102
2103
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2104
            ->disableOriginalConstructor()
2105
            ->getMock();
2106
2107
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2108
            ->method('getClass')
2109
            ->will($this->returnValue('stdClass'));
2110
2111
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2112
            ->method('getForm')
2113
            ->will($this->returnValue($form));
2114
2115
        $form->expects($this->once())
2116
            ->method('isSubmitted')
2117
            ->will($this->returnValue(true));
2118
2119
        $form->expects($this->once())
2120
            ->method('getData')
2121
            ->will($this->returnValue($object));
2122
2123
        $form->expects($this->once())
2124
            ->method('isValid')
2125
            ->will($this->returnValue(true));
2126
2127
        $this->request->setMethod('POST');
2128
2129
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2130
    }
2131
2132
    /**
2133
     * @dataProvider getToStringValues
2134
     */
2135
    public function testCreateActionError($expectedToStringValue, $toStringValue)
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(true));
2141
2142
        $object = new \stdClass();
2143
2144
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2149
            ->method('getNewInstance')
2150
            ->will($this->returnValue($object));
2151
2152
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2153
            ->disableOriginalConstructor()
2154
            ->getMock();
2155
2156
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2157
            ->method('getForm')
2158
            ->will($this->returnValue($form));
2159
2160
        $form->expects($this->once())
2161
            ->method('isSubmitted')
2162
            ->will($this->returnValue(true));
2163
2164
        $form->expects($this->once())
2165
            ->method('isValid')
2166
            ->will($this->returnValue(false));
2167
2168
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2169
            ->method('toString')
2170
            ->with($this->equalTo($object))
2171
            ->will($this->returnValue($toStringValue));
2172
2173
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2174
2175
        $this->request->setMethod('POST');
2176
2177
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2178
2179
        $form->expects($this->any())
2180
            ->method('createView')
2181
            ->will($this->returnValue($formView));
2182
2183
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2184
2185
        $this->assertSame($this->admin, $this->parameters['admin']);
2186
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2187
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2188
2189
        $this->assertSame('create', $this->parameters['action']);
2190
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2191
        $this->assertSame($object, $this->parameters['object']);
2192
2193
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2194
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2195
    }
2196
2197
    /**
2198
     * @dataProvider getToStringValues
2199
     */
2200
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue)
2201
    {
2202
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2203
            ->method('checkAccess')
2204
            ->with($this->equalTo('create'))
2205
            ->will($this->returnValue(true));
2206
2207
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2208
            ->method('getClass')
2209
            ->will($this->returnValue('stdClass'));
2210
2211
        $object = new \stdClass();
2212
2213
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2214
            ->method('getNewInstance')
2215
            ->will($this->returnValue($object));
2216
2217
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2218
            ->disableOriginalConstructor()
2219
            ->getMock();
2220
2221
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2222
            ->method('getForm')
2223
            ->will($this->returnValue($form));
2224
2225
        $form->expects($this->once())
2226
            ->method('isValid')
2227
            ->will($this->returnValue(true));
2228
2229
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2230
            ->method('toString')
2231
            ->with($this->equalTo($object))
2232
            ->will($this->returnValue($toStringValue));
2233
2234
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2235
2236
        $form->expects($this->once())
2237
            ->method('isSubmitted')
2238
            ->will($this->returnValue(true));
2239
2240
        $form->expects($this->once())
2241
            ->method('getData')
2242
            ->will($this->returnValue($object));
2243
2244
        $this->request->setMethod('POST');
2245
2246
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2247
2248
        $form->expects($this->any())
2249
            ->method('createView')
2250
            ->will($this->returnValue($formView));
2251
2252
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2253
2254
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2255
2256
        $this->assertSame($this->admin, $this->parameters['admin']);
2257
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2258
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2259
2260
        $this->assertSame('create', $this->parameters['action']);
2261
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2262
        $this->assertSame($object, $this->parameters['object']);
2263
2264
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2265
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2266
    }
2267
2268
    public function testCreateActionAjaxSuccess()
2269
    {
2270
        $object = new \stdClass();
2271
2272
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2273
            ->method('checkAccess')
2274
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2275
                if ($name != 'create') {
2276
                    return false;
2277
                }
2278
2279
                if ($objectIn === null) {
2280
                    return true;
2281
                }
2282
2283
                return $objectIn === $object;
2284
            }));
2285
2286
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2287
            ->method('getNewInstance')
2288
            ->will($this->returnValue($object));
2289
2290
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2291
            ->method('create')
2292
            ->will($this->returnArgument(0));
2293
2294
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2295
            ->disableOriginalConstructor()
2296
            ->getMock();
2297
2298
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2299
            ->method('getForm')
2300
            ->will($this->returnValue($form));
2301
2302
        $form->expects($this->once())
2303
            ->method('isSubmitted')
2304
            ->will($this->returnValue(true));
2305
2306
        $form->expects($this->once())
2307
            ->method('isValid')
2308
            ->will($this->returnValue(true));
2309
2310
        $form->expects($this->once())
2311
            ->method('getData')
2312
            ->will($this->returnValue($object));
2313
2314
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2315
            ->method('getClass')
2316
            ->will($this->returnValue('stdClass'));
2317
2318
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2319
            ->method('getNormalizedIdentifier')
2320
            ->with($this->equalTo($object))
2321
            ->will($this->returnValue('foo_normalized'));
2322
2323
        $this->request->setMethod('POST');
2324
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2325
2326
        $response = $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2327
2328
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
2329
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized']), $response->getContent());
2330
        $this->assertSame([], $this->session->getFlashBag()->all());
2331
    }
2332
2333
    public function testCreateActionAjaxError()
2334
    {
2335
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2336
            ->method('checkAccess')
2337
            ->with($this->equalTo('create'))
2338
            ->will($this->returnValue(true));
2339
2340
        $object = new \stdClass();
2341
2342
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2343
            ->method('getNewInstance')
2344
            ->will($this->returnValue($object));
2345
2346
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2347
            ->disableOriginalConstructor()
2348
            ->getMock();
2349
2350
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2351
            ->method('getClass')
2352
            ->will($this->returnValue('stdClass'));
2353
2354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2355
            ->method('getForm')
2356
            ->will($this->returnValue($form));
2357
2358
        $form->expects($this->once())
2359
            ->method('isSubmitted')
2360
            ->will($this->returnValue(true));
2361
2362
        $form->expects($this->once())
2363
            ->method('isValid')
2364
            ->will($this->returnValue(false));
2365
2366
        $this->request->setMethod('POST');
2367
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2368
2369
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2370
2371
        $form->expects($this->any())
2372
            ->method('createView')
2373
            ->will($this->returnValue($formView));
2374
2375
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2376
2377
        $this->assertSame($this->admin, $this->parameters['admin']);
2378
        $this->assertSame('SonataAdminBundle::ajax_layout.html.twig', $this->parameters['base_template']);
2379
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2380
2381
        $this->assertSame('create', $this->parameters['action']);
2382
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2383
        $this->assertSame($object, $this->parameters['object']);
2384
2385
        $this->assertSame([], $this->session->getFlashBag()->all());
2386
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2387
    }
2388
2389
    public function testCreateActionWithPreview()
2390
    {
2391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2392
            ->method('checkAccess')
2393
            ->with($this->equalTo('create'))
2394
            ->will($this->returnValue(true));
2395
2396
        $object = new \stdClass();
2397
2398
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2399
            ->method('getNewInstance')
2400
            ->will($this->returnValue($object));
2401
2402
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2403
            ->disableOriginalConstructor()
2404
            ->getMock();
2405
2406
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2407
            ->method('getClass')
2408
            ->will($this->returnValue('stdClass'));
2409
2410
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2411
            ->method('getForm')
2412
            ->will($this->returnValue($form));
2413
2414
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2415
            ->method('supportsPreviewMode')
2416
            ->will($this->returnValue(true));
2417
2418
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2419
2420
        $form->expects($this->any())
2421
            ->method('createView')
2422
            ->will($this->returnValue($formView));
2423
2424
        $form->expects($this->once())
2425
            ->method('isSubmitted')
2426
            ->will($this->returnValue(true));
2427
2428
        $form->expects($this->once())
2429
            ->method('isValid')
2430
            ->will($this->returnValue(true));
2431
2432
        $this->request->setMethod('POST');
2433
        $this->request->request->set('btn_preview', 'Preview');
2434
2435
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2436
2437
        $this->assertSame($this->admin, $this->parameters['admin']);
2438
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2439
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2440
2441
        $this->assertSame('create', $this->parameters['action']);
2442
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2443
        $this->assertSame($object, $this->parameters['object']);
2444
2445
        $this->assertSame([], $this->session->getFlashBag()->all());
2446
        $this->assertSame('SonataAdminBundle:CRUD:preview.html.twig', $this->template);
2447
    }
2448
2449
    public function testExportActionAccessDenied()
2450
    {
2451
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2452
2453
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2454
            ->method('checkAccess')
2455
            ->with($this->equalTo('export'))
2456
            ->will($this->throwException(new AccessDeniedException()));
2457
2458
        $this->controller->exportAction($this->request);
2459
    }
2460
2461
    public function testExportActionWrongFormat()
2462
    {
2463
        $this->expectException('RuntimeException', 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2467
            ->with($this->equalTo('export'))
2468
            ->will($this->returnValue(true));
2469
2470
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2471
            ->method('getExportFormats')
2472
            ->will($this->returnValue(['json']));
2473
2474
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2475
            ->method('getClass')
2476
            ->will($this->returnValue('Foo'));
2477
2478
        $this->request->query->set('format', 'csv');
2479
2480
        $this->controller->exportAction($this->request);
2481
    }
2482
2483
    public function testExportAction()
2484
    {
2485
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2486
            ->method('checkAccess')
2487
            ->with($this->equalTo('export'))
2488
            ->will($this->returnValue(true));
2489
2490
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2491
            ->method('getExportFormats')
2492
            ->will($this->returnValue(['json']));
2493
2494
        $dataSourceIterator = $this->createMock('Exporter\Source\SourceIteratorInterface');
2495
2496
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2497
            ->method('getDataSourceIterator')
2498
            ->will($this->returnValue($dataSourceIterator));
2499
2500
        $this->request->query->set('format', 'json');
2501
2502
        $response = $this->controller->exportAction($this->request);
2503
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
2504
        $this->assertSame(200, $response->getStatusCode());
2505
        $this->assertSame([], $this->session->getFlashBag()->all());
2506
    }
2507
2508
    public function testHistoryActionAccessDenied()
2509
    {
2510
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2511
2512
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2513
            ->method('getObject')
2514
            ->will($this->returnValue(new \StdClass()));
2515
2516
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2517
            ->method('checkAccess')
2518
            ->with($this->equalTo('history'))
2519
            ->will($this->throwException(new AccessDeniedException()));
2520
2521
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2522
    }
2523
2524
    public function testHistoryActionNotFoundException()
2525
    {
2526
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
2527
2528
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2529
            ->method('getObject')
2530
            ->will($this->returnValue(false));
2531
2532
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2533
    }
2534
2535
    public function testHistoryActionNoReader()
2536
    {
2537
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
2538
2539
        $this->request->query->set('id', 123);
2540
2541
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2542
            ->method('checkAccess')
2543
            ->with($this->equalTo('history'))
2544
            ->will($this->returnValue(true));
2545
2546
        $object = new \stdClass();
2547
2548
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2549
            ->method('getObject')
2550
            ->will($this->returnValue($object));
2551
2552
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2553
            ->method('getClass')
2554
            ->will($this->returnValue('Foo'));
2555
2556
        $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...
2557
            ->method('hasReader')
2558
            ->with($this->equalTo('Foo'))
2559
            ->will($this->returnValue(false));
2560
2561
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2562
    }
2563
2564
    public function testHistoryAction()
2565
    {
2566
        $this->request->query->set('id', 123);
2567
2568
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2569
            ->method('checkAccess')
2570
            ->with($this->equalTo('history'))
2571
            ->will($this->returnValue(true));
2572
2573
        $object = new \stdClass();
2574
2575
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2576
            ->method('getObject')
2577
            ->will($this->returnValue($object));
2578
2579
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2580
            ->method('getClass')
2581
            ->will($this->returnValue('Foo'));
2582
2583
        $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...
2584
            ->method('hasReader')
2585
            ->with($this->equalTo('Foo'))
2586
            ->will($this->returnValue(true));
2587
2588
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
2589
2590
        $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...
2591
            ->method('getReader')
2592
            ->with($this->equalTo('Foo'))
2593
            ->will($this->returnValue($reader));
2594
2595
        $reader->expects($this->once())
2596
            ->method('findRevisions')
2597
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2598
            ->will($this->returnValue([]));
2599
2600
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->historyAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2601
2602
        $this->assertSame($this->admin, $this->parameters['admin']);
2603
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2604
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2605
2606
        $this->assertSame('history', $this->parameters['action']);
2607
        $this->assertSame([], $this->parameters['revisions']);
2608
        $this->assertSame($object, $this->parameters['object']);
2609
2610
        $this->assertSame([], $this->session->getFlashBag()->all());
2611
        $this->assertSame('SonataAdminBundle:CRUD:history.html.twig', $this->template);
2612
    }
2613
2614
    public function testAclActionAclNotEnabled()
2615
    {
2616
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'ACL are not enabled for this admin');
2617
2618
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2619
    }
2620
2621
    public function testAclActionNotFoundException()
2622
    {
2623
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
2624
2625
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2630
            ->method('getObject')
2631
            ->will($this->returnValue(false));
2632
2633
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2634
    }
2635
2636
    public function testAclActionAccessDenied()
2637
    {
2638
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2639
2640
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2641
            ->method('isAclEnabled')
2642
            ->will($this->returnValue(true));
2643
2644
        $object = new \stdClass();
2645
2646
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2647
            ->method('getObject')
2648
            ->will($this->returnValue($object));
2649
2650
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2651
            ->method('checkAccess')
2652
            ->with($this->equalTo('acl'), $this->equalTo($object))
2653
            ->will($this->throwException(new AccessDeniedException()));
2654
2655
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2656
    }
2657
2658
    public function testAclAction()
2659
    {
2660
        $this->request->query->set('id', 123);
2661
2662
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2669
            ->method('getObject')
2670
            ->will($this->returnValue($object));
2671
2672
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2673
            ->method('checkAccess')
2674
            ->will($this->returnValue(true));
2675
2676
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2719
            ->method('getSecurityHandler')
2720
            ->will($this->returnValue($aclSecurityHandler));
2721
2722
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->aclAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2723
2724
        $this->assertSame($this->admin, $this->parameters['admin']);
2725
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2726
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2727
2728
        $this->assertSame('acl', $this->parameters['action']);
2729
        $this->assertSame([], $this->parameters['permissions']);
2730
        $this->assertSame($object, $this->parameters['object']);
2731
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['users']);
2732
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['roles']);
2733
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclUsersForm']);
2734
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclRolesForm']);
2735
2736
        $this->assertSame([], $this->session->getFlashBag()->all());
2737
        $this->assertSame('SonataAdminBundle:CRUD:acl.html.twig', $this->template);
2738
    }
2739
2740
    public function testAclActionInvalidUpdate()
2741
    {
2742
        $this->request->query->set('id', 123);
2743
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2744
2745
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2752
            ->method('getObject')
2753
            ->will($this->returnValue($object));
2754
2755
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2756
            ->method('checkAccess')
2757
            ->will($this->returnValue(true));
2758
2759
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2760
            ->method('getSecurityInformation')
2761
            ->will($this->returnValue([]));
2762
2763
        $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...
2764
            ->method('getMaskBuilderClass')
2765
            ->will($this->returnValue('\Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap'));
2766
2767
        $aclUsersForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2768
            ->disableOriginalConstructor()
2769
            ->getMock();
2770
2771
        $aclUsersForm->expects($this->once())
2772
            ->method('isValid')
2773
            ->will($this->returnValue(false));
2774
2775
        $aclUsersForm->expects($this->once())
2776
            ->method('createView')
2777
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2778
2779
        $aclRolesForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2780
            ->disableOriginalConstructor()
2781
            ->getMock();
2782
2783
        $aclRolesForm->expects($this->once())
2784
            ->method('createView')
2785
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2786
2787
        $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...
2788
            ->method('createAclUsersForm')
2789
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2790
            ->will($this->returnValue($aclUsersForm));
2791
2792
        $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...
2793
            ->method('createAclRolesForm')
2794
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2795
            ->will($this->returnValue($aclRolesForm));
2796
2797
        $aclSecurityHandler = $this->getMockBuilder('Sonata\AdminBundle\Security\Handler\AclSecurityHandler')
2798
            ->disableOriginalConstructor()
2799
            ->getMock();
2800
2801
        $aclSecurityHandler->expects($this->any())
2802
            ->method('getObjectPermissions')
2803
            ->will($this->returnValue([]));
2804
2805
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2806
            ->method('getSecurityHandler')
2807
            ->will($this->returnValue($aclSecurityHandler));
2808
2809
        $this->request->setMethod('POST');
2810
2811
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->aclAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2812
2813
        $this->assertSame($this->admin, $this->parameters['admin']);
2814
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2815
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2816
2817
        $this->assertSame('acl', $this->parameters['action']);
2818
        $this->assertSame([], $this->parameters['permissions']);
2819
        $this->assertSame($object, $this->parameters['object']);
2820
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['users']);
2821
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['roles']);
2822
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclUsersForm']);
2823
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclRolesForm']);
2824
2825
        $this->assertSame([], $this->session->getFlashBag()->all());
2826
        $this->assertSame('SonataAdminBundle:CRUD:acl.html.twig', $this->template);
2827
    }
2828
2829
    public function testAclActionSuccessfulUpdate()
2830
    {
2831
        $this->request->query->set('id', 123);
2832
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2833
2834
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2835
            ->method('isAclEnabled')
2836
            ->will($this->returnValue(true));
2837
2838
        $object = new \stdClass();
2839
2840
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2841
            ->method('getObject')
2842
            ->will($this->returnValue($object));
2843
2844
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2845
            ->method('checkAccess')
2846
            ->will($this->returnValue(true));
2847
2848
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2849
            ->method('getSecurityInformation')
2850
            ->will($this->returnValue([]));
2851
2852
        $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...
2853
            ->method('getMaskBuilderClass')
2854
            ->will($this->returnValue('\Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap'));
2855
2856
        $aclUsersForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2857
            ->disableOriginalConstructor()
2858
            ->getMock();
2859
2860
        $aclUsersForm->expects($this->any())
2861
            ->method('createView')
2862
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2863
2864
        $aclRolesForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2865
            ->disableOriginalConstructor()
2866
            ->getMock();
2867
2868
        $aclRolesForm->expects($this->any())
2869
            ->method('createView')
2870
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2871
2872
        $aclRolesForm->expects($this->once())
2873
            ->method('isValid')
2874
            ->will($this->returnValue(true));
2875
2876
        $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...
2877
            ->method('createAclUsersForm')
2878
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2879
            ->will($this->returnValue($aclUsersForm));
2880
2881
        $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...
2882
            ->method('createAclRolesForm')
2883
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2884
            ->will($this->returnValue($aclRolesForm));
2885
2886
        $aclSecurityHandler = $this->getMockBuilder('Sonata\AdminBundle\Security\Handler\AclSecurityHandler')
2887
            ->disableOriginalConstructor()
2888
            ->getMock();
2889
2890
        $aclSecurityHandler->expects($this->any())
2891
            ->method('getObjectPermissions')
2892
            ->will($this->returnValue([]));
2893
2894
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2895
            ->method('getSecurityHandler')
2896
            ->will($this->returnValue($aclSecurityHandler));
2897
2898
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2899
2900
        $this->request->setMethod('POST');
2901
2902
        $response = $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2903
2904
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
2905
2906
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2907
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2908
    }
2909
2910
    public function testHistoryViewRevisionActionAccessDenied()
2911
    {
2912
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2913
2914
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2915
            ->method('getObject')
2916
            ->will($this->returnValue(new \StdClass()));
2917
2918
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2919
            ->method('checkAccess')
2920
            ->with($this->equalTo('historyViewRevision'))
2921
            ->will($this->throwException(new AccessDeniedException()));
2922
2923
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2924
    }
2925
2926
    public function testHistoryViewRevisionActionNotFoundException()
2927
    {
2928
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the object with id: 123');
2929
2930
        $this->request->query->set('id', 123);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(false));
2935
2936
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2937
    }
2938
2939
    public function testHistoryViewRevisionActionNoReader()
2940
    {
2941
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
2942
2943
        $this->request->query->set('id', 123);
2944
2945
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2946
            ->method('checkAccess')
2947
            ->with($this->equalTo('historyViewRevision'))
2948
            ->will($this->returnValue(true));
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\AbstractAdmin>.

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

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

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

Loading history...
2957
            ->method('getClass')
2958
            ->will($this->returnValue('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
            ->will($this->returnValue(false));
2964
2965
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2966
    }
2967
2968
    public function testHistoryViewRevisionActionNotFoundRevision()
2969
    {
2970
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
2971
2972
        $this->request->query->set('id', 123);
2973
2974
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
2986
            ->method('getClass')
2987
            ->will($this->returnValue('Foo'));
2988
2989
        $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...
2990
            ->method('hasReader')
2991
            ->with($this->equalTo('Foo'))
2992
            ->will($this->returnValue(true));
2993
2994
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
2995
2996
        $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...
2997
            ->method('getReader')
2998
            ->with($this->equalTo('Foo'))
2999
            ->will($this->returnValue($reader));
3000
3001
        $reader->expects($this->once())
3002
            ->method('find')
3003
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3004
            ->will($this->returnValue(null));
3005
3006
        $this->controller->historyViewRevisionAction(123, 456, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3007
    }
3008
3009
    public function testHistoryViewRevisionAction()
3010
    {
3011
        $this->request->query->set('id', 123);
3012
3013
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
3025
            ->method('getClass')
3026
            ->will($this->returnValue('Foo'));
3027
3028
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\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...
3029
            ->method('hasReader')
3030
            ->with($this->equalTo('Foo'))
3031
            ->will($this->returnValue(true));
3032
3033
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
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('getReader')
3037
            ->with($this->equalTo('Foo'))
3038
            ->will($this->returnValue($reader));
3039
3040
        $objectRevision = new \stdClass();
3041
        $objectRevision->revision = 456;
3042
3043
        $reader->expects($this->once())
3044
            ->method('find')
3045
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3046
            ->will($this->returnValue($objectRevision));
3047
3048
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3049
            ->method('setSubject')
3050
            ->with($this->equalTo($objectRevision))
3051
            ->will($this->returnValue(null));
3052
3053
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3054
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3055
            ->method('getShow')
3056
            ->will($this->returnValue($fieldDescriptionCollection));
3057
3058
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->historyViewRevisionAction(123, 456, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3059
3060
        $this->assertSame($this->admin, $this->parameters['admin']);
3061
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3062
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3063
3064
        $this->assertSame('show', $this->parameters['action']);
3065
        $this->assertSame($objectRevision, $this->parameters['object']);
3066
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3067
3068
        $this->assertSame([], $this->session->getFlashBag()->all());
3069
        $this->assertSame('SonataAdminBundle:CRUD:show.html.twig', $this->template);
3070
    }
3071
3072
    public function testHistoryCompareRevisionsActionAccessDenied()
3073
    {
3074
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
3075
3076
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3077
            ->method('checkAccess')
3078
            ->with($this->equalTo('historyCompareRevisions'))
3079
            ->will($this->throwException(new AccessDeniedException()));
3080
3081
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3082
    }
3083
3084
    public function testHistoryCompareRevisionsActionNotFoundException()
3085
    {
3086
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the object with id: 123');
3087
3088
        $this->request->query->set('id', 123);
3089
3090
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3091
            ->method('checkAccess')
3092
            ->with($this->equalTo('historyCompareRevisions'))
3093
            ->will($this->returnValue(true));
3094
3095
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3096
            ->method('getObject')
3097
            ->will($this->returnValue(false));
3098
3099
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3100
    }
3101
3102
    public function testHistoryCompareRevisionsActionNoReader()
3103
    {
3104
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
3105
3106
        $this->request->query->set('id', 123);
3107
3108
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3109
            ->method('checkAccess')
3110
            ->with($this->equalTo('historyCompareRevisions'))
3111
            ->will($this->returnValue(true));
3112
3113
        $object = new \stdClass();
3114
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\AbstractAdmin>.

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

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

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

Loading history...
3120
            ->method('getClass')
3121
            ->will($this->returnValue('Foo'));
3122
3123
        $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...
3124
            ->method('hasReader')
3125
            ->with($this->equalTo('Foo'))
3126
            ->will($this->returnValue(false));
3127
3128
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3129
    }
3130
3131
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision()
3132
    {
3133
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3134
3135
        $this->request->query->set('id', 123);
3136
3137
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3138
            ->method('checkAccess')
3139
            ->with($this->equalTo('historyCompareRevisions'))
3140
            ->will($this->returnValue(true));
3141
3142
        $object = new \stdClass();
3143
3144
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3145
            ->method('getObject')
3146
            ->will($this->returnValue($object));
3147
3148
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3149
            ->method('getClass')
3150
            ->will($this->returnValue('Foo'));
3151
3152
        $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...
3153
            ->method('hasReader')
3154
            ->with($this->equalTo('Foo'))
3155
            ->will($this->returnValue(true));
3156
3157
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3158
3159
        $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...
3160
            ->method('getReader')
3161
            ->with($this->equalTo('Foo'))
3162
            ->will($this->returnValue($reader));
3163
3164
        // once because it will not be found and therefore the second call won't be executed
3165
        $reader->expects($this->once())
3166
            ->method('find')
3167
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3168
            ->will($this->returnValue(null));
3169
3170
        $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3171
    }
3172
3173
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision()
3174
    {
3175
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3176
3177
        $this->request->query->set('id', 123);
3178
3179
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3180
            ->method('checkAccess')
3181
            ->with($this->equalTo('historyCompareRevisions'))
3182
            ->will($this->returnValue(true));
3183
3184
        $object = new \stdClass();
3185
3186
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3187
            ->method('getObject')
3188
            ->will($this->returnValue($object));
3189
3190
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3191
            ->method('getClass')
3192
            ->will($this->returnValue('Foo'));
3193
3194
        $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...
3195
            ->method('hasReader')
3196
            ->with($this->equalTo('Foo'))
3197
            ->will($this->returnValue(true));
3198
3199
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3200
3201
        $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...
3202
            ->method('getReader')
3203
            ->with($this->equalTo('Foo'))
3204
            ->will($this->returnValue($reader));
3205
3206
        $objectRevision = new \stdClass();
3207
        $objectRevision->revision = 456;
3208
3209
        // first call should return, so the second call will throw an exception
3210
        $reader->expects($this->at(0))
3211
            ->method('find')
3212
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3213
            ->will($this->returnValue($objectRevision));
3214
3215
        $reader->expects($this->at(1))
3216
            ->method('find')
3217
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3218
            ->will($this->returnValue(null));
3219
3220
        $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3221
    }
3222
3223
    public function testHistoryCompareRevisionsActionAction()
3224
    {
3225
        $this->request->query->set('id', 123);
3226
3227
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3228
            ->method('checkAccess')
3229
            ->with($this->equalTo('historyCompareRevisions'))
3230
            ->will($this->returnValue(true));
3231
3232
        $object = new \stdClass();
3233
3234
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3235
            ->method('getObject')
3236
            ->will($this->returnValue($object));
3237
3238
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3239
            ->method('getClass')
3240
            ->will($this->returnValue('Foo'));
3241
3242
        $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...
3243
            ->method('hasReader')
3244
            ->with($this->equalTo('Foo'))
3245
            ->will($this->returnValue(true));
3246
3247
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3248
3249
        $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...
3250
            ->method('getReader')
3251
            ->with($this->equalTo('Foo'))
3252
            ->will($this->returnValue($reader));
3253
3254
        $objectRevision = new \stdClass();
3255
        $objectRevision->revision = 456;
3256
3257
        $compareObjectRevision = new \stdClass();
3258
        $compareObjectRevision->revision = 789;
3259
3260
        $reader->expects($this->at(0))
3261
            ->method('find')
3262
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3263
            ->will($this->returnValue($objectRevision));
3264
3265
        $reader->expects($this->at(1))
3266
            ->method('find')
3267
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3268
            ->will($this->returnValue($compareObjectRevision));
3269
3270
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3271
            ->method('setSubject')
3272
            ->with($this->equalTo($objectRevision))
3273
            ->will($this->returnValue(null));
3274
3275
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3276
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3277
            ->method('getShow')
3278
            ->will($this->returnValue($fieldDescriptionCollection));
3279
3280
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3281
3282
        $this->assertSame($this->admin, $this->parameters['admin']);
3283
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3284
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3285
3286
        $this->assertSame('show', $this->parameters['action']);
3287
        $this->assertSame($objectRevision, $this->parameters['object']);
3288
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3289
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3290
3291
        $this->assertSame([], $this->session->getFlashBag()->all());
3292
        $this->assertSame('SonataAdminBundle:CRUD:show_compare.html.twig', $this->template);
3293
    }
3294
3295
    public function testBatchActionWrongMethod()
3296
    {
3297
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'Invalid request type "GET", POST expected');
3298
3299
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3300
    }
3301
3302
    public function testBatchActionActionNotDefined()
3303
    {
3304
        $this->expectException('RuntimeException', 'The `foo` batch action is not defined');
3305
3306
        $batchActions = [];
3307
3308
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3309
            ->method('getBatchActions')
3310
            ->will($this->returnValue($batchActions));
3311
3312
        $this->request->setMethod('POST');
3313
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3314
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3315
3316
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3317
    }
3318
3319
    public function testBatchActionActionInvalidCsrfToken()
3320
    {
3321
        $this->request->setMethod('POST');
3322
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3323
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3324
3325
        try {
3326
            $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3327
        } catch (HttpException $e) {
3328
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3329
            $this->assertSame(400, $e->getStatusCode());
3330
        }
3331
    }
3332
3333
    public function testBatchActionMethodNotExist()
3334
    {
3335
        $this->expectException('RuntimeException', 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3336
3337
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3338
3339
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3340
            ->method('getBatchActions')
3341
            ->will($this->returnValue($batchActions));
3342
3343
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3344
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3345
            ->method('getDatagrid')
3346
            ->will($this->returnValue($datagrid));
3347
3348
        $this->request->setMethod('POST');
3349
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3350
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3351
3352
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3353
    }
3354
3355
    public function testBatchActionWithoutConfirmation()
3356
    {
3357
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3358
3359
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3360
            ->method('getBatchActions')
3361
            ->will($this->returnValue($batchActions));
3362
3363
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3364
3365
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3366
        $datagrid->expects($this->once())
3367
            ->method('getQuery')
3368
            ->will($this->returnValue($query));
3369
3370
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3371
            ->method('getDatagrid')
3372
            ->will($this->returnValue($datagrid));
3373
3374
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3375
3376
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3377
            ->method('checkAccess')
3378
            ->with($this->equalTo('batchDelete'))
3379
            ->will($this->returnValue(true));
3380
3381
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3382
            ->method('getModelManager')
3383
            ->will($this->returnValue($modelManager));
3384
3385
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3386
            ->method('getClass')
3387
            ->will($this->returnValue('Foo'));
3388
3389
        $modelManager->expects($this->once())
3390
            ->method('addIdentifiersToQuery')
3391
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3392
            ->will($this->returnValue(true));
3393
3394
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3395
3396
        $this->request->setMethod('POST');
3397
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3398
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3399
3400
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3401
3402
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3403
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3404
        $this->assertSame('list?', $result->getTargetUrl());
3405
    }
3406
3407
    public function testBatchActionWithoutConfirmation2()
3408
    {
3409
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3410
3411
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3412
            ->method('getBatchActions')
3413
            ->will($this->returnValue($batchActions));
3414
3415
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3416
3417
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3418
        $datagrid->expects($this->once())
3419
            ->method('getQuery')
3420
            ->will($this->returnValue($query));
3421
3422
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3423
            ->method('getDatagrid')
3424
            ->will($this->returnValue($datagrid));
3425
3426
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3427
3428
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3429
            ->method('checkAccess')
3430
            ->with($this->equalTo('batchDelete'))
3431
            ->will($this->returnValue(true));
3432
3433
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3434
            ->method('getModelManager')
3435
            ->will($this->returnValue($modelManager));
3436
3437
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3438
            ->method('getClass')
3439
            ->will($this->returnValue('Foo'));
3440
3441
        $modelManager->expects($this->once())
3442
            ->method('addIdentifiersToQuery')
3443
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3444
            ->will($this->returnValue(true));
3445
3446
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3447
3448
        $this->request->setMethod('POST');
3449
        $this->request->request->set('action', 'delete');
3450
        $this->request->request->set('idx', ['123', '456']);
3451
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3452
3453
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3454
3455
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3456
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3457
        $this->assertSame('list?', $result->getTargetUrl());
3458
    }
3459
3460
    public function testBatchActionWithConfirmation()
3461
    {
3462
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3463
3464
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3465
            ->method('getBatchActions')
3466
            ->will($this->returnValue($batchActions));
3467
3468
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3469
3470
        $this->request->setMethod('POST');
3471
        $this->request->request->set('data', json_encode($data));
3472
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3473
3474
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3475
3476
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3477
            ->method('getDatagrid')
3478
            ->will($this->returnValue($datagrid));
3479
3480
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
3481
            ->disableOriginalConstructor()
3482
            ->getMock();
3483
3484
        $form->expects($this->once())
3485
            ->method('createView')
3486
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
3487
3488
        $datagrid->expects($this->once())
3489
            ->method('getForm')
3490
            ->will($this->returnValue($form));
3491
3492
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->batchAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3493
3494
        $this->assertSame($this->admin, $this->parameters['admin']);
3495
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3496
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3497
3498
        $this->assertSame('list', $this->parameters['action']);
3499
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3500
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
3501
        $this->assertSame($data, $this->parameters['data']);
3502
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3503
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3504
3505
        $this->assertSame([], $this->session->getFlashBag()->all());
3506
        $this->assertSame('SonataAdminBundle:CRUD:batch_confirmation.html.twig', $this->template);
3507
    }
3508
3509
    public function testBatchActionNonRelevantAction()
3510
    {
3511
        $controller = new BatchAdminController();
3512
        $controller->setContainer($this->container);
3513
3514
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3515
3516
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3517
            ->method('getBatchActions')
3518
            ->will($this->returnValue($batchActions));
3519
3520
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3521
3522
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3523
            ->method('getDatagrid')
3524
            ->will($this->returnValue($datagrid));
3525
3526
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3527
3528
        $this->request->setMethod('POST');
3529
        $this->request->request->set('action', 'foo');
3530
        $this->request->request->set('idx', ['789']);
3531
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3532
3533
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3534
3535
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3536
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3537
        $this->assertSame('list?', $result->getTargetUrl());
3538
    }
3539
3540
    public function testBatchActionNonRelevantAction2()
3541
    {
3542
        $controller = new BatchAdminController();
3543
        $controller->setContainer($this->container);
3544
3545
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3546
3547
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3548
            ->method('getBatchActions')
3549
            ->will($this->returnValue($batchActions));
3550
3551
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3552
3553
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3554
            ->method('getDatagrid')
3555
            ->will($this->returnValue($datagrid));
3556
3557
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3558
3559
        $this->request->setMethod('POST');
3560
        $this->request->request->set('action', 'foo');
3561
        $this->request->request->set('idx', ['999']);
3562
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3563
3564
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3565
3566
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3567
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3568
        $this->assertSame('list?', $result->getTargetUrl());
3569
    }
3570
3571
    public function testBatchActionNoItems()
3572
    {
3573
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3574
3575
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3576
            ->method('getBatchActions')
3577
            ->will($this->returnValue($batchActions));
3578
3579
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3580
3581
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3582
            ->method('getDatagrid')
3583
            ->will($this->returnValue($datagrid));
3584
3585
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3586
3587
        $this->request->setMethod('POST');
3588
        $this->request->request->set('action', 'delete');
3589
        $this->request->request->set('idx', []);
3590
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3591
3592
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3593
3594
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3595
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3596
        $this->assertSame('list?', $result->getTargetUrl());
3597
    }
3598
3599
    public function testBatchActionNoItemsEmptyQuery()
3600
    {
3601
        $controller = new BatchAdminController();
3602
        $controller->setContainer($this->container);
3603
3604
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3605
3606
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3607
            ->method('getBatchActions')
3608
            ->will($this->returnValue($batchActions));
3609
3610
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3611
3612
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3613
        $datagrid->expects($this->once())
3614
            ->method('getQuery')
3615
            ->will($this->returnValue($query));
3616
3617
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3618
            ->method('getDatagrid')
3619
            ->will($this->returnValue($datagrid));
3620
3621
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3622
3623
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3624
            ->method('getModelManager')
3625
            ->will($this->returnValue($modelManager));
3626
3627
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3628
            ->method('getClass')
3629
            ->will($this->returnValue('Foo'));
3630
3631
        $this->request->setMethod('POST');
3632
        $this->request->request->set('action', 'bar');
3633
        $this->request->request->set('idx', []);
3634
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3635
3636
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3637
3638
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $result);
3639
        $this->assertSame('batchActionBar executed', $result->getContent());
3640
    }
3641
3642
    public function testBatchActionWithRequesData()
3643
    {
3644
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3645
3646
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3647
            ->method('getBatchActions')
3648
            ->will($this->returnValue($batchActions));
3649
3650
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3651
3652
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3653
        $datagrid->expects($this->once())
3654
            ->method('getQuery')
3655
            ->will($this->returnValue($query));
3656
3657
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3658
            ->method('getDatagrid')
3659
            ->will($this->returnValue($datagrid));
3660
3661
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3662
3663
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3664
            ->method('checkAccess')
3665
            ->with($this->equalTo('batchDelete'))
3666
            ->will($this->returnValue(true));
3667
3668
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3669
            ->method('getModelManager')
3670
            ->will($this->returnValue($modelManager));
3671
3672
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3673
            ->method('getClass')
3674
            ->will($this->returnValue('Foo'));
3675
3676
        $modelManager->expects($this->once())
3677
            ->method('addIdentifiersToQuery')
3678
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3679
            ->will($this->returnValue(true));
3680
3681
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3682
3683
        $this->request->setMethod('POST');
3684
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3685
        $this->request->request->set('foo', 'bar');
3686
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3687
3688
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3689
3690
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3691
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3692
        $this->assertSame('list?', $result->getTargetUrl());
3693
        $this->assertSame('bar', $this->request->request->get('foo'));
3694
    }
3695
3696
    public function getCsrfProvider()
3697
    {
3698
        return $this->csrfProvider;
3699
    }
3700
3701
    public function getToStringValues()
3702
    {
3703
        return [
3704
            ['', ''],
3705
            ['Foo', 'Foo'],
3706
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3707
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3708
        ];
3709
    }
3710
3711
    private function assertLoggerLogsModelManagerException($subject, $method)
3712
    {
3713
        $exception = new ModelManagerException(
3714
            $message = 'message',
3715
            1234,
3716
            new \Exception($previousExceptionMessage = 'very useful message')
3717
        );
3718
3719
        $subject->expects($this->once())
3720
            ->method($method)
3721
            ->will($this->returnCallback(function () use ($exception) {
3722
                throw $exception;
3723
            }));
3724
3725
        $this->logger->expects($this->once())
3726
            ->method('error')
3727
            ->with($message, [
3728
                'exception' => $exception,
3729
                'previous_exception_message' => $previousExceptionMessage,
3730
            ]);
3731
    }
3732
3733
    private function expectTranslate($id, array $parameters = [], $domain = null, $locale = null)
3734
    {
3735
        $this->translator->expects($this->once())
3736
            ->method('trans')
3737
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3738
            ->will($this->returnValue($id));
3739
    }
3740
}
3741