From 7b425d229d6f2a215fbafb2b22fb3e8513fcce80 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Wed, 30 Apr 2014 09:30:54 +0200 Subject: [PATCH 1/3] [WebProfilerBundle] Added test case for #10806 --- .../Controller/ProfilerControllerTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php new file mode 100644 index 0000000000..de8a952fe9 --- /dev/null +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.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\WebProfilerBundle\Tests\Controller; + +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; +use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController; +use Symfony\Component\HttpFoundation\Request; + +class ProfilerControllerTest extends TestCase +{ + /** + * @dataProvider getEmptyTokenCases + */ + public function testEmptyToken($token) + { + $urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'); + $twig = $this->getMock('Twig_Environment'); + $profiler = $this + ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') + ->disableOriginalConstructor() + ->getMock(); + + $controller = new ProfilerController($urlGenerator, $profiler, $twig, array()); + + $response = $controller->toolbarAction(Request::create('/_wdt/empty'), $token); + $this->assertEquals(200, $response->getStatusCode()); + } + + public function getEmptyTokenCases() + { + return array( + array(null), + // "empty" is also a valid empty token case, see https://github.com/symfony/symfony/issues/10806 + array('empty'), + ); + } +} From 5b91e70777c2e3bb72970f0f7b8e217b62074196 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Wed, 30 Apr 2014 09:32:22 +0200 Subject: [PATCH 2/3] [WebProfilerBundle] fixed profiler homepage, fixed #10806 --- .../Bundle/WebProfilerBundle/Controller/ProfilerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index cd3e17c7f5..a106feae99 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -232,7 +232,7 @@ class ProfilerController $session->getFlashBag()->setAll($session->getFlashBag()->peekAll()); } - if (null === $token) { + if ('empty' === $token || null === $token) { return new Response('', 200, array('Content-Type' => 'text/html')); } From 16dd0e5dda25edd50e2a1a83ac70c03fb8fee673 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Wed, 30 Apr 2014 09:45:11 +0200 Subject: [PATCH 3/3] [WebProfilerBundle] added test case for #10773 --- .../Controller/ProfilerControllerTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php index de8a952fe9..bff1919aa9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController; +use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpFoundation\Request; class ProfilerControllerTest extends TestCase @@ -43,4 +44,34 @@ class ProfilerControllerTest extends TestCase array('empty'), ); } + + public function testReturns404onTokenNotFound() + { + $urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'); + $twig = $this->getMock('Twig_Environment'); + $profiler = $this + ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') + ->disableOriginalConstructor() + ->getMock(); + + $controller = new ProfilerController($urlGenerator, $profiler, $twig, array()); + + $profiler + ->expects($this->exactly(2)) + ->method('loadProfile') + ->will($this->returnCallback(function ($token) { + if ('found' == $token) { + return new Profile($token); + } + + return; + })) + ; + + $response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found'); + $this->assertEquals(200, $response->getStatusCode()); + + $response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound'); + $this->assertEquals(404, $response->getStatusCode()); + } }