| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 11 class WactTemplateFiltersTest extends WactTemplateTestCase 12 { 13 function testStringConstant() 14 { 15 $template = '{$"hello"|uppercase}'; 16 17 $this->registerTestingTemplate('/template/filter/string.html', $template); 18 $page = $this->initTemplate('/template/filter/string.html'); 19 $output = $page->capture(); 20 $this->assertEqual($output, 'HELLO'); 21 } 22 23 function testWactAttributeVariableFilter() 24 { 25 $template = '<form id="test" extra="{$Var|uppercase}" runat="server">contents</form>'; 26 27 $this->registerTestingTemplate('/template/filter/wactattributevarfilter.html', $template); 28 $page = $this->initTemplate('/template/filter/wactattributevarfilter.html'); 29 30 $form = $page->getChild('test'); 31 $data = new WactArrayObject(); 32 $data->set('Var', 'Foo'); 33 $form->registerDataSource($data); 34 35 $output = $page->capture(); 36 $this->assertEqual($output, '<form id="test" extra="FOO">contents</form>'); 37 } 38 39 function testFilter() 40 { 41 $template = '{$Var|uppercase}'; 42 43 $this->registerTestingTemplate('/template/filter/filter.html', $template); 44 $page = $this->initTemplate('/template/filter/filter.html'); 45 $page->set('Var', 'Foo'); 46 47 $output = $page->capture(); 48 $this->assertEqual($output, 'FOO'); 49 } 50 51 function testFilterChain() 52 { 53 $template = '{$Var|trim|uppercase}'; 54 55 $this->registerTestingTemplate('/template/filter/filterchain.html', $template); 56 $page = $this->initTemplate('/template/filter/filterchain.html'); 57 $page->set('Var', ' Foo '); 58 59 $output = $page->capture(); 60 $this->assertEqual($output, 'FOO'); 61 } 62 63 function testFilterChainOrder() 64 { 65 $template = '{$Var|lowercase|uppercase}'; 66 67 $this->registerTestingTemplate('/template/filter/filterchainorder.html', $template); 68 69 $page = $this->initTemplate('/template/filter/filterchainorder.html'); 70 $page->set('Var', 'Hello'); 71 72 $output = $page->capture(); 73 $this->assertEqual($output, 'HELLO'); 74 } 75 76 function testVarSetFilterChain() 77 { 78 $template = '<core:set var2="{$Var|uppercase}"/>{$var2|trim}'; 79 80 $this->registerTestingTemplate('/template/filter/varfiltersetchain.html', $template); 81 $page = $this->initTemplate('/template/filter/varfiltersetchain.html'); 82 $page->set('Var', ' Foo '); 83 84 $output = $page->capture(); 85 $this->assertEqual($output, 'FOO'); 86 } 87 88 function testSetFilterChain() 89 { 90 $template = '<core:set var1=" Foo "/><core:set var2="{$var1|uppercase}"/>{$var2|trim}'; 91 92 $this->registerTestingTemplate('/template/filter/filtersetchain.html', $template); 93 $page = $this->initTemplate('/template/filter/filtersetchain.html'); 94 95 $output = $page->capture(); 96 $this->assertEqual($output, 'FOO'); 97 } 98 99 function testFilterParameter() 100 { 101 $template = '{$Var|wordwrap:10}'; 102 103 $this->registerTestingTemplate('/template/filter/parameter.html', $template); 104 $page = $this->initTemplate('/template/filter/parameter.html'); 105 $page->set('Var', 'The quick brown fox jumped over the lazy dog.'); 106 107 $output = $page->capture(); 108 $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog."); 109 } 110 111 function testFilterVariableParameter() 112 { 113 $template = '{$Var|wordwrap:Size}'; 114 115 $this->registerTestingTemplate('/template/filter/varparameter.html', $template); 116 $page = $this->initTemplate('/template/filter/varparameter.html'); 117 $page->set('Var', 'The quick brown fox jumped over the lazy dog.'); 118 $page->set('Size', 10); 119 120 $output = $page->capture(); 121 $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog."); 122 } 123 124 function testFilterParameterExpression() 125 { 126 $template = '{$Var|wordwrap:5*2}'; 127 128 $this->registerTestingTemplate('/template/filter/parameter_expression.html', $template); 129 $page = $this->initTemplate('/template/filter/parameter_expression.html'); 130 $page->set('Var', 'The quick brown fox jumped over the lazy dog.'); 131 132 $output = $page->capture(); 133 $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog."); 134 } 135 136 function testFilterParameterComplexExpression() 137 { 138 $template = '{$Var|wordwrap:3*3 + Size}'; 139 140 $this->registerTestingTemplate('/template/filter/parameter_complex_expression.html', $template); 141 $page = $this->initTemplate('/template/filter/parameter_complex_expression.html'); 142 $page->set('Var', 'The quick brown fox jumped over the lazy dog.'); 143 $page->set('Size', 1); 144 145 $output = $page->capture(); 146 $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog."); 147 } 148 149 function testTooManyFilterParameters() 150 { 151 $template = '{$Var|uppercase:80}'; 152 153 $this->registerTestingTemplate('/template/filter/toomany-parameters.html', $template); 154 try 155 { 156 $page = $this->initTemplate('/template/filter/toomany-parameters.html'); 157 $this->assertTrue(false); 158 } 159 catch(WactException $e){} 160 } 161 162 function testParameterParsing() 163 { 164 $template = '{$Var | default : "|trim"}'; 165 166 $this->registerTestingTemplate('/template/filter/parameterparsing.html', $template); 167 $page = $this->initTemplate('/template/filter/parameterparsing.html'); 168 $output = $page->capture(); 169 $this->assertEqual($output, "|trim"); 170 } 171 172 function testParameterParsing2() 173 { 174 $template = '{$Var | default : "test: 99"}'; 175 176 $this->registerTestingTemplate('/template/filter/parameterparsing2.html', $template); 177 $page = $this->initTemplate('/template/filter/parameterparsing2.html'); 178 $output = $page->capture(); 179 $this->assertEqual($output, "test: 99"); 180 } 181 182 function testParameterParsing3() 183 { 184 $template = '{$Var | default : ", test: 99"}'; 185 186 $this->registerTestingTemplate('/template/filter/parameterparsing3.html', $template); 187 $page = $this->initTemplate('/template/filter/parameterparsing3.html'); 188 $output = $page->capture(); 189 $this->assertEqual($output, ", test: 99"); 190 } 191 192 function testNumberFormatFilter() 193 { 194 $template = '{$Var|number} {$Var|number:2} {$Var|number:3, ",", "."}'; 195 196 $this->registerTestingTemplate('/template/filter/number_format_filter.html', $template); 197 $page = $this->initTemplate('/template/filter/number_format_filter.html'); 198 $page->set('Var', 1234567.4321); 199 200 $output = $page->capture(); 201 $this->assertEqual($output, '1,234,567 1,234,567.43 1.234.567,432'); 202 } 203 204 function testManualHtmlEscape() 205 { 206 $template = '{$Var|html}'; 207 208 $this->registerTestingTemplate('/template/filter/manual_html_escape.html', $template); 209 $page = $this->initTemplate('/template/filter/manual_html_escape.html'); 210 $page->set('Var', '<tag>'); 211 212 $output = $page->capture(); 213 $this->assertEqual($output, '<tag>'); 214 } 215 216 function testHexConstant() 217 { 218 $template = '{$"hello"|hex|raw}'; 219 $this->registerTestingTemplate('/template/filter/hex_string.html', $template); 220 221 $page = $this->initTemplate('/template/filter/hex_string.html'); 222 $output = $page->capture(); 223 $this->assertEqual($output, 'hello'); 224 } 225 226 function testHexVariable() 227 { 228 $template = '{$email|hex|raw}'; 229 $this->registerTestingTemplate('/template/filter/hex_email.html', $template); 230 231 $page = $this->initTemplate('/template/filter/hex_email.html'); 232 $page->set('email', 'user@domain.com'); 233 $output = $page->capture(); 234 $this->assertEqual($output, 'user@domain.com'); 235 } 236 } 237 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Dec 1 03:56:46 2008 | Cross-referenced by PHPXref 0.7 |