From 82dbaee06debb743308caa02c85e826adee04356 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Jul 2013 10:25:51 +0200 Subject: [PATCH] [HttpKernel] fixed the inline renderer when passing objects as attributes (closes #7124) --- .../Controller/FragmentController.php | 46 +++++++++++++++++++ .../TestBundle/Resources/config/routing.yml | 8 ++++ .../Tests/Functional/FragmentTest.php | 41 +++++++++++++++++ .../Tests/Functional/app/Fragment/bundles.php | 9 ++++ .../Tests/Functional/app/Fragment/config.yml | 7 +++ .../Tests/Functional/app/Fragment/routing.yml | 2 + .../Fragment/InlineFragmentRenderer.php | 8 ++++ .../Fragment/InlineFragmentRendererTest.php | 6 +-- 8 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/bundles.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/config.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/routing.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php new file mode 100644 index 0000000000000..7c8a4b48ad948 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/FragmentController.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\DependencyInjection\ContainerAware; + +class FragmentController extends ContainerAware +{ + public function indexAction() + { + $actions = $this->container->get('templating')->get('actions'); + + return new Response($actions->render($actions->controller('TestBundle:Fragment:inlined', array( + 'options' => array( + 'bar' => new Bar(), + 'eleven' => 11, + ), + )))); + } + + public function inlinedAction($options, $_format) + { + return new Response($options['bar']->getBar().' '.$_format); + } +} + +class Bar +{ + private $bar = 'bar'; + + public function getBar() + { + return $this->bar; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml index d9b380ef8dbd1..ae72dc64ad457 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml @@ -21,3 +21,11 @@ session_showflash: profiler: path: /profiler defaults: { _controller: TestBundle:Profiler:index } + +fragment_home: + path: /fragment_home + defaults: { _controller: TestBundle:Fragment:index, _format: txt } + +fragment_inlined: + path: /fragment_inlined + defaults: { _controller: TestBundle:Fragment:inlined } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php new file mode 100644 index 0000000000000..a054d7c2e2288 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; + +/** + * @group functional + */ +class FragmentTest extends WebTestCase +{ + /** + * @dataProvider getConfigs + */ + public function testFragment($insulate) + { + $client = $this->createClient(array('test_case' => 'Fragment', 'root_config' => 'config.yml')); + if ($insulate) { + $client->insulate(); + } + + $client->request('GET', '/fragment_home'); + + $this->assertEquals('bar txt', $client->getResponse()->getContent()); + } + + public function getConfigs() + { + return array( + array(false), + array(true), + ); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/bundles.php new file mode 100644 index 0000000000000..351cf79d43231 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Fragment/bundles.php @@ -0,0 +1,9 @@ +attributes; + $reference->attributes = array(); $uri = $this->generateFragmentUri($uri, $request); + $reference->attributes = $attributes; } $subRequest = $this->createSubRequest($uri, $request); diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index ea6c7244537b5..2da3c80677688 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -50,11 +50,7 @@ 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->attributes->replace(array('object' => $object)); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $kernel