[WebProfilerBundle] made toolbar listener instantiation conditional

This commit is contained in:
Jean-François Simon 2013-07-31 11:17:13 +02:00
parent 70bbf96498
commit 17cbfc8cf1
2 changed files with 18 additions and 17 deletions

View File

@ -44,18 +44,13 @@ class WebProfilerExtension extends Extension
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('profiler.xml');
$loader->load('toolbar.xml');
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
if (!$config['toolbar']) {
$mode = WebDebugToolbarListener::DISABLED;
} else {
$mode = WebDebugToolbarListener::ENABLED;
}
$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
if ($config['toolbar'] || $config['intercept_redirects']) {
$loader->load('toolbar.xml');
$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
}
}
/**

View File

@ -86,7 +86,7 @@ class WebProfilerExtensionTest extends TestCase
$extension = new WebProfilerExtension();
$extension->load(array(array()), $this->container);
$this->assertFalse($this->container->get('web_profiler.debug_toolbar')->isEnabled());
$this->assertFalse($this->container->has('web_profiler.debug_toolbar'));
$this->assertSaneContainer($this->getDumpedContainer());
}
@ -94,12 +94,16 @@ class WebProfilerExtensionTest extends TestCase
/**
* @dataProvider getDebugModes
*/
public function testToolbarConfig($enabled)
public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listenerInjected, $listenerEnabled)
{
$extension = new WebProfilerExtension();
$extension->load(array(array('toolbar' => $enabled)), $this->container);
$extension->load(array(array('toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects)), $this->container);
$this->assertSame($enabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));
if ($listenerInjected) {
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
}
$this->assertSaneContainer($this->getDumpedContainer());
}
@ -107,8 +111,10 @@ class WebProfilerExtensionTest extends TestCase
public function getDebugModes()
{
return array(
array(true),
array(false),
array(false, false, false, false),
array(true, false, true, true),
array(false, true, true, false),
array(true, true, true, true),
);
}