2011-01-13 13:58:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-13 13:58:17 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-26 13:53:12 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
|
2011-01-13 13:58:17 +00:00
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
2011-02-10 17:20:44 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
2014-12-08 10:32:45 +00:00
|
|
|
use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
|
2011-01-13 13:58:17 +00:00
|
|
|
|
|
|
|
class TemplateNameParserTest extends TestCase
|
|
|
|
{
|
2011-02-10 17:20:44 +00:00
|
|
|
protected $parser;
|
|
|
|
|
2011-06-14 09:44:38 +01:00
|
|
|
protected function setUp()
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
2011-04-21 20:49:05 +01:00
|
|
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
|
|
|
$kernel
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getBundle')
|
|
|
|
->will($this->returnCallback(function ($bundle) {
|
|
|
|
if (in_array($bundle, array('SensioFooBundle', 'SensioCmsFooBundle', 'FooBundle'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}))
|
|
|
|
;
|
2011-02-10 17:20:44 +00:00
|
|
|
$this->parser = new TemplateNameParser($kernel);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
2011-06-14 09:44:38 +01:00
|
|
|
$this->parser = null;
|
2011-02-10 17:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getLogicalNameToTemplateProvider
|
|
|
|
*/
|
|
|
|
public function testParse($name, $ref)
|
|
|
|
{
|
|
|
|
$template = $this->parser->parse($name);
|
|
|
|
|
2011-03-31 13:54:25 +01:00
|
|
|
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
|
|
|
|
$this->assertEquals($template->getLogicalName(), $name);
|
2011-01-13 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 17:20:44 +00:00
|
|
|
public function getLogicalNameToTemplateProvider()
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
|
|
|
return array(
|
2011-04-04 10:10:56 +01:00
|
|
|
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')),
|
2011-02-10 17:20:44 +00:00
|
|
|
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
|
|
|
|
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
2011-07-04 21:38:34 +01:00
|
|
|
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
|
2014-12-08 10:32:45 +00:00
|
|
|
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')),
|
2011-01-13 13:58:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
2014-12-08 10:32:45 +00:00
|
|
|
public function testParseValidNameWithNotFoundBundle()
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
2014-12-08 10:32:45 +00:00
|
|
|
$this->parser->parse('BarBundle:Post:index.html.php');
|
2011-01-13 13:58:17 +00:00
|
|
|
}
|
|
|
|
}
|