ChainLoaderTest.php 2.2 KB

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