|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Configuration\ActionConfiguration; |
|
6
|
|
|
use LAG\AdminBundle\Configuration\AdminConfiguration; |
|
7
|
|
|
use LAG\AdminBundle\Factory\ConfigurationFactory; |
|
8
|
|
|
use LAG\AdminBundle\Factory\FieldFactory; |
|
9
|
|
|
use LAG\AdminBundle\Factory\MenuFactory; |
|
10
|
|
|
use LAG\AdminBundle\Factory\ViewFactory; |
|
11
|
|
|
use LAG\AdminBundle\Tests\AdminTestBase; |
|
12
|
|
|
use Symfony\Component\Form\FormInterface; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
15
|
|
|
|
|
16
|
|
|
class ViewFactoryTest extends AdminTestBase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testCreate() |
|
19
|
|
|
{ |
|
20
|
|
|
$request = new Request(); |
|
21
|
|
|
$adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class); |
|
22
|
|
|
$actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
|
23
|
|
|
$entities = []; |
|
24
|
|
|
|
|
25
|
|
|
$configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
|
26
|
|
|
|
|
27
|
|
|
$fieldFactory = $this->getMockWithoutConstructor(FieldFactory::class); |
|
28
|
|
|
$fieldFactory |
|
29
|
|
|
->expects($this->once()) |
|
30
|
|
|
->method('getFields') |
|
31
|
|
|
->with($actionConfiguration) |
|
32
|
|
|
->willReturn([]) |
|
33
|
|
|
; |
|
34
|
|
|
|
|
35
|
|
|
$menuFactory = $this->getMockWithoutConstructor(MenuFactory::class); |
|
36
|
|
|
$router = $this->getMockWithoutConstructor(RouterInterface::class); |
|
37
|
|
|
|
|
38
|
|
|
$factory = new ViewFactory( |
|
39
|
|
|
$configurationFactory, |
|
40
|
|
|
$fieldFactory, |
|
41
|
|
|
$menuFactory, |
|
42
|
|
|
$router |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
$form = $this->getMockWithoutConstructor(FormInterface::class); |
|
46
|
|
|
$form |
|
47
|
|
|
->expects($this->once()) |
|
48
|
|
|
->method('createView') |
|
49
|
|
|
; |
|
50
|
|
|
$forms = [ |
|
51
|
|
|
'planet_form' => $form, |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
$view = $factory->create( |
|
55
|
|
|
$request, |
|
56
|
|
|
'atomize', |
|
57
|
|
|
'planet', |
|
58
|
|
|
$adminConfiguration, |
|
59
|
|
|
$actionConfiguration, |
|
60
|
|
|
$entities, |
|
61
|
|
|
$forms |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testCreateWithRedirection() |
|
66
|
|
|
{ |
|
67
|
|
|
$request = new Request([ |
|
68
|
|
|
'submit_and_redirect' => 'submit_and_redirect', |
|
69
|
|
|
]); |
|
70
|
|
|
$entities = []; |
|
71
|
|
|
|
|
72
|
|
|
$adminConfiguration = $this->getMockWithoutConstructor(AdminConfiguration::class); |
|
73
|
|
|
$adminConfiguration |
|
74
|
|
|
->expects($this->atLeastOnce()) |
|
75
|
|
|
->method('getParameter') |
|
76
|
|
|
->willReturnMap([ |
|
77
|
|
|
['actions', [ |
|
78
|
|
|
'list' => [], |
|
79
|
|
|
]], |
|
80
|
|
|
['routing_name_pattern', '{admin}.{action}'], |
|
81
|
|
|
]) |
|
82
|
|
|
; |
|
83
|
|
|
$actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
|
84
|
|
|
|
|
85
|
|
|
$entityForm = $this->getMockWithoutConstructor(FormInterface::class); |
|
86
|
|
|
$entityForm |
|
87
|
|
|
->expects($this->once()) |
|
88
|
|
|
->method('isSubmitted') |
|
89
|
|
|
->willReturn(true) |
|
90
|
|
|
; |
|
91
|
|
|
$entityForm |
|
92
|
|
|
->expects($this->once()) |
|
93
|
|
|
->method('isValid') |
|
94
|
|
|
->willReturn(true) |
|
95
|
|
|
; |
|
96
|
|
|
$forms = [ |
|
97
|
|
|
'entity' => $entityForm, |
|
98
|
|
|
]; |
|
99
|
|
|
|
|
100
|
|
|
$configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
|
101
|
|
|
|
|
102
|
|
|
$fieldFactory = $this->getMockWithoutConstructor(FieldFactory::class); |
|
103
|
|
|
$fieldFactory |
|
104
|
|
|
->expects($this->never()) |
|
105
|
|
|
->method('getFields') |
|
106
|
|
|
; |
|
107
|
|
|
|
|
108
|
|
|
$menuFactory = $this->getMockWithoutConstructor(MenuFactory::class); |
|
109
|
|
|
$router = $this->getMockWithoutConstructor(RouterInterface::class); |
|
110
|
|
|
$router |
|
111
|
|
|
->expects($this->once()) |
|
112
|
|
|
->method('generate') |
|
113
|
|
|
->with('planet.list') |
|
114
|
|
|
->willReturn('/planet/atomize') |
|
115
|
|
|
; |
|
116
|
|
|
|
|
117
|
|
|
$factory = new ViewFactory( |
|
118
|
|
|
$configurationFactory, |
|
119
|
|
|
$fieldFactory, |
|
120
|
|
|
$menuFactory, |
|
121
|
|
|
$router |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$factory->create( |
|
125
|
|
|
$request, |
|
126
|
|
|
'atomize', |
|
127
|
|
|
'planet', |
|
128
|
|
|
$adminConfiguration, |
|
129
|
|
|
$actionConfiguration, |
|
130
|
|
|
$entities, |
|
131
|
|
|
$forms |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|