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

Public Member Functions

 testDisplayBlocksAcceptTemplateOnlyAsBlocks ()
 LogicException More...
 
 testGetAttributeExceptions ($template, $message)
 getAttributeExceptions More...
 
 getAttributeExceptions ()
 
 testGetAttributeWithSandbox ($object, $item, $allowed)
 getGetAttributeWithSandbox More...
 
 getGetAttributeWithSandbox ()
 
 testGetAttributeWithTemplateAsObject ()
 legacy More...
 
 testGetAttributeWithTemplateAsObjectForDeprecations ()
 legacy Calling "string" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. More...
 
 testRenderBlockWithUndefinedBlock ()
 legacy Silent display of undefined block "unknown" in template "index.twig" is deprecated since version 1.29 and will throw an exception in 2.0. More...
 
 testGetAttributeOnArrayWithConfusableKey ()
 
 testGetAttribute ($defined, $value, $object, $item, $arguments, $type)
 getGetAttributeTests More...
 
 testGetAttributeStrict ($defined, $value, $object, $item, $arguments, $type, $exceptionMessage=null)
 getGetAttributeTests More...
 
 testGetAttributeDefined ($defined, $value, $object, $item, $arguments, $type)
 getGetAttributeTests More...
 
 testGetAttributeDefinedStrict ($defined, $value, $object, $item, $arguments, $type)
 getGetAttributeTests More...
 
 testGetAttributeCallExceptions ()
 
 getGetAttributeTests ()
 
 testGetIsMethods ()
 Twig_Error_Runtime More...
 

Detailed Description

Definition at line 11 of file TemplateTest.php.

Member Function Documentation

◆ getAttributeExceptions()

Twig_Tests_TemplateTest::getAttributeExceptions ( )

Definition at line 49 of file TemplateTest.php.

References array.

50  {
51  return array(
52  array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1.'),
53  array('{{ null["a"] }}', 'Impossible to access a key ("a") on a null variable in "%s" at line 1.'),
54  array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1.'),
55  array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1.'),
56  array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1.'),
57  array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1.'),
58  array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1.'),
59  array('{{ null.a }}', 'Impossible to access an attribute ("a") on a null variable in "%s" at line 1.'),
60  array('{{ null.a() }}', 'Impossible to invoke a method ("a") on a null variable in "%s" at line 1.'),
61  array('{{ array.a() }}', 'Impossible to invoke a method ("a") on an array in "%s" at line 1.'),
62  array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1.'),
63  array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1.'),
64  array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1.'),
65  array('{{ array_access.a }}', 'Neither the property "a" nor one of the methods "a()", "geta()"/"isa()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1.'),
66  array('{% from _self import foo %}{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ foo(array_access) }}', 'Neither the property "missing_method" nor one of the methods "missing_method()", "getmissing_method()"/"ismissing_method()" or "__call()" exist and have public access in class "Twig_TemplateArrayAccessObject" in "%s" at line 1.'),
67  array('{{ magic_exception.test }}', 'An exception has been thrown during the rendering of a template ("Hey! Don\'t try to isset me!") in "%s" at line 1.'),
68  array('{{ object["a"] }}', 'Impossible to access a key "a" on an object of class "stdClass" that does not implement ArrayAccess interface in "%s" at line 1.'),
69  );
70  }
Create styles array
The data for the language used.

◆ getGetAttributeTests()

Twig_Tests_TemplateTest::getGetAttributeTests ( )

Definition at line 304 of file TemplateTest.php.

References $test, Twig_TemplateInterface\ANY_CALL, array, Twig_TemplateInterface\ARRAY_CALL, Twig_TemplateInterface\METHOD_CALL, and object.

