summaryrefslogtreecommitdiff
path: root/tests/UnitTests/TemplateSource/Spacing/SpacingTest.php
blob: eeb4477b03e391c59f403d69621334c3d0b8e39b (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
<?php
/**
 * Smarty PHPunit tests spacing in template output
 *

 * @author  Uwe Tews
 */

/**
 * class for spacing test
 *
 * 
 * @preserveGlobalState    disabled
 * 
 */
class SpacingTest extends PHPUnit_Smarty
{
    public function setUp(): void
    {
        $this->setUpSmarty(__DIR__);
    }


    /**
     * Test spacings
     *
     * 
     * @dataProvider        dataTestSpacing
     * 
     */
    public function testSpacing($code, $result, $testName, $testNumber)
    {
        $name = empty($testName) ? $testNumber : $testName;
        $file = "Spacing_{$name}.tpl";
        $this->makeTemplateFile($file, $code);
        $this->smarty->assign('file', $file);
        $this->smarty->assign('foo', 'bar');
        $this->assertEquals($result,
                            $this->smarty->fetch($file),
                            $file);
    }

    /*
      * Data provider für testSpacing
      */
    public function dataTestSpacing()
    {
        $i = 1;
        /*
                    * Code
                    * result
                    * test name
                    * test number
                    */
        return array(array('{$foo}', 'bar', 'T1', $i++),
                     array('{$foo}{$foo}', 'barbar', 'T2', $i++),
                     array('A{$foo}{$foo}B', 'AbarbarB', 'T3', $i++),
                     array('{$foo} {$foo}', 'bar bar', 'T4', $i++),
                     array('A{$foo}B', 'AbarB', 'T5', $i++),
                     array('A{counter}B', 'A1B', 'T6', $i++),
                     array('A {$foo}B', 'A barB', 'T7', $i++),
                     array('A{$foo} B', 'Abar B', 'T8', $i++),
                     array("A{\$foo}\nB", "Abar\nB", 'T9', $i++),
                     array("A{counter start=1}\nB", "A1\nB", 'T10', $i++),
                     array("A{\$foo}B\nC", "AbarB\nC", 'T11', $i++),
                     array("A{assign var=zoo value='blah'}B", "AB", 'T12', $i++),
                     array("A\n{assign var=zoo value='blah'}\nB", "A\nB", 'T13', $i++),
                     array("E{assign var=zoo value='blah'}\nF", "EF", 'T14', $i++),
                     array("G\n{assign var=zoo value='blah'}H", "G\nH", 'T15', $i++),
        );
    }
}