|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[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 Symfony\Bundle\FrameworkBundle\Tests\Controller; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
| 15 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 16 | +use Symfony\Component\HttpFoundation\Request; |
| 17 | +use Symfony\Component\HttpFoundation\Response; |
| 18 | + |
| 19 | +class ControllerTest extends TestCase |
| 20 | +{ |
| 21 | + public function testForward() |
| 22 | + { |
| 23 | + $request = Request::create('/'); |
| 24 | + $request->setLocale('fr'); |
| 25 | + $request->setRequestFormat('xml'); |
| 26 | + |
| 27 | + $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); |
| 28 | + $kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) { |
| 29 | + return new Response($request->getRequestFormat().'--'.$request->getLocale()); |
| 30 | + })); |
| 31 | + |
| 32 | + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
| 33 | + $container->expects($this->at(0))->method('get')->will($this->returnValue($request)); |
| 34 | + $container->expects($this->at(1))->method('get')->will($this->returnValue($kernel)); |
| 35 | + |
| 36 | + $controller = new Controller(); |
| 37 | + $controller->setContainer($container); |
| 38 | + |
| 39 | + $response = $controller->forward('a_controller'); |
| 40 | + $this->assertEquals('xml--fr', $response->getContent()); |
| 41 | + } |
| 42 | +} |
0 commit comments