Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[WebProfilerBundle] made toolbar listener instantiation conditional
  • Loading branch information
jfsimon committed Jul 31, 2013
1 parent 70bbf96 commit 17cbfc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Expand Up @@ -44,18 +44,13 @@ public function load(array $configs, ContainerBuilder $container)

$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']);
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);

if (!$config['toolbar']) {
$mode = WebDebugToolbarListener::DISABLED;
} else {
$mode = WebDebugToolbarListener::ENABLED;
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);
}

$container->setParameter('web_profiler.debug_toolbar.mode', $mode);
$container->setParameter('web_profiler.debug_toolbar.position', $config['position']);
}

/**
Expand Down
Expand Up @@ -86,29 +86,35 @@ public function testDefaultConfig($debug)
$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());
}

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

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

Expand Down

0 comments on commit 17cbfc8

Please sign in to comment.