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

Public Member Functions

 testRandomFunction ($value, $expectedInArray)
 getRandomFunctionTestData More...
 
 getRandomFunctionTestData ()
 
 testRandomFunctionWithoutParameter ()
 
 testRandomFunctionReturnsAsIs ()
 
 testRandomFunctionOfEmptyArrayThrowsException ()
 Twig_Error_Runtime More...
 
 testRandomFunctionOnNonUTF8String ()
 
 testReverseFilterOnNonUTF8String ()
 
 testCustomEscaper ($expected, $string, $strategy)
 provideCustomEscaperCases More...
 
 provideCustomEscaperCases ()
 
 testUnknownCustomEscaper ()
 Twig_Error_Runtime More...
 
 testTwigFirst ($expected, $input)
 provideTwigFirstCases More...
 
 provideTwigFirstCases ()
 
 testTwigLast ($expected, $input)
 provideTwigLastCases More...
 
 provideTwigLastCases ()
 
 testArrayKeysFilter (array $expected, $input)
 provideArrayKeyCases More...
 
 provideArrayKeyCases ()
 
 testInFilter ($expected, $value, $compare)
 provideInFilterCases More...
 
 provideInFilterCases ()
 
 testSliceFilter ($expected, $input, $start, $length=null, $preserveKeys=false)
 provideSliceFilterCases More...
 
 provideSliceFilterCases ()
 

Detailed Description

Definition at line 12 of file CoreTest.php.

Member Function Documentation

◆ getRandomFunctionTestData()

Twig_Tests_Extension_CoreTest::getRandomFunctionTestData ( )

Definition at line 26 of file CoreTest.php.

27  {
28  return array(
29  array(// array
30  array('apple', 'orange', 'citrus'),
31  array('apple', 'orange', 'citrus'),
32  ),
33  array(// Traversable
34  new ArrayObject(array('apple', 'orange', 'citrus')),
35  array('apple', 'orange', 'citrus'),
36  ),
37  array(// unicode string
38  'Ä€é',
39  array('Ä', '€', 'é'),
40  ),
41  array(// numeric but string
42  '123',
43  array('1', '2', '3'),
44  ),
45  array(// integer
46  5,
47  range(0, 5, 1),
48  ),
49  array(// float
50  5.9,
51  range(0, 5, 1),
52  ),
53  array(// negative
54  -2,
55  array(0, -1, -2),
56  ),
57  );
58  }

◆ provideArrayKeyCases()

Twig_Tests_Extension_CoreTest::provideArrayKeyCases ( )

Definition at line 198 of file CoreTest.php.

References $keys.

199  {
200  $array = array('a' => 'a1', 'b' => 'b1', 'c' => 'c1');
201  $keys = array_keys($array);
202 
203  return array(
204  array($keys, $array),
205  array($keys, new CoreTestIterator($array, $keys)),
206  array($keys, new CoreTestIteratorAggregate($array, $keys)),
207  array($keys, new CoreTestIteratorAggregateAggregate($array, $keys)),
208  array(array(), null),
209  array(array('a'), new SimpleXMLElement('<xml><a></a></xml>')),
210  );
211  }
$keys

◆ provideCustomEscaperCases()

Twig_Tests_Extension_CoreTest::provideCustomEscaperCases ( )

Definition at line 129 of file CoreTest.php.

130  {
131  return array(
132  array('fooUTF-8', 'foo', 'foo'),
133  array('UTF-8', null, 'foo'),
134  array('42UTF-8', 42, 'foo'),
135  );
136  }

◆ provideInFilterCases()

Twig_Tests_Extension_CoreTest::provideInFilterCases ( )

Definition at line 221 of file CoreTest.php.

References $keys.

222  {
223  $array = array(1, 2, 'a' => 3, 5, 6, 7);
224  $keys = array_keys($array);
225 
226  return array(
227  array(true, 1, $array),
228  array(true, '3', $array),
229  array(true, '3', 'abc3def'),
230  array(true, 1, new CoreTestIterator($array, $keys, true, 1)),
231  array(true, '3', new CoreTestIterator($array, $keys, true, 3)),
232  array(true, '3', new CoreTestIteratorAggregateAggregate($array, $keys, true, 3)),
233  array(false, 4, $array),
234  array(false, 4, new CoreTestIterator($array, $keys, true)),
235  array(false, 4, new CoreTestIteratorAggregateAggregate($array, $keys, true)),
236  array(false, 1, 1),
237  array(true, 'b', new SimpleXMLElement('<xml><a>b</a></xml>')),
238  );
239  }
$keys

