Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.7 KiB

  1. <?php
  2. /**
  3. * this test tests the expand_acl function
  4. *
  5. * @package test.util
  6. */
  7. /** required, it is the file under test */
  8. require_once('include/text.php');
  9. /**
  10. * TestCase for the expand_acl function
  11. *
  12. * @author Alexander Kampmann
  13. * @package test.util
  14. */
  15. class ExpandAclTest extends PHPUnit_Framework_TestCase {
  16. /**
  17. * test expand_acl, perfect input
  18. */
  19. public function testExpandAclNormal() {
  20. $text='<1><2><3>';
  21. $this->assertEquals(array(1, 2, 3), expand_acl($text));
  22. }
  23. /**
  24. * test with a big number
  25. */
  26. public function testExpandAclBigNumber() {
  27. $text='<1><'.PHP_INT_MAX.'><15>';
  28. $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
  29. }
  30. /**
  31. * test with a string in it.
  32. *
  33. * TODO: is this valid input? Otherwise: should there be an exception?
  34. */
  35. public function testExpandAclString() {
  36. $text="<1><279012><tt>";
  37. $this->assertEquals(array(1, 279012), expand_acl($text));
  38. }
  39. /**
  40. * test with a ' ' in it.
  41. *
  42. * TODO: is this valid input? Otherwise: should there be an exception?
  43. */
  44. public function testExpandAclSpace() {
  45. $text="<1><279 012><32>";
  46. $this->assertEquals(array(1, "279", "32"), expand_acl($text));
  47. }
  48. /**
  49. * test empty input
  50. */
  51. public function testExpandAclEmpty() {
  52. $text="";
  53. $this->assertEquals(array(), expand_acl($text));
  54. }
  55. /**
  56. * test invalid input, no < at all
  57. *
  58. * TODO: should there be an exception?
  59. */
  60. public function testExpandAclNoBrackets() {
  61. $text="According to documentation, that's invalid. "; //should be invalid
  62. $this->assertEquals(array(), expand_acl($text));
  63. }
  64. /**
  65. * test invalid input, just open <
  66. *
  67. * TODO: should there be an exception?
  68. */
  69. public function testExpandAclJustOneBracket1() {
  70. $text="<Another invalid string"; //should be invalid
  71. $this->assertEquals(array(), expand_acl($text));
  72. }
  73. /**
  74. * test invalid input, just close >
  75. *
  76. * TODO: should there be an exception?
  77. */
  78. public function testExpandAclJustOneBracket2() {
  79. $text="Another invalid> string"; //should be invalid
  80. $this->assertEquals(array(), expand_acl($text));
  81. }
  82. /**
  83. * test invalid input, just close >
  84. *
  85. * TODO: should there be an exception?
  86. */
  87. public function testExpandAclCloseOnly() {
  88. $text="Another> invalid> string>"; //should be invalid
  89. $this->assertEquals(array(), expand_acl($text));
  90. }
  91. /**
  92. * test invalid input, just open <
  93. *
  94. * TODO: should there be an exception?
  95. */
  96. public function testExpandAclOpenOnly() {
  97. $text="<Another< invalid string<"; //should be invalid
  98. $this->assertEquals(array(), expand_acl($text));
  99. }
  100. /**
  101. * test invalid input, open and close do not match
  102. *
  103. * TODO: should there be an exception?
  104. */
  105. public function testExpandAclNoMatching1() {
  106. $text="<Another<> invalid <string>"; //should be invalid
  107. $this->assertEquals(array(), expand_acl($text));
  108. }
  109. /**
  110. * test invalid input, open and close do not match
  111. *
  112. * TODO: should there be an exception?
  113. */
  114. public function testExpandAclNoMatching2() {
  115. $text="<1>2><3>";
  116. // The angles are delimiters which aren't important
  117. // the important thing is the numeric content, this returns array(1,2,3) currently
  118. // we may wish to eliminate 2 from the results, though it isn't harmful
  119. // It would be a better test to figure out if there is any ACL input which can
  120. // produce this $text and fix that instead.
  121. // $this->assertEquals(array(), expand_acl($text));
  122. }
  123. /**
  124. * test invalid input, empty <>
  125. *
  126. * TODO: should there be an exception? Or array(1, 3)
  127. * (This should be array(1,3) - mike)
  128. */
  129. public function testExpandAclEmptyMatch() {
  130. $text="<1><><3>";
  131. $this->assertEquals(array(1,3), expand_acl($text));
  132. }
  133. }