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

Skip to content

[2.7] adds legacy tests for deprecated configuration keys. #13344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
),
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$container->loadFromExtension('twig', array(
'form' => array(
'resources' => array(
'form_table_layout.html.twig',
'MyBundle:Form:my_theme.html.twig',
),
),
));
Original file line number Diff line number Diff line change
@@ -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',
),
));
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
twig:
form_themes:
- MyBundle::form.html.twig
form:
resources:
- MyBundle::formDeprecated.html.twig
globals:
foo: "@bar"
baz: "@@qux"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
twig:
form:
resources:
- "form_table_layout.html.twig"
- "MyBundle:Form:my_theme.html.twig"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@

class TwigExtensionTest extends TestCase
{
/**
* @dataProvider getFormats
*/
public function testLegacyFormResourcesConfigurationKey($format)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing the iniSet() call here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Same in the other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

$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();
Expand Down Expand Up @@ -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();
Expand Down