forked from wallabag/wallabag
twig implementation
This commit is contained in:
69
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php
vendored
Normal file
69
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\CodeExtension;
|
||||
|
||||
class CodeExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $helper;
|
||||
|
||||
public function testFormatFile()
|
||||
{
|
||||
$expected = sprintf('<a href="txmt://open?url=file://%s&line=25" title="Click to open this file" class="file_link">%s at line 25</a>', __FILE__, __FILE__);
|
||||
$this->assertEquals($expected, $this->getExtension()->formatFile(__FILE__, 25));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getClassNameProvider
|
||||
*/
|
||||
public function testGettingClassAbbreviation($class, $abbr)
|
||||
{
|
||||
$this->assertEquals($this->getExtension()->abbrClass($class), $abbr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getMethodNameProvider
|
||||
*/
|
||||
public function testGettingMethodAbbreviation($method, $abbr)
|
||||
{
|
||||
$this->assertEquals($this->getExtension()->abbrMethod($method), $abbr);
|
||||
}
|
||||
|
||||
public function getClassNameProvider()
|
||||
{
|
||||
return array(
|
||||
array('F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'),
|
||||
array('Bare', '<abbr title="Bare">Bare</abbr>'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getMethodNameProvider()
|
||||
{
|
||||
return array(
|
||||
array('F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'),
|
||||
array('Bare::Method', '<abbr title="Bare">Bare</abbr>::Method()'),
|
||||
array('Closure', '<abbr title="Closure">Closure</abbr>'),
|
||||
array('Method', '<abbr title="Method">Method</abbr>()')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$this->assertEquals('code', $this->getExtension()->getName());
|
||||
}
|
||||
|
||||
protected function getExtension()
|
||||
{
|
||||
return new CodeExtension('txmt://open?url=file://%f&line=%l', '/root', 'UTF-8');
|
||||
}
|
||||
}
|
||||
30
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
vendored
Normal file
30
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubFilesystemLoader.php
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?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\Extension\Fixtures;
|
||||
|
||||
// Preventing autoloader throwing E_FATAL when Twig is now available
|
||||
if (!class_exists('Twig_Environment')) {
|
||||
class StubFilesystemLoader
|
||||
{
|
||||
}
|
||||
} else {
|
||||
class StubFilesystemLoader extends \Twig_Loader_Filesystem
|
||||
{
|
||||
protected function findTemplate($name)
|
||||
{
|
||||
// strip away bundle name
|
||||
$parts = explode(':', $name);
|
||||
|
||||
return parent::findTemplate(end($parts));
|
||||
}
|
||||
}
|
||||
}
|
||||
35
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php
vendored
Normal file
35
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
<?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\Extension\Fixtures;
|
||||
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class StubTranslator implements TranslatorInterface
|
||||
{
|
||||
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
|
||||
{
|
||||
return '[trans]'.$id.'[/trans]';
|
||||
}
|
||||
|
||||
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
|
||||
{
|
||||
return '[trans]'.$id.'[/trans]';
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
}
|
||||
}
|
||||
209
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
vendored
Normal file
209
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\FormExtension;
|
||||
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
||||
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
|
||||
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
|
||||
|
||||
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
{
|
||||
/**
|
||||
* @var FormExtension
|
||||
*/
|
||||
protected $extension;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Locale\Locale')) {
|
||||
$this->markTestSkipped('The "Locale" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
|
||||
$this->markTestSkipped('The "EventDispatcher" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Form\Form')) {
|
||||
$this->markTestSkipped('The "Form" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Twig_Environment')) {
|
||||
$this->markTestSkipped('Twig is not available.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$rendererEngine = new TwigRendererEngine(array(
|
||||
'form_div_layout.html.twig',
|
||||
'custom_widgets.html.twig',
|
||||
));
|
||||
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
|
||||
|
||||
$this->extension = new FormExtension($renderer);
|
||||
|
||||
$loader = new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../Resources/views/Form',
|
||||
__DIR__,
|
||||
));
|
||||
|
||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||
$environment->addGlobal('global', '');
|
||||
$environment->addExtension($this->extension);
|
||||
|
||||
$this->extension->initRuntime($environment);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->extension = null;
|
||||
}
|
||||
|
||||
public function testThemeBlockInheritanceUsingUse()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamed('name', 'email')
|
||||
->createView()
|
||||
;
|
||||
|
||||
$this->setTheme($view, array('theme_use.html.twig'));
|
||||
|
||||
$this->assertMatchesXpath(
|
||||
$this->renderWidget($view),
|
||||
'/input[@type="email"][@rel="theme"]'
|
||||
);
|
||||
}
|
||||
|
||||
public function testThemeBlockInheritanceUsingExtend()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamed('name', 'email')
|
||||
->createView()
|
||||
;
|
||||
|
||||
$this->setTheme($view, array('theme_extends.html.twig'));
|
||||
|
||||
$this->assertMatchesXpath(
|
||||
$this->renderWidget($view),
|
||||
'/input[@type="email"][@rel="theme"]'
|
||||
);
|
||||
}
|
||||
|
||||
public function isSelectedChoiceProvider()
|
||||
{
|
||||
// The commented cases should not be necessary anymore, because the
|
||||
// choice lists should assure that both values passed here are always
|
||||
// strings
|
||||
return array(
|
||||
// array(true, 0, 0),
|
||||
array(true, '0', '0'),
|
||||
array(true, '1', '1'),
|
||||
// array(true, false, 0),
|
||||
// array(true, true, 1),
|
||||
array(true, '', ''),
|
||||
// array(true, null, ''),
|
||||
array(true, '1.23', '1.23'),
|
||||
array(true, 'foo', 'foo'),
|
||||
array(true, 'foo10', 'foo10'),
|
||||
array(true, 'foo', array(1, 'foo', 'foo10')),
|
||||
|
||||
array(false, 10, array(1, 'foo', 'foo10')),
|
||||
array(false, 0, array(1, 'foo', 'foo10')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider isSelectedChoiceProvider
|
||||
*/
|
||||
public function testIsChoiceSelected($expected, $choice, $value)
|
||||
{
|
||||
$choice = new ChoiceView($choice, $choice, $choice.' label');
|
||||
|
||||
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
|
||||
}
|
||||
|
||||
protected function renderForm(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
||||
}
|
||||
|
||||
protected function renderEnctype(FormView $view)
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
|
||||
}
|
||||
|
||||
protected function renderLabel(FormView $view, $label = null, array $vars = array())
|
||||
{
|
||||
if ($label !== null) {
|
||||
$vars += array('label' => $label);
|
||||
}
|
||||
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
|
||||
}
|
||||
|
||||
protected function renderErrors(FormView $view)
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
|
||||
}
|
||||
|
||||
protected function renderWidget(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
|
||||
}
|
||||
|
||||
protected function renderRow(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
|
||||
}
|
||||
|
||||
protected function renderRest(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
|
||||
}
|
||||
|
||||
protected function renderStart(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
|
||||
}
|
||||
|
||||
protected function renderEnd(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
|
||||
}
|
||||
|
||||
protected function setTheme(FormView $view, array $themes)
|
||||
{
|
||||
$this->extension->renderer->setTheme($view, $themes);
|
||||
}
|
||||
|
||||
public static function themeBlockInheritanceProvider()
|
||||
{
|
||||
return array(
|
||||
array(array('theme.html.twig'))
|
||||
);
|
||||
}
|
||||
|
||||
public static function themeInheritanceProvider()
|
||||
{
|
||||
return array(
|
||||
array(array('parent_label.html.twig'), array('child_label.html.twig'))
|
||||
);
|
||||
}
|
||||
}
|
||||
131
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
vendored
Normal file
131
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
||||
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
|
||||
use Symfony\Bridge\Twig\Extension\FormExtension;
|
||||
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||
use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||
|
||||
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
||||
{
|
||||
/**
|
||||
* @var FormExtension
|
||||
*/
|
||||
protected $extension;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Locale\Locale')) {
|
||||
$this->markTestSkipped('The "Locale" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
|
||||
$this->markTestSkipped('The "EventDispatcher" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Form\Form')) {
|
||||
$this->markTestSkipped('The "Form" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Twig_Environment')) {
|
||||
$this->markTestSkipped('Twig is not available.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$rendererEngine = new TwigRendererEngine(array(
|
||||
'form_table_layout.html.twig',
|
||||
'custom_widgets.html.twig',
|
||||
));
|
||||
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
|
||||
|
||||
$this->extension = new FormExtension($renderer);
|
||||
|
||||
$loader = new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../Resources/views/Form',
|
||||
__DIR__,
|
||||
));
|
||||
|
||||
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||
$environment->addGlobal('global', '');
|
||||
$environment->addExtension($this->extension);
|
||||
|
||||
$this->extension->initRuntime($environment);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->extension = null;
|
||||
}
|
||||
|
||||
protected function renderForm(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
||||
}
|
||||
|
||||
protected function renderEnctype(FormView $view)
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
|
||||
}
|
||||
|
||||
protected function renderLabel(FormView $view, $label = null, array $vars = array())
|
||||
{
|
||||
if ($label !== null) {
|
||||
$vars += array('label' => $label);
|
||||
}
|
||||
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
|
||||
}
|
||||
|
||||
protected function renderErrors(FormView $view)
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
|
||||
}
|
||||
|
||||
protected function renderWidget(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
|
||||
}
|
||||
|
||||
protected function renderRow(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
|
||||
}
|
||||
|
||||
protected function renderRest(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
|
||||
}
|
||||
|
||||
protected function renderStart(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
|
||||
}
|
||||
|
||||
protected function renderEnd(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
|
||||
}
|
||||
|
||||
protected function setTheme(FormView $view, array $themes)
|
||||
{
|
||||
$this->extension->renderer->setTheme($view, $themes);
|
||||
}
|
||||
}
|
||||
68
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
vendored
Normal file
68
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
|
||||
use Symfony\Bridge\Twig\Tests\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
|
||||
class HttpKernelExtensionTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
|
||||
$this->markTestSkipped('The "HttpKernel" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Twig_Environment')) {
|
||||
$this->markTestSkipped('Twig is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Twig_Error_Runtime
|
||||
*/
|
||||
public function testFragmentWithError()
|
||||
{
|
||||
$kernel = $this->getFragmentHandler($this->throwException(new \Exception('foo')));
|
||||
|
||||
$loader = new \Twig_Loader_Array(array('index' => '{{ fragment("foo") }}'));
|
||||
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
||||
$twig->addExtension(new HttpKernelExtension($kernel));
|
||||
|
||||
$this->renderTemplate($kernel);
|
||||
}
|
||||
|
||||
protected function getFragmentHandler($return)
|
||||
{
|
||||
$strategy = $this->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
|
||||
$strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
|
||||
$strategy->expects($this->once())->method('render')->will($return);
|
||||
|
||||
$renderer = new FragmentHandler(array($strategy));
|
||||
$renderer->setRequest(Request::create('/'));
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
|
||||
{
|
||||
$loader = new \Twig_Loader_Array(array('index' => $template));
|
||||
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
||||
$twig->addExtension(new HttpKernelExtension($renderer));
|
||||
|
||||
return $twig->render('index');
|
||||
}
|
||||
}
|
||||
60
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
vendored
Normal file
60
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
||||
use Symfony\Bridge\Twig\Tests\TestCase;
|
||||
|
||||
class RoutingExtensionTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!class_exists('Symfony\Component\Routing\Route')) {
|
||||
$this->markTestSkipped('The "Routing" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getEscapingTemplates
|
||||
*/
|
||||
public function testEscaping($template, $mustBeEscaped)
|
||||
{
|
||||
$twig = new \Twig_Environment(null, array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0));
|
||||
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
|
||||
|
||||
$nodes = $twig->parse($twig->tokenize($template));
|
||||
|
||||
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
|
||||
}
|
||||
|
||||
public function getEscapingTemplates()
|
||||
{
|
||||
return array(
|
||||
array('{{ path("foo") }}', false),
|
||||
array('{{ path("foo", {}) }}', false),
|
||||
array('{{ path("foo", { foo: "foo" }) }}', false),
|
||||
array('{{ path("foo", foo) }}', true),
|
||||
array('{{ path("foo", { foo: foo }) }}', true),
|
||||
array('{{ path("foo", { foo: ["foo", "bar"] }) }}', true),
|
||||
array('{{ path("foo", { foo: "foo", bar: "bar" }) }}', true),
|
||||
|
||||
array('{{ path(name = "foo", parameters = {}) }}', false),
|
||||
array('{{ path(name = "foo", parameters = { foo: "foo" }) }}', false),
|
||||
array('{{ path(name = "foo", parameters = foo) }}', true),
|
||||
array('{{ path(name = "foo", parameters = { foo: ["foo", "bar"] }) }}', true),
|
||||
array('{{ path(name = "foo", parameters = { foo: foo }) }}', true),
|
||||
array('{{ path(name = "foo", parameters = { foo: "foo", bar: "bar" }) }}', true),
|
||||
);
|
||||
}
|
||||
}
|
||||
151
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
vendored
Normal file
151
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
<?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\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\MessageSelector;
|
||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||
use Symfony\Bridge\Twig\Tests\TestCase;
|
||||
|
||||
class TranslationExtensionTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!class_exists('Symfony\Component\Translation\Translator')) {
|
||||
$this->markTestSkipped('The "Translation" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Twig_Environment')) {
|
||||
$this->markTestSkipped('Twig is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testEscaping()
|
||||
{
|
||||
$output = $this->getTemplate('{% trans %}Percent: %value%%% (%msg%){% endtrans %}')->render(array('value' => 12, 'msg' => 'approx.'));
|
||||
|
||||
$this->assertEquals('Percent: 12% (approx.)', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTransTests
|
||||
*/
|
||||
public function testTrans($template, $expected, array $variables = array())
|
||||
{
|
||||
if ($expected != $this->getTemplate($template)->render($variables)) {
|
||||
print $template."\n";
|
||||
$loader = new \Twig_Loader_Array(array('index' => $template));
|
||||
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
||||
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
|
||||
|
||||
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n";
|
||||
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
|
||||
}
|
||||
|
||||
public function getTransTests()
|
||||
{
|
||||
return array(
|
||||
// trans tag
|
||||
array('{% trans %}Hello{% endtrans %}', 'Hello'),
|
||||
array('{% trans %}%name%{% endtrans %}', 'Symfony2', array('name' => 'Symfony2')),
|
||||
|
||||
array('{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'),
|
||||
|
||||
array('{% trans %}Hello %name%{% endtrans %}', 'Hello Symfony2', array('name' => 'Symfony2')),
|
||||
array('{% trans with { \'%name%\': \'Symfony2\' } %}Hello %name%{% endtrans %}', 'Hello Symfony2'),
|
||||
array('{% set vars = { \'%name%\': \'Symfony2\' } %}{% trans with vars %}Hello %name%{% endtrans %}', 'Hello Symfony2'),
|
||||
|
||||
array('{% trans into "fr"%}Hello{% endtrans %}', 'Hello'),
|
||||
|
||||
// transchoice
|
||||
array('{% transchoice count from "messages" %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
|
||||
'There is no apples', array('count' => 0)),
|
||||
array('{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
|
||||
'There is 5 apples', array('count' => 5)),
|
||||
array('{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
|
||||
'There is 5 apples (Symfony2)', array('count' => 5, 'name' => 'Symfony2')),
|
||||
array('{% transchoice count with { \'%name%\': \'Symfony2\' } %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
|
||||
'There is 5 apples (Symfony2)', array('count' => 5)),
|
||||
array('{% transchoice count into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
|
||||
'There is no apples', array('count' => 0)),
|
||||
|
||||
// trans filter
|
||||
array('{{ "Hello"|trans }}', 'Hello'),
|
||||
array('{{ name|trans }}', 'Symfony2', array('name' => 'Symfony2')),
|
||||
array('{{ hello|trans({ \'%name%\': \'Symfony2\' }) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
|
||||
array('{% set vars = { \'%name%\': \'Symfony2\' } %}{{ hello|trans(vars) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
|
||||
array('{{ "Hello"|trans({}, "messages", "fr") }}', 'Hello'),
|
||||
|
||||
// transchoice filter
|
||||
array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count) }}', 'There is 5 apples', array('count' => 5)),
|
||||
array('{{ text|transchoice(5, {\'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')),
|
||||
array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {}, "messages", "fr") }}', 'There is 5 apples', array('count' => 5)),
|
||||
);
|
||||
}
|
||||
|
||||
public function testDefaultTranslationDomain()
|
||||
{
|
||||
$templates = array(
|
||||
'index' => '
|
||||
{%- extends "base" %}
|
||||
|
||||
{%- trans_default_domain "foo" %}
|
||||
|
||||
{%- block content %}
|
||||
{%- trans %}foo{% endtrans %}
|
||||
{%- trans from "custom" %}foo{% endtrans %}
|
||||
{{- "foo"|trans }}
|
||||
{{- "foo"|trans({}, "custom") }}
|
||||
{{- "foo"|transchoice(1) }}
|
||||
{{- "foo"|transchoice(1, {}, "custom") }}
|
||||
{% endblock %}
|
||||
',
|
||||
|
||||
'base' => '
|
||||
{%- block content "" %}
|
||||
',
|
||||
);
|
||||
|
||||
$translator = new Translator('en', new MessageSelector());
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foo (messages)'), 'en');
|
||||
$translator->addResource('array', array('foo' => 'foo (custom)'), 'en', 'custom');
|
||||
$translator->addResource('array', array('foo' => 'foo (foo)'), 'en', 'foo');
|
||||
|
||||
$template = $this->getTemplate($templates, $translator);
|
||||
|
||||
$this->assertEquals('foo (foo)foo (custom)foo (foo)foo (custom)foo (foo)foo (custom)', trim($template->render(array())));
|
||||
}
|
||||
|
||||
protected function getTemplate($template, $translator = null)
|
||||
{
|
||||
if (null === $translator) {
|
||||
$translator = new Translator('en', new MessageSelector());
|
||||
}
|
||||
|
||||
if (is_array($template)) {
|
||||
$loader = new \Twig_Loader_Array($template);
|
||||
} else {
|
||||
$loader = new \Twig_Loader_Array(array('index' => $template));
|
||||
}
|
||||
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
||||
$twig->addExtension(new TranslationExtension($translator));
|
||||
|
||||
return $twig->loadTemplate('index');
|
||||
}
|
||||
}
|
||||
3
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig
vendored
Normal file
3
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/child_label.html.twig
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{% block form_label %}
|
||||
<label>{{ global }}child</label>
|
||||
{% endblock form_label %}
|
||||
16
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig
vendored
Normal file
16
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{% block _text_id_widget %}
|
||||
{% spaceless %}
|
||||
<div id="container">
|
||||
{{ form_widget(form) }}
|
||||
</div>
|
||||
{% endspaceless %}
|
||||
{% endblock _text_id_widget %}
|
||||
|
||||
{% block _name_entry_label %}
|
||||
{% spaceless %}
|
||||
{% if label is empty %}
|
||||
{% set label = name|humanize %}
|
||||
{% endif %}
|
||||
<label>Custom label: {{ label|trans({}, translation_domain) }}</label>
|
||||
{% endspaceless %}
|
||||
{% endblock _name_entry_label %}
|
||||
3
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig
vendored
Normal file
3
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/parent_label.html.twig
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{% block form_label %}
|
||||
<label>parent</label>
|
||||
{% endblock form_label %}
|
||||
6
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig
vendored
Normal file
6
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme.html.twig
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_simple %}
|
||||
8
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig
vendored
Normal file
8
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_extends.html.twig
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
{% extends 'form_div_layout.html.twig' %}
|
||||
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_simple %}
|
||||
8
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig
vendored
Normal file
8
vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/theme_use.html.twig
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
{% use 'form_div_layout.html.twig' %}
|
||||
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_simple %}
|
||||
Reference in New Issue
Block a user