|
2 | 2 |
|
3 | 3 | class TwigTest extends PHPUnit_Framework_TestCase |
4 | 4 | { |
5 | | - public static function setUpBeforeClass() |
6 | | - { |
7 | | - parent::setUpBeforeClass(); |
8 | | - $CI =& get_instance(); |
9 | | - $CI->load->library('twig'); |
10 | | - $CI->load->helper('url_helper'); |
11 | | - $CI->load->helper('form_helper'); |
12 | | - } |
13 | | - |
14 | | - public function testRedner() |
15 | | - { |
16 | | - $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
17 | | - |
18 | | - $data = [ |
19 | | - 'name' => 'CodeIgniter', |
20 | | - ]; |
21 | | - $output = $obj->render('welcome', $data); |
22 | | - $this->assertEquals('Hello CodeIgniter!'."\n", $output); |
23 | | - } |
24 | | - |
25 | | - public function testDisplay() |
26 | | - { |
27 | | - $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
28 | | - |
29 | | - $data = [ |
30 | | - 'name' => 'CodeIgniter', |
31 | | - ]; |
32 | | - $obj->display('welcome', $data); |
33 | | - $CI =& get_instance(); |
34 | | - $output = $CI->output->get_output(); |
35 | | - $this->assertEquals('Hello CodeIgniter!'."\n", $output); |
36 | | - } |
37 | | - |
38 | | - public function testAddGlobal() |
39 | | - { |
40 | | - $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
41 | | - $obj->addGlobal('sitename', 'Twig Test Site'); |
42 | | - |
43 | | - $output = $obj->render('global'); |
44 | | - $this->assertEquals('<title>Twig Test Site</title>'."\n", $output); |
45 | | - } |
46 | | - |
47 | | - public function testAddFunctionsRunsOnlyOnce() |
48 | | - { |
49 | | - $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
50 | | - |
51 | | - $data = [ |
52 | | - 'name' => 'CodeIgniter', |
53 | | - ]; |
54 | | - |
55 | | - $ref_obj = new ReflectionObject($obj); |
56 | | - $ref_property = $ref_obj->getProperty('functions_added'); |
57 | | - $ref_property->setAccessible(true); |
58 | | - $functions_added = $ref_property->getValue($obj); |
59 | | - $this->assertEquals(false, $functions_added); |
60 | | - |
61 | | - $output = $obj->render('welcome', $data); |
62 | | - |
63 | | - $ref_obj = new ReflectionObject($obj); |
64 | | - $ref_property = $ref_obj->getProperty('functions_added'); |
65 | | - $ref_property->setAccessible(true); |
66 | | - $functions_added = $ref_property->getValue($obj); |
67 | | - $this->assertEquals(true, $functions_added); |
68 | | - |
69 | | - // Calls render() twice |
70 | | - $output = $obj->render('welcome', $data); |
71 | | - |
72 | | - $ref_obj = new ReflectionObject($obj); |
73 | | - $ref_property = $ref_obj->getProperty('functions_added'); |
74 | | - $ref_property->setAccessible(true); |
75 | | - $functions_added = $ref_property->getValue($obj); |
76 | | - $this->assertEquals(true, $functions_added); |
77 | | - } |
78 | | - |
79 | | - public function testFunctionAsIs() |
80 | | - { |
81 | | - $obj = new Twig([ |
82 | | - 'paths' => __DIR__ . '/../templates/', |
83 | | - 'functions' => ['md5'], |
84 | | - 'cache' => false, |
85 | | - ]); |
86 | | - |
87 | | - $output = $obj->render('functions_asis'); |
88 | | - $this->assertEquals('900150983cd24fb0d6963f7d28e17f72'."\n", $output); |
89 | | - } |
90 | | - |
91 | | - public function testFunctionSafe() |
92 | | - { |
93 | | - $obj = new Twig([ |
94 | | - 'paths' => __DIR__ . '/../templates/', |
95 | | - 'functions_safe' => ['test_safe'], |
96 | | - 'cache' => false, |
97 | | - ]); |
98 | | - |
99 | | - $output = $obj->render('functions_safe'); |
100 | | - $this->assertEquals('<s>test</s>'."\n", $output); |
101 | | - } |
| 5 | + public static function setUpBeforeClass() |
| 6 | + { |
| 7 | + parent::setUpBeforeClass(); |
| 8 | + $CI =& get_instance(); |
| 9 | + $CI->load->library('twig'); |
| 10 | + $CI->load->helper('url_helper'); |
| 11 | + $CI->load->helper('form_helper'); |
| 12 | + } |
| 13 | + |
| 14 | + public function testRedner() |
| 15 | + { |
| 16 | + $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
| 17 | + |
| 18 | + $data = [ |
| 19 | + 'name' => 'CodeIgniter', |
| 20 | + ]; |
| 21 | + $output = $obj->render('welcome', $data); |
| 22 | + $this->assertEquals('Hello CodeIgniter!' . "\n", $output); |
| 23 | + } |
| 24 | + |
| 25 | + public function testDisplay() |
| 26 | + { |
| 27 | + $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
| 28 | + |
| 29 | + $data = [ |
| 30 | + 'name' => 'CodeIgniter', |
| 31 | + ]; |
| 32 | + $obj->display('welcome', $data); |
| 33 | + $CI =& get_instance(); |
| 34 | + $output = $CI->output->get_output(); |
| 35 | + $this->assertEquals('Hello CodeIgniter!' . "\n", $output); |
| 36 | + } |
| 37 | + |
| 38 | + public function testAddGlobal() |
| 39 | + { |
| 40 | + $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
| 41 | + $obj->addGlobal('sitename', 'Twig Test Site'); |
| 42 | + |
| 43 | + $output = $obj->render('global'); |
| 44 | + $this->assertEquals('<title>Twig Test Site</title>' . "\n", $output); |
| 45 | + } |
| 46 | + |
| 47 | + public function testAddFunctionsRunsOnlyOnce() |
| 48 | + { |
| 49 | + $obj = new Twig(['paths' => __DIR__ . '/../templates/']); |
| 50 | + |
| 51 | + $data = [ |
| 52 | + 'name' => 'CodeIgniter', |
| 53 | + ]; |
| 54 | + |
| 55 | + $ref_obj = new ReflectionObject($obj); |
| 56 | + $ref_property = $ref_obj->getProperty('functions_added'); |
| 57 | + $ref_property->setAccessible(true); |
| 58 | + $functions_added = $ref_property->getValue($obj); |
| 59 | + $this->assertEquals(false, $functions_added); |
| 60 | + |
| 61 | + $output = $obj->render('welcome', $data); |
| 62 | + |
| 63 | + $ref_obj = new ReflectionObject($obj); |
| 64 | + $ref_property = $ref_obj->getProperty('functions_added'); |
| 65 | + $ref_property->setAccessible(true); |
| 66 | + $functions_added = $ref_property->getValue($obj); |
| 67 | + $this->assertEquals(true, $functions_added); |
| 68 | + |
| 69 | + // Calls render() twice |
| 70 | + $output = $obj->render('welcome', $data); |
| 71 | + |
| 72 | + $ref_obj = new ReflectionObject($obj); |
| 73 | + $ref_property = $ref_obj->getProperty('functions_added'); |
| 74 | + $ref_property->setAccessible(true); |
| 75 | + $functions_added = $ref_property->getValue($obj); |
| 76 | + $this->assertEquals(true, $functions_added); |
| 77 | + } |
| 78 | + |
| 79 | + public function testFunctionAsIs() |
| 80 | + { |
| 81 | + $obj = new Twig([ |
| 82 | + 'paths' => __DIR__ . '/../templates/', |
| 83 | + 'functions' => ['md5'], |
| 84 | + 'cache' => false, |
| 85 | + ]); |
| 86 | + |
| 87 | + $output = $obj->render('functions_asis'); |
| 88 | + $this->assertEquals('900150983cd24fb0d6963f7d28e17f72' . "\n", $output); |
| 89 | + } |
| 90 | + |
| 91 | + public function testFunctionSafe() |
| 92 | + { |
| 93 | + $obj = new Twig([ |
| 94 | + 'paths' => __DIR__ . '/../templates/', |
| 95 | + 'functions_safe' => ['test_safe'], |
| 96 | + 'cache' => false, |
| 97 | + ]); |
| 98 | + |
| 99 | + $output = $obj->render('functions_safe'); |
| 100 | + $this->assertEquals('<s>test</s>' . "\n", $output); |
| 101 | + } |
102 | 102 | } |
103 | 103 |
|
104 | 104 | function test_safe() |
105 | 105 | { |
106 | | - return '<s>test</s>'; |
| 106 | + return '<s>test</s>'; |
107 | 107 | } |
0 commit comments