summaryrefslogtreecommitdiff
path: root/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php
blob: d3d489ee57d340a17652828d3522450156ef128f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
 * Smarty PHPunit tests of delimiter
 *

 * @author  Uwe Tews
 */

/**
 * class for delimiter tests
 *
 * 
 * 
 *
 */
class DelimiterTest extends PHPUnit_Smarty
{
    public function setUp(): void
    {
        $this->setUpSmarty(__DIR__);
    }


    /**
     * test <{ }> delimiter
     */
    public function testDelimiter1()
    {
        $this->smarty->setLeftDelimiter('<{');
        $this->smarty->setRightDelimiter('}>');
        $tpl = $this->smarty->createTemplate('eval:start <{* comment *}>hello <{if true}><{"world"}><{/if}> end');
        $this->assertEquals("start hello world end", $this->smarty->fetch($tpl));
    }
    /**
     * test <{ }> delimiter
     */
    public function testDelimiter10()
    {
        $this->smarty->setLeftDelimiter('<');
        $this->smarty->setRightDelimiter('>');
        $tpl = $this->smarty->createTemplate('eval:start <* comment *>hello <if 1 < 2><"world"></if> end');
        $this->assertEquals("start hello world end", $this->smarty->fetch($tpl));
    }

    /**
     * test <-{ }-> delimiter
     */
    public function testDelimiter2()
    {
        $this->smarty->setLeftDelimiter('<-{');
        $this->smarty->setRightDelimiter('}->');
        $tpl = $this->smarty->createTemplate('eval:<-<-{* comment *}-><-{if true}-><-{"hello world"}-><-{/if}->->');
        $this->assertEquals("<-hello world->", $this->smarty->fetch($tpl));
    }

    /**
     * test <--{ }--> delimiter
     */
    public function testDelimiter3()
    {
        $this->smarty->setLeftDelimiter('<--{');
        $this->smarty->setRightDelimiter('}-->');
        $tpl = $this->smarty->createTemplate('eval:<--{* comment *}--><--{if true}--><--{"hello world"}--><--{/if}-->');
        $this->assertEquals("hello world", $this->smarty->fetch($tpl));
    }

    /**
     * test {{ }} delimiter
     */
    public function testDelimiter4()
    {
        $this->smarty->setLeftDelimiter('{{');
        $this->smarty->setRightDelimiter('}}');
        $tpl = $this->smarty->createTemplate('eval:{{* comment *}}{{if true}}{{"hello world"}}{{/if}}');
        $this->assertEquals("hello world", $this->smarty->fetch($tpl));
    }

    /**
     * test {= =} delimiter for conficts with option flags
     */
    public function testDelimiter5()
    {
        $this->smarty->setLeftDelimiter('{=');
        $this->smarty->setRightDelimiter('=}');
        $tpl = $this->smarty->createTemplate('eval:{=assign var=foo value="hello world" nocache=}{=$foo=}');
        $this->assertEquals("hello world", $this->smarty->fetch($tpl));
    }
    /**
     * test {= =} delimiter for conficts with option flags
     */
    public function testDelimiterIssue450()
    {
        $this->smarty->setLeftDelimiter('{^');
        $this->smarty->setRightDelimiter('^}');
        $tpl = $this->smarty->createTemplate('eval:{^assign var=foo value="hello world" nocache^}{^$foo^}');
        $this->assertEquals("hello world", $this->smarty->fetch($tpl));
    }
}