diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 8b70f3eaad02..6154dcb790e7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -107,11 +107,11 @@ public function render($controller, array $options = array()) // enforce all attribute values to be scalars to be sure that the same // render() call will work with or without a reverse proxy - foreach ($options['attributes'] as $key => $value) { - if (!is_scalar($value)) { - throw new \InvalidArgumentException(sprintf('Unable to render the "%s" controller as the "%s" attribute is not a scalar.', $controller, $key)); + array_walk_recursive($options['attributes'], function ($value) use ($controller) { + if (is_object($value)) { + throw new \InvalidArgumentException(sprintf('Unable to render the "%s" controller as one of the attribute is an object.', $controller)); } - } + }); if (!is_array($options['alt'])) { $options['alt'] = array($options['alt']); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php index b0379b26035e..c18d88eeb71e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php @@ -220,6 +220,64 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() $this->assertEquals('Foo', ob_get_clean()); } + public function testRenderAttributes() + { + $dispatcher = new EventDispatcher(); + $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); + + $phpunit = $this; + $esi = $this->getMock('Symfony\\Component\\HttpKernel\\HttpCache\\Esi'); + $esi + ->expects($this->once()) + ->method('hasSurrogateEsiCapability') + ->will($this->returnValue(true)) + ; + $esi + ->expects($this->once()) + ->method('renderIncludeTag') + ->will($this->returnCallback(function ($uri) use ($phpunit) { + $phpunit->assertEquals('foo[bar]=foo', urldecode($uri)); + + return 'foo'; + })) + ; + + $router = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface'); + $router + ->expects($this->once()) + ->method('generate') + ->will($this->returnCallback(function ($name, $options) { + return $options['path']; + })) + ; + + $request = new Request(); + + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container->expects($this->at(2))->method('get')->with($this->equalTo('esi'))->will($this->returnValue($esi)); + $container->expects($this->at(3))->method('get')->with($this->equalTo('request'))->will($this->returnValue($request)); + $container->expects($this->at(4))->method('get')->with($this->equalTo('router'))->will($this->returnValue($router)); + $container->expects($this->at(5))->method('get')->with($this->equalTo('request'))->will($this->returnValue($request)); + $container->expects($this->at(6))->method('get')->with($this->equalTo('esi'))->will($this->returnValue($esi)); + + $container + ->expects($this->once()) + ->method('has') + ->with($this->equalTo('esi')) + ->will($this->returnValue(true)) + ; + + $kernel = new HttpKernel($dispatcher, $container, $resolver); + + $content = $kernel->render('foo_controller', array( + 'standalone' => true, + 'attributes' => array('foo' => array('bar' => 'foo')), + )); + + // if this assertion fails, it means that the assertion in 'returnCallback' failed + $this->assertEquals('foo', $content); + } + /** * @expectedException \InvalidArgumentException */ @@ -230,6 +288,6 @@ public function testRenderOnlyAllowScalarAttributes() $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); $kernel = new HttpKernel($dispatcher, $container, $resolver); - $kernel->render('/', array('attributes' => array('foo' => new \stdClass()))); + $kernel->render('/', array('attributes' => array('foo' => array('bar' => new \stdClass())))); } }