Skip to content

Commit

Permalink
[HttpKernel] fixed the inline renderer when passing objects as attrib…
Browse files Browse the repository at this point in the history
…utes (closes #7124)
  • Loading branch information
fabpot committed Jul 8, 2013
1 parent 6dbd1e1 commit 82dbaee
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 5 deletions.
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;
}
}
Expand Up @@ -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 }
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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),
);
}
}
@@ -0,0 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return array(
new FrameworkBundle(),
new TestBundle(),
);
@@ -0,0 +1,7 @@
imports:
- { resource: ../config/default.yml }

framework:
fragments: ~
templating:
engines: ['php']
@@ -0,0 +1,2 @@
_fragmenttest_bundle:
resource: @TestBundle/Resources/config/routing.yml
Expand Up @@ -47,7 +47,15 @@ public function render($uri, Request $request, array $options = array())
$reference = null;
if ($uri instanceof ControllerReference) {
$reference = $uri;

// Remove attributes from the genereated URI because if not, the Symfony
// routing system will use them to populate the Request attributes. We don't
// want that as we want to preserve objects (so we manually set Request attributes
// below instead)
$attributes = $reference->attributes;
$reference->attributes = array();
$uri = $this->generateFragmentUri($uri, $request);
$reference->attributes = $attributes;
}

$subRequest = $this->createSubRequest($uri, $request);
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 82dbaee

Please sign in to comment.