2010-03-18 14:26:21 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2010-03-18 14:26:21 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2010-04-07 02:07:59 +01:00
*
2010-03-18 14:26:21 +00:00
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Tests\Component\Templating\Loader ;
2010-03-18 14:26:21 +00:00
2010-06-28 08:31:54 +01:00
require_once __DIR__ . '/../Fixtures/ProjectTemplateDebugger.php' ;
2010-03-18 14:26:21 +00:00
2010-08-20 22:09:55 +01:00
use Symfony\Component\Templating\Loader\ChainLoader ;
use Symfony\Component\Templating\Loader\FilesystemLoader ;
use Symfony\Component\Templating\Storage\FileStorage ;
2011-02-10 17:20:44 +00:00
use Symfony\Component\Templating\TemplateReference ;
2010-03-18 14:26:21 +00:00
class ChainLoaderTest extends \PHPUnit_Framework_TestCase
{
2011-01-13 13:58:17 +00:00
protected $loader1 ;
protected $loader2 ;
2010-05-06 12:25:53 +01:00
2011-01-13 13:58:17 +00:00
public function setUp ()
2010-05-06 12:25:53 +01:00
{
2010-06-28 08:31:54 +01:00
$fixturesPath = realpath ( __DIR__ . '/../Fixtures/' );
2011-01-26 13:53:12 +00:00
$this -> loader1 = new FilesystemLoader ( $fixturesPath . '/null/%name%' );
$this -> loader2 = new FilesystemLoader ( $fixturesPath . '/templates/%name%' );
2010-05-06 12:25:53 +01:00
}
public function testConstructor ()
{
2011-01-13 13:58:17 +00:00
$loader = new ProjectTemplateLoader1 ( array ( $this -> loader1 , $this -> loader2 ));
$this -> assertEquals ( array ( $this -> loader1 , $this -> loader2 ), $loader -> getLoaders (), '__construct() takes an array of template loaders as its second argument' );
2010-05-06 12:25:53 +01:00
}
public function testAddLoader ()
{
2011-01-13 13:58:17 +00:00
$loader = new ProjectTemplateLoader1 ( array ( $this -> loader1 ));
$loader -> addLoader ( $this -> loader2 );
$this -> assertEquals ( array ( $this -> loader1 , $this -> loader2 ), $loader -> getLoaders (), '->addLoader() adds a template loader at the end of the loaders' );
2010-05-06 12:25:53 +01:00
}
public function testLoad ()
{
2011-01-13 13:58:17 +00:00
$loader = new ProjectTemplateLoader1 ( array ( $this -> loader1 , $this -> loader2 ));
2011-02-10 17:20:44 +00:00
$this -> assertFalse ( $loader -> load ( new TemplateReference ( 'bar' , 'php' )), '->load() returns false if the template is not found' );
$this -> assertFalse ( $loader -> load ( new TemplateReference ( 'foo' , 'php' )), '->load() returns false if the template does not exists for the given renderer' );
$this -> assertInstanceOf (
'Symfony\Component\Templating\Storage\FileStorage' ,
$loader -> load ( new TemplateReference ( 'foo.php' , 'php' )),
'->load() returns a FileStorage if the template exists'
);
2010-05-06 12:25:53 +01:00
}
2010-03-18 14:26:21 +00:00
}
class ProjectTemplateLoader1 extends ChainLoader
{
2010-05-06 12:25:53 +01:00
public function getLoaders ()
{
return $this -> loaders ;
}
2010-03-18 14:26:21 +00:00
}