2013-07-23 13:30:22 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bridge\Twig\Tests;
|
|
|
|
|
|
|
|
use Symfony\Bridge\Twig\TwigEngine;
|
2013-09-04 13:01:22 +01:00
|
|
|
use Symfony\Component\Templating\TemplateReference;
|
2013-07-23 13:30:22 +01:00
|
|
|
|
2013-09-17 15:25:42 +01:00
|
|
|
class TwigEngineTest extends \PHPUnit_Framework_TestCase
|
2013-07-23 13:30:22 +01:00
|
|
|
{
|
|
|
|
public function testExistsWithTemplateInstances()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$this->assertTrue($engine->exists($this->getMockForAbstractClass('Twig_Template', array(), '', false)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExistsWithNonExistentTemplates()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$this->assertFalse($engine->exists('foobar'));
|
2013-09-04 13:01:22 +01:00
|
|
|
$this->assertFalse($engine->exists(new TemplateReference('foorbar')));
|
2013-07-23 13:30:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExistsWithTemplateWithSyntaxErrors()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$this->assertTrue($engine->exists('error'));
|
2013-09-04 13:01:22 +01:00
|
|
|
$this->assertTrue($engine->exists(new TemplateReference('error')));
|
2013-07-23 13:30:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExists()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$this->assertTrue($engine->exists('index'));
|
2013-09-04 13:01:22 +01:00
|
|
|
$this->assertTrue($engine->exists(new TemplateReference('index')));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRender()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$this->assertSame('foo', $engine->render('index'));
|
|
|
|
$this->assertSame('foo', $engine->render(new TemplateReference('index')));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Twig_Error_Syntax
|
|
|
|
*/
|
|
|
|
public function testRenderWithError()
|
|
|
|
{
|
|
|
|
$engine = $this->getTwig();
|
|
|
|
|
|
|
|
$engine->render(new TemplateReference('error'));
|
2013-07-23 13:30:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTwig()
|
|
|
|
{
|
|
|
|
$twig = new \Twig_Environment(new \Twig_Loader_Array(array(
|
|
|
|
'index' => 'foo',
|
|
|
|
'error' => '{{ foo }',
|
|
|
|
)));
|
|
|
|
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
|
|
|
|
|
|
|
|
return new TwigEngine($twig, $parser);
|
|
|
|
}
|
|
|
|
}
|