Skip to content

Commit e246860

Browse files
committed
[WebProfiler] Fixed CR feedback: split unit tests to separate legacy option intercept_redirects.
1 parent dc3fdbf commit e246860

File tree

2 files changed

+134
-18
lines changed

2 files changed

+134
-18
lines changed

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,80 @@
1818
class ConfigurationTest extends TestCase
1919
{
2020
/**
21-
* @group legacy
22-
*
2321
* @dataProvider getDebugModes
2422
*/
25-
public function testConfigTree($options, $results)
23+
public function testConfigTree(array $options, array $expectedResult)
2624
{
2725
$processor = new Processor();
2826
$configuration = new Configuration();
2927
$config = $processor->processConfiguration($configuration, [$options]);
3028

31-
$this->assertEquals($results, $config);
29+
$this->assertEquals($expectedResult, $config);
3230
}
3331

3432
public function getDebugModes()
3533
{
3634
return [
37-
[[], ['intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt']],
38-
[['intercept_redirects' => true], ['intercept_redirects' => true, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt']],
39-
[['intercept_redirects' => false], ['intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt']],
40-
[['toolbar' => true], ['intercept_redirects' => false, 'toolbar' => true, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt']],
41-
[['excluded_ajax_paths' => 'test'], ['intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => 'test']],
35+
[
36+
'options' => [],
37+
'expectedResult' => [
38+
'intercept_redirects' => false,
39+
'toolbar' => false,
40+
'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt',
41+
],
42+
],
43+
[
44+
'options' => ['toolbar' => true],
45+
'expectedResult' => [
46+
'intercept_redirects' => false,
47+
'toolbar' => true,
48+
'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt',
49+
],
50+
],
51+
[
52+
'options' => ['excluded_ajax_paths' => 'test'],
53+
'expectedResult' => [
54+
'intercept_redirects' => false,
55+
'toolbar' => false,
56+
'excluded_ajax_paths' => 'test',
57+
],
58+
],
59+
];
60+
}
61+
62+
/**
63+
* @group legacy
64+
*
65+
* @dataProvider getInterceptRedirectsConfiguration
66+
*/
67+
public function testConfigTreeUsingInterceptRedirects(bool $interceptRedirects, array $expectedResult)
68+
{
69+
$processor = new Processor();
70+
$configuration = new Configuration();
71+
$config = $processor->processConfiguration($configuration, [['intercept_redirects' => $interceptRedirects]]);
72+
73+
$this->assertEquals($expectedResult, $config);
74+
}
75+
76+
public function getInterceptRedirectsConfiguration()
77+
{
78+
return [
79+
[
80+
'interceptRedirects' => true,
81+
'expectedResult' => [
82+
'intercept_redirects' => true,
83+
'toolbar' => false,
84+
'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt',
85+
],
86+
],
87+
[
88+
'interceptRedirects' => false,
89+
'expectedResult' => [
90+
'intercept_redirects' => false,
91+
'toolbar' => false,
92+
'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt',
93+
],
94+
],
4295
];
4396
}
4497
}

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,64 @@ public function testDefaultConfig($debug)
9999
self::assertSaneContainer($this->getCompiledContainer());
100100
}
101101

102+
public function getDebugModes()
103+
{
104+
return [
105+
['debug' => false],
106+
['debug' => true],
107+
];
108+
}
109+
110+
/**
111+
* @dataProvider getToolbarConfig
112+
*/
113+
public function testToolbarConfig(bool $toolbarEnabled, bool $listenerInjected, bool $listenerEnabled)
114+
{
115+
$extension = new WebProfilerExtension();
116+
$extension->load([['toolbar' => $toolbarEnabled]], $this->container);
117+
$this->container->removeDefinition('web_profiler.controller.exception');
118+
119+
$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));
120+
121+
self::assertSaneContainer($this->getCompiledContainer(), '', ['web_profiler.csp.handler']);
122+
123+
if ($listenerInjected) {
124+
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
125+
}
126+
}
127+
128+
public function getToolbarConfig()
129+
{
130+
return [
131+
[
132+
'toolbarEnabled' => false,
133+
'listenerInjected' => false,
134+
'listenerEnabled' => false,
135+
],
136+
[
137+
'toolbarEnabled' => true,
138+
'listenerInjected' => true,
139+
'listenerEnabled' => true,
140+
],
141+
];
142+
}
143+
102144
/**
103145
* @group legacy
104146
*
105-
* @dataProvider getDebugModes
147+
* @dataProvider getInterceptRedirectsToolbarConfig
106148
*/
107-
public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listenerInjected, $listenerEnabled)
108-
{
149+
public function testToolbarConfigUsingInterceptRedirects(
150+
bool $toolbarEnabled,
151+
bool $interceptRedirects,
152+
bool $listenerInjected,
153+
bool $listenerEnabled
154+
) {
109155
$extension = new WebProfilerExtension();
110-
$extension->load([['toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects]], $this->container);
156+
$extension->load(
157+
[['toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects]],
158+
$this->container
159+
);
111160
$this->container->removeDefinition('web_profiler.controller.exception');
112161

113162
$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));
@@ -119,13 +168,27 @@ public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listene
119168
}
120169
}
121170

122-
public function getDebugModes()
171+
public function getInterceptRedirectsToolbarConfig()
123172
{
124173
return [
125-
[false, false, false, false],
126-
[true, false, true, true],
127-
[false, true, true, false],
128-
[true, true, true, true],
174+
[
175+
'toolbarEnabled' => false,
176+
'interceptRedirects' => true,
177+
'listenerInjected' => true,
178+
'listenerEnabled' => false,
179+
],
180+
[
181+
'toolbarEnabled' => false,
182+
'interceptRedirects' => false,
183+
'listenerInjected' => false,
184+
'listenerEnabled' => false,
185+
],
186+
[
187+
'toolbarEnabled' => true,
188+
'interceptRedirects' => true,
189+
'listenerInjected' => true,
190+
'listenerEnabled' => true,
191+
],
129192
];
130193
}
131194

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy