ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Tests_Node_TransTest Class Reference
+ Inheritance diagram for Twig_Tests_Node_TransTest:
+ Collaboration diagram for Twig_Tests_Node_TransTest:

Public Member Functions

 testConstructor ()
 ::__construct More...
 
 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)
 

Additional Inherited Members

- 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 TransTest.php.

Member Function Documentation

◆ getTests()

Twig_Tests_Node_TransTest::getTests ( )

Definition at line 37 of file TransTest.php.

References array, and Twig_Test_NodeTestCase\getVariableGetter().

38  {
39  $tests = array();
40 
41  $body = new Twig_Node_Expression_Name('foo', 0);
42  $node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
43  $tests[] = array($node, sprintf('echo gettext(%s);', $this->getVariableGetter('foo')));
44 
45  $body = new Twig_Node_Expression_Constant('Hello', 0);
46  $node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
47  $tests[] = array($node, 'echo gettext("Hello");');
48 
49  $body = new Twig_Node(array(
50  new Twig_Node_Text('Hello', 0),
51  ), array(), 0);
52  $node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
53  $tests[] = array($node, 'echo gettext("Hello");');
54 
55  $body = new Twig_Node(array(
56  new Twig_Node_Text('J\'ai ', 0),
57  new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0),
58  new Twig_Node_Text(' pommes', 0),
59  ), array(), 0);
60  $node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
61  $tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
62 
63  $count = new Twig_Node_Expression_Constant(12, 0);
64  $body = new Twig_Node(array(
65  new Twig_Node_Text('Hey ', 0),
66  new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
67  new Twig_Node_Text(', I have one apple', 0),
68  ), array(), 0);
69  $plural = new Twig_Node(array(
70  new Twig_Node_Text('Hey ', 0),
71  new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
72  new Twig_Node_Text(', I have ', 0),
73  new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
74  new Twig_Node_Text(' apples', 0),
75  ), array(), 0);
76  $node = new Twig_Extensions_Node_Trans($body, $plural, $count, null, 0);
77  $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')));
78 
79  // with escaper extension set to on
80  $body = new Twig_Node(array(
81  new Twig_Node_Text('J\'ai ', 0),
83  new Twig_Node_Text(' pommes', 0),
84  ), array(), 0);
85 
86  $node = new Twig_Extensions_Node_Trans($body, null, null, null, 0);
87  $tests[] = array($node, sprintf('echo strtr(gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));', $this->getVariableGetter('foo')));
88 
89  // with notes
90  $body = new Twig_Node_Expression_Constant('Hello', 0);
91  $notes = new Twig_Node_Text('Notes for translators', 0);
92  $node = new Twig_Extensions_Node_Trans($body, null, null, $notes, 0);
93  $tests[] = array($node, "// notes: Notes for translators\necho gettext(\"Hello\");");
94 
95  $body = new Twig_Node_Expression_Constant('Hello', 0);
96  $notes = new Twig_Node_Text("Notes for translators\nand line breaks", 0);
97  $node = new Twig_Extensions_Node_Trans($body, null, null, $notes, 0);
98  $tests[] = array($node, "// notes: Notes for translators and line breaks\necho gettext(\"Hello\");");
99 
100  $count = new Twig_Node_Expression_Constant(5, 0);
101  $body = new Twig_Node_Text('There is 1 pending task', 0);
102  $plural = new Twig_Node(array(
103  new Twig_Node_Text('There are ', 0),
104  new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
105  new Twig_Node_Text(' pending tasks', 0),
106  ), array(), 0);
107  $notes = new Twig_Node_Text('Notes for translators', 0);
108  $node = new Twig_Extensions_Node_Trans($body, $plural, $count, $notes, 0);
109  $tests[] = array($node, "// notes: Notes for translators\n".'echo strtr(ngettext("There is 1 pending task", "There are %count% pending tasks", abs(5)), array("%count%" => abs(5), ));');
110 
111  return $tests;
112  }
Represents a node in the AST.
Definition: Node.php:18
Represents a node that outputs an expression.
Definition: Print.php:18
Create styles array
The data for the language used.
Represents a text node.
Definition: Text.php:18
getVariableGetter($name, $line=false)
+ Here is the call graph for this function:

◆ testConstructor()

Twig_Tests_Node_TransTest::testConstructor ( )

::__construct

Definition at line 17 of file TransTest.php.

References array.

18  {
19  $count = new Twig_Node_Expression_Constant(12, 0);
20  $body = new Twig_Node(array(
21  new Twig_Node_Text('Hello', 0),
22  ), array(), 0);
23  $plural = new Twig_Node(array(
24  new Twig_Node_Text('Hey ', 0),
25  new Twig_Node_Print(new Twig_Node_Expression_Name('name', 0), 0),
26  new Twig_Node_Text(', I have ', 0),
27  new Twig_Node_Print(new Twig_Node_Expression_Name('count', 0), 0),
28  new Twig_Node_Text(' apples', 0),
29  ), array(), 0);
30  $node = new Twig_Extensions_Node_Trans($body, $plural, $count, null, 0);
31 
32  $this->assertEquals($body, $node->getNode('body'));
33  $this->assertEquals($count, $node->getNode('count'));
34  $this->assertEquals($plural, $node->getNode('plural'));
35  }
Represents a node in the AST.
Definition: Node.php:18
Represents a node that outputs an expression.
Definition: Print.php:18
Create styles array
The data for the language used.
Represents a text node.
Definition: Text.php:18

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