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 templatescd42e2d
[FrameworkBundle] Add path verification to the template parsing test cases
This commit is contained in:
commit
40035327b2
@ -56,7 +56,7 @@ class TemplateNameParser extends BaseTemplateNameParser
|
|||||||
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
|
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
|
||||||
return parent::parse($name);
|
return parent::parse($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,30 +43,33 @@ class TemplateNameParserTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getLogicalNameToTemplateProvider
|
* @dataProvider parseProvider
|
||||||
*/
|
*/
|
||||||
public function testParse($name, $ref)
|
public function testParse($name, $logicalName, $path, $ref)
|
||||||
{
|
{
|
||||||
$template = $this->parser->parse($name);
|
$template = $this->parser->parse($name);
|
||||||
|
|
||||||
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
|
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
|
||||||
$this->assertEquals($template->getLogicalName(), $name);
|
$this->assertSame($logicalName, $template->getLogicalName());
|
||||||
|
$this->assertSame($path, $template->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogicalNameToTemplateProvider()
|
public function parseProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('FooBundle:Post:index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')),
|
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')),
|
||||||
array('FooBundle:Post:index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')),
|
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')),
|
||||||
array('FooBundle:Post:index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
|
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')),
|
||||||
array('SensioFooBundle:Post:index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
|
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')),
|
||||||
array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
|
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')),
|
||||||
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
|
array(':Post:index.html.php', ':Post:index.html.php', 'views/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
|
||||||
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
||||||
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
|
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
||||||
array('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
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')),
|
||||||
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
|
||||||
array('name', new BaseTemplateReference('name')),
|
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
|
||||||
|
array('name', 'name', 'name', new BaseTemplateReference('name')),
|
||||||
|
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user