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

Public Member Functions

 testErrorWithObjectFilename ()
 
 testErrorWithArrayFilename ()
 
 testTwigExceptionGuessWithMissingVarAndArrayLoader ()
 
 testTwigExceptionGuessWithExceptionAndArrayLoader ()
 
 testTwigExceptionGuessWithMissingVarAndFilesystemLoader ()
 
 testTwigExceptionGuessWithExceptionAndFilesystemLoader ()
 
 testTwigExceptionAddsFileAndLine ($templates, $name, $line)
 @dataProvider getErroredTemplates More...
 
 getErroredTemplates ()
 

Detailed Description

Definition at line 12 of file ErrorTest.php.

Member Function Documentation

◆ getErroredTemplates()

Twig_Tests_ErrorTest::getErroredTemplates ( )

Definition at line 155 of file ErrorTest.php.

156 {
157 return array(
158 // error occurs in a template
159 array(
160 array(
161 'index' => "\n\n{{ foo.bar }}\n\n\n{{ 'foo' }}",
162 ),
163 'index', 3,
164 ),
165
166 // error occurs in an included template
167 array(
168 array(
169 'index' => "{% include 'partial' %}",
170 'partial' => '{{ foo.bar }}',
171 ),
172 'partial', 1,
173 ),
174
175 // error occurs in a parent block when called via parent()
176 array(
177 array(
178 'index' => "{% extends 'base' %}
179 {% block content %}
180 {{ parent() }}
181 {% endblock %}",
182 'base' => '{% block content %}{{ foo.bar }}{% endblock %}',
183 ),
184 'base', 1,
185 ),
186
187 // error occurs in a block from the child
188 array(
189 array(
190 'index' => "{% extends 'base' %}
191 {% block content %}
192 {{ foo.bar }}
193 {% endblock %}
194 {% block foo %}
195 {{ foo.bar }}
196 {% endblock %}",
197 'base' => '{% block content %}{% endblock %}',
198 ),
199 'index', 3,
200 ),
201 );
202 }

◆ testErrorWithArrayFilename()

Twig_Tests_ErrorTest::testErrorWithArrayFilename ( )

Definition at line 22 of file ErrorTest.php.

23 {
24 $error = new Twig_Error('foo');
25 $error->setSourceContext(new Twig_Source('', array('foo' => 'bar')));
26
27 $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
28 }
Twig base exception.
Definition: Error.php:35
Holds information about a non-compiled Twig template.
Definition: Source.php:20
$error
Definition: Error.php:17

References $error.

◆ testErrorWithObjectFilename()

Twig_Tests_ErrorTest::testErrorWithObjectFilename ( )

Definition at line 14 of file ErrorTest.php.

15 {
16 $error = new Twig_Error('foo');
17 $error->setSourceContext(new Twig_Source('', new SplFileInfo(__FILE__)));
18
19 $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
20 }

References $error.

◆ testTwigExceptionAddsFileAndLine()

Twig_Tests_ErrorTest::testTwigExceptionAddsFileAndLine (   $templates,
  $name,
  $line 
)

@dataProvider getErroredTemplates

Definition at line 127 of file ErrorTest.php.

128 {
129 $loader = new Twig_Loader_Array($templates);
130 $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
131
132 $template = $twig->loadTemplate('index');
133
134 try {
135 $template->render(array());
136
137 $this->fail();
138 } catch (Twig_Error_Runtime $e) {
139 $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage());
140 $this->assertEquals($line, $e->getTemplateLine());
141 $this->assertEquals($name, $e->getSourceContext()->getName());
142 }
143
144 try {
145 $template->render(array('foo' => new Twig_Tests_ErrorTest_Foo()));
146
147 $this->fail();
148 } catch (Twig_Error_Runtime $e) {
149 $this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage());
150 $this->assertEquals($line, $e->getTemplateLine());
151 $this->assertEquals($name, $e->getSourceContext()->getName());
152 }
153 }
sprintf('%.4f', $callTime)
Stores the Twig configuration.
Definition: Environment.php:18
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:19
getSourceContext()
Gets the source context of the Twig template where the error occurred.
Definition: Error.php:191
getTemplateLine()
Gets the template line where the error occurred.
Definition: Error.php:169
Loads a template from an array.
Definition: Array.php:27
$template
if($format !==null) $name
Definition: metadata.php:146

References $loader, $name, $template, Twig_Error\getSourceContext(), Twig_Error\getTemplateLine(), and sprintf.

+ Here is the call graph for this function:

