/lib/limb/wact/tests/cases/functional/WactTemplateFiltersTest.class.php

https://github.com/limb-php-framework/limb-app-buildman · PHP · 216 lines · 158 code · 48 blank · 10 comment · 0 complexity · 133f38ddce511847dd586ffac75e8694 MD5 · raw file

  1. <?php
  2. /**
  3. * Limb Web Application Framework
  4. *
  5. * @link http://limb-project.com
  6. *
  7. * @copyright Copyright &copy; 2004-2007 BIT
  8. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  9. * @version $Id: WactTemplateFiltersTest.class.php 5021 2007-02-12 13:04:07Z pachanga $
  10. * @package wact
  11. */
  12. class WactTemplateFiltersTest extends WactTemplateTestCase
  13. {
  14. function testStringConstant()
  15. {
  16. $template = '{$"hello"|uppercase}';
  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. function testWactAttributeVariableFilter()
  23. {
  24. $template = '<form id="test" extra="{$Var|uppercase}" runat="server">contents</form>';
  25. $this->registerTestingTemplate('/template/filter/wactattributevarfilter.html', $template);
  26. $page = $this->initTemplate('/template/filter/wactattributevarfilter.html');
  27. $form = $page->getChild('test');
  28. $data = new WactArrayObject();
  29. $data->set('Var', 'Foo');
  30. $form->registerDataSource($data);
  31. $output = $page->capture();
  32. $this->assertEqual($output, '<form id="test" extra="FOO">contents</form>');
  33. }
  34. function testFilter()
  35. {
  36. $template = '{$Var|uppercase}';
  37. $this->registerTestingTemplate('/template/filter/filter.html', $template);
  38. $page = $this->initTemplate('/template/filter/filter.html');
  39. $page->set('Var', 'Foo');
  40. $output = $page->capture();
  41. $this->assertEqual($output, 'FOO');
  42. }
  43. function testFilterChain()
  44. {
  45. $template = '{$Var|trim|uppercase}';
  46. $this->registerTestingTemplate('/template/filter/filterchain.html', $template);
  47. $page = $this->initTemplate('/template/filter/filterchain.html');
  48. $page->set('Var', ' Foo ');
  49. $output = $page->capture();
  50. $this->assertEqual($output, 'FOO');
  51. }
  52. function testFilterChainOrder()
  53. {
  54. $template = '{$Var|lowercase|uppercase}';
  55. $this->registerTestingTemplate('/template/filter/filterchainorder.html', $template);
  56. $page = $this->initTemplate('/template/filter/filterchainorder.html');
  57. $page->set('Var', 'Hello');
  58. $output = $page->capture();
  59. $this->assertEqual($output, 'HELLO');
  60. }
  61. function testVarSetFilterChain()
  62. {
  63. $template = '<core:set var2="{$Var|uppercase}">{$var2|trim}';
  64. $this->registerTestingTemplate('/template/filter/varfiltersetchain.html', $template);
  65. $page = $this->initTemplate('/template/filter/varfiltersetchain.html');
  66. $page->set('Var', ' Foo ');
  67. $output = $page->capture();
  68. $this->assertEqual($output, 'FOO');
  69. }
  70. function testSetFilterChain()
  71. {
  72. $template = '<core:set var1=" Foo "><core:set var2="{$var1|uppercase}">{$var2|trim}';
  73. $this->registerTestingTemplate('/template/filter/filtersetchain.html', $template);
  74. $page = $this->initTemplate('/template/filter/filtersetchain.html');
  75. $output = $page->capture();
  76. $this->assertEqual($output, 'FOO');
  77. }
  78. function testFilterParameter()
  79. {
  80. $template = '{$Var|wordwrap:10}';
  81. $this->registerTestingTemplate('/template/filter/parameter.html', $template);
  82. $page = $this->initTemplate('/template/filter/parameter.html');
  83. $page->set('Var', 'The quick brown fox jumped over the lazy dog.');
  84. $output = $page->capture();
  85. $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog.");
  86. }
  87. function testFilterVariableParameter()
  88. {
  89. $template = '{$Var|wordwrap:Size}';
  90. $this->registerTestingTemplate('/template/filter/varparameter.html', $template);
  91. $page = $this->initTemplate('/template/filter/varparameter.html');
  92. $page->set('Var', 'The quick brown fox jumped over the lazy dog.');
  93. $page->set('Size', 10);
  94. $output = $page->capture();
  95. $this->assertEqual($output, "The quick\nbrown fox\njumped\nover the\nlazy dog.");
  96. }
  97. function testTooManyFilterParameters()
  98. {
  99. $template = '{$Var|uppercase:80}';
  100. $this->registerTestingTemplate('/template/filter/toomany-parameters.html', $template);
  101. try
  102. {
  103. $page = $this->initTemplate('/template/filter/toomany-parameters.html');
  104. $this->assertTrue(false);
  105. }
  106. catch(WactException $e){}
  107. }
  108. function testParameterParsing()
  109. {
  110. $template = '{$Var | default : "|trim"}';
  111. $this->registerTestingTemplate('/template/filter/parameterparsing.html', $template);
  112. $page = $this->initTemplate('/template/filter/parameterparsing.html');
  113. $output = $page->capture();
  114. $this->assertEqual($output, "|trim");
  115. }
  116. function testParameterParsing2()
  117. {
  118. $template = '{$Var | default : "test: 99"}';
  119. $this->registerTestingTemplate('/template/filter/parameterparsing2.html', $template);
  120. $page = $this->initTemplate('/template/filter/parameterparsing2.html');
  121. $output = $page->capture();
  122. $this->assertEqual($output, "test: 99");
  123. }
  124. function testParameterParsing3()
  125. {
  126. $template = '{$Var | default : ", test: 99"}';
  127. $this->registerTestingTemplate('/template/filter/parameterparsing3.html', $template);
  128. $page = $this->initTemplate('/template/filter/parameterparsing3.html');
  129. $output = $page->capture();
  130. $this->assertEqual($output, ", test: 99");
  131. }
  132. function testNumberFormatFilter()
  133. {
  134. $template = '{$Var|number} {$Var|number:2} {$Var|number:3, ",", "."}';
  135. $this->registerTestingTemplate('/template/filter/number_format_filter.html', $template);
  136. $page = $this->initTemplate('/template/filter/number_format_filter.html');
  137. $page->set('Var', 1234567.4321);
  138. $output = $page->capture();
  139. $this->assertEqual($output, '1,234,567 1,234,567.43 1.234.567,432');
  140. }
  141. function testManualHtmlEscape()
  142. {
  143. $template = '{$Var|html}';
  144. $this->registerTestingTemplate('/template/filter/manual_html_escape.html', $template);
  145. $page = $this->initTemplate('/template/filter/manual_html_escape.html');
  146. $page->set('Var', '<tag>');
  147. $output = $page->capture();
  148. $this->assertEqual($output, '&lt;tag&gt;');
  149. }
  150. function testHexConstant()
  151. {
  152. $template = '{$"hello"|hex|raw}';
  153. $this->registerTestingTemplate('/template/filter/hex_string.html', $template);
  154. $page = $this->initTemplate('/template/filter/hex_string.html');
  155. $output = $page->capture();
  156. $this->assertEqual($output, '&#x68;&#x65;&#x6c;&#x6c;&#x6f;');
  157. }
  158. function testHexVariable()
  159. {
  160. $template = '{$email|hex|raw}';
  161. $this->registerTestingTemplate('/template/filter/hex_email.html', $template);
  162. $page = $this->initTemplate('/template/filter/hex_email.html');
  163. $page->set('email', 'user@domain.com');
  164. $output = $page->capture();
  165. $this->assertEqual($output, '&#x75;&#x73;&#x65;&#x72;&#x40;&#x64;&#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;');
  166. }
  167. }
  168. ?>