TemplateFinderTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\CacheWarmer;
  11. use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder;
  12. use Symfony\Bundle\FrameworkBundle\Templating\TemplateFilenameParser;
  13. use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BaseBundle\BaseBundle;
  14. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  15. class TemplateFinderTest extends TestCase
  16. {
  17. public function testFindAllTemplates()
  18. {
  19. $kernel = $this
  20. ->getMockBuilder('Symfony\Component\HttpKernel\Kernel')
  21. ->disableOriginalConstructor()
  22. ->getMock()
  23. ;
  24. $kernel
  25. ->expects($this->any())
  26. ->method('getBundle')
  27. ;
  28. $kernel
  29. ->expects($this->once())
  30. ->method('getBundles')
  31. ->will($this->returnValue(array('BaseBundle' => new BaseBundle())))
  32. ;
  33. $parser = new TemplateFilenameParser();
  34. $finder = new TemplateFinder($kernel, $parser, __DIR__.'/../Fixtures/Resources');
  35. $templates = array_map(
  36. function ($template) { return $template->getLogicalName(); },
  37. $finder->findAllTemplates()
  38. );
  39. $this->assertCount(7, $templates, '->findAllTemplates() find all templates in the bundles and global folders');
  40. $this->assertContains('BaseBundle::base.format.engine', $templates);
  41. $this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates);
  42. $this->assertContains('BaseBundle:controller:base.format.engine', $templates);
  43. $this->assertContains('BaseBundle:controller:custom.format.engine', $templates);
  44. $this->assertContains('::this.is.a.template.format.engine', $templates);
  45. $this->assertContains('::resource.format.engine', $templates);
  46. }
  47. }