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\MediaBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
15
|
|
|
use Sonata\MediaBundle\DependencyInjection\SonataMediaExtension; |
16
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
17
|
|
|
|
18
|
|
|
class SonataMediaExtensionTest extends AbstractExtensionTestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
$this->container->setParameter('kernel.bundles', array('SonataAdminBundle' => true)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testLoadWithDefaultAndCustomCategoryManager() |
31
|
|
|
{ |
32
|
|
|
$this->load(array( |
33
|
|
|
'class' => array( |
34
|
|
|
'category' => '\stdClass', |
35
|
|
|
), |
36
|
|
|
'category_manager' => 'dummy.service.name', |
37
|
|
|
)); |
38
|
|
|
|
39
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category', 'dummy.service.name'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testLoadWithForceDisableTrueAndWithCategoryManager() |
43
|
|
|
{ |
44
|
|
|
$this->load(array( |
45
|
|
|
'class' => array( |
46
|
|
|
'category' => '\stdClass', |
47
|
|
|
), |
48
|
|
|
'category_manager' => 'dummy.service.name', |
49
|
|
|
'force_disable_category' => true, |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
$this->assertContainerBuilderNotHasService('sonata.media.manager.category'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnable() |
56
|
|
|
{ |
57
|
|
|
$this->load(); |
58
|
|
|
|
59
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category'); |
60
|
|
|
$this->assertContainerBuilderHasService( |
61
|
|
|
'sonata.media.manager.category.default', |
62
|
|
|
'Sonata\MediaBundle\Model\CategoryManager' |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndForceDisableCategory() |
67
|
|
|
{ |
68
|
|
|
$this->load(array( |
69
|
|
|
'force_disable_category' => true, |
70
|
|
|
)); |
71
|
|
|
|
72
|
|
|
$this->assertContainerBuilderNotHasService('sonata.media.manager.category'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndCustomCategoryManager() |
76
|
|
|
{ |
77
|
|
|
$this->load(array( |
78
|
|
|
'class' => array( |
79
|
|
|
'category' => '\stdClass', |
80
|
|
|
), |
81
|
|
|
'category_manager' => 'dummy.service.name', |
82
|
|
|
)); |
83
|
|
|
|
84
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category', 'dummy.service.name'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testDefaultAdapter() |
88
|
|
|
{ |
89
|
|
|
$this->load(); |
90
|
|
|
|
91
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.adapter.image.default', 'sonata.media.adapter.image.gd'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $serviceId |
96
|
|
|
* @param string $extension |
97
|
|
|
* @param string $type |
98
|
|
|
* |
99
|
|
|
* @dataProvider dataAdapter |
100
|
|
|
*/ |
101
|
|
|
public function testAdapter($serviceId, $extension, $type) |
102
|
|
|
{ |
103
|
|
|
$this->load(); |
104
|
|
|
|
105
|
|
|
$this->assertContainerBuilderHasService($serviceId); |
106
|
|
|
if (extension_loaded($extension)) { |
107
|
|
|
$this->isInstanceOf($type, $this->container->get($serviceId)); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function dataAdapter() |
112
|
|
|
{ |
113
|
|
|
return array( |
114
|
|
|
array('sonata.media.adapter.image.gd', 'gd', 'Imagine\\Gd\\Imagine'), |
115
|
|
|
array('sonata.media.adapter.image.gmagick', 'gmagick', 'Imagine\\Gmagick\\Imagine'), |
116
|
|
|
array('sonata.media.adapter.image.imagick', 'imagick', 'Imagine\\Imagick\\Imagine'), |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testDefaultResizer() |
121
|
|
|
{ |
122
|
|
|
$this->load(); |
123
|
|
|
|
124
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.resizer.default', 'sonata.media.resizer.simple'); |
125
|
|
|
if (extension_loaded('gd')) { |
126
|
|
|
$this->assertContainerBuilderHasService( |
127
|
|
|
'sonata.media.resizer.default', |
128
|
|
|
'Sonata\\MediaBundle\\Resizer\\SimpleResizer' |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param $serviceId |
135
|
|
|
* @param $type |
136
|
|
|
* |
137
|
|
|
* @dataProvider dataResizer |
138
|
|
|
*/ |
139
|
|
|
public function testResizer($serviceId, $type) |
140
|
|
|
{ |
141
|
|
|
$this->load(); |
142
|
|
|
|
143
|
|
|
$this->assertContainerBuilderHasService($serviceId); |
144
|
|
|
if (extension_loaded('gd')) { |
145
|
|
|
$this->isInstanceOf($type, $this->container->get($serviceId)); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function dataResizer() |
150
|
|
|
{ |
151
|
|
|
return array( |
152
|
|
|
array('sonata.media.resizer.simple', 'Sonata\\MediaBundle\\Resizer\\SimpleResizer'), |
153
|
|
|
array('sonata.media.resizer.square', 'Sonata\\MediaBundle\\Resizer\\SquareResizer'), |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function testLoadWithSonataAdminDefaults() |
158
|
|
|
{ |
159
|
|
|
$this->load(); |
160
|
|
|
|
161
|
|
|
$this->assertEquals( |
162
|
|
|
$this->container->getDefinition('sonata.media.security.superadmin_strategy')->getArgument(2), |
163
|
|
|
array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN') |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testLoadWithSonataAdminCustomConfiguration() |
168
|
|
|
{ |
169
|
|
|
$fakeContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') |
170
|
|
|
->setMethods(array('getParameter', 'getExtensionConfig')) |
171
|
|
|
->getMock(); |
172
|
|
|
|
173
|
|
|
$fakeContainer->expects($this->once()) |
174
|
|
|
->method('getParameter') |
175
|
|
|
->with($this->equalTo('kernel.bundles')) |
176
|
|
|
->willReturn($this->container->getParameter('kernel.bundles')); |
177
|
|
|
|
178
|
|
|
$fakeContainer->expects($this->once()) |
179
|
|
|
->method('getExtensionConfig') |
180
|
|
|
->with($this->equalTo('sonata_admin')) |
181
|
|
|
->willReturn(array(array( |
182
|
|
|
'security' => array( |
183
|
|
|
'role_admin' => 'ROLE_FOO', |
184
|
|
|
'role_super_admin' => 'ROLE_BAR', |
185
|
|
|
), |
186
|
|
|
))); |
187
|
|
|
|
188
|
|
|
$configs = array($this->getMinimalConfiguration()); |
189
|
|
|
foreach ($this->getContainerExtensions() as $extension) { |
190
|
|
|
if ($extension instanceof PrependExtensionInterface) { |
191
|
|
|
$extension->prepend($fakeContainer); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$extension->load($configs, $this->container); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$this->assertEquals( |
198
|
|
|
$this->container->getDefinition('sonata.media.security.superadmin_strategy')->getArgument(2), |
199
|
|
|
array('ROLE_FOO', 'ROLE_BAR') |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
protected function getMinimalConfiguration() |
204
|
|
|
{ |
205
|
|
|
return array( |
206
|
|
|
'default_context' => 'default', |
207
|
|
|
'db_driver' => 'doctrine_orm', |
208
|
|
|
'contexts' => array( |
209
|
|
|
'default' => array( |
210
|
|
|
'formats' => array( |
211
|
|
|
'small' => array( |
212
|
|
|
'width' => 100, |
213
|
|
|
'quality' => 50, |
214
|
|
|
), |
215
|
|
|
), |
216
|
|
|
), |
217
|
|
|
), |
218
|
|
|
'filesystem' => array( |
219
|
|
|
'local' => array( |
220
|
|
|
'directory' => '/tmp/', |
221
|
|
|
), |
222
|
|
|
), |
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* {@inheritdoc} |
228
|
|
|
*/ |
229
|
|
|
protected function getContainerExtensions() |
230
|
|
|
{ |
231
|
|
|
return array( |
232
|
|
|
new SonataMediaExtension(), |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|