◆ testTwigExceptionGuessWithExceptionAndArrayLoader()

Twig_Tests_ErrorTest::testTwigExceptionGuessWithExceptionAndArrayLoader ( )

Definition at line 58 of file ErrorTest.php.

59 {
60 $loader = new Twig_Loader_Array(array(
61 'base.html' => '{% block content %}{% endblock %}',
62 'index.html' => <<<EOHTML
63{% extends 'base.html' %}
64{% block content %}
65 {{ foo.bar }}
66{% endblock %}
67{% block foo %}
68 {{ foo.bar }}
69{% endblock %}
70EOHTML
71 ));
72 $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
73
74 $template = $twig->loadTemplate('index.html');
75 try {
76 $template->render(array('foo' => new Twig_Tests_ErrorTest_Foo()));
77
78 $this->fail();
79 } catch (Twig_Error_Runtime $e) {
80 $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage());
81 $this->assertEquals(3, $e->getTemplateLine());
82 $this->assertEquals('index.html', $e->getSourceContext()->getName());
83 }
84 }

References $loader, $template, Twig_Error\getSourceContext(), and Twig_Error\getTemplateLine().

+ Here is the call graph for this function:

◆ testTwigExceptionGuessWithExceptionAndFilesystemLoader()

Twig_Tests_ErrorTest::testTwigExceptionGuessWithExceptionAndFilesystemLoader ( )

Definition at line 105 of file ErrorTest.php.

106 {
107 $loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors');
108 $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
109
110 $template = $twig->loadTemplate('index.html');
111 try {
112 $template->render(array('foo' => new Twig_Tests_ErrorTest_Foo()));
113
114 $this->fail();
115 } catch (Twig_Error_Runtime $e) {
116 $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
117 $this->assertEquals(3, $e->getTemplateLine());
118 $this->assertEquals('index.html', $e->getSourceContext()->getName());
119 $this->assertEquals(3, $e->getLine());
120 $this->assertEquals(strtr(dirname(__FILE__).'/Fixtures/errors/index.html', '/', DIRECTORY_SEPARATOR), $e->getFile());
121 }
122 }
Loads template from the filesystem.
Definition: Filesystem.php:18

References $loader, $template, Twig_Error\getSourceContext(), and Twig_Error\getTemplateLine().

+ Here is the call graph for this function:

◆ testTwigExceptionGuessWithMissingVarAndArrayLoader()

Twig_Tests_ErrorTest::testTwigExceptionGuessWithMissingVarAndArrayLoader ( )

Definition at line 30 of file ErrorTest.php.

31 {
32 $loader = new Twig_Loader_Array(array(
33 'base.html' => '{% block content %}{% endblock %}',
34 'index.html' => <<<EOHTML
35{% extends 'base.html' %}
36{% block content %}
37 {{ foo.bar }}
38{% endblock %}
39{% block foo %}
40 {{ foo.bar }}
41{% endblock %}
42EOHTML
43 ));
44 $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
45
46 $template = $twig->loadTemplate('index.html');
47 try {
48 $template->render(array());
49
50 $this->fail();
51 } catch (Twig_Error_Runtime $e) {
52 $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage());
53 $this->assertEquals(3, $e->getTemplateLine());
54 $this->assertEquals('index.html', $e->getSourceContext()->getName());
55 }
56 }

References $loader, $template, Twig_Error\getSourceContext(), and Twig_Error\getTemplateLine().

+ Here is the call graph for this function:

◆ testTwigExceptionGuessWithMissingVarAndFilesystemLoader()

Twig_Tests_ErrorTest::testTwigExceptionGuessWithMissingVarAndFilesystemLoader ( )

Definition at line 86 of file ErrorTest.php.

87 {
88 $loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors');
89 $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
90
91 $template = $twig->loadTemplate('index.html');
92 try {
93 $template->render(array());
94
95 $this->fail();
96 } catch (Twig_Error_Runtime $e) {
97 $this->assertEquals('Variable "foo" does not exist.', $e->getMessage());
98 $this->assertEquals(3, $e->getTemplateLine());
99 $this->assertEquals('index.html', $e->getSourceContext()->getName());
100 $this->assertEquals(3, $e->getLine());
101 $this->assertEquals(strtr(dirname(__FILE__).'/Fixtures/errors/index.html', '/', DIRECTORY_SEPARATOR), $e->getFile());
102 }
103 }

References $loader, $template, Twig_Error\getSourceContext(), and Twig_Error\getTemplateLine().

+ Here is the call graph for this function:

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