Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b048296

Browse files
committed
Merge branch '3.2'
* 3.2: Fixes a typo in the form collector styles [WebProfilerBundle] Fix content-security-policy compatibility [WebProfilerBundle] Drop dead code [HttpKernel] Fixed bug with purging of HTTPS URLs fix some risky tests [DI] [YamlFileLoader] change error message of a non existing file [WebProfilerBundle] Handle Content-Security-Policy-Report-Only header correctly [Security] Added option to return true in the method isRememberMeRequested
2 parents 4c0006a + 8cd835e commit b048296

File tree

40 files changed

+236
-142
lines changed

40 files changed

+236
-142
lines changed

src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ public function testConstruct()
2525
{
2626
$connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
2727
$handler = new DbalSessionHandler($connection);
28+
29+
$this->assertInstanceOf('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', $handler);
2830
}
2931
}

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public function testThemeBlockInheritanceUsingDynamicExtend()
8989
;
9090

9191
$this->renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
92-
$this->renderer->searchAndRenderBlock($view, 'row');
92+
$this->assertMatchesXpath(
93+
$this->renderer->searchAndRenderBlock($view, 'row'),
94+
'/div/label[text()="child"]'
95+
);
9396
}
9497

9598
public function isSelectedChoiceProvider()

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/StopwatchHelperTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ public function testDevEnvironment()
3030
public function testProdEnvironment()
3131
{
3232
$helper = new StopwatchHelper(null);
33+
$helper->start('foo');
3334

34-
try {
35-
$helper->start('foo');
36-
} catch (\BadMethodCallException $e) {
37-
$this->fail('Assumed stopwatch is not called when not provided');
38-
}
35+
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
36+
// can be executed without throwing any exceptions
37+
$this->addToAssertionCount(1);
3938
}
4039
}

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,9 @@ class TemplateTest extends TestCase
1919
/**
2020
* @dataProvider getTemplateToPathProvider
2121
*/
22-
public function testGetPathForTemplatesInABundle($template, $path)
22+
public function testGetPathForTemplate($template, $path)
2323
{
24-
if ($template->get('bundle')) {
25-
$this->assertEquals($template->getPath(), $path);
26-
}
27-
}
28-
29-
/**
30-
* @dataProvider getTemplateToPathProvider
31-
*/
32-
public function testGetPathForTemplatesOutOfABundle($template, $path)
33-
{
34-
if (!$template->get('bundle')) {
35-
$this->assertEquals($template->getPath(), $path);
36-
}
24+
$this->assertSame($template->getPath(), $path);
3725
}
3826

