|
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\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
|
15
|
|
|
use Sonata\AdminBundle\Bridge\Exporter\AdminExporter; |
|
16
|
|
|
use Sonata\AdminBundle\DependencyInjection\SonataAdminExtension; |
|
17
|
|
|
|
|
18
|
|
|
class SonataAdminExtensionTest extends AbstractExtensionTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string[] |
|
22
|
|
|
*/ |
|
23
|
|
|
private $defaultStylesheets = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $defaultJavascripts = []; |
|
29
|
|
|
|
|
30
|
|
|
protected function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::setUp(); |
|
33
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
34
|
|
|
$this->load(); |
|
35
|
|
|
$this->defaultStylesheets = $this->container |
|
36
|
|
|
->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets'] |
|
37
|
|
|
; |
|
38
|
|
|
$this->defaultJavascripts = $this->container |
|
39
|
|
|
->getDefinition('sonata.admin.pool')->getArgument(3)['javascripts'] |
|
40
|
|
|
; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @group legacy |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testContainerCompileWithJMSDiExtraBundle() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->container->setParameter('kernel.bundles', [ |
|
49
|
|
|
'JMSDiExtraBundle' => true, |
|
50
|
|
|
]); |
|
51
|
|
|
|
|
52
|
|
|
$this->container->compile(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testHasServiceDefinitionForLockExtension() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
58
|
|
|
$this->load(['options' => ['lock_protection' => true]]); |
|
59
|
|
|
$this->assertContainerBuilderHasService('sonata.admin.lock.extension'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testNotHasServiceDefinitionForLockExtension() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
65
|
|
|
$this->load(['options' => ['lock_protection' => false]]); |
|
66
|
|
|
$this->assertContainerBuilderNotHasService('sonata.admin.lock.extension'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testLoadsExporterServiceDefinitionWhenExporterBundleIsRegistered() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->container->setParameter('kernel.bundles', ['SonataExporterBundle' => 'whatever']); |
|
72
|
|
|
$this->load(); |
|
73
|
|
|
$this->assertContainerBuilderHasService( |
|
74
|
|
|
'sonata.admin.admin_exporter', |
|
75
|
|
|
AdminExporter::class |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testHasSecurityRoleParameters() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
82
|
|
|
$this->load(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertContainerBuilderHasParameter('sonata.admin.configuration.security.role_admin'); |
|
85
|
|
|
$this->assertContainerBuilderHasParameter('sonata.admin.configuration.security.role_super_admin'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testExtraStylesheetsGetAdded() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
91
|
|
|
$extraStylesheets = ['foo/bar.css', 'bar/quux.css']; |
|
92
|
|
|
$this->load([ |
|
93
|
|
|
'assets' => [ |
|
94
|
|
|
'extra_stylesheets' => $extraStylesheets, |
|
95
|
|
|
], |
|
96
|
|
|
]); |
|
97
|
|
|
$stylesheets = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; |
|
98
|
|
|
|
|
99
|
|
|
$this->assertSame(array_merge($this->defaultStylesheets, $extraStylesheets), $stylesheets); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testRemoveStylesheetsGetRemoved() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
105
|
|
|
$removeStylesheets = [ |
|
106
|
|
|
'bundles/sonataadmin/vendor/admin-lte/dist/css/skins/skin-black.min.css', |
|
107
|
|
|
'bundles/sonataadmin/vendor/jqueryui/themes/base/jquery-ui.css', |
|
108
|
|
|
]; |
|
109
|
|
|
$this->load([ |
|
110
|
|
|
'assets' => [ |
|
111
|
|
|
'remove_stylesheets' => $removeStylesheets, |
|
112
|
|
|
], |
|
113
|
|
|
]); |
|
114
|
|
|
$stylesheets = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets']; |
|
115
|
|
|
|
|
116
|
|
|
$this->assertSame(array_values(array_diff($this->defaultStylesheets, $removeStylesheets)), $stylesheets); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testExtraJavascriptsGetAdded() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
122
|
|
|
$extraJavascripts = ['foo/bar.js', 'bar/quux.js']; |
|
123
|
|
|
$this->load([ |
|
124
|
|
|
'assets' => [ |
|
125
|
|
|
'extra_javascripts' => $extraJavascripts, |
|
126
|
|
|
], |
|
127
|
|
|
]); |
|
128
|
|
|
$javascripts = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['javascripts']; |
|
129
|
|
|
|
|
130
|
|
|
$this->assertSame(array_merge($this->defaultJavascripts, $extraJavascripts), $javascripts); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testRemoveJavascriptsGetRemoved() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
136
|
|
|
$removeJavascripts = [ |
|
137
|
|
|
'bundles/sonataadmin/vendor/readmore-js/readmore.min.js', |
|
138
|
|
|
'bundles/sonataadmin/jquery/jquery.confirmExit.js', |
|
139
|
|
|
]; |
|
140
|
|
|
$this->load([ |
|
141
|
|
|
'assets' => [ |
|
142
|
|
|
'remove_javascripts' => $removeJavascripts, |
|
143
|
|
|
], |
|
144
|
|
|
]); |
|
145
|
|
|
$javascripts = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['javascripts']; |
|
146
|
|
|
|
|
147
|
|
|
$this->assertSame(array_values(array_diff($this->defaultJavascripts, $removeJavascripts)), $javascripts); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function testAssetsCanBeAddedAndRemoved() |
|
151
|
|
|
{ |
|
152
|
|
|
$this->container->setParameter('kernel.bundles', []); |
|
153
|
|
|
$extraStylesheets = ['foo/bar.css', 'bar/quux.css']; |
|
154
|
|
|
$extraJavascripts = ['foo/bar.js', 'bar/quux.js']; |
|
155
|
|
|
$removeStylesheets = [ |
|
156
|
|
|
'bundles/sonataadmin/vendor/admin-lte/dist/css/skins/skin-black.min.css', |
|
157
|
|
|
'bundles/sonataadmin/vendor/jqueryui/themes/base/jquery-ui.css', |
|
158
|
|
|
]; |
|
159
|
|
|
$removeJavascripts = [ |
|
160
|
|
|
'bundles/sonataadmin/vendor/readmore-js/readmore.min.js', |
|
161
|
|
|
'bundles/sonataadmin/jquery/jquery.confirmExit.js', |
|
162
|
|
|
]; |
|
163
|
|
|
$this->load([ |
|
164
|
|
|
'assets' => [ |
|
165
|
|
|
'extra_stylesheets' => $extraStylesheets, |
|
166
|
|
|
'remove_stylesheets' => $removeStylesheets, |
|
167
|
|
|
'extra_javascripts' => $extraJavascripts, |
|
168
|
|
|
'remove_javascripts' => $removeJavascripts, |
|
169
|
|
|
], |
|
170
|
|
|
]); |
|
171
|
|
|
$stylesheets = $this->container |
|
172
|
|
|
->getDefinition('sonata.admin.pool')->getArgument(3)['stylesheets'] |
|
173
|
|
|
; |
|
174
|
|
|
|
|
175
|
|
|
$this->assertSame( |
|
176
|
|
|
array_merge(array_diff($this->defaultStylesheets, $removeStylesheets), $extraStylesheets), |
|
177
|
|
|
$stylesheets |
|
178
|
|
|
); |
|
179
|
|
|
|
|
180
|
|
|
$javascripts = $this->container->getDefinition('sonata.admin.pool')->getArgument(3)['javascripts']; |
|
181
|
|
|
|
|
182
|
|
|
$this->assertSame( |
|
183
|
|
|
array_merge(array_diff($this->defaultJavascripts, $removeJavascripts), $extraJavascripts), |
|
184
|
|
|
$javascripts |
|
185
|
|
|
); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
protected function getContainerExtensions() |
|
189
|
|
|
{ |
|
190
|
|
|
return [new SonataAdminExtension()]; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|