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

Skip to content

Commit b68b147

Browse files
author
Hugo Hamon
committed
[TwigBundle] adds legacy tests for deprecated configuration keys.
1 parent 9a6f52e commit b68b147

10 files changed

+122
-35
lines changed
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
<?php
22

33
$container->loadFromExtension('twig', array(
4-
'form' => array(
5-
'resources' => array(
6-
'MyBundle::formDeprecated.html.twig',
7-
),
8-
),
9-
'form_themes' => array(
10-
'MyBundle::form.html.twig',
11-
),
12-
'globals' => array(
13-
'foo' => '@bar',
14-
'baz' => '@@qux',
15-
'pi' => 3.14,
16-
'bad' => array('key' => 'foo'),
17-
),
18-
'auto_reload' => true,
19-
'autoescape' => true,
20-
'base_template_class' => 'stdClass',
21-
'cache' => '/tmp',
22-
'charset' => 'ISO-8859-1',
23-
'debug' => true,
24-
'strict_variables' => true,
25-
'paths' => array(
26-
'path1',
27-
'path2',
28-
'namespaced_path1' => 'namespace1',
29-
'namespaced_path2' => 'namespace2',
30-
),
4+
'form_themes' => array(
5+
'MyBundle::form.html.twig',
6+
),
7+
'globals' => array(
8+
'foo' => '@bar',
9+
'baz' => '@@qux',
10+
'pi' => 3.14,
11+
'bad' => array('key' => 'foo'),
12+
),
13+
'auto_reload' => true,
14+
'autoescape' => true,
15+
'base_template_class' => 'stdClass',
16+
'cache' => '/tmp',
17+
'charset' => 'ISO-8859-1',
18+
'debug' => true,
19+
'strict_variables' => true,
20+
'paths' => array(
21+
'path1',
22+
'path2',
23+
'namespaced_path1' => 'namespace1',
24+
'namespaced_path2' => 'namespace2',
25+
),
3126
));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$container->loadFromExtension('twig', array(
4+
'form' => array(
5+
'resources' => array(
6+
'form_table_layout.html.twig',
7+
'MyBundle:Form:my_theme.html.twig',
8+
),
9+
),
10+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$container->loadFromExtension('twig', array(
4+
'form' => array(
5+
'resources' => array(
6+
'form_table_layout.html.twig',
7+
'MyBundle:Form:my_theme.html.twig',
8+
),
9+
),
10+
'form_themes' => array(
11+
'FooBundle:Form:bar.html.twig',
12+
),
13+
));

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
88

99
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
10-
<twig:form>
11-
<twig:resource>MyBundle::formDeprecated.html.twig</twig:resource>
12-
</twig:form>
1310
<twig:form-theme>MyBundle::form.html.twig</twig:form-theme>
1411
<twig:global key="foo" id="bar" type="service" />
1512
<twig:global key="baz">@@qux</twig:global>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:twig="http://symfony.com/schema/dic/twig"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
8+
9+
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
10+
<twig:form>
11+
<twig:resource>form_table_layout.html.twig</twig:resource>
12+
<twig:resource>MyBundle:Form:my_theme.html.twig</twig:resource>
13+
</twig:form>
14+
</twig:config>
15+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:twig="http://symfony.com/schema/dic/twig"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
8+
9+
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true">
10+
<twig:form>
11+
<twig:resource>form_table_layout.html.twig</twig:resource>
12+
<twig:resource>MyBundle:Form:my_theme.html.twig</twig:resource>
13+
</twig:form>
14+
<twig:form-theme>FooBundle:Form:bar.html.twig</twig:form-theme>
15+
</twig:config>
16+
</container>

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
twig:
22
form_themes:
33
- MyBundle::form.html.twig
4-
form:
5-
resources:
6-
- MyBundle::formDeprecated.html.twig
74
globals:
85
foo: "@bar"
96
baz: "@@qux"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
twig:
2+
form:
3+
resources:
4+
- "form_table_layout.html.twig"
5+
- "MyBundle:Form:my_theme.html.twig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
twig:
2+
form_themes:
3+
- "FooBundle:Form:bar.html.twig"
4+
form:
5+
resources:
6+
- "form_table_layout.html.twig"
7+
- "MyBundle:Form:my_theme.html.twig"

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@
2323

2424
class TwigExtensionTest extends TestCase
2525
{
26+
/**
27+
* @dataProvider getFormats
28+
*/
29+
public function testLegacyFormResourcesConfigurationKey($format)
30+
{
31+
$container = $this->createContainer();
32+
$container->registerExtension(new TwigExtension());
33+
$this->loadFromFile($container, 'legacy-form-resources-only', $format);
34+
$this->compileContainer($container);
35+
36+
// Form resources
37+
$this->assertCount(3, $container->getParameter('twig.form.resources'));
38+
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
39+
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
40+
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
41+
}
42+
43+
/**
44+
* @dataProvider getFormats
45+
*/
46+
public function testLegacyMergeFormResourcesConfigurationKeyWithFormThemesConfigurationKey($format)
47+
{
48+
$container = $this->createContainer();
49+
$container->registerExtension(new TwigExtension());
50+
$this->loadFromFile($container, 'legacy-merge-form-resources-with-form-themes', $format);
51+
$this->compileContainer($container);
52+
53+
$this->assertCount(4, $container->getParameter('twig.form.resources'));
54+
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'));
55+
$this->assertContains('form_table_layout.html.twig', $container->getParameter('twig.form.resources'));
56+
$this->assertContains('MyBundle:Form:my_theme.html.twig', $container->getParameter('twig.form.resources'));
57+
$this->assertContains('FooBundle:Form:bar.html.twig', $container->getParameter('twig.form.resources'));
58+
}
59+
2660
public function testLoadEmptyConfiguration()
2761
{
2862
$container = $this->createContainer();
@@ -57,8 +91,6 @@ public function testLoadFullConfiguration($format)
5791
$resources = $container->getParameter('twig.form.resources');
5892
$this->assertContains('form_div_layout.html.twig', $resources, '->load() includes default template for form resources');
5993
$this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources');
60-
// @deprecated since version 2.6, to be removed in 3.0
61-
$this->assertContains('MyBundle::formDeprecated.html.twig', $resources, '->load() merges new templates into form resources');
6294

6395
// Globals
6496
$calls = $container->getDefinition('twig')->getMethodCalls();

0 commit comments

Comments
 (0)