◆ provideSliceFilterCases()

Twig_Tests_Extension_CoreTest::provideSliceFilterCases ( )

Definition at line 250 of file CoreTest.php.

References $i, and $keys.

251  {
252  $i = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4);
253  $keys = array_keys($i);
254 
255  return array(
256  array(array('a' => 1), $i, 0, 1, true),
257  array(array('a' => 1), $i, 0, 1, false),
258  array(array('b' => 2, 'c' => 3), $i, 1, 2),
259  array(array(1), array(1, 2, 3, 4), 0, 1),
260  array(array(2, 3), array(1, 2, 3, 4), 1, 2),
261  array(array(2, 3), new CoreTestIterator($i, $keys, true), 1, 2),
262  array(array('c' => 3, 'd' => 4), new CoreTestIteratorAggregate($i, $keys, true), 2, null, true),
263  array($i, new CoreTestIterator($i, $keys, true), 0, count($keys) + 10, true),
264  array(array(), new CoreTestIterator($i, $keys, true), count($keys) + 10),
265  array('de', 'abcdef', 3, 2),
266  array(array(), new SimpleXMLElement('<items><item>1</item><item>2</item></items>'), 3),
267  array(array(), new ArrayIterator(array(1, 2)), 3),
268  );
269  }
$keys
$i
Definition: disco.tpl.php:19

◆ provideTwigFirstCases()

Twig_Tests_Extension_CoreTest::provideTwigFirstCases ( )

Definition at line 155 of file CoreTest.php.

References $i.

156  {
157  $i = array(1 => 'a', 2 => 'b', 3 => 'c');
158 
159  return array(
160  array('a', 'abc'),
161  array(1, array(1, 2, 3)),
162  array('', null),
163  array('', ''),
164  array('a', new CoreTestIterator($i, array_keys($i), true, 3)),
165  );
166  }
$i
Definition: disco.tpl.php:19

◆ provideTwigLastCases()

Twig_Tests_Extension_CoreTest::provideTwigLastCases ( )

Definition at line 177 of file CoreTest.php.

References $i.

178  {
179  $i = array(1 => 'a', 2 => 'b', 3 => 'c');
180 
181  return array(
182  array('c', 'abc'),
183  array(3, array(1, 2, 3)),
184  array('', null),
185  array('', ''),
186  array('c', new CoreTestIterator($i, array_keys($i), true)),
187  );
188  }
$i
Definition: disco.tpl.php:19

◆ testArrayKeysFilter()

Twig_Tests_Extension_CoreTest::testArrayKeysFilter ( array  $expected,
  $input 
)

provideArrayKeyCases

Definition at line 193 of file CoreTest.php.

References $input.

194  {
195  $this->assertSame($expected, twig_get_array_keys_filter($input));
196  }

◆ testCustomEscaper()

Twig_Tests_Extension_CoreTest::testCustomEscaper (   $expected,
  $string,
  $strategy 
)

provideCustomEscaperCases

Definition at line 121 of file CoreTest.php.

122  {
123  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
124  $twig->getExtension('Twig_Extension_Core')->setEscaper('foo', 'foo_escaper_for_test');
125 
126  $this->assertSame($expected, twig_escape_filter($twig, $string, $strategy));
127  }
Stores the Twig configuration.
Definition: Environment.php:17

◆ testInFilter()

Twig_Tests_Extension_CoreTest::testInFilter (   $expected,
  $value,
  $compare 
)

provideInFilterCases

Definition at line 216 of file CoreTest.php.

217  {
218  $this->assertSame($expected, twig_in_filter($value, $compare));
219  }

◆ testRandomFunction()

Twig_Tests_Extension_CoreTest::testRandomFunction (   $value,
  $expectedInArray 
)

getRandomFunctionTestData

Definition at line 17 of file CoreTest.php.

References $env, $i, and twig_random().

18  {
19  $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
20 
21  for ($i = 0; $i < 100; ++$i) {
22  $this->assertTrue(in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type
23  }
24  }
$env
$i
Definition: disco.tpl.php:19
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:309
Stores the Twig configuration.
Definition: Environment.php:17
+ Here is the call graph for this function:

◆ testRandomFunctionOfEmptyArrayThrowsException()

Twig_Tests_Extension_CoreTest::testRandomFunctionOfEmptyArrayThrowsException ( )

Twig_Error_Runtime

Definition at line 82 of file CoreTest.php.

References twig_random().

83  {
84  twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), array());
85  }
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:309
Stores the Twig configuration.
Definition: Environment.php:17
+ Here is the call graph for this function:

