Skip to content

Commit

Permalink
bug #15272 [FrameworkBundle] Fix template location for PHP templates …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
fabpot committed Jan 25, 2016
2 parents a0a97d7 + 132a4e4 commit 4003532
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Expand Up @@ -56,7 +56,7 @@ public function parse($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);
}

Expand Down
Expand Up @@ -43,30 +43,33 @@ protected function tearDown()
}

/**
* @dataProvider getLogicalNameToTemplateProvider
* @dataProvider parseProvider
*/
public function testParse($name, $ref)
public function testParse($name, $logicalName, $path, $ref)
{
$template = $this->parser->parse($name);

$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
$this->assertEquals($template->getLogicalName(), $name);
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
$this->assertSame($logicalName, $template->getLogicalName());
$this->assertSame($path, $template->getPath());
}

public function getLogicalNameToTemplateProvider()
public function parseProvider()
{
return array(
array('FooBundle: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.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
array('SensioFooBundle: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(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::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('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', new BaseTemplateReference('name')),
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', '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', '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', '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', 'SensioCmsFooBundle:Post:index.html.php', '@SensioCmsFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioCmsFooBundle', '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', '::index.html.php', 'views/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', '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('/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.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')),
);
}

Expand Down

0 comments on commit 4003532

Please sign in to comment.