ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Tests_Node_Expression_FunctionTest Class Reference
+ Inheritance diagram for Twig_Tests_Node_Expression_FunctionTest:
+ Collaboration diagram for Twig_Tests_Node_Expression_FunctionTest:

Public Member Functions

 testConstructor ()
 
 getTests ()
 
- Public Member Functions inherited from Twig_Test_NodeTestCase
 getTests ()
 
 testCompile ($node, $source, $environment=null, $isPattern=false)
 getTests More...
 
 assertNodeCompilation ($source, Twig_Node $node, Twig_Environment $environment=null, $isPattern=false)
 

Protected Member Functions

 createFunction ($name, array $arguments=array())
 
 getEnvironment ()
 
- Protected Member Functions inherited from Twig_Test_NodeTestCase
 getCompiler (Twig_Environment $environment=null)
 
 getEnvironment ()
 
 getVariableGetter ($name, $line=false)
 
 getAttributeGetter ()
 

Detailed Description

Definition at line 12 of file FunctionTest.php.

Member Function Documentation

◆ createFunction()

Twig_Tests_Node_Expression_FunctionTest::createFunction (   $name,
array  $arguments = array() 
)
protected

Definition at line 93 of file FunctionTest.php.

References $name.

Referenced by getTests().

94  {
95  return new Twig_Node_Expression_Function($name, new Twig_Node($arguments), 1);
96  }
Represents a node in the AST.
Definition: Node.php:18
+ Here is the caller graph for this function:

◆ getEnvironment()

Twig_Tests_Node_Expression_FunctionTest::getEnvironment ( )
protected

Definition at line 98 of file FunctionTest.php.

99  {
100  if (PHP_VERSION_ID >= 50300) {
101  return include 'PHP53/FunctionInclude.php';
102  }
103 
104  return parent::getEnvironment();
105  }

◆ getTests()

Twig_Tests_Node_Expression_FunctionTest::getTests ( )

Definition at line 24 of file FunctionTest.php.

References $tests, and createFunction().

25  {
26  $environment = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
27  $environment->addFunction(new Twig_SimpleFunction('foo', 'foo', array()));
28  $environment->addFunction(new Twig_SimpleFunction('bar', 'bar', array('needs_environment' => true)));
29  $environment->addFunction(new Twig_SimpleFunction('foofoo', 'foofoo', array('needs_context' => true)));
30  $environment->addFunction(new Twig_SimpleFunction('foobar', 'foobar', array('needs_environment' => true, 'needs_context' => true)));
31  $environment->addFunction(new Twig_SimpleFunction('barbar', 'twig_tests_function_barbar', array('is_variadic' => true)));
32 
33  $tests = array();
34 
35  $node = $this->createFunction('foo');
36  $tests[] = array($node, 'foo()', $environment);
37 
38  $node = $this->createFunction('foo', array(new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1)));
39  $tests[] = array($node, 'foo("bar", "foobar")', $environment);
40 
41  $node = $this->createFunction('bar');
42  $tests[] = array($node, 'bar($this->env)', $environment);
43 
44  $node = $this->createFunction('bar', array(new Twig_Node_Expression_Constant('bar', 1)));
45  $tests[] = array($node, 'bar($this->env, "bar")', $environment);
46 
47  $node = $this->createFunction('foofoo');
48  $tests[] = array($node, 'foofoo($context)', $environment);
49 
50  $node = $this->createFunction('foofoo', array(new Twig_Node_Expression_Constant('bar', 1)));
51  $tests[] = array($node, 'foofoo($context, "bar")', $environment);
52 
53  $node = $this->createFunction('foobar');
54  $tests[] = array($node, 'foobar($this->env, $context)', $environment);
55 
56  $node = $this->createFunction('foobar', array(new Twig_Node_Expression_Constant('bar', 1)));
57  $tests[] = array($node, 'foobar($this->env, $context, "bar")', $environment);
58 
59  // named arguments
60  $node = $this->createFunction('date', array(
61  'timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1),
62  'date' => new Twig_Node_Expression_Constant(0, 1),
63  ));
64  $tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")');
65 
66  // arbitrary named arguments
67  $node = $this->createFunction('barbar');
68  $tests[] = array($node, 'twig_tests_function_barbar()', $environment);
69 
70  $node = $this->createFunction('barbar', array('foo' => new Twig_Node_Expression_Constant('bar', 1)));
71  $tests[] = array($node, 'twig_tests_function_barbar(null, null, array("foo" => "bar"))', $environment);
72 
73  $node = $this->createFunction('barbar', array('arg2' => new Twig_Node_Expression_Constant('bar', 1)));
74  $tests[] = array($node, 'twig_tests_function_barbar(null, "bar")', $environment);
75 
76  $node = $this->createFunction('barbar', array(
80  'foo' => new Twig_Node_Expression_Constant('bar', 1),
81  ));
82  $tests[] = array($node, 'twig_tests_function_barbar("1", "2", array(0 => "3", "foo" => "bar"))', $environment);
83 
84  // function as an anonymous function
85  if (PHP_VERSION_ID >= 50300) {
86  $node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
87  $tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
88  }
89 
90  return $tests;
91  }
Represents a template function.
$tests
Definition: bench.php:104
Stores the Twig configuration.
Definition: Environment.php:17
createFunction($name, array $arguments=array())
+ Here is the call graph for this function:

◆ testConstructor()

Twig_Tests_Node_Expression_FunctionTest::testConstructor ( )

Definition at line 14 of file FunctionTest.php.

References $name.

15  {
16  $name = 'function';
17  $args = new Twig_Node();
18  $node = new Twig_Node_Expression_Function($name, $args, 1);
19 
20  $this->assertEquals($name, $node->getAttribute('name'));
21  $this->assertEquals($args, $node->getNode('arguments'));
22  }
Represents a node in the AST.
Definition: Node.php:18

The documentation for this class was generated from the following file: