minor #13344 [2.7] adds legacy tests for deprecated configuration keys. (hhamon)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7] adds legacy tests for deprecated configuration keys.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

814527f [FrameworkBundle] adds legacy tests for deprecated configuration keys.
a290286 [TwigBundle] adds legacy tests for deprecated configuration keys.
This commit is contained in:
Fabien Potencier 2015-01-09 16:31:09 +01:00
commit 7f8ff501a5
14 changed files with 141 additions and 42 deletions

View File

@ -3,12 +3,15 @@
$container->loadFromExtension('framework', array(
'secret' => 's3cr3t',
'default_locale' => 'fr',
'form' => null,
'form' => array(
'csrf_protection' => array(
'field_name' => '_csrf',
),
),
'http_method_override' => false,
'trusted_proxies' => array('127.0.0.1', '10.0.0.1'),
'csrf_protection' => array(
'enabled' => true,
'field_name' => '_csrf',
),
'esi' => array(
'enabled' => true,

View File

@ -7,8 +7,10 @@
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" trusted-proxies="127.0.0.1, 10.0.0.1" http-method-override="false">
<framework:csrf-protection enabled="true" field-name="_csrf" />
<framework:form />
<framework:csrf-protection enabled="true" />
<framework:form>
<framework:csrf-protection field-name="_csrf"/>
</framework:form>
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" enabled="false" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />

View File

@ -1,12 +1,13 @@
framework:
secret: s3cr3t
default_locale: fr
form: ~
form:
csrf_protection:
field_name: _csrf
http_method_override: false
trusted_proxies: ['127.0.0.1', '10.0.0.1']
csrf_protection:
enabled: true
field_name: _csrf
esi:
enabled: true
profiler:

View File

@ -457,8 +457,10 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertFalse($container->getParameter('form.type_extension.csrf.enabled'));
}
public function testFormCsrfFieldNameCanBeSetUnderCsrfSettings()
public function testLegacyFormCsrfFieldNameCanBeSetUnderCsrfSettings()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = $this->createContainerFromFile('form_csrf_sets_field_name');
$this->assertTrue($container->getParameter('form.type_extension.csrf.enabled'));

View File

@ -1,31 +1,26 @@
<?php
$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'MyBundle::formDeprecated.html.twig',
),
),
'form_themes' => array(
'MyBundle::form.html.twig',
),
'globals' => array(
'foo' => '@bar',
'baz' => '@@qux',
'pi' => 3.14,
'bad' => array('key' => 'foo'),
),
'auto_reload' => true,
'autoescape' => true,
'base_template_class' => 'stdClass',
'cache' => '/tmp',
'charset' => 'ISO-8859-1',
'debug' => true,
'strict_variables' => true,
'paths' => array(
'path1',
'path2',
'namespaced_path1' => 'namespace1',
'namespaced_path2' => 'namespace2',
),
'form_themes' => array(
'MyBundle::form.html.twig',
),
'globals' => array(
'foo' => '@bar',
'baz' => '@@qux',
'pi' => 3.14,
'bad' => array('key' => 'foo'),
),
'auto_reload' => true,
'autoescape' => true,
'base_template_class' => 'stdClass',
'cache' => '/tmp',
'charset' => 'ISO-8859-1',
'debug' => true,
'strict_variables' => true,
'paths' => array(
'path1',
'path2',
'namespaced_path1' => 'namespace1',
'namespaced_path2' => 'namespace2',
),
));

View File

@ -0,0 +1,10 @@
<?php
$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'form_table_layout.html.twig',
'MyBundle:Form:my_theme.html.twig',
),
),
));

View File

@ -0,0 +1,13 @@
<?php
$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'form_table_layout.html.twig',
'MyBundle:Form:my_theme.html.twig',
),
),
'form_themes' => array(
'FooBundle:Form:bar.html.twig',
),
));

View File

@ -7,9 +7,6 @@
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
<twig:form>
<twig:resource>MyBundle::formDeprecated.html.twig</twig:resource>
</twig:form>
<twig:form-theme>MyBundle::form.html.twig</twig:form-theme>
<twig:global key="foo" id="bar" type="service" />
<twig:global key="baz">@@qux</twig:global>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:twig="http://symfony.com/schema/dic/twig"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
<twig:form>
<twig:resource>form_table_layout.html.twig</twig:resource>
<twig:resource>MyBundle:Form:my_theme.html.twig</twig:resource>
</twig:form>
</twig:config>
</container>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:twig="http://symfony.com/schema/dic/twig"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
<twig:form>
<twig:resource>form_table_layout.html.twig</twig:resource>
<twig:resource>MyBundle:Form:my_theme.html.twig</twig:resource>
</twig:form>
<twig:form-theme>FooBundle:Form:bar.html.twig</twig:form-theme>
</twig:config>
</container>

View File

@ -1,9 +1,6 @@
twig:
form_themes:
- MyBundle::form.html.twig
form:
resources:
- MyBundle::formDeprecated.html.twig
globals:
foo: "@bar"
baz: "@@qux"

View File

@ -0,0 +1,5 @@
twig:
form:
resources:
- "form_table_layout.html.twig"
- "MyBundle:Form:my_theme.html.twig"

View File

@ -0,0 +1,7 @@
twig:
form_themes:
- "FooBundle:Form:bar.html.twig"
form:
resources:
- "form_table_layout.html.twig"
- "MyBundle:Form:my_theme.html.twig"

View File

@ -23,6 +23,44 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class TwigExtensionTest extends TestCase
{
/**
* @dataProvider getFormats
*/
public function testLegacyFormResourcesConfigurationKey($format)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$this->loadFromFile($container, 'legacy-form-resources-only', $format);
$this->compileContainer($container);
// Form resources
$this->assertCount(3, $container->getParameter('twig.form.resources'));
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
}
/**
* @dataProvider getFormats
*/
public function testLegacyMergeFormResourcesConfigurationKeyWithFormThemesConfigurationKey($format)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$container = $this->createContainer();
$container->registerExtension(new TwigExtension());
$this->loadFromFile($container, 'legacy-merge-form-resources-with-form-themes', $format);
$this->compileContainer($container);
$this->assertCount(4, $container->getParameter('twig.form.resources'));
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
$this->assertContains('FooBundle:Form:bar.html.twig', $container->getParameter('twig.form.resources'));
}
public function testLoadEmptyConfiguration()
{
$container = $this->createContainer();
@ -57,8 +95,6 @@ class TwigExtensionTest extends TestCase
$resources = $container->getParameter('twig.form.resources');
$this->assertContains('form_div_layout.html.twig', $resources, '->load() includes default template for form resources');
$this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources');
// @deprecated since version 2.6, to be removed in 3.0
$this->assertContains('MyBundle::formDeprecated.html.twig', $resources, '->load() merges new templates into form resources');
// Globals
$calls = $container->getDefinition('twig')->getMethodCalls();