Skip to content

Commit 53566ba

Browse files
committed
bug #15272 [FrameworkBundle] Fix template location for PHP templates (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- [FrameworkBundle] Fix template location for PHP templates | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14804 | License | MIT | Doc PR | - - [x] improve the test to cover logical path & filesystem path - [x] Add a new test case and fix the path to the template As the first commit only enchanced the test, and the second commit fixed the bug, it's best to review them seperately. Commits ------- 132a4e4 [FrameworkBundle] Fix template location for PHP templates cd42e2d [FrameworkBundle] Add path verification to the template parsing test cases
2 parents c9c279b + a571ea7 commit 53566ba

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Templating/TemplateNameParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function parse($name)
5656
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
5757
}
5858

59-
if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
59+
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
6060
return parent::parse($name);
6161
}
6262

Tests/Templating/TemplateNameParserTest.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,33 @@ protected function tearDown()
4343
}
4444

4545
/**
46-
* @dataProvider getLogicalNameToTemplateProvider
46+
* @dataProvider parseProvider
4747
*/
48-
public function testParse($name, $ref)
48+
public function testParse($name, $logicalName, $path, $ref)
4949
{
5050
$template = $this->parser->parse($name);
5151

52-
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
53-
$this->assertEquals($template->getLogicalName(), $name);
52+
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
53+
$this->assertSame($logicalName, $template->getLogicalName());
54+
$this->assertSame($path, $template->getPath());
5455
}
5556

56-
public function getLogicalNameToTemplateProvider()
57+
public function parseProvider()
5758
{
5859
return array(
59-
array('FooBundle:Post:index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')),
60-
array('FooBundle:Post:index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')),
61-
array('FooBundle:Post:index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
62-
array('SensioFooBundle:Post:index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
63-
array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
64-
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
65-
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
66-
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
67-
array('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
68-
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
69-
array('name', new BaseTemplateReference('name')),
60+
array('FooBundle:Post:index.html.php', 'FooBundle:Post:index.html.php', '@FooBundle/Resources/views/Post/index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')),
61+
array('FooBundle:Post:index.html.twig', 'FooBundle:Post:index.html.twig', '@FooBundle/Resources/views/Post/index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')),
62+
array('FooBundle:Post:index.xml.php', 'FooBundle:Post:index.xml.php', '@FooBundle/Resources/views/Post/index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
63+
array('SensioFooBundle:Post:index.html.php', 'SensioFooBundle:Post:index.html.php', '@SensioFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
64+
array('SensioCmsFooBundle:Post:index.html.php', 'SensioCmsFooBundle:Post:index.html.php', '@SensioCmsFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
65+
array(':Post:index.html.php', ':Post:index.html.php', 'views/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
66+
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
67+
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
68+
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
69+
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
70+
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
71+
array('name', 'name', 'name', new BaseTemplateReference('name')),
72+
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
7073
);
7174
}
7275

0 commit comments

Comments
 (0)