template.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
  23. public function setUp() {
  24. $loader = new \OC\Autoloader();
  25. $loader->load('OC_Template');
  26. }
  27. public function testP() {
  28. // FIXME: do we need more testcases?
  29. $htmlString = "<script>alert('xss');</script>";
  30. ob_start();
  31. p($htmlString);
  32. $result = ob_get_clean();
  33. $this->assertEquals("&lt;script&gt;alert(&#039;xss&#039;);&lt;/script&gt;", $result);
  34. }
  35. public function testPNormalString() {
  36. $normalString = "This is a good string!";
  37. ob_start();
  38. p($normalString);
  39. $result = ob_get_clean();
  40. $this->assertEquals("This is a good string!", $result);
  41. }
  42. public function testPrintUnescaped() {
  43. $htmlString = "<script>alert('xss');</script>";
  44. ob_start();
  45. print_unescaped($htmlString);
  46. $result = ob_get_clean();
  47. $this->assertEquals($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. $this->assertEquals("This is a good string!", $result);
  55. }
  56. }