ChainLoaderTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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__.'/../../../../../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. class ChainLoaderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. static protected $loader1, $loader2;
  18. static public function setUpBeforeClass()
  19. {
  20. $fixturesPath = realpath(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/');
  21. self::$loader1 = new FilesystemLoader($fixturesPath.'/null/%name%');
  22. self::$loader2 = new FilesystemLoader($fixturesPath.'/templates/%name%.%renderer%');
  23. }
  24. public function testConstructor()
  25. {
  26. $loader = new ProjectTemplateLoader1(array(self::$loader1, self::$loader2));
  27. $this->assertEquals(array(self::$loader1, self::$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(self::$loader1));
  32. $loader->addLoader(self::$loader2);
  33. $this->assertEquals(array(self::$loader1, self::$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(self::$loader1, self::$loader2));
  38. $this->assertFalse($loader->load('bar'), '->load() returns false if the template is not found');
  39. $this->assertFalse($loader->load('foo', array('renderer' => 'xml')), '->load() returns false if the template does not exists for the given renderer');
  40. $this->assertInstanceOf('Symfony\Components\Templating\Storage\FileStorage', $loader->load('foo'), '->load() returns a FileStorage if the template exists');
  41. }
  42. }
  43. class ProjectTemplateLoader1 extends ChainLoader
  44. {
  45. public function getLoaders()
  46. {
  47. return $this->loaders;
  48. }
  49. }