3927
public function getTemplateToPathProvider()

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ProfilerController
4747
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
4848
* @param string $baseDir The project root directory
4949
*/
50-
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
50+
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
5151
{
5252
$this->generator = $generator;
5353
$this->profiler = $profiler;

src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private function removeCspHeaders(Response $response)
108108
{
109109
$response->headers->remove('X-Content-Security-Policy');
110110
$response->headers->remove('Content-Security-Policy');
111+
$response->headers->remove('Content-Security-Policy-Report-Only');
111112
}
112113

113114
/**
@@ -257,6 +258,10 @@ private function getCspHeaders(Response $response)
257258
$headers['Content-Security-Policy'] = $this->parseDirectives($response->headers->get('Content-Security-Policy'));
258259
}
259260

261+
if ($response->headers->has('Content-Security-Policy-Report-Only')) {
262+
$headers['Content-Security-Policy-Report-Only'] = $this->parseDirectives($response->headers->get('Content-Security-Policy-Report-Only'));
263+
}
264+
260265
if ($response->headers->has('X-Content-Security-Policy')) {
261266
$headers['X-Content-Security-Policy'] = $this->parseDirectives($response->headers->get('X-Content-Security-Policy'));
262267
}
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
<!-- START of Symfony Web Debug Toolbar -->
2-
{% if 'normal' != position %}
3-
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
4-
<a href="#" title="Show Symfony toolbar" tabindex="-1" id="sfToolbarMiniToggler-{{ token }}" accesskey="D">
5-
{{ include('@WebProfiler/Icon/symfony.svg') }}
6-
</a>
7-
</div>
8-
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
9-
{{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }}
10-
</style>
11-
<div id="sfToolbarClearer-{{ token }}" class="sf-toolbar-clearer"></div>
12-
{% endif %}
2+
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
3+
<a href="#" title="Show Symfony toolbar" tabindex="-1" id="sfToolbarMiniToggler-{{ token }}" accesskey="D">
4+
{{ include('@WebProfiler/Icon/symfony.svg') }}
5+
</a>
6+
</div>
7+
<div id="sfToolbarClearer-{{ token }}" class="sf-toolbar-clearer"></div>
138

149
<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
1510
{% for name, template in templates %}
@@ -28,10 +23,8 @@
2823
{% endif %}
2924
{% endfor %}
3025

31-
{% if 'normal' != position %}
32-
<a class="hide-button" id="sfToolbarHideButton-{{ token }}" title="Close Toolbar" tabindex="-1" accesskey="D">
33-
{{ include('@WebProfiler/Icon/close.svg') }}
34-
</a>
35-
{% endif %}
26+
<a class="hide-button" id="sfToolbarHideButton-{{ token }}" title="Close Toolbar" tabindex="-1" accesskey="D">
27+
{{ include('@WebProfiler/Icon/close.svg') }}
28+
</a>
3629
</div>
3730
<!-- END of Symfony Web Debug Toolbar -->

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<div id="sfwdt{{ token }}" class="sf-toolbar sf-display-none"></div>
22
{{ include('@WebProfiler/Profiler/base_js.html.twig') }}
3+
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
4+
{{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }}
5+
</style>
36
<script{% if csp_script_nonce %} nonce={{ csp_script_nonce }}{% endif %}>/*<![CDATA[*/
47
(function () {
58
{% if 'top' == position %}

src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ private function createController($profiler, $twig, $withCSP)
157157
if ($withCSP) {
158158
$nonceGenerator = $this->getMockBuilder('Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator')->getMock();
159159

160-
return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal', new ContentSecurityPolicyHandler($nonceGenerator));
160+
return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'bottom', new ContentSecurityPolicyHandler($nonceGenerator));
161161
}
162162

163-
return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal');
163+
return new ProfilerController($urlGenerator, $profiler, $twig, array());
164164
}
165165
}

src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,41 +97,41 @@ public function provideRequestAndResponsesForOnKernelResponse()
9797
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
9898
$this->createRequest(),
9999
$this->createResponse(),
100-
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
100+
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
101101
),
102102
array(
103103
$nonce, array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce),
104104
$this->createRequest($requestNonceHeaders),
105105
$this->createResponse($responseNonceHeaders),
106-
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
106+
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
107107
),
108108
array(
109109
$nonce,
110110
array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce),
111111
$this->createRequest($requestNonceHeaders),
112112
$this->createResponse(),
113-
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
113+
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
114114
),
115115
array(
116116
$nonce,
117117
array('csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce),
118118
$this->createRequest(),
119119
$this->createResponse($responseNonceHeaders),
120-
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
120+
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
121121
),
122122
array(
123123
$nonce,
124124
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
125125
$this->createRequest(),
126-
$this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:')),
127-
array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'X-Content-Security-Policy' => null),
126+
$this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:')),
127+
array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:', 'X-Content-Security-Policy' => null),
128128
),
129129
array(
130130
$nonce,
131131
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
132132
$this->createRequest(),
133-
$this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'')),
134-
array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null),
133+
$this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'')),
134+
array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null),
135135
),
136136
array(
137137
$nonce,

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,12 @@ public function testVerboseValueNotBreakArguments()
718718
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
719719
$application->run($input, $output);
720720

721+
$this->addToAssertionCount(1);
722+
721723
$input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar'));
722724
$application->run($input, $output);
725+
726+
$this->addToAssertionCount(1);
723727
}
724728

725729
public function testRunReturnsIntegerExitCode()

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function tearDown()
3434
}
3535

