summaryrefslogtreecommitdiff
path: root/tests/UnitTests/Compiler/CompilerPlugin/CompileCompilerPluginTest.php
blob: 06f6862f1d5afaa8b40182fc982936989872154a (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
<?php
/**
 * Smarty PHPunit tests compilation of compiler plugins
 *

 * @author  Uwe Tews
 */

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


    /**
     * test compiler plugin tag in template file
     */
    public function testCompilerPluginFunction()
    {
        $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
        $this->smarty->setCompileId('function');
        $this->assertEquals("Hello World", $this->smarty->fetch('compilerplugintest.tpl'));
    }
    /**
     * test compiler plugin tag in template file
     */
    public function testCompilerPluginClassStatic()
    {
        $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array('CompilerPluginClass', 'statCompile'));
        $this->smarty->setCompileId('static');
        $this->assertEquals("Static World", $this->smarty->fetch('compilerplugintest.tpl'));
    }
    /**
     * test compiler plugin tag in template file
     */
    public function testCompilerPluginClassObject()
    {
        $plugin = new CompilerPluginClass;
        $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array($plugin, 'compile'));
        $this->smarty->setCompileId('object');
        $this->assertEquals("Public World", $this->smarty->fetch('compilerplugintest.tpl'));
    }
}

function mycompilerplugin($params, $compiler)
{
    return '<?php echo \'Hello World\';?>';
}

class CompilerPluginClass
{
    static function statCompile ($params, $compiler) {
        return '<?php echo \'Static World\';?>';
    }
    public function compile ($params, $compiler) {
        return '<?php echo \'Public World\';?>';
    }
}