TemplateFilenameParserTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
  11. use Symfony\Bundle\FrameworkBundle\Templating\TemplateFilenameParser;
  12. use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
  13. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  14. class TemplateFilenameParserTest extends TestCase
  15. {
  16. protected $parser;
  17. protected function setUp()
  18. {
  19. $this->parser = new TemplateFilenameParser();
  20. }
  21. protected function tearDown()
  22. {
  23. $this->parser = null;
  24. }
  25. /**
  26. * @dataProvider getFilenameToTemplateProvider
  27. */
  28. public function testParseFromFilename($file, $ref)
  29. {
  30. $template = $this->parser->parse($file);
  31. if (false === $ref) {
  32. $this->assertFalse($template);
  33. } else {
  34. $this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
  35. }
  36. }
  37. public function getFilenameToTemplateProvider()
  38. {
  39. return array(
  40. array('/path/to/section/name.format.engine', new TemplateReference('', '/path/to/section', 'name', 'format', 'engine')),
  41. array('\\path\\to\\section\\name.format.engine', new TemplateReference('', '/path/to/section', 'name', 'format', 'engine')),
  42. array('name.format.engine', new TemplateReference('', '', 'name', 'format', 'engine')),
  43. array('name.format', false),
  44. array('name', false),
  45. );
  46. }
  47. }