summaryrefslogtreecommitdiff
path: root/tests/UnitTests/SmartyMethodsTests/Append/AppendTest.php
blob: c59fef813e98d74649d8f6505b77e3548682830b (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
<?php
/**
 * Smarty PHPunit tests append method
 *

 * @author  Uwe Tews
 */

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


    /**
     * test append
     */
    public function testAppend()
    {
        $this->smarty->assign('foo', 'bar');
        $this->smarty->append('foo', 'bar2');
        $this->assertEquals('bar bar2', $this->smarty->fetch('eval:{$foo[0]} {$foo[1]}'));
    }

    /**
     * test append to unassigned variable
     */
    public function testAppendUnassigned()
    {
        $this->smarty->append('foo', 'bar');
        $this->assertEquals('bar', $this->smarty->fetch('eval:{$foo[0]}'));
    }

    /**
     * test append merge
     */
    public function testAppendMerge()
    {
        $this->smarty->assign('foo', array('a' => 'a', 'b' => 'b', 'c' => 'c'));
        $this->smarty->append('foo', array('b' => 'd'), true);
        $this->assertEquals('a d c', $this->smarty->fetch('eval:{$foo["a"]} {$foo["b"]} {$foo["c"]}'));
    }

    /**
     * test append array merge
     */
    public function testAppendArrayMerge()
    {
        $this->smarty->assign('foo', array('b' => 'd'));
        $this->smarty->append('foo', array('a' => 'a', 'b' => 'b', 'c' => 'c'), true);
        $this->assertEquals('a b c', $this->smarty->fetch('eval:{$foo["a"]} {$foo["b"]} {$foo["c"]}'));
    }

    /**
     * test array append
     */
    public function testArrayAppend()
    {
        $this->smarty->assign('foo', 'foo');
        $this->smarty->append(array('bar' => 'bar2', 'foo' => 'foo2'));
        $this->assertEquals('foo foo2 bar2', $this->smarty->fetch('eval:{$foo[0]} {$foo[1]} {$bar[0]}'));
    }

    /**
     * test array append array merge
     */
    public function testArrayAppendArrayMerge()
    {
        $this->smarty->assign('foo', array('b' => 'd'));
        $this->smarty->append(array('bar' => 'bar', 'foo' => array('a' => 'a', 'b' => 'b', 'c' => 'c')), null, true);
        $this->assertEquals('a b c bar', $this->smarty->fetch('eval:{$foo["a"]} {$foo["b"]} {$foo["c"]} {$bar[0]}'));
    }
}