ChainLoaderTest.php 2.3 KB

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