ChainLoaderTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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. require_once __DIR__.'/../../../../bootstrap.php';
  11. require_once __DIR__.'/../../../../../lib/SymfonyTests/Components/Templating/ProjectTemplateDebugger.php';
  12. use Symfony\Components\Templating\Loader\ChainLoader;
  13. use Symfony\Components\Templating\Loader\FilesystemLoader;
  14. use Symfony\Components\Templating\Storage\FileStorage;
  15. $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/');
  16. $t = new LimeTest(5);
  17. class ProjectTemplateLoader extends ChainLoader
  18. {
  19. public function getLoaders()
  20. {
  21. return $this->loaders;
  22. }
  23. }
  24. $loader1 = new FilesystemLoader($fixturesPath.'/null/%name%');
  25. $loader2 = new FilesystemLoader($fixturesPath.'/templates/%name%.%renderer%');
  26. // __construct()
  27. $t->diag('__construct()');
  28. $loader = new ProjectTemplateLoader(array($loader1, $loader2));
  29. $t->is($loader->getLoaders(), array($loader1, $loader2), '__construct() takes an array of template loaders as its second argument');
  30. // ->addLoader()
  31. $t->diag('->addLoader()');
  32. $loader = new ProjectTemplateLoader(array($loader1));
  33. $loader->addLoader($loader2);
  34. $t->is($loader->getLoaders(), array($loader1, $loader2), '->addLoader() adds a template loader at the end of the loaders');
  35. // ->load()
  36. $t->diag('->load()');
  37. $loader = new ProjectTemplateLoader(array($loader1, $loader2));
  38. $t->ok($loader->load('bar') === false, '->load() returns false if the template is not found');
  39. $t->ok($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer');
  40. $t->ok($loader->load('foo') instanceof FileStorage, '->load() returns a FileStorage if the template exists');