2011-01-13 13:58:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* 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-01-15 14:11:02 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\Kernel;
|
2011-02-10 17:20:44 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
2011-01-13 13:58:17 +00:00
|
|
|
|
|
|
|
class TemplateNameParserTest extends TestCase
|
|
|
|
{
|
2011-02-10 17:20:44 +00:00
|
|
|
protected $parser;
|
|
|
|
|
|
|
|
protected function setUp()
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
2011-01-15 14:11:02 +00:00
|
|
|
$kernel = new Kernel();
|
|
|
|
$kernel->boot();
|
2011-01-13 13:58:17 +00:00
|
|
|
|
2011-02-10 17:20:44 +00:00
|
|
|
$this->parser = new TemplateNameParser($kernel);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
unset($this->parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getLogicalNameToTemplateProvider
|
|
|
|
*/
|
|
|
|
public function testParse($name, $ref)
|
|
|
|
{
|
|
|
|
$template = $this->parser->parse($name);
|
|
|
|
|
|
|
|
$this->assertEquals($template->getSignature(), $ref->getSignature());
|
|
|
|
|
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-02-10 17:20:44 +00: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')),
|
|
|
|
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
|
|
|
|
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
|
2011-01-13 13:58:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-10 17:20:44 +00:00
|
|
|
* @dataProvider getInvalidLogicalNameProvider
|
2011-01-13 13:58:17 +00:00
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
2011-02-10 17:20:44 +00:00
|
|
|
public function testParseInvalidName($name)
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
2011-02-10 17:20:44 +00:00
|
|
|
$this->parser->parse($name);
|
2011-01-13 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 17:20:44 +00:00
|
|
|
public function getInvalidLogicalNameProvider()
|
2011-01-13 13:58:17 +00:00
|
|
|
{
|
|
|
|
return array(
|
2011-01-21 12:23:20 +00:00
|
|
|
array('BarBundle:Post:index.html.php'),
|
2011-01-15 14:11:02 +00:00
|
|
|
array('FooBundle:Post:index'),
|
|
|
|
array('FooBundle:Post'),
|
|
|
|
array('FooBundle:Post:foo:bar'),
|
|
|
|
array('FooBundle:Post:index.foo.bar.foobar'),
|
2011-01-13 13:58:17 +00:00
|
|
|
);
|
|
|
|
}
|
2011-02-10 17:20:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getFilenameToTemplateProvider
|
|
|
|
*/
|
|
|
|
public function testParseFromFilename($file, $ref)
|
|
|
|
{
|
|
|
|
$template = $this->parser->parseFromFilename($file);
|
|
|
|
|
|
|
|
if ($ref === false) {
|
|
|
|
$this->assertFalse($template);
|
|
|
|
} else {
|
|
|
|
$this->assertEquals($template->getSignature(), $ref->getSignature());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFilenameToTemplateProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('/path/to/section/name.format.engine', new TemplateReference('', '/path/to/section', 'name', 'format', 'engine')),
|
|
|
|
array('\\path\\to\\section\\name.format.engine', new TemplateReference('', '/path/to/section', 'name', 'format', 'engine')),
|
|
|
|
array('name.format.engine', new TemplateReference('', '', 'name', 'format', 'engine')),
|
|
|
|
array('name.format', false),
|
|
|
|
array('name', false),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-01-13 13:58:17 +00:00
|
|
|
}
|