305  {
306  $array = array(
307  'defined' => 'defined',
308  'zero' => 0,
309  'null' => null,
310  '1' => 1,
311  'bar' => true,
312  'baz' => 'baz',
313  '09' => '09',
314  '+4' => '+4',
315  );
316 
317  $objectArray = new Twig_TemplateArrayAccessObject();
318  $stdObject = (object) $array;
319  $magicPropertyObject = new Twig_TemplateMagicPropertyObject();
320  $propertyObject = new Twig_TemplatePropertyObject();
321  $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator();
322  $propertyObject2 = new Twig_TemplatePropertyObjectAndArrayAccess();
324  $methodObject = new Twig_TemplateMethodObject();
325  $magicMethodObject = new Twig_TemplateMagicMethodObject();
326 
327  $anyType = Twig_Template::ANY_CALL;
328  $methodType = Twig_Template::METHOD_CALL;
329  $arrayType = Twig_Template::ARRAY_CALL;
330 
331  $basicTests = array(
332  // array(defined, value, property to fetch)
333  array(true, 'defined', 'defined'),
334  array(false, null, 'undefined'),
335  array(false, null, 'protected'),
336  array(true, 0, 'zero'),
337  array(true, 1, 1),
338  array(true, 1, 1.0),
339  array(true, null, 'null'),
340  array(true, true, 'bar'),
341  array(true, 'baz', 'baz'),
342  array(true, '09', '09'),
343  array(true, '+4', '+4'),
344  );
345  $testObjects = array(
346  // array(object, type of fetch)
347  array($array, $arrayType),
348  array($objectArray, $arrayType),
349  array($stdObject, $anyType),
350  array($magicPropertyObject, $anyType),
351  array($methodObject, $methodType),
352  array($methodObject, $anyType),
353  array($propertyObject, $anyType),
354  array($propertyObject1, $anyType),
355  array($propertyObject2, $anyType),
356  );
357 
358  $tests = array();
359  foreach ($testObjects as $testObject) {
360  foreach ($basicTests as $test) {
361  // properties cannot be numbers
362  if (($testObject[0] instanceof stdClass || $testObject[0] instanceof Twig_TemplatePropertyObject) && is_numeric($test[2])) {
363  continue;
364  }
365 
366  if ('+4' === $test[2] && $methodObject === $testObject[0]) {
367  continue;
368  }
369 
370  $tests[] = array($test[0], $test[1], $testObject[0], $test[2], array(), $testObject[1]);
371  }
372  }
373 
374  // additional properties tests
375  $tests = array_merge($tests, array(
376  array(true, null, $propertyObject3, 'foo', array(), $anyType),
377  ));
378 
379  // additional method tests
380  $tests = array_merge($tests, array(
381  array(true, 'defined', $methodObject, 'defined', array(), $methodType),
382  array(true, 'defined', $methodObject, 'DEFINED', array(), $methodType),
383  array(true, 'defined', $methodObject, 'getDefined', array(), $methodType),
384  array(true, 'defined', $methodObject, 'GETDEFINED', array(), $methodType),
385  array(true, 'static', $methodObject, 'static', array(), $methodType),
386  array(true, 'static', $methodObject, 'getStatic', array(), $methodType),
387 
388  array(true, '__call_undefined', $magicMethodObject, 'undefined', array(), $methodType),
389  array(true, '__call_UNDEFINED', $magicMethodObject, 'UNDEFINED', array(), $methodType),
390  ));
391 
392  // add the same tests for the any type
393  foreach ($tests as $test) {
394  if ($anyType !== $test[5]) {
395  $test[5] = $anyType;
396  $tests[] = $test;
397  }
398  }
399 
400  $methodAndPropObject = new Twig_TemplateMethodAndPropObject();
401 
402  // additional method tests
403  $tests = array_merge($tests, array(
404  array(true, 'a', $methodAndPropObject, 'a', array(), $anyType),
405  array(true, 'a', $methodAndPropObject, 'a', array(), $methodType),
406  array(false, null, $methodAndPropObject, 'a', array(), $arrayType),
407 
408  array(true, 'b_prop', $methodAndPropObject, 'b', array(), $anyType),
409  array(true, 'b', $methodAndPropObject, 'B', array(), $anyType),
410  array(true, 'b', $methodAndPropObject, 'b', array(), $methodType),
411  array(true, 'b', $methodAndPropObject, 'B', array(), $methodType),
412  array(false, null, $methodAndPropObject, 'b', array(), $arrayType),
413 
414  array(false, null, $methodAndPropObject, 'c', array(), $anyType),
415  array(false, null, $methodAndPropObject, 'c', array(), $methodType),
416  array(false, null, $methodAndPropObject, 'c', array(), $arrayType),
417  ));
418 
419  // tests when input is not an array or object
420  $tests = array_merge($tests, array(
421  array(false, null, 42, 'a', array(), $anyType, 'Impossible to access an attribute ("a") on a integer variable ("42") in "index.twig".'),
422  array(false, null, 'string', 'a', array(), $anyType, 'Impossible to access an attribute ("a") on a string variable ("string") in "index.twig".'),
423  array(false, null, array(), 'a', array(), $anyType, 'Key "a" does not exist as the array is empty in "index.twig".'),
424  ));
425 
426  return $tests;
427  }
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
$test
Definition: Utf8Test.php:84

