PageRenderTime 23ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

https://gitlab.com/cuza/Clinic_Recods
PHP | 89 lines | 64 code | 11 blank | 14 comment | 1 complexity | dc4bf29a8954bbb1c50e052c5d6980d3 MD5 | raw file
  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\Tests\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
  13. use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
  14. use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
  15. class TemplateNameParserTest extends TestCase
  16. {
  17. protected $parser;
  18. protected function setUp()
  19. {
  20. $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
  21. $kernel
  22. ->expects($this->any())
  23. ->method('getBundle')
  24. ->will($this->returnCallback(function ($bundle) {
  25. if (in_array($bundle, array('SensioFooBundle', 'SensioCmsFooBundle', 'FooBundle'))) {
  26. return true;
  27. }
  28. throw new \InvalidArgumentException();
  29. }))
  30. ;
  31. $this->parser = new TemplateNameParser($kernel);
  32. }
  33. protected function tearDown()
  34. {
  35. $this->parser = null;
  36. }
  37. /**
  38. * @dataProvider parseProvider
  39. */
  40. public function testParse($name, $logicalName, $path, $ref)
  41. {
  42. $template = $this->parser->parse($name);
  43. $this->assertSame($ref->getLogicalName(), $template->getLogicalName());
  44. $this->assertSame($logicalName, $template->getLogicalName());
  45. $this->assertSame($path, $template->getPath());
  46. }
  47. public function parseProvider()
  48. {
  49. return array(
  50. 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')),
  51. 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')),
  52. 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')),
  53. 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')),
  54. 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')),
  55. array(':Post:index.html.php', ':Post:index.html.php', 'views/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
  56. array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
  57. array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
  58. 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')),
  59. array('@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', '@FooBundle/Resources/views/layout.html.twig', new BaseTemplateReference('@FooBundle/Resources/views/layout.html.twig', 'twig')),
  60. array('@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', '@FooBundle/Foo/layout.html.twig', new BaseTemplateReference('@FooBundle/Foo/layout.html.twig', 'twig')),
  61. array('/path/to/section/index.html.php', '/path/to/section/index.html.php', '/path/to/section/index.html.php', new BaseTemplateReference('/path/to/section/index.html.php', 'php')),
  62. array('C:\\path\\to\\section\\name.html.php', 'C:path/to/section/name.html.php', 'C:path/to/section/name.html.php', new BaseTemplateReference('C:path/to/section/name.html.php', 'php')),
  63. array('C:\\path\\to\\section\\name:foo.html.php', 'C:path/to/section/name:foo.html.php', 'C:path/to/section/name:foo.html.php', new BaseTemplateReference('C:path/to/section/name:foo.html.php', 'php')),
  64. array('\\path\\to\\section\\name.html.php', '/path/to/section/name.html.php', '/path/to/section/name.html.php', new BaseTemplateReference('/path/to/section/name.html.php', 'php')),
  65. array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
  66. array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
  67. array('name', 'name', 'name', new BaseTemplateReference('name')),
  68. array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
  69. );
  70. }
  71. /**
  72. * @expectedException \InvalidArgumentException
  73. */
  74. public function testParseValidNameWithNotFoundBundle()
  75. {
  76. $this->parser->parse('BarBundle:Post:index.html.php');
  77. }
  78. }