summaryrefslogtreecommitdiff
path: root/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php
blob: 2c98fae4cd8498fe34b8fd159b231d120eaccce3 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
 * Smarty PHPunit tests resource plugins
 *

 * @author  Uwe Tews
 */
if (MysqlResourceEnable == true) {
    /**
     * class for resource plugins tests
     *
     * 
     * 
     * 
     */
    class ResourceMysqlPluginTest extends PHPUnit_Smarty
    {
        public function setUp(): void
        {
            if (MysqlResourceEnable != true) {
                $this->markTestSkipped('Msqlresource tests are disabled');
            }
                if (self::$init) {
                $this->getConnection();
            }
            $this->setUpSmarty(__DIR__);
            $this->initMysqlResource();
            PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl', '{\$x = \'hello world\'}{\$x}')");
            $this->smarty->addPluginsDir("./PHPunitplugins/");
        }

        /**
        * test resource plugin rendering of a custom resource
        */
        public function testResourcePluginMysql()
        {
             $this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl'));
        }

       /**
        * test must compile
        */
        public function testMustCompile()
        {
           $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
           $this->assertFalse($tpl->mustCompile());
        }

        /**
        * test must compile
        * @group slow
        */
        public function testMustCompile2()
        {
            sleep(2);
            PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl',  '{\$x = \'hello smarty\'}{\$x}' )");
            $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
            $this->assertTrue($tpl->mustCompile());
        }

        /**
        * test resource plugin rendering of a custom resource
        */
        public function testResourcePluginMysql2()
        {
             $this->assertEquals('hello smarty', $this->smarty->fetch('mysqltest:test.tpl'));
        }

         /**
        * test clear compiled
        */
        public function testClearCompiled()
        {
            $this->assertEquals(1, $this->smarty->clearCompiledTemplate('mysqltest:test.tpl'));
        }

       /**
        * test must compile
        */
        public function testMustCompile3()
        {
           $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
           $this->assertTrue($tpl->mustCompile());
        }

        /**
        * test resource plugin compiledFilepath of a custom resource
        */
        public function testResourcePluginMysqlCompiledFilepath()
        {
            //$this->smarty->addPluginsDir("./PHPunitplugins/");
            $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
            $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
        }

        public function testResourcePluginMysqlCompiledFilepathCache()
        {
            $this->smarty->caching = true;
            $this->smarty->cache_lifetime = 1000;
            $this->smarty->setForceCompile(true);
            $this->smarty->fetch('mysqltest:test.tpl');
            $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
            $this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
            $this->smarty->caching = false;
        }

        /**
        * test unknown template
        */
        public function testUnknownTemplate() {
            $this->expectException(\Smarty\Exception::class);
            $this->expectExceptionMessage('Unable to load \'mysqlstest:foo.tpl\'');
            $this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl'));
        }
    }
}