◆ testRandomFunctionOnNonUTF8String()

Twig_Tests_Extension_CoreTest::testRandomFunctionOnNonUTF8String ( )

Definition at line 87 of file CoreTest.php.

References $i, $text, and twig_random().

88  {
89  if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
90  $this->markTestSkipped('needs iconv or mbstring');
91  }
92 
93  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
94  $twig->setCharset('ISO-8859-1');
95 
96  $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
97  for ($i = 0; $i < 30; ++$i) {
98  $rand = twig_random($twig, $text);
99  $this->assertTrue(in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), array('Ä', 'é'), true));
100  }
101  }
$text
Definition: errorreport.php:18
$i
Definition: disco.tpl.php:19
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:309
Stores the Twig configuration.
Definition: Environment.php:17
+ Here is the call graph for this function:

◆ testRandomFunctionReturnsAsIs()

Twig_Tests_Extension_CoreTest::testRandomFunctionReturnsAsIs ( )

Definition at line 70 of file CoreTest.php.

References twig_random().

71  {
72  $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), ''));
73  $this->assertSame('', twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('charset' => null)), ''));
74 
75  $instance = new stdClass();
76  $this->assertSame($instance, twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), $instance));
77  }
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:309
Stores the Twig configuration.
Definition: Environment.php:17
+ Here is the call graph for this function:

◆ testRandomFunctionWithoutParameter()

Twig_Tests_Extension_CoreTest::testRandomFunctionWithoutParameter ( )

Definition at line 60 of file CoreTest.php.

References $i, and twig_random().

61  {
62  $max = mt_getrandmax();
63 
64  for ($i = 0; $i < 100; ++$i) {
65  $val = twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
66  $this->assertTrue(is_int($val) && $val >= 0 && $val <= $max);
67  }
68  }
$i
Definition: disco.tpl.php:19
twig_random(Twig_Environment $env, $values=null)
Returns a random value depending on the supplied parameter type:
Definition: Core.php:309
Stores the Twig configuration.
Definition: Environment.php:17
+ Here is the call graph for this function:

◆ testReverseFilterOnNonUTF8String()

Twig_Tests_Extension_CoreTest::testReverseFilterOnNonUTF8String ( )

Definition at line 103 of file CoreTest.php.

References $input, and Sabre\VObject\$output.

104  {
105  if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
106  $this->markTestSkipped('needs iconv or mbstring');
107  }
108 
109  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
110  $twig->setCharset('ISO-8859-1');
111 
112  $input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
113  $output = twig_convert_encoding(twig_reverse_filter($twig, $input), 'UTF-8', 'ISO-8859-1');
114 
115  $this->assertEquals($output, 'éÄ');
116  }
Stores the Twig configuration.
Definition: Environment.php:17

◆ testSliceFilter()

Twig_Tests_Extension_CoreTest::testSliceFilter (   $expected,
  $input,
  $start,
  $length = null,
  $preserveKeys = false 
)

provideSliceFilterCases

Definition at line 244 of file CoreTest.php.

References $input, and $start.

245  {
246  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
247  $this->assertSame($expected, twig_slice($twig, $input, $start, $length, $preserveKeys));
248  }
$start
Definition: bench.php:8
Stores the Twig configuration.
Definition: Environment.php:17

◆ testTwigFirst()

Twig_Tests_Extension_CoreTest::testTwigFirst (   $expected,
  $input 
)

provideTwigFirstCases

Definition at line 149 of file CoreTest.php.

References $input.

150  {
151  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
152  $this->assertSame($expected, twig_first($twig, $input));
153  }
Stores the Twig configuration.
Definition: Environment.php:17

◆ testTwigLast()

Twig_Tests_Extension_CoreTest::testTwigLast (   $expected,
  $input 
)

provideTwigLastCases

Definition at line 171 of file CoreTest.php.

References $input.

172  {
173  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
174  $this->assertSame($expected, twig_last($twig, $input));
175  }
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownCustomEscaper()

Twig_Tests_Extension_CoreTest::testUnknownCustomEscaper ( )

Twig_Error_Runtime

Definition at line 141 of file CoreTest.php.

142  {
143  twig_escape_filter(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), 'foo', 'bar');
144  }
Stores the Twig configuration.
Definition: Environment.php:17

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