3636
/**
37-
* @dataProvider testRenderProvider
37+
* @dataProvider renderProvider
3838
*/
3939
public function testRender($headers, $rows, $style, $expected, $decorated = false)
4040
{
@@ -50,7 +50,7 @@ public function testRender($headers, $rows, $style, $expected, $decorated = fals
5050
}
5151

5252
/**
53-
* @dataProvider testRenderProvider
53+
* @dataProvider renderProvider
5454
*/
5555
public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false)
5656
{
@@ -66,7 +66,7 @@ public function testRenderAddRows($headers, $rows, $style, $expected, $decorated
6666
}
6767

6868
/**
69-
* @dataProvider testRenderProvider
69+
* @dataProvider renderProvider
7070
*/
7171
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
7272
{
@@ -83,7 +83,7 @@ public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $d
8383
$this->assertEquals($expected, $this->getOutputContent($output));
8484
}
8585

86-
public function testRenderProvider()
86+
public function renderProvider()
8787
{
8888
$books = array(
8989
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ protected function loadFile($file)
594594
}
595595

596596
if (!file_exists($file)) {
597-
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
597+
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
598598
}
599599

600600
if (null === $this->yamlParser) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function testProcessIgnoresMethodCalls()
115115
$container->register('b')->addMethodCall('setA', array(new Reference('a')));
116116

117117
$this->process($container);
118+
119+
$this->addToAssertionCount(1);
118120
}
119121

120122
public function testProcessIgnoresLazyServices()

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function testProcess()
4848
$container->register('d', 'class')->setSynthetic(true);
4949

5050
$this->process($container);
51+
52+
$this->addToAssertionCount(1);
5153
}
5254

5355
public function testValidTags()
@@ -59,6 +61,8 @@ public function testValidTags()
5961
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));
6062

6163
$this->process($container);
64+
65+
$this->addToAssertionCount(1);
6266
}
6367

6468
/**

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function testProcess()
2828
->addArgument(new Reference('b'))
2929
;
3030
$container->register('b', '\stdClass');
31+
32+
$this->process($container);
33+
34+
$this->addToAssertionCount(1);
3135
}
3236

3337
/**

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function testProcess()
3838
$container->register('b');
3939

4040
$this->process($container);
41+
42+
$this->addToAssertionCount(1);
4143
}
4244

4345
protected function process(ContainerBuilder $container)

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ public function testCircularReferenceAllowanceForLazyServices()
487487

488488
$dumper = new PhpDumper($container);
489489
$dumper->dump();
490+
491+
$this->addToAssertionCount(1);
490492
}
491493

492494
public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices()
@@ -524,6 +526,8 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
524526

525527
$dumper->setProxyDumper(new DummyProxyDumper());
526528
$dumper->dump();
529+
530+
$this->addToAssertionCount(1);
527531
}
528532

529533
public function testLazyArgumentProvideGenerator()

src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ public function testCompiledContainerCanBeDumped($containerFile)
157157
$container->compile();
158158
$dumper = new XmlDumper($container);
159159
$dumper->dump();
160+
161+
$this->addToAssertionCount(1);
160162
}
161163

162164
public function provideCompiledContainerData()

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,33 @@ public static function setUpBeforeClass()
4040
require_once self::$fixturesPath.'/includes/ProjectExtension.php';
4141
}
4242

43-
public function testLoadFile()
43+
/**
44+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
45+
* @expectedExceptionMessageRegExp /The file ".+" does not exist./
46+
*/
47+
public function testLoadUnExistFile()
4448
{
4549
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
4650
$r = new \ReflectionObject($loader);
4751
$m = $r->getMethod('loadFile');
4852
$m->setAccessible(true);
4953

50-
try {
51-
$m->invoke($loader, 'foo.yml');
52-
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
53-
} catch (\Exception $e) {
54-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
55-
$this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
56-
}
57-
58-
try {
59-
$m->invoke($loader, 'parameters.ini');
60-
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
61-
} catch (\Exception $e) {
62-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
63-
$this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
64-
}
54+
$m->invoke($loader, 'foo.yml');
55+
}
6556

66-
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
57+
/**
58+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
59+
* @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./
60+
*/
61+
public function testLoadInvalidYamlFile()
62+
{
63+
$path = self::$fixturesPath.'/ini';
64+
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
65+
$r = new \ReflectionObject($loader);
66+
$m = $r->getMethod('loadFile');
67+
$m->setAccessible(true);
6768

68-
foreach (array('nonvalid1', 'nonvalid2') as $fixture) {
69-
try {
70-
$m->invoke($loader, $fixture.'.yml');
71-
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
72-
} catch (\Exception $e) {
73-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate');
74-
$this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate');
75-
}
76-
}
69+
$m->invoke($loader, $path.'/parameters.ini');
7770
}
7871

7972
/**
@@ -97,6 +90,8 @@ public function provideInvalidFiles()
9790
array('bad_service'),
9891
array('bad_calls'),
9992
array('bad_format'),
93+
array('nonvalid1'),
94+
array('nonvalid2'),
10095
);
10196
}
10297

0 commit comments

Comments
 (0)