summaryrefslogtreecommitdiff
path: root/tests/UnitTests/TemplateSource/ValueTests/DoubleQuoted/DoubleQuotedStringTest.php
blob: d3ea8e5ce056c1ca26c7aeeb401254e13268bd7d (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
<?php
/**
 * Smarty PHPunit tests double quoted strings
 *

 * @author  Uwe Tews
 */

/**
 * class for double quoted string tests
 *
 * 
 * 
 * 
*/
class DoubleQuotedStringTest extends PHPUnit_Smarty
{
    public function setUp(): void
    {
        $this->setUpSmarty(__DIR__);
    }

    /**
     * Test double qouted strings
     *
     * 
     * @dataProvider        dataTestDoubleQuoted
     */
    public function testDoubleQuoted($code, $result, $testName, $testNumber)
    {
        $name = empty($testName) ? $testNumber : $testName;
        $file = "testDoubleQuotes_{$name}.tpl";
        $this->makeTemplateFile($file, $code);
        $this->smarty->assignGlobal('file', $file);
        $this->smarty->assign('bar', 'buh');
        $this->assertEquals($result, $this->smarty->fetch($file),
                            "testDoubleQuoted - {$code} - {$name}");
    }

    /*
      * Data provider für testDoubleQuoted
      */
    public function dataTestDoubleQuoted()
    {
        $i = 1;
        /*
                    * Code
                    * result
                    * test name
                    * test number
                    */
        return array(array('{$foo="Hello World"}{$foo}', 'Hello World', 'simple', $i ++),
                     array('{$bar=1}{$foo="Hello {$bar+2} World"}{$foo}', 'Hello 3 World', 'withExpression', $i ++),
                     array('{$bar=\'blah\'}{$foo="Hello $bar World"}{$foo}', 'Hello blah World', 'withVariable', $i ++),
                     array('{$bar=\'blah\'}{$buh=\'wow\'}{$foo="Hello $bar$buh World"}{$foo}', 'Hello blahwow World', 'with2Variables', $i ++),
                     array('{$bar=\'blah\'}{$foo="Hello `$bar`.test World"}{$foo}', 'Hello blah.test World', 'withVarBacktick', $i ++),
                     array('{$bar=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar``$buh`.test World"}{$foo}', 'Hello blahbuh.test World', 'with2VarBacktick', $i ++),
                     array('{$barbuh=\'blah\'}{$buh=\'buh\'}{$foo="Hello `$bar{$buh}`.test World"}{$foo}', 'Hello blah.test World', 'withVariableVarBacktick', $i ++),
                     array('{$bar[1][2]=\'blah\'}{$foo="Hello `$bar.1.2`.test World"}{$foo}', 'Hello blah.test World', 'withVarIndexSmartyBacktick', $i ++),
                     array('{$bar[1][2]=\'blah\'}{$foo="Hello `$bar[1][2]`.test World"}{$foo}', 'Hello blah.test World', 'withVarIndexPhPBacktick', $i ++),
                     array('{$a=1}{"`$a+1`"}', '2', 'withExpressionBacktick', $i ++),
                     array('{$foo="Hello {counter start=3} World"}{$foo}', 'Hello 3 World', 'withCounterTag', $i ++),
                     array('{$foo="Hello {counter start=2}{counter} World"}{$foo}', 'Hello 23 World', 'with2CounterTag', $i ++),
                     array('{$x=1}{$y=2}{$z=true}{"Hello{if $z} {$x} {else}{$y}{/if}World"}', 'Hello 1 World', 'withIfTag', $i ++),
                     array('{$bar=\'blah\'}{$foo="Hello {$bar}.test World"}{$foo}', 'Hello blah.test World', 'withDelimiter', $i ++),
                     array('{$foo="Hello \" World"}{$foo}', 'Hello " World', 'escaped', $i ++),
                     array('{$foo="Hello \'World\'"}{$foo}', 'Hello \'World\'', 'withSingleQuotes', $i ++),
                     array('{$foo="Hello {\'World\'} Test"}{$foo}', 'Hello World Test', 'withSingleQuoteTag', $i ++),
                     array('{$foo=""}{$foo}', '', 'empty', $i ++),
        );
    }


    /**
     * test unclosed block tag
     */
    public function testDoubleQuotedUnclosedBlock_001()
    {
        $this->expectException(\Smarty\CompilerException::class);
        $this->expectExceptionMessage('unclosed \'{if}\' in doubled quoted string');
        $this->smarty->fetch('001_unclosedBlock.tpl');
    }

    /**
     *
     * test closed block tag
     * {"{if true}hello world{/if}"}
     *
     */
    public function testDoubleQuotedClosedBlock_001()
    {
        $this->assertEquals('hello world', $this->smarty->fetch('001_closedBlock.tpl'));
    }

}