@@ -42,7 +42,7 @@ public function testLoadEmptyConfiguration()
42
42
$ container ->loadFromExtension ('twig ' );
43
43
$ this ->compileContainer ($ container );
44
44
45
- $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.xml file ' );
45
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
46
46
47
47
$ this ->assertContains ('form_div_layout.html.twig ' ,$ container ->getParameter ('twig.form.resources ' ),'->load() includes default template for form resources ' );
48
48
@@ -73,7 +73,7 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
73
73
$ this ->loadFromFile ($ container ,'full ' ,$ format );
74
74
$ this ->compileContainer ($ container );
75
75
76
- $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.xml file ' );
76
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
77
77
78
78
// Form resources
79
79
$ resources =$ container ->getParameter ('twig.form.resources ' );
@@ -90,12 +90,51 @@ public function testLoadFullConfiguration(string $format, ?string $buildDir)
90
90
$ this ->assertEquals ('@qux ' ,$ calls [3 ][1 ][1 ],'->load() allows escaping of service identifiers ' );
91
91
$ this ->assertEquals ('pi ' ,$ calls [4 ][1 ][0 ],'->load() registers variables as Twig globals ' );
92
92
$ this ->assertEquals (3.14 ,$ calls [4 ][1 ][1 ],'->load() registers variables as Twig globals ' );
93
+ $ this ->assertEquals ('bad ' ,$ calls [5 ][1 ][0 ],'->load() registers variables as Twig globals ' );
94
+ $ this ->assertEquals (['key ' =>'foo ' ],$ calls [5 ][1 ][1 ],'->load() registers variables as Twig globals ' );
93
95
94
- // Yaml and Php specific configs
95
- if (\in_array ($ format , ['yml ' ,'php ' ])) {
96
- $ this ->assertEquals ('bad ' ,$ calls [5 ][1 ][0 ],'->load() registers variables as Twig globals ' );
97
- $ this ->assertEquals (['key ' =>'foo ' ],$ calls [5 ][1 ][1 ],'->load() registers variables as Twig globals ' );
98
- }
96
+ // Twig options
97
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
98
+ $ this ->assertFalse ($ options ['auto_reload ' ],'->load() sets the auto_reload option ' );
99
+ $ this ->assertSame ('name ' ,$ options ['autoescape ' ],'->load() sets the autoescape option ' );
100
+ $ this ->assertArrayNotHasKey ('base_template_class ' ,$ options ,'->load() does not set the base_template_class if none is provided ' );
101
+ $ this ->assertEquals ('ISO-8859-1 ' ,$ options ['charset ' ],'->load() sets the charset option ' );
102
+ $ this ->assertTrue ($ options ['debug ' ],'->load() sets the debug option ' );
103
+ $ this ->assertTrue ($ options ['strict_variables ' ],'->load() sets the strict_variables option ' );
104
+ $ this ->assertEquals ($ buildDir !==null ?new Reference ('twig.template_cache.chain ' ) :'%kernel.cache_dir%/twig ' ,$ options ['cache ' ],'->load() sets the cache option ' );
105
+ }
106
+
107
+ /**
108
+ * @group legacy
109
+ *
110
+ * @dataProvider getXmlBuildDir
111
+ */
112
+ public function testLoadFullXmlConfiguration (?string $ buildDir )
113
+ {
114
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
115
+
116
+ $ container =$ this ->createContainer ($ buildDir );
117
+ $ container ->registerExtension (new TwigExtension ());
118
+ $ this ->loadFromFile ($ container ,'full ' ,'xml ' );
119
+ $ this ->compileContainer ($ container );
120
+
121
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
122
+
123
+ // Form resources
124
+ $ resources =$ container ->getParameter ('twig.form.resources ' );
125
+ $ this ->assertContains ('form_div_layout.html.twig ' ,$ resources ,'->load() includes default template for form resources ' );
126
+ $ this ->assertContains ('MyBundle::form.html.twig ' ,$ resources ,'->load() merges new templates into form resources ' );
127
+
128
+ // Globals
129
+ $ calls =$ container ->getDefinition ('twig ' )->getMethodCalls ();
130
+ $ this ->assertEquals ('app ' ,$ calls [0 ][1 ][0 ],'->load() registers services as Twig globals ' );
131
+ $ this ->assertEquals (new Reference ('twig.app_variable ' ),$ calls [0 ][1 ][1 ]);
132
+ $ this ->assertEquals ('foo ' ,$ calls [2 ][1 ][0 ],'->load() registers services as Twig globals ' );
133
+ $ this ->assertEquals (new Reference ('bar ' ),$ calls [2 ][1 ][1 ],'->load() registers services as Twig globals ' );
134
+ $ this ->assertEquals ('baz ' ,$ calls [3 ][1 ][0 ],'->load() registers variables as Twig globals ' );
135
+ $ this ->assertEquals ('@qux ' ,$ calls [3 ][1 ][1 ],'->load() allows escaping of service identifiers ' );
136
+ $ this ->assertEquals ('pi ' ,$ calls [4 ][1 ][0 ],'->load() registers variables as Twig globals ' );
137
+ $ this ->assertEquals (3.14 ,$ calls [4 ][1 ][1 ],'->load() registers variables as Twig globals ' );
99
138
100
139
// Twig options
101
140
$ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -118,7 +157,28 @@ public function testLoadNoCacheConfiguration(string $format, ?string $buildDir)
118
157
$ this ->loadFromFile ($ container ,'no-cache ' ,$ format );
119
158
$ this ->compileContainer ($ container );
120
159
121
- $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.xml file ' );
160
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
161
+
162
+ // Twig options
163
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
164
+ $ this ->assertFalse ($ options ['cache ' ],'->load() sets cache option to false ' );
165
+ }
166
+
167
+ /**
168
+ * @group legacy
169
+ *
170
+ * @dataProvider getXmlBuildDir
171
+ */
172
+ public function testLoadNoCacheXmlConfiguration (?string $ buildDir )
173
+ {
174
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
175
+
176
+ $ container =$ this ->createContainer ($ buildDir );
177
+ $ container ->registerExtension (new TwigExtension ());
178
+ $ this ->loadFromFile ($ container ,'no-cache ' ,'xml ' );
179
+ $ this ->compileContainer ($ container );
180
+
181
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
122
182
123
183
// Twig options
124
184
$ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -135,7 +195,28 @@ public function testLoadPathCacheConfiguration(string $format, ?string $buildDir
135
195
$ this ->loadFromFile ($ container ,'path-cache ' ,$ format );
136
196
$ this ->compileContainer ($ container );
137
197
138
- $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.xml file ' );
198
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
199
+
200
+ // Twig options
201
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
202
+ $ this ->assertSame ('random-path ' ,$ options ['cache ' ],'->load() sets cache option to string path ' );
203
+ }
204
+
205
+ /**
206
+ * @group legacy
207
+ *
208
+ * @dataProvider getXmlBuildDir
209
+ */
210
+ public function testLoadPathCacheXmlConfiguration (?string $ buildDir )
211
+ {
212
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
213
+
214
+ $ container =$ this ->createContainer ($ buildDir );
215
+ $ container ->registerExtension (new TwigExtension ());
216
+ $ this ->loadFromFile ($ container ,'path-cache ' ,'xml ' );
217
+ $ this ->compileContainer ($ container );
218
+
219
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
139
220
140
221
// Twig options
141
222
$ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -152,7 +233,28 @@ public function testLoadProdCacheConfiguration(string $format, ?string $buildDir
152
233
$ this ->loadFromFile ($ container ,'prod-cache ' ,$ format );
153
234
$ this ->compileContainer ($ container );
154
235
155
- $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.xml file ' );
236
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
237
+
238
+ // Twig options
239
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
240
+ $ this ->assertEquals ($ buildDir !==null ?new Reference ('twig.template_cache.chain ' ) :'%kernel.cache_dir%/twig ' ,$ options ['cache ' ],'->load() sets cache option to CacheChain reference ' );
241
+ }
242
+
243
+ /**
244
+ * @group legacy
245
+ *
246
+ * @dataProvider getXmlBuildDir
247
+ */
248
+ public function testLoadProdCacheXmlConfiguration (?string $ buildDir )
249
+ {
250
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
251
+
252
+ $ container =$ this ->createContainer ($ buildDir );
253
+ $ container ->registerExtension (new TwigExtension ());
254
+ $ this ->loadFromFile ($ container ,'prod-cache ' ,'xml ' );
255
+ $ this ->compileContainer ($ container );
256
+
257
+ $ this ->assertEquals (Environment::class,$ container ->getDefinition ('twig ' )->getClass (),'->load() loads the twig.php file ' );
156
258
157
259
// Twig options
158
260
$ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
@@ -192,6 +294,22 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration(string $forma
192
294
$ this ->assertEquals ([new Reference ('my_project.some_bundle.template_escaping_guesser ' ),'guess ' ],$ options ['autoescape ' ]);
193
295
}
194
296
297
+ /**
298
+ * @group legacy
299
+ */
300
+ public function testLoadCustomTemplateEscapingGuesserXmlConfiguration ()
301
+ {
302
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
303
+
304
+ $ container =$ this ->createContainer ();
305
+ $ container ->registerExtension (new TwigExtension ());
306
+ $ this ->loadFromFile ($ container ,'customTemplateEscapingGuesser ' ,'xml ' );
307
+ $ this ->compileContainer ($ container );
308
+
309
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
310
+ $ this ->assertEquals ([new Reference ('my_project.some_bundle.template_escaping_guesser ' ),'guess ' ],$ options ['autoescape ' ]);
311
+ }
312
+
195
313
/**
196
314
* @dataProvider getFormats
197
315
*/
@@ -206,6 +324,22 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration(string $form
206
324
$ this ->assertEquals ('name ' ,$ options ['autoescape ' ]);
207
325
}
208
326
327
+ /**
328
+ * @group legacy
329
+ */
330
+ public function testLoadDefaultTemplateEscapingGuesserXmlConfiguration ()
331
+ {
332
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
333
+
334
+ $ container =$ this ->createContainer ();
335
+ $ container ->registerExtension (new TwigExtension ());
336
+ $ this ->loadFromFile ($ container ,'empty ' ,'xml ' );
337
+ $ this ->compileContainer ($ container );
338
+
339
+ $ options =$ container ->getDefinition ('twig ' )->getArgument (1 );
340
+ $ this ->assertEquals ('name ' ,$ options ['autoescape ' ]);
341
+ }
342
+
209
343
/**
210
344
* @dataProvider getFormats
211
345
*/
@@ -226,6 +360,28 @@ public function testLoadCustomDateFormats(string $fileFormat)
226
360
$ this ->assertSame ('. ' ,$ environmentConfigurator ->getArgument (5 ));
227
361
}
228
362
363
+ /**
364
+ * @group legacy
365
+ */
366
+ public function testLoadXmlCustomDateFormats ()
367
+ {
368
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
369
+
370
+ $ container =$ this ->createContainer ();
371
+ $ container ->registerExtension (new TwigExtension ());
372
+ $ this ->loadFromFile ($ container ,'formats ' ,'xml ' );
373
+ $ this ->compileContainer ($ container );
374
+
375
+ $ environmentConfigurator =$ container ->getDefinition ('twig.configurator.environment ' );
376
+
377
+ $ this ->assertSame ('Y-m-d ' ,$ environmentConfigurator ->getArgument (0 ));
378
+ $ this ->assertSame ('%d ' ,$ environmentConfigurator ->getArgument (1 ));
379
+ $ this ->assertSame ('Europe/Berlin ' ,$ environmentConfigurator ->getArgument (2 ));
380
+ $ this ->assertSame (2 ,$ environmentConfigurator ->getArgument (3 ));
381
+ $ this ->assertSame (', ' ,$ environmentConfigurator ->getArgument (4 ));
382
+ $ this ->assertSame ('. ' ,$ environmentConfigurator ->getArgument (5 ));
383
+ }
384
+
229
385
public function testGlobalsWithDifferentTypesAndValues ()
230
386
{
231
387
$ globals = [
@@ -287,12 +443,45 @@ public function testTwigLoaderPaths(string $format)
287
443
],$ paths );
288
444
}
289
445
446
+ /**
447
+ * @group legacy
448
+ */
449
+ public function testTwigXmlLoaderPaths ()
450
+ {
451
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
452
+
453
+ $ container =$ this ->createContainer ();
454
+ $ container ->registerExtension (new TwigExtension ());
455
+ $ this ->loadFromFile ($ container ,'full ' ,'xml ' );
456
+ $ this ->loadFromFile ($ container ,'extra ' ,'xml ' );
457
+ $ this ->compileContainer ($ container );
458
+
459
+ $ def =$ container ->getDefinition ('twig.loader.native_filesystem ' );
460
+ $ paths = [];
461
+ foreach ($ def ->getMethodCalls ()as $ call ) {
462
+ if ('addPath ' ===$ call [0 ] && !str_contains ($ call [1 ][0 ],'Form ' )) {
463
+ $ paths [] =$ call [1 ];
464
+ }
465
+ }
466
+
467
+ $ this ->assertEquals ([
468
+ ['path1 ' ],
469
+ ['path2 ' ],
470
+ ['namespaced_path1 ' ,'namespace1 ' ],
471
+ ['namespaced_path2 ' ,'namespace2 ' ],
472
+ ['namespaced_path3 ' ,'namespace3 ' ],
473
+ [__DIR__ .'/Fixtures/templates/bundles/AcmeBundle ' ,'Acme ' ],
474
+ [__DIR__ .'/AcmeBundle/Resources/views ' ,'Acme ' ],
475
+ [__DIR__ .'/AcmeBundle/Resources/views ' ,'!Acme ' ],
476
+ [__DIR__ .'/Fixtures/templates ' ],
477
+ ],$ paths );
478
+ }
479
+
290
480
public static function getFormats ():array
291
481
{
292
482
return [
293
483
['php ' ],
294
484
['yml ' ],
295
- ['xml ' ],
296
485
];
297
486
}
298
487
@@ -303,8 +492,14 @@ public static function getFormatsAndBuildDir(): array
303
492
['php ' ,__DIR__ .'/build ' ],
304
493
['yml ' ,null ],
305
494
['yml ' ,__DIR__ .'/build ' ],
306
- ['xml ' ,null ],
307
- ['xml ' ,__DIR__ .'/build ' ],
495
+ ];
496
+ }
497
+
498
+ public static function getXmlBuildDir ():array
499
+ {
500
+ return [
501
+ [null ],
502
+ [__DIR__ .'/build ' ],
308
503
];
309
504
}
310
505
@@ -383,6 +578,27 @@ public function testCustomHtmlToTextConverterService(string $format)
383
578
$ this ->assertEquals (new Reference ('my_converter ' ),$ bodyRenderer ->getArgument ('$converter ' ));
384
579
}
385
580
581
+ /**
582
+ * @group legacy
583
+ */
584
+ public function testXmlCustomHtmlToTextConverterService ()
585
+ {
586
+ if (!class_exists (Mailer::class)) {
587
+ $ this ->markTestSkipped ('The "twig.mime_body_renderer" service requires the Mailer component ' );
588
+ }
589
+
590
+ $ this ->expectUserDeprecationMessage ('Since symfony/dependency-injection 7.4: XML configuration format is deprecated, use YAML or PHP instead. ' );
591
+
592
+ $ container =$ this ->createContainer ();
593
+ $ container ->registerExtension (new TwigExtension ());
594
+ $ this ->loadFromFile ($ container ,'mailer ' ,'xml ' );
595
+ $ this ->compileContainer ($ container );
596
+
597
+ $ bodyRenderer =$ container ->getDefinition ('twig.mime_body_renderer ' );
598
+ $ this ->assertCount (3 ,$ bodyRenderer ->getArguments ());
599
+ $ this ->assertEquals (new Reference ('my_converter ' ),$ bodyRenderer ->getArgument ('$converter ' ));
600
+ }
601
+
386
602
private function createContainer (?string $ buildDir =null ):ContainerBuilder
387
603
{
388
604
$ container =new ContainerBuilder (new ParameterBag ([