util.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Lukas Reschke <lukas@statuscode.ch>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class Test_Util extends UnitTestCase {
  9. // Constructor
  10. function Test_Util() {
  11. date_default_timezone_set("UTC");
  12. }
  13. function testFormatDate() {
  14. $result = OC_Util::formatDate(1350129205);
  15. $expected = 'October 13, 2012 11:53';
  16. $this->assertEquals($expected, $result);
  17. $result = OC_Util::formatDate(1102831200, true);
  18. $expected = 'December 12, 2004';
  19. $this->assertEquals($expected, $result);
  20. }
  21. function testCallRegister() {
  22. $result = strlen(OC_Util::callRegister());
  23. $this->assertEquals(20, $result);
  24. }
  25. function testSanitizeHTML() {
  26. $badString = "<script>alert('Hacked!');</script>";
  27. $result = OC_Util::sanitizeHTML($badString);
  28. $this->assertEquals("&lt;script&gt;alert(&#039;Hacked!&#039;);&lt;/script&gt;", $result);
  29. $goodString = "This is an harmless string.";
  30. $result = OC_Util::sanitizeHTML($goodString);
  31. $this->assertEquals("This is an harmless string.", $result);
  32. }
  33. function testGenerate_random_bytes() {
  34. $result = strlen(OC_Util::generate_random_bytes(59));
  35. $this->assertEquals(59, $result);
  36. }
  37. }