|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\AdminBundle\Action; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Action\Configuration\ActionConfiguration; |
|
6
|
|
|
use LAG\AdminBundle\Controller\ListAction; |
|
7
|
|
|
use LAG\AdminBundle\Action\Responder\ListResponder; |
|
8
|
|
|
use LAG\AdminBundle\Admin\AdminInterface; |
|
9
|
|
|
use LAG\AdminBundle\Filter\Factory\FilterFormBuilder; |
|
10
|
|
|
use LAG\AdminBundle\Tests\AdminTestBase; |
|
11
|
|
|
use LAG\AdminBundle\Tests\Entity\TestSimpleEntity; |
|
12
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
13
|
|
|
use Symfony\Component\Form\FormInterface; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
|
|
16
|
|
|
class ListActionTest extends AdminTestBase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testInvoke() |
|
19
|
|
|
{ |
|
20
|
|
|
$request = new Request(); |
|
21
|
|
|
$entity = new TestSimpleEntity(); |
|
22
|
|
|
|
|
23
|
|
|
$actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
|
24
|
|
|
$actionConfiguration |
|
25
|
|
|
->method('getParameter') |
|
26
|
|
|
->willReturnMap([ |
|
27
|
|
|
['form', 'MyForm'], |
|
28
|
|
|
['form_options', [ |
|
29
|
|
|
'required' => false, |
|
30
|
|
|
]], |
|
31
|
|
|
]) |
|
32
|
|
|
; |
|
33
|
|
|
|
|
34
|
|
|
$admin = $this->getMockWithoutConstructor(AdminInterface::class); |
|
35
|
|
|
$admin |
|
36
|
|
|
->expects($this->once()) |
|
37
|
|
|
->method('handleRequest') |
|
38
|
|
|
->with($request) |
|
39
|
|
|
; |
|
40
|
|
|
$admin |
|
41
|
|
|
->expects($this->once()) |
|
42
|
|
|
->method('getEntities') |
|
43
|
|
|
->willReturn([ |
|
44
|
|
|
$entity, |
|
45
|
|
|
]) |
|
46
|
|
|
; |
|
47
|
|
|
|
|
48
|
|
|
$form = $this->getMockWithoutConstructor(FormInterface::class); |
|
49
|
|
|
$form |
|
50
|
|
|
->expects($this->once()) |
|
51
|
|
|
->method('handleRequest') |
|
52
|
|
|
->with($request) |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$filterForm = $this->getMockWithoutConstructor(FormInterface::class); |
|
56
|
|
|
$filterForm |
|
57
|
|
|
->expects($this->once()) |
|
58
|
|
|
->method('handleRequest') |
|
59
|
|
|
; |
|
60
|
|
|
|
|
61
|
|
|
$formFactory = $this->getMockWithoutConstructor(FormFactoryInterface::class); |
|
62
|
|
|
$formFactory |
|
63
|
|
|
->expects($this->once()) |
|
64
|
|
|
->method('create') |
|
65
|
|
|
->with('MyForm', [ |
|
66
|
|
|
$entity, |
|
67
|
|
|
], [ |
|
68
|
|
|
'required' => false, |
|
69
|
|
|
]) |
|
70
|
|
|
->willReturn($form) |
|
71
|
|
|
; |
|
72
|
|
|
|
|
73
|
|
|
$responder = $this->getMockWithoutConstructor(ListResponder::class); |
|
74
|
|
|
$responder |
|
75
|
|
|
->method('respond') |
|
76
|
|
|
->with($actionConfiguration, $admin, $form, $filterForm) |
|
77
|
|
|
; |
|
78
|
|
|
|
|
79
|
|
|
$builder = $this->getMockWithoutConstructor(FilterFormBuilder::class); |
|
80
|
|
|
$builder |
|
81
|
|
|
->method('build') |
|
82
|
|
|
->with($actionConfiguration) |
|
83
|
|
|
->willReturn($filterForm) |
|
84
|
|
|
; |
|
85
|
|
|
|
|
86
|
|
|
$action = new ListAction( |
|
87
|
|
|
'list', |
|
88
|
|
|
$formFactory, |
|
89
|
|
|
$responder, |
|
90
|
|
|
$builder |
|
91
|
|
|
); |
|
92
|
|
|
$action->setConfiguration($actionConfiguration); |
|
93
|
|
|
$action->setAdmin($admin); |
|
94
|
|
|
|
|
95
|
|
|
$action->__invoke($request); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|