Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[HttpKernel] Fixed Inconsistent locale handling in subrequests #8604

Closed
wants to merge 2 commits into from

3 participants

@csarrazi
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #6932 #5532
License MIT
Doc PR -

The fix consists in passing the locale in the controller reference,
inside the routablefragment renderer.

@jakzal
Collaborator

There's one test failing related to hinclude.

@csarrazi

I actually have an issue with this test when running PHPunit, even without my modifications, which explains why I didn't fix this test yet.

PHPUnit 3.7.22 by Sebastian Bergmann.

Configuration read from /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/phpunit.xml.dist

........F...PHP Fatal error:  Call to undefined method Mock_EngineInterface_4280ee6a::exists() in /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php on line 134
PHP Stack trace:
PHP   1. {main}() /Users/csarrazi/.phpbrew/php/php-5.5.0/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /Users/csarrazi/.phpbrew/php/php-5.5.0/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/TestRunner.php:349
PHP   6. PHPUnit_Framework_TestSuite->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:705
PHP   7. PHPUnit_Framework_TestSuite->runTest() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:745
PHP   8. PHPUnit_Framework_TestCase->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:776
PHP  10. PHPUnit_Framework_TestCase->runBare() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestResult.php:648
PHP  11. PHPUnit_Framework_TestCase->runTest() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:831
PHP  12. ReflectionMethod->invokeArgs() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:976
PHP  13. Symfony\Component\HttpKernel\Fragment\Tests\FragmentRenderer\HIncludeFragmentRendererTest->testRenderWithDefaultText() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:976
PHP  14. Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer->render() /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php:93
PHP  15. Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer->templateExists() /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php:101

Fatal error: Call to undefined method Mock_EngineInterface_4280ee6a::exists() in /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php on line 134

Call Stack:
    0.0002     228720   1. {main}() /Users/csarrazi/.phpbrew/php/php-5.5.0/bin/phpunit:0
    0.0038     504440   2. PHPUnit_TextUI_Command::main() /Users/csarrazi/.phpbrew/php/php-5.5.0/bin/phpunit:46
    0.0038     505064   3. PHPUnit_TextUI_Command->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/Command.php:129
    0.0640    2900248   4. PHPUnit_TextUI_TestRunner->doRun() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/Command.php:176
    0.0674    3192592   5. PHPUnit_Framework_TestSuite->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/TextUI/TestRunner.php:349
    0.1147    4867984   6. PHPUnit_Framework_TestSuite->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:705
    0.1234    5014272   7. PHPUnit_Framework_TestSuite->runTest() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:745
    0.1234    5014272   8. PHPUnit_Framework_TestCase->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestSuite.php:775
    0.1235    5014272   9. PHPUnit_Framework_TestResult->run() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:776
    0.1235    5015184  10. PHPUnit_Framework_TestCase->runBare() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestResult.php:648
    0.1236    5032016  11. PHPUnit_Framework_TestCase->runTest() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:831
    0.1236    5032952  12. ReflectionMethod->invokeArgs() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:976
    0.1236    5033192  13. Symfony\Component\HttpKernel\Fragment\Tests\FragmentRenderer\HIncludeFragmentRendererTest->testRenderWithDefaultText() /Users/csarrazi/.phpbrew/php/php-5.5.0/lib/php/PHPUnit/Framework/TestCase.php:976
    0.1251    5087224  14. Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer->render() /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php:93
    0.1251    5087488  15. Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer->templateExists() /Users/csarrazi/Projects/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php:101

I'll try fixing the issue first, then fixing the last test.

@csarrazi

It seems that the composer.json file doesn't include the templating component in the require-dev node. I'm fixing that too.

@jakzal
Collaborator

@csarrazi error you've pasted is about something else. See: https://travis-ci.org/symfony/symfony/jobs/9626013#L295

If the templating component is missing from the composer.json, please send a separate PR.

@csarrazi

That's a given! ;)

csarrazi added some commits
@csarrazi csarrazi Fixed issue #6932 - Inconsistent locale handling in subrequests
The fix consists in passing the locale in the controller reference,
inside the routablefragment renderer.
2e1bba1
@csarrazi csarrazi [Tests] Fixed fragments tests 5205acd
@csarrazi

Fixed

@jakzal
Collaborator

:+1: for tests (one build failed but that's a travis issue)

@fabpot
Owner

Closing in favor of #8822

@fabpot fabpot closed this
@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch fabpot/fragment-locale (PR #8822)
This PR was merged into the 2.2 branch.

Discussion
----------

fixed locale management in sub-requests

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6932, #5532, #8604
| License       | MIT
| Doc PR        | n/a

Same fix as #8821 but for `_locale`, and a rebase of #8604.

Commits
-------

7117328 [HttpKernel] added a comment to warn about possible inconsistencies
c4636e1 added a functional test for locale handling in sub-requests
05fdb12 Fixed issue #6932 - Inconsistent locale handling in subrequests
b3c3159 fixed locale of sub-requests when explicitely set by the developer (refs #8821)
dac6e3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2013
  1. @csarrazi

    Fixed issue #6932 - Inconsistent locale handling in subrequests

    csarrazi authored
    The fix consists in passing the locale in the controller reference,
    inside the routablefragment renderer.
  2. @csarrazi
This page is out of date. Refresh to see the latest.
View
4 src/Symfony/Component/HttpKernel/Fragment/RoutableFragmentRenderer.php
@@ -55,6 +55,10 @@ protected function generateFragmentUri(ControllerReference $reference, Request $
$reference->attributes['_format'] = $request->getRequestFormat();
}
+ if (!isset($reference->attributes['_locale'])) {
+ $reference->attributes['_locale'] = $request->getLocale();
+ }
+
$reference->attributes['_controller'] = $reference->controller;
$reference->query['_path'] = http_build_query($reference->attributes, '', '&');
View
3  src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php
@@ -42,12 +42,13 @@ public function testRender()
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
$request = Request::create('/');
+ $request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
- $this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
+ $this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
}
private function getInlineStrategy($called = false)
View
2  src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php
@@ -38,7 +38,7 @@ public function testRenderWithControllerAndSigner()
{
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
- $this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller&amp;_hash=VI25qJj8J0qveB3bGKPhsJtexKg%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
+ $this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=g4b3vtCnhkZBFKrciEFwG7fucVo%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
}
public function testRenderWithUri()
View
4 src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php
@@ -50,8 +50,8 @@ public function testRenderWithObjectsAsAttributes()
{
$object = new \stdClass();
- $subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller');
- $subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller'));
+ $subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller');
+ $subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en'));
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
View
16 src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php
@@ -27,12 +27,13 @@ public function testGenerateFragmentUri($uri, $controller)
public function getGenerateFragmentUriData()
{
return array(
- array('http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
- array('http://localhost/_fragment?_path=_format%3Dxml%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
- array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
- array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
- array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
- array('http://localhost/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => array('foo', 'bar')), array())),
+ array('http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
+ array('http://localhost/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
+ array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
+ array('http://localhost/_fragment?_path=foo%3Dfoo%26_locale%3Dfr%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_locale' => 'fr'), array())),
+ array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
+ array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
+ array('http://localhost/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => array('foo', 'bar')), array())),
);
}
@@ -40,9 +41,10 @@ public function testGenerateFragmentUriWithARequest()
{
$request = Request::create('/');
$request->attributes->set('_format', 'json');
+ $request->setLocale('fr');
$controller = new ControllerReference('controller', array(), array());
- $this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request));
+ $this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request));
}
/**
Something went wrong with that request. Please try again.