|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien.potencier@symfony-project.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\WebProfilerBundle\Tests; |
| 13 | + |
| 14 | +use Symfony\Bundle\WebProfilerBundle\WebDebugToolbarListener; |
| 15 | +use Symfony\Component\HttpFoundation\Response; |
| 16 | + |
| 17 | +class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider getInjectToolbarTests |
| 21 | + */ |
| 22 | + public function testInjectToolbar($content, $expected) |
| 23 | + { |
| 24 | + $resolver = $this->getMock('Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver', array(), array(), '', false); |
| 25 | + $resolver->expects($this->any()) |
| 26 | + ->method('render') |
| 27 | + ->will($this->returnValue('WDT')); |
| 28 | + ; |
| 29 | + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); |
| 30 | + $listener = new WebDebugToolbarListener($resolver); |
| 31 | + $r = new \ReflectionObject($listener); |
| 32 | + $m = $r->getMethod('injectToolbar'); |
| 33 | + $m->setAccessible(true); |
| 34 | + |
| 35 | + $response = new Response($content); |
| 36 | + |
| 37 | + $m->invoke($listener, $request, $response); |
| 38 | + $this->assertEquals($expected, $response->getContent()); |
| 39 | + } |
| 40 | + |
| 41 | + public function getInjectToolbarTests() |
| 42 | + { |
| 43 | + return array( |
| 44 | + array('<html><head></head><body></body></html>', "<html><head></head><body>\nWDT\n</body></html>"), |
| 45 | + array('<html> |
| 46 | + <head></head> |
| 47 | + <body> |
| 48 | + <textarea><html><head></head><body></body></html></textarea> |
| 49 | + </body> |
| 50 | + </html>', "<html> |
| 51 | + <head></head> |
| 52 | + <body> |
| 53 | + <textarea><html><head></head><body></body></html></textarea> |
| 54 | + |
| 55 | +WDT |
| 56 | +</body> |
| 57 | + </html>"), |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments