ChainLoaderTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Component\Templating\Tests\Loader;
  11. use Symfony\Component\Templating\Loader\ChainLoader;
  12. use Symfony\Component\Templating\Loader\FilesystemLoader;
  13. use Symfony\Component\Templating\TemplateReference;
  14. class ChainLoaderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected $loader1;
  17. protected $loader2;
  18. protected function setUp()
  19. {
  20. $fixturesPath = realpath(__DIR__.'/../Fixtures/');
  21. $this->loader1 = new FilesystemLoader($fixturesPath.'/null/%name%');
  22. $this->loader2 = new FilesystemLoader($fixturesPath.'/templates/%name%');
  23. }
  24. public function testConstructor()
  25. {
  26. $loader = new ProjectTemplateLoader1(array($this->loader1, $this->loader2));
  27. $this->assertEquals(array($this->loader1, $this->loader2), $loader->getLoaders(), '__construct() takes an array of template loaders as its second argument');
  28. }
  29. public function testAddLoader()
  30. {
  31. $loader = new ProjectTemplateLoader1(array($this->loader1));
  32. $loader->addLoader($this->loader2);
  33. $this->assertEquals(array($this->loader1, $this->loader2), $loader->getLoaders(), '->addLoader() adds a template loader at the end of the loaders');
  34. }
  35. public function testLoad()
  36. {
  37. $loader = new ProjectTemplateLoader1(array($this->loader1, $this->loader2));
  38. $this->assertFalse($loader->load(new TemplateReference('bar', 'php')), '->load() returns false if the template is not found');
  39. $this->assertFalse($loader->load(new TemplateReference('foo', 'php')), '->load() returns false if the template does not exist for the given renderer');
  40. $this->assertInstanceOf(
  41. 'Symfony\Component\Templating\Storage\FileStorage',
  42. $loader->load(new TemplateReference('foo.php', 'php')),
  43. '->load() returns a FileStorage if the template exists'
  44. );
  45. }
  46. }
  47. class ProjectTemplateLoader1 extends ChainLoader
  48. {
  49. public function getLoaders()
  50. {
  51. return $this->loaders;
  52. }
  53. }