template.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. OC::autoload('OC_Template');
  23. class Test_TemplateFunctions extends UnitTestCase {
  24. public function testP() {
  25. // FIXME: do we need more testcases?
  26. $htmlString = "<script>alert('xss');</script>";
  27. ob_start();
  28. p($htmlString);
  29. $result = ob_get_clean();
  30. ob_end_clean();
  31. $this->assertEqual("&lt;script&gt;alert(&#039;xss&#039;);&lt;/script&gt;", $result);
  32. }
  33. public function testPNormalString() {
  34. $normalString = "This is a good string!";
  35. ob_start();
  36. p($normalString);
  37. $result = ob_get_clean();
  38. ob_end_clean();
  39. $this->assertEqual("This is a good string!", $result);
  40. }
  41. public function testPrintUnescaped() {
  42. $htmlString = "<script>alert('xss');</script>";
  43. ob_start();
  44. print_unescaped($htmlString);
  45. $result = ob_get_clean();
  46. ob_end_clean();
  47. $this->assertEqual($htmlString, $result);
  48. }
  49. public function testPrintUnescapedNormalString() {
  50. $normalString = "This is a good string!";
  51. ob_start();
  52. print_unescaped($normalString);
  53. $result = ob_get_clean();
  54. ob_end_clean();
  55. $this->assertEqual("This is a good string!", $result);
  56. }
  57. }