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
|
|
|
|
17
|
|
|
class SonataMediaExtensionTest extends AbstractExtensionTestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->container->setParameter('kernel.bundles', array('SonataAdminBundle' => true)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testLoadWithDefaultAndCustomCategoryManager() |
30
|
|
|
{ |
31
|
|
|
$this->load(array( |
32
|
|
|
'class' => array( |
33
|
|
|
'category' => '\stdClass', |
34
|
|
|
), |
35
|
|
|
'category_manager' => 'dummy.service.name', |
36
|
|
|
)); |
37
|
|
|
|
38
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category', 'dummy.service.name'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testLoadWithForceDisableTrueAndWithCategoryManager() |
42
|
|
|
{ |
43
|
|
|
$this->load(array( |
44
|
|
|
'class' => array( |
45
|
|
|
'category' => '\stdClass', |
46
|
|
|
), |
47
|
|
|
'category_manager' => 'dummy.service.name', |
48
|
|
|
'force_disable_category' => true, |
49
|
|
|
)); |
50
|
|
|
|
51
|
|
|
$this->assertContainerBuilderNotHasService('sonata.media.manager.category'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnable() |
55
|
|
|
{ |
56
|
|
|
$this->load(); |
57
|
|
|
|
58
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category'); |
59
|
|
|
$this->assertContainerBuilderHasService( |
60
|
|
|
'sonata.media.manager.category.default', |
61
|
|
|
'Sonata\MediaBundle\Model\CategoryManager' |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndForceDisableCategory() |
66
|
|
|
{ |
67
|
|
|
$this->load(array( |
68
|
|
|
'force_disable_category' => true, |
69
|
|
|
)); |
70
|
|
|
|
71
|
|
|
$this->assertContainerBuilderNotHasService('sonata.media.manager.category'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testLoadWithDefaultAndClassificationBundleEnableAndCustomCategoryManager() |
75
|
|
|
{ |
76
|
|
|
$this->load(array( |
77
|
|
|
'class' => array( |
78
|
|
|
'category' => '\stdClass', |
79
|
|
|
), |
80
|
|
|
'category_manager' => 'dummy.service.name', |
81
|
|
|
)); |
82
|
|
|
|
83
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.manager.category', 'dummy.service.name'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testDefaultAdapter() |
87
|
|
|
{ |
88
|
|
|
$this->load(); |
89
|
|
|
|
90
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.adapter.image.default', 'sonata.media.adapter.image.gd'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $serviceId |
95
|
|
|
* @param string $extension |
96
|
|
|
* @param string $type |
97
|
|
|
* |
98
|
|
|
* @dataProvider dataAdapter |
99
|
|
|
*/ |
100
|
|
|
public function testAdapter($serviceId, $extension, $type) |
101
|
|
|
{ |
102
|
|
|
$this->load(); |
103
|
|
|
|
104
|
|
|
$this->assertContainerBuilderHasService($serviceId); |
105
|
|
|
if (extension_loaded($extension)) { |
106
|
|
|
$this->isInstanceOf($type, $this->container->get($serviceId)); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function dataAdapter() |
111
|
|
|
{ |
112
|
|
|
return array( |
113
|
|
|
array('sonata.media.adapter.image.gd', 'gd', 'Imagine\\Gd\\Imagine'), |
114
|
|
|
array('sonata.media.adapter.image.gmagick', 'gmagick', 'Imagine\\Gmagick\\Imagine'), |
115
|
|
|
array('sonata.media.adapter.image.imagick', 'imagick', 'Imagine\\Imagick\\Imagine'), |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testDefaultResizer() |
120
|
|
|
{ |
121
|
|
|
$this->load(); |
122
|
|
|
|
123
|
|
|
$this->assertContainerBuilderHasAlias('sonata.media.resizer.default', 'sonata.media.resizer.simple'); |
124
|
|
|
if (extension_loaded('gd')) { |
125
|
|
|
$this->assertContainerBuilderHasService( |
126
|
|
|
'sonata.media.resizer.default', |
127
|
|
|
'Sonata\\MediaBundle\\Resizer\\SimpleResizer' |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param $serviceId |
134
|
|
|
* @param $type |
135
|
|
|
* |
136
|
|
|
* @dataProvider dataResizer |
137
|
|
|
*/ |
138
|
|
|
public function testResizer($serviceId, $type) |
139
|
|
|
{ |
140
|
|
|
$this->load(); |
141
|
|
|
|
142
|
|
|
$this->assertContainerBuilderHasService($serviceId); |
143
|
|
|
if (extension_loaded('gd')) { |
144
|
|
|
$this->isInstanceOf($type, $this->container->get($serviceId)); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function dataResizer() |
149
|
|
|
{ |
150
|
|
|
return array( |
151
|
|
|
array('sonata.media.resizer.simple', 'Sonata\\MediaBundle\\Resizer\\SimpleResizer'), |
152
|
|
|
array('sonata.media.resizer.square', 'Sonata\\MediaBundle\\Resizer\\SquareResizer'), |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
protected function getMinimalConfiguration() |
157
|
|
|
{ |
158
|
|
|
return array( |
159
|
|
|
'default_context' => 'default', |
160
|
|
|
'db_driver' => 'doctrine_orm', |
161
|
|
|
'contexts' => array( |
162
|
|
|
'default' => array( |
163
|
|
|
'formats' => array( |
164
|
|
|
'small' => array( |
165
|
|
|
'width' => 100, |
166
|
|
|
'quality' => 50, |
167
|
|
|
), |
168
|
|
|
), |
169
|
|
|
), |
170
|
|
|
), |
171
|
|
|
'filesystem' => array( |
172
|
|
|
'local' => array( |
173
|
|
|
'directory' => '/tmp/', |
174
|
|
|
), |
175
|
|
|
), |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* {@inheritdoc} |
181
|
|
|
*/ |
182
|
|
|
protected function getContainerExtensions() |
183
|
|
|
{ |
184
|
|
|
return array( |
185
|
|
|
new SonataMediaExtension(), |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|