Vendor update && Started using DoctrineMigrations
This commit is contained in:
2
vendor/twig/extensions/.gitignore
vendored
Normal file
2
vendor/twig/extensions/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
phpunit.xml
|
7
vendor/twig/extensions/README
vendored
Normal file
7
vendor/twig/extensions/README
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Twig Extensions Repository
|
||||
==========================
|
||||
|
||||
This repository hosts Twig Extensions that do not belong to the core but can
|
||||
be nonetheless interesting to share with other developers.
|
||||
|
||||
Fork this repository, add your extension, and request a pull.
|
30
vendor/twig/extensions/doc/debug.rst
vendored
Normal file
30
vendor/twig/extensions/doc/debug.rst
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
The Debug Extension
|
||||
===================
|
||||
|
||||
.. caution::
|
||||
|
||||
This extension is deprecated as of Twig 1.5. Use the Twig built-in `dump`_
|
||||
function instead.
|
||||
|
||||
The ``debug`` extension provides a ``debug`` tag that can be used to
|
||||
output the content of the current context:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% debug %}
|
||||
|
||||
This is really useful when a template does not work as expected. You can also
|
||||
output a specific variable or an expression:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% debug items %}
|
||||
|
||||
{% debug post.body %}
|
||||
|
||||
.. caution::
|
||||
|
||||
The ``debug`` tag only works when the ``debug`` environment option is set
|
||||
to ``true``.
|
||||
|
||||
.. _`dump`: http://twig.sensiolabs.org/dump
|
156
vendor/twig/extensions/doc/i18n.rst
vendored
Normal file
156
vendor/twig/extensions/doc/i18n.rst
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
The i18n Extension
|
||||
==================
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The ``i18n`` extension adds `gettext`_ support to Twig. It defines one tag,
|
||||
``trans``.
|
||||
|
||||
You need to register this extension before using the ``trans`` block::
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
Note that you must configure the ``gettext`` extension before rendering any
|
||||
internationalized template. Here is a simple configuration example from the
|
||||
PHP `documentation`_::
|
||||
|
||||
// Set language to French
|
||||
putenv('LC_ALL=fr_FR');
|
||||
setlocale(LC_ALL, 'fr_FR');
|
||||
|
||||
// Specify the location of the translation tables
|
||||
bindtextdomain('myAppPhp', 'includes/locale');
|
||||
bind_textdomain_codeset('myAppPhp', 'UTF-8');
|
||||
|
||||
// Choose domain
|
||||
textdomain('myAppPhp');
|
||||
|
||||
.. caution::
|
||||
|
||||
The ``i18n`` extension only works if the PHP `gettext`_ extension is
|
||||
enabled.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Use the ``trans`` block to mark parts in the template as translatable:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans "Hello World!" %}
|
||||
|
||||
{% trans string_var %}
|
||||
|
||||
{% trans %}
|
||||
Hello World!
|
||||
{% endtrans %}
|
||||
|
||||
In a translatable string, you can embed variables:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans %}
|
||||
Hello {{ name }}!
|
||||
{% endtrans %}
|
||||
|
||||
During the gettext lookup these placeholders are converted. ``{{ name }}`` becomes ``%name%`` so the gettext ``msgid`` for this string would be ``Hello %name%!``.
|
||||
|
||||
.. note::
|
||||
|
||||
``{% trans "Hello {{ name }}!" %}`` is not a valid statement.
|
||||
|
||||
If you need to apply filters to the variables, you first need to assign the
|
||||
result to a variable:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set name = name|capitalize %}
|
||||
|
||||
{% trans %}
|
||||
Hello {{ name }}!
|
||||
{% endtrans %}
|
||||
|
||||
To pluralize a translatable string, use the ``plural`` block:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% trans %}
|
||||
Hey {{ name }}, I have one apple.
|
||||
{% plural apple_count %}
|
||||
Hey {{ name }}, I have {{ count }} apples.
|
||||
{% endtrans %}
|
||||
|
||||
The ``plural`` tag should provide the ``count`` used to select the right
|
||||
string. Within the translatable string, the special ``count`` variable always
|
||||
contain the count value (here the value of ``apple_count``).
|
||||
|
||||
Within an expression or in a tag, you can use the ``trans`` filter to translate
|
||||
simple strings or variables:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ var|default(default_value|trans) }}
|
||||
|
||||
Complex Translations within an Expression or Tag
|
||||
------------------------------------------------
|
||||
|
||||
Translations can be done with both the ``trans`` tag and the ``trans`` filter.
|
||||
The filter is less powerful as it only works for simple variables or strings.
|
||||
For more complex scenario, like pluralization, you can use a two-step
|
||||
strategy:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{# assign the translation to a temporary variable #}
|
||||
{% set default_value %}
|
||||
{% trans %}
|
||||
Hey {{ name }}, I have one apple.
|
||||
{% plural apple_count %}
|
||||
Hey {{ name }}, I have {{ count }} apples.
|
||||
{% endtrans %}
|
||||
{% endset %}
|
||||
|
||||
{# use the temporary variable within an expression #}
|
||||
{{ var|default(default_value|trans) }}
|
||||
|
||||
Extracting Template Strings
|
||||
---------------------------
|
||||
|
||||
If you use the Twig I18n extension, you will probably need to extract the
|
||||
template strings at some point. Unfortunately, the ``xgettext`` utility does
|
||||
not understand Twig templates natively. But there is a simple workaround: as
|
||||
Twig converts templates to PHP files, you can use ``xgettext`` on the template
|
||||
cache instead.
|
||||
|
||||
Create a script that forces the generation of the cache for all your
|
||||
templates. Here is a simple example to get you started::
|
||||
|
||||
$tplDir = dirname(__FILE__).'/templates';
|
||||
$tmpDir = '/tmp/cache/';
|
||||
$loader = new Twig_Loader_Filesystem($tplDir);
|
||||
|
||||
// force auto-reload to always have the latest version of the template
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => $tmpDir,
|
||||
'auto_reload' => true
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
// configure Twig the way you want
|
||||
|
||||
// iterate over all your templates
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
|
||||
{
|
||||
// force compilation
|
||||
$twig->loadTemplate(str_replace($tplDir.'/', '', $file));
|
||||
}
|
||||
|
||||
Use the standard ``xgettext`` utility as you would have done with plain PHP
|
||||
code:
|
||||
|
||||
.. code-block:: text
|
||||
|
||||
xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP /tmp/cache/*.php
|
||||
|
||||
.. _`gettext`: http://www.php.net/gettext
|
||||
.. _`documentation`: http://fr.php.net/manual/en/function.gettext.php
|
18
vendor/twig/extensions/doc/index.rst
vendored
Normal file
18
vendor/twig/extensions/doc/index.rst
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Twig Extensions
|
||||
===============
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
debug
|
||||
text
|
||||
i18n
|
||||
|
||||
The Twig Extensions repository provides several useful extensions for Twig:
|
||||
|
||||
* :doc:`Debug <debug>`: Provides tags and filters to ease template debugging;
|
||||
|
||||
* :doc:`Text <text>`: Provides useful filters for text manipulation;
|
||||
|
||||
* :doc:`I18n <i18n>`: Adds internationalization support via the ``gettext``
|
||||
library.
|
8
vendor/twig/extensions/doc/text.rst
vendored
Normal file
8
vendor/twig/extensions/doc/text.rst
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
The Text Extension
|
||||
==================
|
||||
|
||||
The Text extensions provides the following filters:
|
||||
|
||||
* ``truncate``
|
||||
* ``wordwrap``
|
||||
* ``nl2br``
|
30
vendor/twig/extensions/phpunit.xml.dist
vendored
Normal file
30
vendor/twig/extensions/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="test/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Twig Extensions Test Suite">
|
||||
<directory>./test/Twig/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./lib/Twig/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<php>
|
||||
<!-- path to the Twig lib dir -->
|
||||
<const name="TWIG_LIB_DIR" value="NOT_SET" />
|
||||
</php>
|
||||
</phpunit>
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ArgumentsTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ArgumentsTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ArgumentsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Arguments('foo');
|
||||
$this->assertEquals('<foo:arguments>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ArrayTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ArrayTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ArrayTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Array('foo');
|
||||
$this->assertEquals('<foo:array>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/BodyTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/BodyTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_BodyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Body('foo');
|
||||
$this->assertEquals('<foo:body>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/BooleanTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/BooleanTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_BooleanTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Boolean('foo');
|
||||
$this->assertEquals('<foo:boolean>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ConstantTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ConstantTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ConstantTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Constant('foo');
|
||||
$this->assertEquals('foo', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ExpressionTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/ExpressionTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_ExpressionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Expression('foo');
|
||||
$this->assertEquals('<foo>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/NumberTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/NumberTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_NumberTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Number('foo');
|
||||
$this->assertEquals('<foo:number>', (string) $grammar);
|
||||
}
|
||||
}
|
19
vendor/twig/extensions/test/Twig/Tests/Grammar/OptionalTest.php
vendored
Normal file
19
vendor/twig/extensions/test/Twig/Tests/Grammar/OptionalTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_OptionalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Optional(new Twig_Extensions_Grammar_Constant('foo'), new Twig_Extensions_Grammar_Number('bar'));
|
||||
$this->assertEquals('[foo <bar:number>]', (string) $grammar);
|
||||
}
|
||||
}
|
23
vendor/twig/extensions/test/Twig/Tests/Grammar/TagTest.php
vendored
Normal file
23
vendor/twig/extensions/test/Twig/Tests/Grammar/TagTest.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_Grammar_TagTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMagicToString()
|
||||
{
|
||||
$grammar = new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('foo'),
|
||||
new Twig_Extensions_Grammar_Number('bar'),
|
||||
new Twig_Extensions_Grammar_Optional(new Twig_Extensions_Grammar_Constant('foo'), new Twig_Extensions_Grammar_Number('bar'))
|
||||
);
|
||||
$this->assertEquals('foo <bar:number> [foo <bar:number>]', (string) $grammar);
|
||||
}
|
||||
}
|
67
vendor/twig/extensions/test/Twig/Tests/Node/DebugTest.php
vendored
Normal file
67
vendor/twig/extensions/test/Twig/Tests/Node/DebugTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once TWIG_LIB_DIR.'/../test/Twig/Tests/Node/TestCase.php';
|
||||
|
||||
class Twig_Tests_Node_DebugTest extends Twig_Tests_Node_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Twig_Node_Debug::__construct
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$expr = new Twig_Node_Expression_Name('foo', 0);
|
||||
$node = new Twig_Extensions_Node_Debug($expr, 0);
|
||||
$this->assertEquals($expr, $node->getNode('expr'));
|
||||
|
||||
$node = new Twig_Extensions_Node_Debug(null, 0);
|
||||
$this->assertEquals(null, $node->getNode('expr'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Twig_Node_Debug::compile
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testCompile($node, $source, $environment = null)
|
||||
{
|
||||
parent::testCompile($node, $source, $environment);
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$tests[] = array(new Twig_Extensions_Node_Debug(null, 0), <<<EOF
|
||||
if (\$this->env->isDebug()) {
|
||||
\$vars = array();
|
||||
foreach (\$context as \$key => \$value) {
|
||||
if (!\$value instanceof Twig_Template) {
|
||||
\$vars[\$key] = \$value;
|
||||
}
|
||||
}
|
||||
var_dump(\$vars);
|
||||
}
|
||||
EOF
|
||||
);
|
||||
|
||||
$expr = new Twig_Node_Expression_Name('foo', 0);
|
||||
$node = new Twig_Extensions_Node_Debug($expr, 0);
|
||||
|
||||
$tests[] = array($node, sprintf(<<<EOF
|
||||
if (\$this->env->isDebug()) {
|
||||
var_dump(%s);
|
||||
}
|
||||
EOF
|
||||
, $this->getVariableGetter('foo')));
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
93
vendor/twig/extensions/test/Twig/Tests/Node/TransTest.php
vendored
Normal file
93
vendor/twig/extensions/test/Twig/Tests/Node/TransTest.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once TWIG_LIB_DIR.'/../test/Twig/Tests/Node/TestCase.php';
|
||||
|
||||
class Twig_Tests_Node_TransTest extends Twig_Tests_Node_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Twig_Node_Trans::__construct
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$count = new Twig_Node_Expression_Constant(12, 0);
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hello', 0),
|
||||
), array(), 0);
|
||||
$plural = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
|
||||
new Twig_Node_Text(' apples', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, $plural, $count, 0);
|
||||
|
||||
$this->assertEquals($body, $node->getNode('body'));
|
||||
$this->assertEquals($count, $node->getNode('count'));
|
||||
$this->assertEquals($plural, $node->getNode('plural'));
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$tests = array();
|
||||
|
||||
$body = new Twig_Node_Expression_Name('foo', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo gettext(%s);', $this->getVariableGetter('foo')));
|
||||
|
||||
$body = new Twig_Node_Expression_Constant('Hello', 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, 0);
|
||||
$tests[] = array($node, 'echo gettext("Hello");');
|
||||
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hello', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, 0);
|
||||
$tests[] = array($node, 'echo gettext("Hello");');
|
||||
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('J\'ai ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0),
|
||||
new Twig_Node_Text(' pommes', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
|
||||
|
||||
$count = new Twig_Node_Expression_Constant(12, 0);
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have one apple', 0),
|
||||
), array(), 0);
|
||||
$plural = new Twig_Node(array(
|
||||
new Twig_Node_Text('Hey ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
|
||||
new Twig_Node_Text(', I have ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
|
||||
new Twig_Node_Text(' apples', 0),
|
||||
), array(), 0);
|
||||
$node = new Twig_Extensions_Node_Trans($body, $plural, $count, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(ngettext("Hey %%name%%, I have one apple", "Hey %%name%%, I have %%count%% apples", abs(12)), array("%%name%%" => %s, "%%name%%" => %s, "%%count%%" => abs(12), ));', $this->getVariableGetter('name'), $this->getVariableGetter('name')));
|
||||
|
||||
// with escaper extension set to on
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Text('J\'ai ', 0),
|
||||
new Twig_Node_Print(new Twig_Node_Expression_Filter(new Twig_Node_Expression_Name('foo', 0), new Twig_Node_Expression_Constant('escape', 0), new Twig_Node(), 0), 0),
|
||||
new Twig_Node_Text(' pommes', 0),
|
||||
), array(), 0);
|
||||
|
||||
$node = new Twig_Extensions_Node_Trans($body, null, null, 0);
|
||||
$tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
48
vendor/twig/extensions/test/Twig/Tests/SimpleTokenParser.php
vendored
Normal file
48
vendor/twig/extensions/test/Twig/Tests/SimpleTokenParser.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class SimpleTokenParser extends Twig_Extensions_SimpleTokenParser
|
||||
{
|
||||
protected $tag;
|
||||
protected $grammar;
|
||||
|
||||
public function __construct($tag, $grammar)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
$this->grammar = $grammar;
|
||||
}
|
||||
|
||||
public function getGrammar()
|
||||
{
|
||||
return $this->grammar;
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
public function getNode(array $values, $line)
|
||||
{
|
||||
$nodes = array();
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof Twig_NodeInterface) {
|
||||
$nodes[] = new Twig_Node_Print($value, $line);
|
||||
} else {
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant($value, $line), $line);
|
||||
}
|
||||
$nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
|
||||
}
|
||||
|
||||
return new Twig_Node($nodes);
|
||||
}
|
||||
}
|
112
vendor/twig/extensions/test/Twig/Tests/SimpleTokenParserTest.php
vendored
Normal file
112
vendor/twig/extensions/test/Twig/Tests/SimpleTokenParserTest.php
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class Twig_Tests_SimpleTokenParserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testParseGrammar($str, $grammar)
|
||||
{
|
||||
$this->assertEquals($grammar, Twig_Extensions_SimpleTokenParser::parseGrammar($str), '::parseGrammar() parses a grammar');
|
||||
}
|
||||
|
||||
public function testParseGrammarExceptions()
|
||||
{
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo>');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
|
||||
try {
|
||||
Twig_Extensions_SimpleTokenParser::parseGrammar('<foo:foo> (with');
|
||||
$this->fail();
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals('Twig_Error_Runtime', get_class($e));
|
||||
}
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array('', new Twig_Extensions_Grammar_Tag()),
|
||||
array('const', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('const')
|
||||
)),
|
||||
array(' const ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Constant('const')
|
||||
)),
|
||||
array('<expr>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array('<expr:expression>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array(' <expr:expression> ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr')
|
||||
)),
|
||||
array('<nb:number>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Number('nb')
|
||||
)),
|
||||
array('<bool:boolean>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Boolean('bool')
|
||||
)),
|
||||
array('<content:body>', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Body('content')
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array>]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments')
|
||||
)
|
||||
)),
|
||||
array(' <expr:expression> [ with <arguments:array> ] ', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments')
|
||||
)
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array> [or <optional:expression>]]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('or'),
|
||||
new Twig_Extensions_Grammar_Expression('optional')
|
||||
)
|
||||
)
|
||||
)),
|
||||
array('<expr:expression> [with <arguments:array> [, <optional:expression>]]', new Twig_Extensions_Grammar_Tag(
|
||||
new Twig_Extensions_Grammar_Expression('expr'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant('with'),
|
||||
new Twig_Extensions_Grammar_Array('arguments'),
|
||||
new Twig_Extensions_Grammar_Optional(
|
||||
new Twig_Extensions_Grammar_Constant(',', Twig_Token::PUNCTUATION_TYPE),
|
||||
new Twig_Extensions_Grammar_Expression('optional')
|
||||
)
|
||||
)
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
63
vendor/twig/extensions/test/Twig/Tests/grammarTest.php
vendored
Normal file
63
vendor/twig/extensions/test/Twig/Tests/grammarTest.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__).'/SimpleTokenParser.php';
|
||||
|
||||
class grammarTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testGrammar($tag, $grammar, $template, $output, $exception)
|
||||
{
|
||||
$twig = new Twig_Environment(new Twig_Loader_String(), array('cache' => false));
|
||||
$twig->addTokenParser(new SimpleTokenParser($tag, $grammar));
|
||||
|
||||
$ok = true;
|
||||
try {
|
||||
$template = $twig->loadTemplate($template);
|
||||
} catch (Exception $e) {
|
||||
$ok = false;
|
||||
|
||||
if (false === $exception) {
|
||||
$this->fail('Exception not expected');
|
||||
} else {
|
||||
$this->assertEquals($exception, get_class($e));
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
if (false !== $exception) {
|
||||
$this->fail(sprintf('Exception "%s" expected', $exception));
|
||||
}
|
||||
|
||||
$actual = $template->render(array());
|
||||
$this->assertEquals($output, $actual);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array('foo1', '', '{% foo1 %}', '|', false),
|
||||
array('foo2', '', '{% foo2 "bar" %}', '|', 'Twig_Error_Syntax'),
|
||||
array('foo3', '<foo>', '{% foo3 "bar" %}', '|bar|', false),
|
||||
array('foo4', '<foo>', '{% foo4 1 + 2 %}', '|3|', false),
|
||||
array('foo5', '<foo:expression>', '{% foo5 1 + 2 %}', '|3|', false),
|
||||
array('foo6', '<foo:array>', '{% foo6 1 + 2 %}', '|3|', 'Twig_Error_Syntax'),
|
||||
array('foo7', '<foo>', '{% foo7 %}', '|3|', 'Twig_Error_Syntax'),
|
||||
array('foo8', '<foo:array>', '{% foo8 [1, 2] %}', '|Array|', false),
|
||||
array('foo9', '<foo> with <bar>', '{% foo9 "bar" with "foobar" %}', '|bar|with|foobar|', false),
|
||||
array('foo10', '<foo> [with <bar>]', '{% foo10 "bar" with "foobar" %}', '|bar|with|foobar|', false),
|
||||
array('foo11', '<foo> [with <bar>]', '{% foo11 "bar" %}', '|bar|', false),
|
||||
);
|
||||
}
|
||||
}
|
20
vendor/twig/extensions/test/bootstrap.php
vendored
Normal file
20
vendor/twig/extensions/test/bootstrap.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (!defined('TWIG_LIB_DIR') || 'NOT_SET' === TWIG_LIB_DIR) {
|
||||
die('The path to the Twig lib/ directory must be defined in phpunit.xml configuration.');
|
||||
}
|
||||
|
||||
require_once TWIG_LIB_DIR.'/Twig/Autoloader.php';
|
||||
Twig_Autoloader::register();
|
||||
|
||||
require_once dirname(__FILE__).'/../lib/Twig/Extensions/Autoloader.php';
|
||||
Twig_Extensions_Autoloader::register();
|
Reference in New Issue
Block a user