mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-10 17:36:53 +00:00
fixed tests
This commit is contained in:
@@ -64,7 +64,6 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
return array(
|
||||
array('{{ [1, "a": "b"] }}'),
|
||||
array('{{ {a: "b"} }}'),
|
||||
array('{{ {"a": "b", 2} }}'),
|
||||
);
|
||||
}
|
||||
@@ -74,6 +73,9 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
// simple array
|
||||
array('{{ [1, 2] }}', new Twig_Node_Expression_Array(array(
|
||||
new Twig_Node_Expression_Constant(0, 1),
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
new Twig_Node_Expression_Constant(2, 1),
|
||||
), 1),
|
||||
@@ -81,6 +83,9 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
// array with trailing ,
|
||||
array('{{ [1, 2, ] }}', new Twig_Node_Expression_Array(array(
|
||||
new Twig_Node_Expression_Constant(0, 1),
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
new Twig_Node_Expression_Constant(2, 1),
|
||||
), 1),
|
||||
@@ -88,35 +93,52 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
// simple hash
|
||||
array('{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array(array(
|
||||
'a' => new Twig_Node_Expression_Constant('b', 1),
|
||||
'b' => new Twig_Node_Expression_Constant('c', 1),
|
||||
new Twig_Node_Expression_Constant('a', 1),
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
new Twig_Node_Expression_Constant('c', 1),
|
||||
), 1),
|
||||
),
|
||||
|
||||
// hash with trailing ,
|
||||
array('{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array(array(
|
||||
'a' => new Twig_Node_Expression_Constant('b', 1),
|
||||
'b' => new Twig_Node_Expression_Constant('c', 1),
|
||||
new Twig_Node_Expression_Constant('a', 1),
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
new Twig_Node_Expression_Constant('c', 1),
|
||||
), 1),
|
||||
),
|
||||
|
||||
// hash in an array
|
||||
array('{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array(array(
|
||||
new Twig_Node_Expression_Constant(0, 1),
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
new Twig_Node_Expression_Array(array(
|
||||
'a' => new Twig_Node_Expression_Constant('b', 1),
|
||||
'b' => new Twig_Node_Expression_Constant('c', 1),
|
||||
new Twig_Node_Expression_Constant('a', 1),
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
new Twig_Node_Expression_Constant('c', 1),
|
||||
), 1),
|
||||
), 1),
|
||||
),
|
||||
|
||||
// array in a hash
|
||||
array('{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array(array(
|
||||
'a' => new Twig_Node_Expression_Array(array(
|
||||
new Twig_Node_Expression_Constant('a', 1),
|
||||
new Twig_Node_Expression_Array(array(
|
||||
new Twig_Node_Expression_Constant(0, 1),
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
|
||||
new Twig_Node_Expression_Constant(1, 1),
|
||||
new Twig_Node_Expression_Constant(2, 1),
|
||||
), 1),
|
||||
'b' => new Twig_Node_Expression_Constant('c', 1),
|
||||
new Twig_Node_Expression_Constant('b', 1),
|
||||
new Twig_Node_Expression_Constant('c', 1),
|
||||
), 1),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -43,3 +43,6 @@ bar
|
||||
FOO,BAR,
|
||||
|
||||
1,2
|
||||
|
||||
1,foo,c,1foo
|
||||
a,b,c,d
|
||||
|
||||
@@ -18,10 +18,10 @@ class Twig_Tests_Node_Expression_ArrayTest extends Twig_Tests_Node_TestCase
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$elements = array('foo' => $foo = new Twig_Node_Expression_Constant('bar', 0));
|
||||
$elements = array(new Twig_Node_Expression_Constant('foo', 0), $foo = new Twig_Node_Expression_Constant('bar', 0));
|
||||
$node = new Twig_Node_Expression_Array($elements, 0);
|
||||
|
||||
$this->assertEquals($foo, $node->getNode('foo'));
|
||||
$this->assertEquals($foo, $node->getNode(1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,8 +36,11 @@ class Twig_Tests_Node_Expression_ArrayTest extends Twig_Tests_Node_TestCase
|
||||
public function getTests()
|
||||
{
|
||||
$elements = array(
|
||||
'foo' => new Twig_Node_Expression_Constant('bar', 0),
|
||||
'bar' => new Twig_Node_Expression_Constant('foo', 0),
|
||||
new Twig_Node_Expression_Constant('foo', 0),
|
||||
new Twig_Node_Expression_Constant('bar', 0),
|
||||
|
||||
new Twig_Node_Expression_Constant('bar', 0),
|
||||
new Twig_Node_Expression_Constant('foo', 0),
|
||||
);
|
||||
$node = new Twig_Node_Expression_Array($elements, 0);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class Twig_Tests_Node_IncludeTest extends Twig_Tests_Node_TestCase
|
||||
$this->assertEquals($expr, $node->getNode('expr'));
|
||||
$this->assertFalse($node->getAttribute('only'));
|
||||
|
||||
$vars = new Twig_Node_Expression_Array(array('foo' => new Twig_Node_Expression_Constant(true, 0)), 0);
|
||||
$vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 0), new Twig_Node_Expression_Constant(true, 0)), 0);
|
||||
$node = new Twig_Node_Include($expr, $vars, true, false, 0);
|
||||
$this->assertEquals($vars, $node->getNode('variables'));
|
||||
$this->assertTrue($node->getAttribute('only'));
|
||||
@@ -62,7 +62,7 @@ EOF
|
||||
);
|
||||
|
||||
$expr = new Twig_Node_Expression_Constant('foo.twig', 0);
|
||||
$vars = new Twig_Node_Expression_Array(array('foo' => new Twig_Node_Expression_Constant(true, 0)), 0);
|
||||
$vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 0), new Twig_Node_Expression_Constant(true, 0)), 0);
|
||||
$node = new Twig_Node_Include($expr, $vars, false, false, 0);
|
||||
$tests[] = array($node, '$this->env->loadTemplate("foo.twig")->display(array_merge($context, array("foo" => true)));');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user