◆ getGetAttributeWithSandbox()

Twig_Tests_TemplateTest::getGetAttributeWithSandbox ( )

Definition at line 101 of file TemplateTest.php.

References array.

102  {
103  return array(
104  array(new Twig_TemplatePropertyObject(), 'defined', false),
105  array(new Twig_TemplatePropertyObject(), 'defined', true),
106  array(new Twig_TemplateMethodObject(), 'defined', false),
107  array(new Twig_TemplateMethodObject(), 'defined', true),
108  );
109  }
Create styles array
The data for the language used.

◆ testDisplayBlocksAcceptTemplateOnlyAsBlocks()

Twig_Tests_TemplateTest::testDisplayBlocksAcceptTemplateOnlyAsBlocks ( )

LogicException

Definition at line 16 of file TemplateTest.php.

References $template, and array.

17  {
18  $template = $this->getMockForAbstractClass('Twig_Template', array(), '', false);
19  $template->displayBlock('foo', array(), array('foo' => array(new stdClass(), 'foo')));
20  }
$template
Create styles array
The data for the language used.

◆ testGetAttribute()

Twig_Tests_TemplateTest::testGetAttribute (   $defined,
  $value,
  $object,
  $item,
  $arguments,
  $type 
)

getGetAttributeTests

Definition at line 246 of file TemplateTest.php.

References $template, and $type.

247  {
248  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
249 
250  $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
251  }
$template
$type
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeCallExceptions()

Twig_Tests_TemplateTest::testGetAttributeCallExceptions ( )

Definition at line 295 of file TemplateTest.php.

References $template.

296  {
297  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
298 
300 
301  $this->assertNull($template->getAttribute($object, 'foo'));
302  }
$template
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeDefined()

Twig_Tests_TemplateTest::testGetAttributeDefined (   $defined,
  $value,
  $object,
  $item,
  $arguments,
  $type 
)

getGetAttributeTests

Definition at line 278 of file TemplateTest.php.

References $template, and $type.

279  {
280  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
281 
282  $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
283  }
$template
$type
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeDefinedStrict()

Twig_Tests_TemplateTest::testGetAttributeDefinedStrict (   $defined,
  $value,
  $object,
  $item,
  $arguments,
  $type 
)

getGetAttributeTests

Definition at line 288 of file TemplateTest.php.

References $template, $type, and array.

289  {
290  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)));
291 
292  $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
293  }
$template
$type
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeExceptions()

Twig_Tests_TemplateTest::testGetAttributeExceptions (   $template,
  $message 
)

getAttributeExceptions

Definition at line 25 of file TemplateTest.php.

References $env, $message, $template, and array.

26  {
27  $templates = array('index' => $template);
28  $env = new Twig_Environment(new Twig_Loader_Array($templates), array('strict_variables' => true));
29  $template = $env->loadTemplate('index');
30 
31  $context = array(
32  'string' => 'foo',
33  'null' => null,
34  'empty_array' => array(),
35  'array' => array('foo' => 'foo'),
36  'array_access' => new Twig_TemplateArrayAccessObject(),
37  'magic_exception' => new Twig_TemplateMagicPropertyObjectWithException(),
38  'object' => new stdClass(),
39  );
40 
41  try {
42  $template->render($context);
43  $this->fail('Accessing an invalid attribute should throw an exception.');
44  } catch (Twig_Error_Runtime $e) {
45  $this->assertSame(sprintf($message, 'index'), $e->getMessage());
46  }
47  }
$template
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:18
$env
catch(Exception $e) $message
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17
Loads a template from an array.
Definition: Array.php:26

◆ testGetAttributeOnArrayWithConfusableKey()

Twig_Tests_TemplateTest::testGetAttributeOnArrayWithConfusableKey ( )

Definition at line 218 of file TemplateTest.php.

References $template, and array.

219  {
220  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
221 
222  $array = array('Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros');
223 
224  $this->assertSame('Zero', $array[false]);
225  $this->assertSame('One', $array[true]);
226  $this->assertSame('One', $array[1.5]);
227  $this->assertSame('One', $array['1']);
228  $this->assertSame('MinusOne', $array[-1.5]);
229  $this->assertSame('FloatButString', $array['1.5']);
230  $this->assertSame('IntegerButStringWithLeadingZeros', $array['01']);
231  $this->assertSame('EmptyString', $array[null]);
232 
233  $this->assertSame('Zero', $template->getAttribute($array, false), 'false is treated as 0 when accessing an array (equals PHP behavior)');
234  $this->assertSame('One', $template->getAttribute($array, true), 'true is treated as 1 when accessing an array (equals PHP behavior)');
235  $this->assertSame('One', $template->getAttribute($array, 1.5), 'float is casted to int when accessing an array (equals PHP behavior)');
236  $this->assertSame('One', $template->getAttribute($array, '1'), '"1" is treated as integer 1 when accessing an array (equals PHP behavior)');
237  $this->assertSame('MinusOne', $template->getAttribute($array, -1.5), 'negative float is casted to int when accessing an array (equals PHP behavior)');
238  $this->assertSame('FloatButString', $template->getAttribute($array, '1.5'), '"1.5" is treated as-is when accessing an array (equals PHP behavior)');
239  $this->assertSame('IntegerButStringWithLeadingZeros', $template->getAttribute($array, '01'), '"01" is treated as-is when accessing an array (equals PHP behavior)');
240  $this->assertSame('EmptyString', $template->getAttribute($array, null), 'null is treated as "" when accessing an array (equals PHP behavior)');
241  }
$template
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeStrict()

Twig_Tests_TemplateTest::testGetAttributeStrict (   $defined,
  $value,
  $object,
  $item,
  $arguments,
  $type,
  $exceptionMessage = null 
)

getGetAttributeTests

Definition at line 256 of file TemplateTest.php.

References $template, $type, and array.

257  {
258  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)));
259 
260  if ($defined) {
261  $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
262  } else {
263  if (method_exists($this, 'expectException')) {
264  $this->expectException('Twig_Error_Runtime');
265  if (null !== $exceptionMessage) {
266  $this->expectExceptionMessage($exceptionMessage);
267  }
268  } else {
269  $this->setExpectedException('Twig_Error_Runtime', $exceptionMessage);
270  }
271  $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
272  }
273  }
$template
$type
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeWithSandbox()

Twig_Tests_TemplateTest::testGetAttributeWithSandbox (   $object,
  $item,
  $allowed 
)

getGetAttributeWithSandbox

Definition at line 75 of file TemplateTest.php.

References $template, and array.

76  {
77  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
78  $policy = new Twig_Sandbox_SecurityPolicy(array(), array(), array(/*method*/), array(/*prop*/), array());
79  $twig->addExtension(new Twig_Extension_Sandbox($policy, !$allowed));
80  $template = new Twig_TemplateTest($twig);
81 
82  try {
83  $template->getAttribute($object, $item, array(), 'any');
84 
85  if (!$allowed) {
86  $this->fail();
87  } else {
88  $this->addToAssertionCount(1);
89  }
90  } catch (Twig_Sandbox_SecurityError $e) {
91  if ($allowed) {
92  $this->fail();
93  } else {
94  $this->addToAssertionCount(1);
95  }
96 
97  $this->assertContains('is not allowed', $e->getMessage());
98  }
99  }
Exception thrown when a security error occurs at runtime.
$template
Create styles array
The data for the language used.
Represents a security policy which need to be enforced when sandbox mode is enabled.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeWithTemplateAsObject()

Twig_Tests_TemplateTest::testGetAttributeWithTemplateAsObject ( )

legacy

Definition at line 114 of file TemplateTest.php.

References $template, Twig_TemplateInterface\ANY_CALL, array, and Twig_TemplateInterface\METHOD_CALL.

115  {
116  // to be removed in 2.0
117  $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
118  //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
119 
120  $template = new Twig_TemplateTest($twig, 'index.twig');
121  $template1 = new Twig_TemplateTest($twig, 'index1.twig');
122 
123  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string'));
124  $this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
125 
126  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true'));
127  $this->assertEquals('1', $template->getAttribute($template1, 'true'));
128 
129  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero'));
130  $this->assertEquals('0', $template->getAttribute($template1, 'zero'));
131 
132  $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
133  $this->assertSame('', $template->getAttribute($template1, 'empty'));
134 
135  $this->assertFalse($template->getAttribute($template1, 'env', array(), Twig_Template::ANY_CALL, true));
136  $this->assertFalse($template->getAttribute($template1, 'environment', array(), Twig_Template::ANY_CALL, true));
137  $this->assertFalse($template->getAttribute($template1, 'getEnvironment', array(), Twig_Template::METHOD_CALL, true));
138  $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', array(), Twig_Template::METHOD_CALL, true));
139  }
$template
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetAttributeWithTemplateAsObjectForDeprecations()

Twig_Tests_TemplateTest::testGetAttributeWithTemplateAsObjectForDeprecations ( )

legacy Calling "string" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.

Calling "string" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "true" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "true" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "zero" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "zero" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "empty" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "empty" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Calling "renderBlock" on template "index.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use block("name") instead). Calling "displayBlock" on template "index.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use block("name") instead). Calling "hasBlock" on template "index.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use "block("name") is defined" instead). Calling "render" on template "index.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use include("index.twig") instead). Calling "display" on template "index.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use include("index.twig") instead). Calling "renderBlock" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use block("name", template) instead). Calling "displayBlock" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use block("name", template) instead). Calling "hasBlock" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use "block("name", template) is defined" instead). Calling "render" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use include("index1.twig") instead). Calling "display" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0. Use include("index1.twig") instead).

Definition at line 162 of file TemplateTest.php.

References $template, Twig_TemplateInterface\ANY_CALL, array, and Twig_TemplateInterface\METHOD_CALL.

163  {
164  // to be removed in 2.0
165  $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
166  //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
167 
168  $template = new Twig_TemplateTest($twig, 'index.twig');
169  $template1 = new Twig_TemplateTest($twig, 'index1.twig');
170 
171  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string'));
172  $this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
173 
174  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true'));
175  $this->assertEquals('1', $template->getAttribute($template1, 'true'));
176 
177  $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero'));
178  $this->assertEquals('0', $template->getAttribute($template1, 'zero'));
179 
180  $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
181  $this->assertSame('', $template->getAttribute($template1, 'empty'));
182 
183  $blocks = array('name' => array($template1, 'block_name'));
184 
185  // trigger some deprecation notice messages to check them with @expectedDeprecation
186  $template->getAttribute($template, 'renderBlock', array('name', array(), $blocks));
187  $template->getAttribute($template, 'displayBlock', array('name', array(), $blocks));
188  $template->getAttribute($template, 'hasBlock', array('name', array()));
189  $template->getAttribute($template, 'render', array(array()));
190  $template->getAttribute($template, 'display', array(array()));
191 
192  $template->getAttribute($template1, 'renderBlock', array('name', array(), $blocks));
193  $template->getAttribute($template1, 'displayBlock', array('name', array(), $blocks));
194  $template->getAttribute($template1, 'hasBlock', array('name', array()));
195  $template->getAttribute($template1, 'render', array(array()));
196  $template->getAttribute($template1, 'display', array(array()));
197 
198  $this->assertFalse($template->getAttribute($template1, 'env', array(), Twig_Template::ANY_CALL, true));
199  $this->assertFalse($template->getAttribute($template1, 'environment', array(), Twig_Template::ANY_CALL, true));
200  $this->assertFalse($template->getAttribute($template1, 'getEnvironment', array(), Twig_Template::METHOD_CALL, true));
201  $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', array(), Twig_Template::METHOD_CALL, true));
202  }
$template
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testGetIsMethods()

Twig_Tests_TemplateTest::testGetIsMethods ( )

Twig_Error_Runtime

Definition at line 432 of file TemplateTest.php.

References $template, and array.

433  {
434  $getIsObject = new Twig_TemplateGetIsMethods();
435  $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)));
436  // first time should not create a cache for "get"
437  $this->assertNull($template->getAttribute($getIsObject, 'get'));
438  // 0 should be in the method cache now, so this should fail
439  $this->assertNull($template->getAttribute($getIsObject, 0));
440  }
$template
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

◆ testRenderBlockWithUndefinedBlock()

Twig_Tests_TemplateTest::testRenderBlockWithUndefinedBlock ( )

legacy Silent display of undefined block "unknown" in template "index.twig" is deprecated since version 1.29 and will throw an exception in 2.0.

Use the "block('unknown') is defined" expression to test for block existence. Silent display of undefined block "unknown" in template "index.twig" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block('unknown') is defined" expression to test for block existence.

Definition at line 209 of file TemplateTest.php.

References $template, and array.

210  {
211  $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
212 
213  $template = new Twig_TemplateTest($twig, 'index.twig');
214  $template->renderBlock('unknown', array());
215  $template->displayBlock('unknown', array());
216  }
$template
Create styles array
The data for the language used.
Stores the Twig configuration.
Definition: Environment.php:17

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