ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TemplateWrapperTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase
12{
13 public function testHasGetBlocks()
14 {
15 $twig = new Twig_Environment(new Twig_Loader_Array(array(
16 'index' => '{% block foo %}{% endblock %}',
17 'index_with_use' => '{% use "imported" %}{% block foo %}{% endblock %}',
18 'index_with_extends' => '{% extends "extended" %}{% block foo %}{% endblock %}',
19 'imported' => '{% block imported %}{% endblock %}',
20 'extended' => '{% block extended %}{% endblock %}',
21 )));
22
23 $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
24 $this->assertTrue($wrapper->hasBlock('foo'));
25 $this->assertFalse($wrapper->hasBlock('bar'));
26 $this->assertEquals(array('foo'), $wrapper->getBlockNames());
27
28 $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_use'));
29 $this->assertTrue($wrapper->hasBlock('foo'));
30 $this->assertTrue($wrapper->hasBlock('imported'));
31 $this->assertEquals(array('imported', 'foo'), $wrapper->getBlockNames());
32
33 $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index_with_extends'));
34 $this->assertTrue($wrapper->hasBlock('foo'));
35 $this->assertTrue($wrapper->hasBlock('extended'));
36 $this->assertEquals(array('foo', 'extended'), $wrapper->getBlockNames());
37 }
38
39 public function testRenderBlock()
40 {
41 $twig = new Twig_Environment(new Twig_Loader_Array(array(
42 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}',
43 )));
44 $twig->addGlobal('bar', 'BAR');
45
46 $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
47 $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', array('foo' => 'FOO')));
48 }
49
50 public function testDisplayBlock()
51 {
52 $twig = new Twig_Environment(new Twig_Loader_Array(array(
53 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}',
54 )));
55 $twig->addGlobal('bar', 'BAR');
56
57 $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index'));
58
59 ob_start();
60 $wrapper->displayBlock('foo', array('foo' => 'FOO'));
61
62 $this->assertEquals('FOOBAR', ob_get_clean());
63 }
64}
An exception for terminatinating execution or to throw for unit testing.
Stores the Twig configuration.
Definition: Environment.php:18
Loads a template from an array.
Definition: Array.php:27
Exposes a template to userland.