4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
16 $expr = new Twig_Node_Expression_Constant('foo', 1);
17 $name = new Twig_Node_Expression_Constant('null', 1);
18 $args = new Twig_Node();
19 $node = new Twig_Node_Expression_Test($expr, $name, $args, 1);
21 $this->assertEquals($expr, $node->getNode('node'));
22 $this->assertEquals($args, $node->getNode('arguments'));
23 $this->assertEquals($name, $node->getAttribute('name'));
26 public function getTests()
28 $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
29 $environment->addTest(new Twig_SimpleTest('barbar', 'twig_tests_test_barbar', array('is_variadic' => true, 'need_context' => true)));
33 $expr = new Twig_Node_Expression_Constant('foo', 1);
34 $node = new Twig_Node_Expression_Test_Null($expr, 'null', new Twig_Node(array()), 1);
35 $tests[] = array($node, '(null === "foo")');
37 // test as an anonymous function
38 if (PHP_VERSION_ID >= 50300) {
39 $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
40 $tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
43 // arbitrary named arguments
44 $string = new Twig_Node_Expression_Constant('abc', 1);
45 $node = $this->createTest($string, 'barbar');
46 $tests[] = array($node, 'twig_tests_test_barbar("abc")', $environment);
48 $node = $this->createTest($string, 'barbar', array('foo' => new Twig_Node_Expression_Constant('bar', 1)));
49 $tests[] = array($node, 'twig_tests_test_barbar("abc", null, null, array("foo" => "bar"))', $environment);
51 $node = $this->createTest($string, 'barbar', array('arg2' => new Twig_Node_Expression_Constant('bar', 1)));
52 $tests[] = array($node, 'twig_tests_test_barbar("abc", null, "bar")', $environment);
54 $node = $this->createTest($string, 'barbar', array(
55 new Twig_Node_Expression_Constant('1', 1),
56 new Twig_Node_Expression_Constant('2', 1),
57 new Twig_Node_Expression_Constant('3', 1),
58 'foo' => new Twig_Node_Expression_Constant('bar', 1),
60 $tests[] = array($node, 'twig_tests_test_barbar("abc", "1", "2", array(0 => "3", "foo" => "bar"))', $environment);
65 protected function createTest($node, $name, array $arguments = array())
67 return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 1);
70 protected function getEnvironment()
72 if (PHP_VERSION_ID >= 50300) {
73 return include 'PHP53/TestInclude.php';
76 return parent::getEnvironment();
80 function twig_tests_test_barbar($string, $arg1 = null, $arg2 = null, array $args = array())