From a290286eeaab5c9d993051ae72ff8d98f080276b Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 9 Jan 2015 12:06:55 +0100 Subject: [PATCH 1/2] [TwigBundle] adds legacy tests for deprecated configuration keys. --- .../DependencyInjection/Fixtures/php/full.php | 49 +++++++++---------- .../php/legacy-form-resources-only.php | 10 ++++ ...-merge-form-resources-with-form-themes.php | 13 +++++ .../DependencyInjection/Fixtures/xml/full.xml | 3 -- .../xml/legacy-form-resources-only.xml | 15 ++++++ ...-merge-form-resources-with-form-themes.xml | 16 ++++++ .../DependencyInjection/Fixtures/yml/full.yml | 3 -- .../yml/legacy-form-resources-only.yml | 5 ++ ...-merge-form-resources-with-form-themes.yml | 7 +++ .../DependencyInjection/TwigExtensionTest.php | 40 ++++++++++++++- 10 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-form-resources-only.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-merge-form-resources-with-form-themes.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-form-resources-only.xml create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-merge-form-resources-with-form-themes.xml create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-form-resources-only.yml create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-merge-form-resources-with-form-themes.yml diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php index 31a462bae4c0c..9385131730d86 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -1,31 +1,26 @@ 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', + ), )); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-form-resources-only.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-form-resources-only.php new file mode 100644 index 0000000000000..fbd2b83f133e3 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-form-resources-only.php @@ -0,0 +1,10 @@ +loadFromExtension('twig', array( + 'form' => array( + 'resources' => array( + 'form_table_layout.html.twig', + 'MyBundle:Form:my_theme.html.twig', + ), + ), +)); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-merge-form-resources-with-form-themes.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-merge-form-resources-with-form-themes.php new file mode 100644 index 0000000000000..dc36daf8cf0c2 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/legacy-merge-form-resources-with-form-themes.php @@ -0,0 +1,13 @@ +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', + ), +)); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index cff14dc3f00a6..14c95af97e8f4 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -7,9 +7,6 @@ http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd"> - - MyBundle::formDeprecated.html.twig - MyBundle::form.html.twig @@qux diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-form-resources-only.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-form-resources-only.xml new file mode 100644 index 0000000000000..9aa2486c5f04f --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-form-resources-only.xml @@ -0,0 +1,15 @@ + + + + + + + form_table_layout.html.twig + MyBundle:Form:my_theme.html.twig + + + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-merge-form-resources-with-form-themes.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-merge-form-resources-with-form-themes.xml new file mode 100644 index 0000000000000..efe83ea7b78e1 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/legacy-merge-form-resources-with-form-themes.xml @@ -0,0 +1,16 @@ + + + + + + + form_table_layout.html.twig + MyBundle:Form:my_theme.html.twig + + FooBundle:Form:bar.html.twig + + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 11173f64e1f30..68ecf463f09f6 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -1,9 +1,6 @@ twig: form_themes: - MyBundle::form.html.twig - form: - resources: - - MyBundle::formDeprecated.html.twig globals: foo: "@bar" baz: "@@qux" diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-form-resources-only.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-form-resources-only.yml new file mode 100644 index 0000000000000..bb1a75f603517 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-form-resources-only.yml @@ -0,0 +1,5 @@ +twig: + form: + resources: + - "form_table_layout.html.twig" + - "MyBundle:Form:my_theme.html.twig" diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-merge-form-resources-with-form-themes.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-merge-form-resources-with-form-themes.yml new file mode 100644 index 0000000000000..8fc9f92e869d5 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/legacy-merge-form-resources-with-form-themes.yml @@ -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" diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 3e382fe0c81de..05d450db73a3f 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -23,6 +23,44 @@ 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 @@ public function testLoadFullConfiguration($format) $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(); From 814527f9d2e1f9364a9ffefc1e0d955795b2955b Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 9 Jan 2015 14:18:23 +0100 Subject: [PATCH 2/2] [FrameworkBundle] adds legacy tests for deprecated configuration keys. --- .../Tests/DependencyInjection/Fixtures/php/full.php | 7 +++++-- .../Tests/DependencyInjection/Fixtures/xml/full.xml | 6 ++++-- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 5 +++-- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 4 +++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index baa17dc92e7b5..ab356dafd7c22 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -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, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 16aef6f09f624..fc6d336a316d1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -7,8 +7,10 @@ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - - + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index b4adc25782d45..d16f24c4cafb6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -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: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 7d2b2762dc27c..4050bf13fec8f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -457,8 +457,10 @@ public function testFormsCanBeEnabledWithoutCsrfProtection() $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'));