...
|
...
|
@@ -134,8 +134,12 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
134
|
134
|
*/
|
135
|
135
|
public function testGetAttributeWithTemplateAsObject($useExt)
|
136
|
136
|
{
|
137
|
|
- $template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), $useExt);
|
138
|
|
- $template1 = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()), false);
|
|
137
|
+ // to be removed in 2.0
|
|
138
|
+ $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
|
|
139
|
+ //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
|
|
140
|
+
|
|
141
|
+ $template = new Twig_TemplateTest($twig, $useExt, 'index.twig');
|
|
142
|
+ $template1 = new Twig_TemplateTest($twig, false, 'index1.twig');
|
139
|
143
|
|
140
|
144
|
$this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string'));
|
141
|
145
|
$this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
|
...
|
...
|
@@ -169,6 +173,67 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
169
|
173
|
}
|
170
|
174
|
|
171
|
175
|
/**
|
|
176
|
+ * @group legacy
|
|
177
|
+ * @expectedDeprecation Calling "getString" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
178
|
+ * @expectedDeprecation Calling "getString" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
179
|
+ * @expectedDeprecation Calling "getTrue" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
180
|
+ * @expectedDeprecation Calling "getTrue" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
181
|
+ * @expectedDeprecation Calling "getZero" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
182
|
+ * @expectedDeprecation Calling "getZero" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
183
|
+ * @expectedDeprecation Calling "getEmpty" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
184
|
+ * @expectedDeprecation Calling "getEmpty" on template "index1.twig" from template "index.twig" is deprecated since version 1.28 and won't be supported anymore in 2.0.
|
|
185
|
+ * @expectedDeprecation 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).
|
|
186
|
+ * @expectedDeprecation 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).
|
|
187
|
+ * @expectedDeprecation 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).
|
|
188
|
+ * @expectedDeprecation 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).
|
|
189
|
+ * @expectedDeprecation 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).
|
|
190
|
+ * @expectedDeprecation 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).
|
|
191
|
+ * @expectedDeprecation 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).
|
|
192
|
+ * @expectedDeprecation 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).
|
|
193
|
+ * @expectedDeprecation 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).
|
|
194
|
+ * @expectedDeprecation 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).
|
|
195
|
+ */
|
|
196
|
+ public function testGetAttributeWithTemplateAsObjectForDeprecations()
|
|
197
|
+ {
|
|
198
|
+ // to be removed in 2.0
|
|
199
|
+ $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock());
|
|
200
|
+ //$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface')->getMock());
|
|
201
|
+
|
|
202
|
+ $template = new Twig_TemplateTest($twig, false, 'index.twig');
|
|
203
|
+ $template1 = new Twig_TemplateTest($twig, false, 'index1.twig');
|
|
204
|
+
|
|
205
|
+ $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string'));
|
|
206
|
+ $this->assertEquals('some_string', $template->getAttribute($template1, 'string'));
|
|
207
|
+
|
|
208
|
+ $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true'));
|
|
209
|
+ $this->assertEquals('1', $template->getAttribute($template1, 'true'));
|
|
210
|
+
|
|
211
|
+ $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero'));
|
|
212
|
+ $this->assertEquals('0', $template->getAttribute($template1, 'zero'));
|
|
213
|
+
|
|
214
|
+ $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty'));
|
|
215
|
+ $this->assertSame('', $template->getAttribute($template1, 'empty'));
|
|
216
|
+
|
|
217
|
+ // trigger some deprecation notice messages to check them with @expectedDeprecation
|
|
218
|
+ $template->getAttribute($template, 'renderBlock', array('name', array()));
|
|
219
|
+ $template->getAttribute($template, 'displayBlock', array('name', array()));
|
|
220
|
+ $template->getAttribute($template, 'hasBlock', array('name', array()));
|
|
221
|
+ $template->getAttribute($template, 'render', array(array()));
|
|
222
|
+ $template->getAttribute($template, 'display', array(array()));
|
|
223
|
+
|
|
224
|
+ $template->getAttribute($template1, 'renderBlock', array('name', array()));
|
|
225
|
+ $template->getAttribute($template1, 'displayBlock', array('name', array()));
|
|
226
|
+ $template->getAttribute($template1, 'hasBlock', array('name', array()));
|
|
227
|
+ $template->getAttribute($template1, 'render', array(array()));
|
|
228
|
+ $template->getAttribute($template1, 'display', array(array()));
|
|
229
|
+
|
|
230
|
+ $this->assertFalse($template->getAttribute($template1, 'env', array(), Twig_Template::ANY_CALL, true));
|
|
231
|
+ $this->assertFalse($template->getAttribute($template1, 'environment', array(), Twig_Template::ANY_CALL, true));
|
|
232
|
+ $this->assertFalse($template->getAttribute($template1, 'getEnvironment', array(), Twig_Template::METHOD_CALL, true));
|
|
233
|
+ $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', array(), Twig_Template::METHOD_CALL, true));
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ /**
|
172
|
237
|
* @dataProvider getTestsDependingOnExtensionAvailability
|
173
|
238
|
*/
|
174
|
239
|
public function testGetAttributeOnArrayWithConfusableKey($useExt = false)
|
...
|
...
|
@@ -388,9 +453,9 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
388
|
453
|
|
389
|
454
|
// tests when input is not an array or object
|
390
|
455
|
$tests = array_merge($tests, array(
|
391
|
|
- array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42").'),
|
392
|
|
- array(false, null, 'string', 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string").'),
|
393
|
|
- array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty.'),
|
|
456
|
+ array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42") in "index.twig".'),
|
|
457
|
+ array(false, null, 'string', 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string") in "index.twig".'),
|
|
458
|
+ array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty in "index.twig".'),
|
394
|
459
|
));
|
395
|
460
|
|
396
|
461
|
// add twig_template_get_attributes tests
|
...
|
...
|
@@ -410,12 +475,14 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
|
410
|
475
|
class Twig_TemplateTest extends Twig_Template
|
411
|
476
|
{
|
412
|
477
|
protected $useExtGetAttribute = false;
|
|
478
|
+ private $name;
|
413
|
479
|
|
414
|
|
- public function __construct(Twig_Environment $env, $useExtGetAttribute = false)
|
|
480
|
+ public function __construct(Twig_Environment $env, $useExtGetAttribute = false, $name = 'index.twig')
|
415
|
481
|
{
|
416
|
482
|
parent::__construct($env);
|
417
|
483
|
$this->useExtGetAttribute = $useExtGetAttribute;
|
418
|
484
|
self::$cache = array();
|
|
485
|
+ $this->name = $name;
|
419
|
486
|
}
|
420
|
487
|
|
421
|
488
|
public function getZero()
|
...
|
...
|
@@ -440,6 +507,7 @@ class Twig_TemplateTest extends Twig_Template
|
440
|
507
|
|
441
|
508
|
public function getTemplateName()
|
442
|
509
|
{
|
|
510
|
+ return $this->name;
|
443
|
511
|
}
|
444
|
512
|
|
445
|
513
|
public function getDebugInfo()
|
...
|
...
|
@@ -447,13 +515,9 @@ class Twig_TemplateTest extends Twig_Template
|
447
|
515
|
return array();
|
448
|
516
|
}
|
449
|
517
|
|
450
|
|
- public function getSource()
|
451
|
|
- {
|
452
|
|
- return '';
|
453
|
|
- }
|
454
|
|
-
|
455
|
518
|
protected function doGetParent(array $context)
|
456
|
519
|
{
|
|
520
|
+ return false;
|
457
|
521
|
}
|
458
|
522
|
|
459
|
523
|
protected function doDisplay(array $context, array $blocks = array())
|
...
|
...
|
@@ -688,3 +752,8 @@ class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface
|
688
|
752
|
return 0;
|
689
|
753
|
}
|
690
|
754
|
}
|
|
755
|
+
|
|
756
|
+// to be removed in 2.0
|
|
757
|
+interface Twig_TemplateTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
|
|
758
|
+{
|
|
759
|
+}
|