ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TestTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 {
14  public function testConstructor()
15  {
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);
20 
21  $this->assertEquals($expr, $node->getNode('node'));
22  $this->assertEquals($args, $node->getNode('arguments'));
23  $this->assertEquals($name, $node->getAttribute('name'));
24  }
25 
26  public function getTests()
27  {
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)));
30 
31  $tests = array();
32 
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")');
36 
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"))');
41  }
42 
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);
47 
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);
50 
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);
53 
54  $node = $this->createTest($string, 'barbar', array(
58  'foo' => new Twig_Node_Expression_Constant('bar', 1),
59  ));
60  $tests[] = array($node, 'twig_tests_test_barbar("abc", "1", "2", array(0 => "3", "foo" => "bar"))', $environment);
61 
62  return $tests;
63  }
64 
65  protected function createTest($node, $name, array $arguments = array())
66  {
67  return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 1);
68  }
69 
70  protected function getEnvironment()
71  {
72  if (PHP_VERSION_ID >= 50300) {
73  return include 'PHP53/TestInclude.php';
74  }
75 
76  return parent::getEnvironment();
77  }
78 }
79 
80 function twig_tests_test_barbar($string, $arg1 = null, $arg2 = null, array $args = array())
81 {
82 }
Represents a node in the AST.
Definition: Node.php:18
createTest($node, $name, array $arguments=array())
Definition: TestTest.php:65
Checks that a variable is null.
Definition: Null.php:21
$tests
Definition: bench.php:104
twig_tests_test_barbar($string, $arg1=null, $arg2=null, array $args=array())
Definition: TestTest.php:80
Represents a template test.
Definition: SimpleTest.php:19
Stores the Twig configuration.
Definition: Environment.php:17