[TwigBundle] adds legacy tests for deprecated configuration keys.

This commit is contained in:
Hugo Hamon 2015-01-09 12:06:55 +01:00
parent 43c05650c6
commit a290286eea
10 changed files with 126 additions and 35 deletions

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();