use load() instead of loadTemplate() in tests

This commit is contained in:
Fabien Potencier
2019-03-11 18:39:46 +01:00
parent c82d7dcaab
commit e2103c87ae
12 changed files with 46 additions and 46 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ final class TemplateWrapper
{ {
// using func_get_args() allows to not expose the blocks argument // using func_get_args() allows to not expose the blocks argument
// as it should only be used by internal code // as it should only be used by internal code
$this->template->display($context, \func_num_args() >= 1 ? func_get_arg(1) : []); $this->template->display($context, \func_num_args() > 1 ? func_get_arg(1) : []);
} }
/** /**
+1 -1
View File
@@ -188,7 +188,7 @@ abstract class IntegrationTestCase extends TestCase
$p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_');
try { try {
$template = $twig->loadTemplate('index.twig'); $template = $twig->load('index.twig');
} catch (\Exception $e) { } catch (\Exception $e) {
if (false !== $exception) { if (false !== $exception) {
$message = $e->getMessage(); $message = $e->getMessage();
+5 -5
View File
@@ -50,7 +50,7 @@ EOHTML
]); ]);
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html'); $template = $twig->load('index.html');
try { try {
$template->render([]); $template->render([]);
@@ -78,7 +78,7 @@ EOHTML
]); ]);
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html'); $template = $twig->load('index.html');
try { try {
$template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]);
@@ -95,7 +95,7 @@ EOHTML
$loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors');
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html'); $template = $twig->load('index.html');
try { try {
$template->render([]); $template->render([]);
@@ -114,7 +114,7 @@ EOHTML
$loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors');
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index.html'); $template = $twig->load('index.html');
try { try {
$template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]);
@@ -136,7 +136,7 @@ EOHTML
$loader = new ArrayLoader($templates); $loader = new ArrayLoader($templates);
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
$template = $twig->loadTemplate('index'); $template = $twig->load('index');
try { try {
$template->render([]); $template->render([]);
+24 -24
View File
@@ -53,20 +53,20 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
public function testSandboxWithInheritance() public function testSandboxWithInheritance()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, ['block']); $twig = $this->getEnvironment(true, [], self::$templates, ['block']);
$twig->loadTemplate('1_child')->render([]); $twig->load('1_child')->render([]);
} }
public function testSandboxGloballySet() public function testSandboxGloballySet()
{ {
$twig = $this->getEnvironment(false, [], self::$templates); $twig = $this->getEnvironment(false, [], self::$templates);
$this->assertEquals('FOO', $twig->loadTemplate('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally'); $this->assertEquals('FOO', $twig->load('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally');
} }
public function testSandboxUnallowedMethodAccessor() public function testSandboxUnallowedMethodAccessor()
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic1')->render(self::$params); $twig->load('1_basic1')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
@@ -79,7 +79,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic2')->render(self::$params); $twig->load('1_basic2')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
@@ -91,7 +91,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic3')->render(self::$params); $twig->load('1_basic3')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
@@ -103,7 +103,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic4')->render(self::$params); $twig->load('1_basic4')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError');
@@ -116,7 +116,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic5')->render(self::$params); $twig->load('1_basic5')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
@@ -129,7 +129,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic6')->render(self::$params); $twig->load('1_basic6')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
@@ -142,7 +142,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_basic7')->render(self::$params); $twig->load('1_basic7')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
@@ -154,7 +154,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('1_range_operator')->render(self::$params); $twig->load('1_range_operator')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called'); $this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
@@ -166,7 +166,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => 'foo']); $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => 'foo']);
FooObject::reset(); FooObject::reset();
$this->assertEquals('foo', $twig->loadTemplate('1_basic1')->render(self::$params), 'Sandbox allow some methods'); $this->assertEquals('foo', $twig->load('1_basic1')->render(self::$params), 'Sandbox allow some methods');
$this->assertEquals(1, FooObject::$called['foo'], 'Sandbox only calls method once'); $this->assertEquals(1, FooObject::$called['foo'], 'Sandbox only calls method once');
} }
@@ -174,7 +174,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => '__toString']); $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => '__toString']);
FooObject::reset(); FooObject::reset();
$this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods'); $this->assertEquals('foo', $twig->load('1_basic5')->render(self::$params), 'Sandbox allow some methods');
$this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once');
} }
@@ -182,38 +182,38 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
{ {
$twig = $this->getEnvironment(false, [], self::$templates); $twig = $this->getEnvironment(false, [], self::$templates);
FooObject::reset(); FooObject::reset();
$this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); $this->assertEquals('foo', $twig->load('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled');
$this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once');
} }
public function testSandboxAllowFilter() public function testSandboxAllowFilter()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], ['upper']); $twig = $this->getEnvironment(true, [], self::$templates, [], ['upper']);
$this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters'); $this->assertEquals('FABIEN', $twig->load('1_basic2')->render(self::$params), 'Sandbox allow some filters');
} }
public function testSandboxAllowTag() public function testSandboxAllowTag()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, ['if']); $twig = $this->getEnvironment(true, [], self::$templates, ['if']);
$this->assertEquals('foo', $twig->loadTemplate('1_basic3')->render(self::$params), 'Sandbox allow some tags'); $this->assertEquals('foo', $twig->load('1_basic3')->render(self::$params), 'Sandbox allow some tags');
} }
public function testSandboxAllowProperty() public function testSandboxAllowProperty()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], ['FooObject' => 'bar']); $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], ['FooObject' => 'bar']);
$this->assertEquals('bar', $twig->loadTemplate('1_basic4')->render(self::$params), 'Sandbox allow some properties'); $this->assertEquals('bar', $twig->load('1_basic4')->render(self::$params), 'Sandbox allow some properties');
} }
public function testSandboxAllowFunction() public function testSandboxAllowFunction()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['cycle']); $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['cycle']);
$this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions'); $this->assertEquals('bar', $twig->load('1_basic7')->render(self::$params), 'Sandbox allow some functions');
} }
public function testSandboxAllowRangeOperator() public function testSandboxAllowRangeOperator()
{ {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['range']); $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['range']);
$this->assertEquals('1', $twig->loadTemplate('1_range_operator')->render(self::$params), 'Sandbox allow the range operator'); $this->assertEquals('1', $twig->load('1_range_operator')->render(self::$params), 'Sandbox allow the range operator');
} }
public function testSandboxAllowFunctionsCaseInsensitive() public function testSandboxAllowFunctionsCaseInsensitive()
@@ -221,10 +221,10 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
foreach (['getfoobar', 'getFoobar', 'getFooBar'] as $name) { foreach (['getfoobar', 'getFoobar', 'getFooBar'] as $name) {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => $name]); $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => $name]);
FooObject::reset(); FooObject::reset();
$this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way'); $this->assertEquals('foobarfoobar', $twig->load('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way');
$this->assertEquals(2, FooObject::$called['getFooBar'], 'Sandbox only calls method once'); $this->assertEquals(2, FooObject::$called['getFooBar'], 'Sandbox only calls method once');
$this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)'); $this->assertEquals('foobarfoobar', $twig->load('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)');
} }
} }
@@ -236,7 +236,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
]; ];
$twig = $this->getEnvironment(false, [], self::$templates); $twig = $this->getEnvironment(false, [], self::$templates);
$this->assertEquals('fooFOOfoo', $twig->loadTemplate('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include'); $this->assertEquals('fooFOOfoo', $twig->load('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include');
self::$templates = [ self::$templates = [
'3_basic' => '{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}', '3_basic' => '{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}',
@@ -245,7 +245,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
$twig = $this->getEnvironment(true, [], self::$templates); $twig = $this->getEnvironment(true, [], self::$templates);
try { try {
$twig->loadTemplate('3_basic')->render(self::$params); $twig->load('3_basic')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed');
} catch (SecurityError $e) { } catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
@@ -264,7 +264,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
EOF EOF
], ['macro', 'import'], ['escape']); ], ['macro', 'import'], ['escape']);
$this->assertEquals('<p>username</p>', $twig->loadTemplate('index')->render([])); $this->assertEquals('<p>username</p>', $twig->load('index')->render([]));
} }
public function testSandboxDisabledAfterIncludeFunctionError() public function testSandboxDisabledAfterIncludeFunctionError()
@@ -273,7 +273,7 @@ EOF
$e = null; $e = null;
try { try {
$twig->loadTemplate('1_include')->render(self::$params); $twig->load('1_include')->render(self::$params);
} catch (\Throwable $e) { } catch (\Throwable $e) {
} catch (\Exception $e) { } catch (\Exception $e) {
} }
@@ -12,7 +12,7 @@
--DATA-- --DATA--
return [ return [
'included_loaded' => $twig->load('included.twig'), 'included_loaded' => $twig->load('included.twig'),
'included_loaded_internal' => $twig->loadTemplate('included.twig'), 'included_loaded_internal' => $twig->load('included.twig'),
] ]
--EXPECT-- --EXPECT--
FOO FOO
@@ -5,6 +5,6 @@
--TEMPLATE(foo.twig)-- --TEMPLATE(foo.twig)--
BAR BAR
--DATA-- --DATA--
return ['foo' => $twig->loadTemplate('foo.twig')] return ['foo' => $twig->load('foo.twig')]
--EXPECT-- --EXPECT--
BAR FOO BAR FOO
@@ -1,10 +1,10 @@
--TEST-- --TEST--
"include" tag accepts Twig_Template instance "include" tag accepts \Twig\TemplateWrapper instance
--TEMPLATE-- --TEMPLATE--
{% include foo %} FOO {% include foo %} FOO
--TEMPLATE(foo.twig)-- --TEMPLATE(foo.twig)--
BAR BAR
--DATA-- --DATA--
return ['foo' => $twig->loadTemplate('foo.twig')] return ['foo' => $twig->load('foo.twig')]
--EXPECT-- --EXPECT--
BAR FOO BAR FOO
@@ -9,6 +9,6 @@
--TEMPLATE(foo.twig)-- --TEMPLATE(foo.twig)--
{% block content %}BAR{% endblock %} {% block content %}BAR{% endblock %}
--DATA-- --DATA--
return ['foo' => $twig->loadTemplate('foo.twig')] return ['foo' => $twig->load('foo.twig')]
--EXPECT-- --EXPECT--
BARFOO BARFOO
@@ -9,7 +9,7 @@
--DATA-- --DATA--
return [ return [
'included_loaded' => $twig->load('included.twig'), 'included_loaded' => $twig->load('included.twig'),
'included_loaded_internal' => $twig->loadTemplate('included.twig'), 'included_loaded_internal' => $twig->load('included.twig'),
] ]
--EXPECT-- --EXPECT--
ok ok
+3 -3
View File
@@ -182,10 +182,10 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase
$twig = new Environment($loader); $twig = new Environment($loader);
$template = $twig->loadTemplate('blocks.html.twig'); $template = $twig->load('blocks.html.twig');
$this->assertSame('block from theme 1', $template->renderBlock('b1', [])); $this->assertSame('block from theme 1', $template->renderBlock('b1', []));
$template = $twig->loadTemplate('blocks.html.twig'); $template = $twig->load('blocks.html.twig');
$this->assertSame('block from theme 2', $template->renderBlock('b2', [])); $this->assertSame('block from theme 2', $template->renderBlock('b2', []));
} }
@@ -211,7 +211,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase
$twig = new Environment($loader); $twig = new Environment($loader);
$template = $twig->loadTemplate($templateName); $template = $twig->load($templateName);
$this->assertSame('VALID Child', $template->renderBlock('body', [])); $this->assertSame('VALID Child', $template->renderBlock('body', []));
} }
+1 -1
View File
@@ -39,7 +39,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase
{ {
$templates = ['index' => $template]; $templates = ['index' => $template];
$env = new Environment(new ArrayLoader($templates), ['strict_variables' => true]); $env = new Environment(new ArrayLoader($templates), ['strict_variables' => true]);
$template = $env->loadTemplate('index'); $template = $env->load('index');
$context = [ $context = [
'string' => 'foo', 'string' => 'foo',
+5 -5
View File
@@ -25,17 +25,17 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase
'extended' => '{% block extended %}{% endblock %}', 'extended' => '{% block extended %}{% endblock %}',
])); ]));
$wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); $wrapper = $twig->load('index');
$this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('foo'));
$this->assertFalse($wrapper->hasBlock('bar')); $this->assertFalse($wrapper->hasBlock('bar'));
$this->assertEquals(['foo'], $wrapper->getBlockNames()); $this->assertEquals(['foo'], $wrapper->getBlockNames());
$wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); $wrapper = $twig->load('index_with_use');
$this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('foo'));
$this->assertTrue($wrapper->hasBlock('imported')); $this->assertTrue($wrapper->hasBlock('imported'));
$this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames()); $this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames());
$wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); $wrapper = $twig->load('index_with_extends');
$this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('foo'));
$this->assertTrue($wrapper->hasBlock('extended')); $this->assertTrue($wrapper->hasBlock('extended'));
$this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames()); $this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames());
@@ -48,7 +48,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase
])); ]));
$twig->addGlobal('bar', 'BAR'); $twig->addGlobal('bar', 'BAR');
$wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); $wrapper = $twig->load('index');
$this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO'])); $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO']));
} }
@@ -59,7 +59,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase
])); ]));
$twig->addGlobal('bar', 'BAR'); $twig->addGlobal('bar', 'BAR');
$wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); $wrapper = $twig->load('index');
ob_start(); ob_start();
$wrapper->displayBlock('foo', ['foo' => 'FOO']); $wrapper->displayBlock('foo', ['foo' => 'FOO']);