Vendor update && Started using DoctrineMigrations

This commit is contained in:
Polonkai Gergely
2012-07-23 17:09:03 +02:00
parent 7c36f93436
commit bf46316347
1102 changed files with 103189 additions and 7 deletions

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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;
}
}

View 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;
}
}

View 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);
}
}

View 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')
)
)
)),
);
}
}

View 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),
);
}
}

View 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();