@@ -209,4 +209,122 @@ public function isCsrfTokenValid($id, $token)
209
209
{
210
210
return parent ::isCsrfTokenValid ($ id , $ token );
211
211
}
212
+
213
+ public function testGenerateUrl ()
214
+ {
215
+ $ router = $ this ->getMock ('Symfony\Component\Routing\RouterInterface ' );
216
+ $ router ->expects ($ this ->once ())->method ('generate ' )->willReturn ('/foo ' );
217
+
218
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
219
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ router ));
220
+
221
+ $ controller = new Controller ();
222
+ $ controller ->setContainer ($ container );
223
+
224
+ $ this ->assertEquals ('/foo ' , $ controller ->generateUrl ('foo ' ));
225
+ }
226
+
227
+ public function testRedirect ()
228
+ {
229
+ $ controller = new Controller ();
230
+ $ response = $ controller ->redirect ('http://dunglas.fr ' , 301 );
231
+
232
+ $ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\RedirectResponse ' , $ response );
233
+ $ this ->assertSame ('http://dunglas.fr ' , $ response ->getTargetUrl ());
234
+ $ this ->assertSame (301 , $ response ->getStatusCode ());
235
+ }
236
+
237
+ public function testRenderViewTemplating ()
238
+ {
239
+ $ templating = $ this ->getMock ('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface ' );
240
+ $ templating ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
241
+
242
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
243
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
244
+
245
+ $ controller = new Controller ();
246
+ $ controller ->setContainer ($ container );
247
+
248
+ $ this ->assertEquals ('bar ' , $ controller ->renderView ('foo ' ));
249
+ }
250
+
251
+ public function testRenderTemplating ()
252
+ {
253
+ $ templating = $ this ->getMock ('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface ' );
254
+ $ templating ->expects ($ this ->once ())->method ('renderResponse ' )->willReturn (new Response ('bar ' ));
255
+
256
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
257
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
258
+
259
+ $ controller = new Controller ();
260
+ $ controller ->setContainer ($ container );
261
+
262
+ $ this ->assertEquals ('bar ' , $ controller ->render ('foo ' )->getContent ());
263
+ }
264
+
265
+ public function testStreamTemplating ()
266
+ {
267
+ $ templating = $ this ->getMock ('Symfony\Component\Routing\RouterInterface ' );
268
+
269
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
270
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ templating ));
271
+
272
+ $ controller = new Controller ();
273
+ $ controller ->setContainer ($ container );
274
+
275
+ $ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\StreamedResponse ' , $ controller ->stream ('foo ' ));
276
+ }
277
+
278
+ public function testCreateNotFoundException ()
279
+ {
280
+ $ controller = new Controller ();
281
+
282
+ $ this ->assertInstanceOf ('Symfony\Component\HttpKernel\Exception\NotFoundHttpException ' , $ controller ->createNotFoundException ());
283
+ }
284
+
285
+ public function testCreateForm ()
286
+ {
287
+ $ form = $ this ->getMock ('Symfony\Component\Form\FormInterface ' );
288
+
289
+ $ formFactory = $ this ->getMock ('Symfony\Component\Form\FormFactoryInterface ' );
290
+ $ formFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ form );
291
+
292
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
293
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
294
+
295
+ $ controller = new Controller ();
296
+ $ controller ->setContainer ($ container );
297
+
298
+ $ this ->assertEquals ($ form , $ controller ->createForm ('foo ' ));
299
+ }
300
+
301
+ public function testCreateFormBuilder ()
302
+ {
303
+ $ formBuilder = $ this ->getMock ('Symfony\Component\Form\FormBuilderInterface ' );
304
+
305
+ $ formFactory = $ this ->getMock ('Symfony\Component\Form\FormFactoryInterface ' );
306
+ $ formFactory ->expects ($ this ->once ())->method ('createBuilder ' )->willReturn ($ formBuilder );
307
+
308
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
309
+ $ container ->expects ($ this ->at (0 ))->method ('get ' )->will ($ this ->returnValue ($ formFactory ));
310
+
311
+ $ controller = new Controller ();
312
+ $ controller ->setContainer ($ container );
313
+
314
+ $ this ->assertEquals ($ formBuilder , $ controller ->createFormBuilder ('foo ' ));
315
+ }
316
+
317
+ public function testGetDoctrine ()
318
+ {
319
+ $ doctrine = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
320
+
321
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
322
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (true ));
323
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ doctrine ));
324
+
325
+ $ controller = new Controller ();
326
+ $ controller ->setContainer ($ container );
327
+
328
+ $ this ->assertEquals ($ doctrine , $ controller ->getDoctrine ());
329
+ }
212
330
}
0 commit comments