Skip to content

[WebProfilerBundle] Fixed profiler seach/homepage with empty token #10820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function toolbarAction(Request $request, $token)
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}

if (null === $token) {
if ('empty' === $token || null === $token) {
return new Response('', 200, array('Content-Type' => 'text/html'));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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\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
{
/**
* @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'),
);
}

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());
}
}