Skip to content

Commit 94ca5e2

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: fixed request format when forwarding a request [HttpKernel] added a comment to warn about possible inconsistencies added a functional test for locale handling in sub-requests Fixed issue #6932 - Inconsistent locale handling in subrequests fixed locale of sub-requests when explicitely set by the developer (refs #8821) Conflicts: src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php
2 parents 040ac7b + 10d29d4 commit 94ca5e2

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

Tests/Controller/ControllerTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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+
}

Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
1313

14+
use Symfony\Component\HttpFoundation\Request;
1415
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\DependencyInjection\ContainerAware;
1617

1718
class FragmentController extends ContainerAware
1819
{
19-
public function indexAction()
20+
public function indexAction(Request $request)
2021
{
2122
$actions = $this->container->get('templating')->get('actions');
2223

@@ -29,7 +30,12 @@ public function indexAction()
2930

3031
$html2 = $actions->render($actions->controller('TestBundle:Fragment:customformat', array('_format' => 'html')));
3132

32-
return new Response($html1.'--'.$html2);
33+
$html3 = $actions->render($actions->controller('TestBundle:Fragment:customlocale', array('_locale' => 'es')));
34+
35+
$request->setLocale('fr');
36+
$html4 = $actions->render($actions->controller('TestBundle:Fragment:forwardlocale'));
37+
38+
return new Response($html1.'--'.$html2.'--'.$html3.'--'.$html4);
3339
}
3440

3541
public function inlinedAction($options, $_format)
@@ -41,6 +47,16 @@ public function customFormatAction($_format)
4147
{
4248
return new Response($_format);
4349
}
50+
51+
public function customLocaleAction(Request $request)
52+
{
53+
return new Response($request->getLocale());
54+
}
55+
56+
public function forwardLocaleAction(Request $request)
57+
{
58+
return new Response($request->getLocale());
59+
}
4460
}
4561

4662
class Bar

Tests/Functional/FragmentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testFragment($insulate)
2828

2929
$client->request('GET', '/fragment_home');
3030

31-
$this->assertEquals('bar txt--html', $client->getResponse()->getContent());
31+
$this->assertEquals('bar txt--html--es--fr', $client->getResponse()->getContent());
3232
}
3333

3434
public function getConfigs()

0 commit comments

Comments
 (0)