|
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\Controller\Api; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
15
|
|
|
use Sonata\MediaBundle\Controller\Api\GalleryController; |
|
16
|
|
|
use Sonata\MediaBundle\Model\GalleryItem; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
|
|
19
|
|
|
class GalleryTest extends GalleryItem |
|
20
|
|
|
{ |
|
21
|
|
|
private $id; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct(); |
|
26
|
|
|
$this->id = rand(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getId() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->id; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @author Hugo Briand <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
class GalleryControllerTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
public function testGetGalleriesAction() |
|
41
|
|
|
{ |
|
42
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
43
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
44
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$galleryManager->expects($this->once())->method('getPager')->will($this->returnValue(array())); |
|
47
|
|
|
|
|
48
|
|
|
$gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test'); |
|
49
|
|
|
|
|
50
|
|
|
$paramFetcher = $this->getMockBuilder('FOS\RestBundle\Request\ParamFetcher') |
|
51
|
|
|
->disableOriginalConstructor() |
|
52
|
|
|
->getMock(); |
|
53
|
|
|
$paramFetcher->expects($this->exactly(3))->method('get'); |
|
54
|
|
|
$paramFetcher |
|
55
|
|
|
->expects($this->once()) |
|
56
|
|
|
->method('all') |
|
57
|
|
|
->will($this->returnValue(array( |
|
58
|
|
|
'page' => 1, |
|
59
|
|
|
'count' => 10, |
|
60
|
|
|
'orderBy' => array('id' => 'ASC'), |
|
61
|
|
|
))); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame(array(), $gController->getGalleriesAction($paramFetcher)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testGetGalleryAction() |
|
67
|
|
|
{ |
|
68
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
69
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
70
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
71
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
74
|
|
|
|
|
75
|
|
|
$gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test'); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertSame($gallery, $gController->getGalleryAction(1)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
82
|
|
|
* @expectedExceptionMessage Gallery (42) not found |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testGetGalleryNotFoundAction() |
|
85
|
|
|
{ |
|
86
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
87
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$galleryManager->expects($this->once())->method('findOneBy'); |
|
92
|
|
|
|
|
93
|
|
|
$gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test'); |
|
94
|
|
|
|
|
95
|
|
|
$gController->getGalleryAction(42); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testGetGalleryGalleryItemsAction() |
|
99
|
|
|
{ |
|
100
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
101
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
102
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
103
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
106
|
|
|
|
|
107
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
108
|
|
|
|
|
109
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test'); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertSame(array($galleryItem), $gController->getGalleryGalleryItemAction(1)); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testGetGalleryMediaAction() |
|
117
|
|
|
{ |
|
118
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
119
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
122
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media)); |
|
123
|
|
|
|
|
124
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
125
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
126
|
|
|
|
|
127
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
128
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
129
|
|
|
|
|
130
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
$gController = new GalleryController($galleryManager, $mediaManager, $formFactory, 'test'); |
|
133
|
|
|
|
|
134
|
|
|
$this->assertSame(array($media), $gController->getGalleryMediasAction(1)); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testPostGalleryMediaGalleryItemAction() |
|
138
|
|
|
{ |
|
139
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
$media2 = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
142
|
|
|
$media2->expects($this->any())->method('getId')->will($this->returnValue(1)); |
|
143
|
|
|
|
|
144
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
145
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media2)); |
|
146
|
|
|
|
|
147
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
148
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
149
|
|
|
|
|
150
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
151
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
152
|
|
|
|
|
153
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
154
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
155
|
|
|
|
|
156
|
|
|
$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
|
157
|
|
|
$form->expects($this->once())->method('handleRequest'); |
|
158
|
|
|
$form->expects($this->once())->method('isValid')->will($this->returnValue(true)); |
|
159
|
|
|
$form->expects($this->once())->method('getData')->will($this->returnValue($galleryItem)); |
|
160
|
|
|
|
|
161
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
162
|
|
|
$formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form)); |
|
163
|
|
|
|
|
164
|
|
|
$galleryController = new GalleryController( |
|
165
|
|
|
$galleryManager, |
|
166
|
|
|
$mediaManager, |
|
167
|
|
|
$formFactory, |
|
168
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
169
|
|
|
); |
|
170
|
|
|
$view = $galleryController->postGalleryMediaGalleryItemAction(1, 2, new Request()); |
|
171
|
|
|
|
|
172
|
|
|
$this->assertInstanceOf('FOS\RestBundle\View\View', $view); |
|
173
|
|
|
$this->assertSame(200, $view->getResponse()->getStatusCode(), 'Should return 200'); |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function testPostGalleryMediaGalleryItemInvalidAction() |
|
177
|
|
|
{ |
|
178
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
179
|
|
|
$media->expects($this->any())->method('getId')->will($this->returnValue(1)); |
|
180
|
|
|
|
|
181
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
182
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media)); |
|
183
|
|
|
|
|
184
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
185
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
186
|
|
|
|
|
187
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
188
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
189
|
|
|
|
|
190
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
191
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
192
|
|
|
|
|
193
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
$galleryController = new GalleryController( |
|
196
|
|
|
$galleryManager, |
|
197
|
|
|
$mediaManager, |
|
198
|
|
|
$formFactory, |
|
199
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
200
|
|
|
); |
|
201
|
|
|
$view = $galleryController->postGalleryMediaGalleryItemAction(1, 1, new Request()); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertInstanceOf('FOS\RestBundle\View\View', $view); |
|
204
|
|
|
$this->assertSame(400, $view->getResponse()->getStatusCode(), 'Should return 400'); |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function testPutGalleryMediaGalleryItemAction() |
|
208
|
|
|
{ |
|
209
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
210
|
|
|
$media->expects($this->any())->method('getId')->will($this->returnValue(1)); |
|
211
|
|
|
|
|
212
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
213
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media)); |
|
214
|
|
|
|
|
215
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
216
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
217
|
|
|
|
|
218
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
219
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
220
|
|
|
|
|
221
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
222
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
223
|
|
|
|
|
224
|
|
|
$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
|
225
|
|
|
$form->expects($this->once())->method('handleRequest'); |
|
226
|
|
|
$form->expects($this->once())->method('isValid')->will($this->returnValue(true)); |
|
227
|
|
|
$form->expects($this->once())->method('getData')->will($this->returnValue($galleryItem)); |
|
228
|
|
|
|
|
229
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
230
|
|
|
$formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form)); |
|
231
|
|
|
|
|
232
|
|
|
$galleryController = new GalleryController( |
|
233
|
|
|
$galleryManager, |
|
234
|
|
|
$mediaManager, |
|
235
|
|
|
$formFactory, |
|
236
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
237
|
|
|
); |
|
238
|
|
|
$view = $galleryController->putGalleryMediaGalleryItemAction(1, 1, new Request()); |
|
239
|
|
|
|
|
240
|
|
|
$this->assertInstanceOf('FOS\RestBundle\View\View', $view); |
|
241
|
|
|
$this->assertSame(200, $view->getResponse()->getStatusCode(), 'Should return 200'); |
|
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function testPutGalleryMediaGalleryItemInvalidAction() |
|
245
|
|
|
{ |
|
246
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
247
|
|
|
$media->expects($this->any())->method('getId')->will($this->returnValue(1)); |
|
248
|
|
|
|
|
249
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
250
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media)); |
|
251
|
|
|
|
|
252
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
253
|
|
|
$gallery->expects($this->once())->method('getGalleryItems')->will($this->returnValue(array($galleryItem))); |
|
254
|
|
|
|
|
255
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
256
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
257
|
|
|
|
|
258
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
259
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
260
|
|
|
|
|
261
|
|
|
$form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
|
262
|
|
|
$form->expects($this->once())->method('handleRequest'); |
|
263
|
|
|
$form->expects($this->once())->method('isValid')->will($this->returnValue(false)); |
|
264
|
|
|
|
|
265
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
266
|
|
|
$formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form)); |
|
267
|
|
|
|
|
268
|
|
|
$galleryController = new GalleryController( |
|
269
|
|
|
$galleryManager, |
|
270
|
|
|
$mediaManager, |
|
271
|
|
|
$formFactory, |
|
272
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
273
|
|
|
); |
|
274
|
|
|
$view = $galleryController->putGalleryMediaGalleryItemAction(1, 1, new Request()); |
|
275
|
|
|
|
|
276
|
|
|
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $view); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
public function testDeleteGalleryMediaGalleryItemAction() |
|
280
|
|
|
{ |
|
281
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
282
|
|
|
$media->expects($this->any())->method('getId')->will($this->returnValue(1)); |
|
283
|
|
|
|
|
284
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
285
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media)); |
|
286
|
|
|
|
|
287
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
288
|
|
|
$gallery |
|
289
|
|
|
->expects($this->any()) |
|
290
|
|
|
->method('getGalleryItems') |
|
291
|
|
|
->will($this->returnValue(new ArrayCollection(array($galleryItem)))); |
|
292
|
|
|
|
|
293
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
294
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
295
|
|
|
|
|
296
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
297
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
298
|
|
|
|
|
299
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
300
|
|
|
|
|
301
|
|
|
$galleryController = new GalleryController( |
|
302
|
|
|
$galleryManager, |
|
303
|
|
|
$mediaManager, |
|
304
|
|
|
$formFactory, |
|
305
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
306
|
|
|
); |
|
307
|
|
|
$view = $galleryController->deleteGalleryMediaGalleryItemAction(1, 1); |
|
308
|
|
|
|
|
309
|
|
|
$this->assertSame(array('deleted' => true), $view); |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
public function testDeleteGalleryMediaGalleryItemInvalidAction() |
|
313
|
|
|
{ |
|
314
|
|
|
$media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
$media2 = $this->getMock('Sonata\MediaBundle\Model\MediaInterface'); |
|
|
|
|
|
|
317
|
|
|
$media2->expects($this->any())->method('getId')->will($this->returnValue(2)); |
|
318
|
|
|
|
|
319
|
|
|
$galleryItem = $this->getMock('Sonata\MediaBundle\Model\GalleryItemInterface'); |
|
|
|
|
|
|
320
|
|
|
$galleryItem->expects($this->once())->method('getMedia')->will($this->returnValue($media2)); |
|
321
|
|
|
|
|
322
|
|
|
$gallery = $this->getMock('Sonata\MediaBundle\Model\GalleryInterface'); |
|
|
|
|
|
|
323
|
|
|
$gallery |
|
324
|
|
|
->expects($this->any()) |
|
325
|
|
|
->method('getGalleryItems') |
|
326
|
|
|
->will($this->returnValue(new ArrayCollection(array($galleryItem)))); |
|
327
|
|
|
|
|
328
|
|
|
$galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface'); |
|
|
|
|
|
|
329
|
|
|
$galleryManager->expects($this->once())->method('findOneBy')->will($this->returnValue($gallery)); |
|
330
|
|
|
|
|
331
|
|
|
$mediaManager = $this->getMock('Sonata\MediaBundle\Model\MediaManagerInterface'); |
|
|
|
|
|
|
332
|
|
|
$mediaManager->expects($this->once())->method('findOneBy')->will($this->returnValue($media)); |
|
333
|
|
|
|
|
334
|
|
|
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
|
|
|
|
|
335
|
|
|
|
|
336
|
|
|
$galleryController = new GalleryController( |
|
337
|
|
|
$galleryManager, |
|
338
|
|
|
$mediaManager, |
|
339
|
|
|
$formFactory, |
|
340
|
|
|
'Sonata\MediaBundle\Tests\Controller\Api\GalleryTest' |
|
341
|
|
|
); |
|
342
|
|
|
$view = $galleryController->deleteGalleryMediaGalleryItemAction(1, 1); |
|
343
|
|
|
|
|
344
|
|
|
$this->assertInstanceOf('FOS\RestBundle\View\View', $view); |
|
345
|
|
|
$this->assertSame(400, $view->getResponse()->getStatusCode(), 'Should return 400'); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.