4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Fragment;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpKernel\Controller\ControllerReference;
18 class RoutableFragmentRendererTest extends TestCase
21 * @dataProvider getGenerateFragmentUriData
23 public function testGenerateFragmentUri($uri, $controller)
25 $this->assertEquals($uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/')));
29 * @dataProvider getGenerateFragmentUriData
31 public function testGenerateAbsoluteFragmentUri($uri, $controller)
33 $this->assertEquals('http://localhost'.$uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/'), true));
36 public function getGenerateFragmentUriData()
39 array('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
40 array('/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
41 array('/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
42 array('/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
43 array('/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
44 array('/_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())),
48 public function testGenerateFragmentUriWithARequest()
50 $request = Request::create('/');
51 $request->attributes->set('_format', 'json');
52 $request->setLocale('fr');
53 $controller = new ControllerReference('controller', array(), array());
55 $this->assertEquals('/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request));
59 * @expectedException \LogicException
60 * @dataProvider getGenerateFragmentUriDataWithNonScalar
62 public function testGenerateFragmentUriWithNonScalar($controller)
64 $this->callGenerateFragmentUriMethod($controller, Request::create('/'));
67 public function getGenerateFragmentUriDataWithNonScalar()
70 array(new ControllerReference('controller', array('foo' => new Foo(), 'bar' => 'bar'), array())),
71 array(new ControllerReference('controller', array('foo' => array('foo' => 'foo'), 'bar' => array('bar' => new Foo())), array())),
75 private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false)
77 $renderer = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer');
78 $r = new \ReflectionObject($renderer);
79 $m = $r->getMethod('generateFragmentUri');
80 $m->setAccessible(true);
82 return $m->invoke($renderer, $reference, $request, $absolute);
90 public function getFoo()