Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #10820 [WebProfilerBundle] Fixed profiler seach/homepage with emp…
…ty token (tucksaun) This PR was merged into the 2.3 branch. Discussion ---------- [WebProfilerBundle] Fixed profiler seach/homepage with empty token | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10806 | License | MIT | Doc PR | none Commits ------- 16dd0e5 [WebProfilerBundle] added test case for #10773 5b91e70 [WebProfilerBundle] fixed profiler homepage, fixed #10806 7b425d2 [WebProfilerBundle] Added test case for #10806
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |