CommandInterperterTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. namespace Tests\Unit;
  17. if (!defined('INSTALLDIR')) {
  18. define('INSTALLDIR', dirname(dirname(__DIR__)));
  19. }
  20. if (!defined('PUBLICDIR')) {
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. }
  23. if (!defined('GNUSOCIAL')) {
  24. define('GNUSOCIAL', true);
  25. }
  26. if (!defined('STATUSNET')) { // Compatibility
  27. define('STATUSNET', true);
  28. }
  29. use CommandInterpreter;
  30. use PHPUnit\Framework\TestCase;
  31. require_once INSTALLDIR . '/lib/util/common.php';
  32. final class CommandInterpreterTest extends TestCase
  33. {
  34. /**
  35. * @dataProvider commandInterpreterCases
  36. * @param $input
  37. * @param $expectedType
  38. * @param string $comment
  39. */
  40. public function testCommandInterpreter($input, $expectedType, $comment = '')
  41. {
  42. $inter = new CommandInterpreter();
  43. $cmd = $inter->handle_command(null, $input);
  44. $type = $cmd ? get_class($cmd) : null;
  45. $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
  46. }
  47. static public function commandInterpreterCases()
  48. {
  49. $sets = array(
  50. array('help', 'HelpCommand'),
  51. array('help me bro', null, 'help does not accept multiple params'),
  52. array('HeLP', 'HelpCommand', 'case check'),
  53. array('HeLP Me BRO!', null, 'case & non-params check'),
  54. array('login', 'LoginCommand'),
  55. array('login to savings!', null, 'login does not accept params'),
  56. array('lose', null, 'lose must have at least 1 parameter'),
  57. array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
  58. array('lose foobar', 'LoseCommand', 'check for space norm'),
  59. array('lose more weight', null, 'lose does not accept multiple params'),
  60. array('subscribers', 'SubscribersCommand'),
  61. array('subscribers foo', null, 'subscribers does not take params'),
  62. array('subscriptions', 'SubscriptionsCommand'),
  63. array('subscriptions foo', null, 'subscriptions does not take params'),
  64. array('groups', 'GroupsCommand'),
  65. array('groups foo', null, 'groups does not take params'),
  66. array('off', 'OffCommand', 'off accepts 0 or 1 params'),
  67. array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
  68. array('off foo bar', null, 'off accepts 0 or 1 params'),
  69. array('stop', 'OffCommand', 'stop accepts 0 params'),
  70. array('stop foo', null, 'stop accepts 0 params'),
  71. array('quit', 'OffCommand', 'quit accepts 0 params'),
  72. array('quit foo', null, 'quit accepts 0 params'),
  73. array('on', 'OnCommand', 'on accepts 0 or 1 params'),
  74. array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
  75. array('on foo bar', null, 'on accepts 0 or 1 params'),
  76. array('join', null),
  77. array('join foo', 'JoinCommand'),
  78. array('join foo bar', null),
  79. array('drop', null),
  80. array('drop foo', 'DropCommand'),
  81. array('drop foo bar', null),
  82. array('follow', null),
  83. array('follow foo', 'SubCommand'),
  84. array('follow foo bar', null),
  85. array('sub', null),
  86. array('sub foo', 'SubCommand'),
  87. array('sub foo bar', null),
  88. array('leave', null),
  89. array('leave foo', 'UnsubCommand'),
  90. array('leave foo bar', null),
  91. array('unsub', null),
  92. array('unsub foo', 'UnsubCommand'),
  93. array('unsub foo bar', null),
  94. array('leave', null),
  95. array('leave foo', 'UnsubCommand'),
  96. array('leave foo bar', null),
  97. array('d', null),
  98. array('d foo', null),
  99. array('d foo bar', 'MessageCommand'),
  100. array('dm', null),
  101. array('dm foo', null),
  102. array('dm foo bar', 'MessageCommand'),
  103. array('r', null),
  104. array('r foo', null),
  105. array('r foo bar', 'ReplyCommand'),
  106. array('reply', null),
  107. array('reply foo', null),
  108. array('reply foo bar', 'ReplyCommand'),
  109. array('repeat', null),
  110. array('repeat foo', 'RepeatCommand'),
  111. array('repeat foo bar', null),
  112. array('rp', null),
  113. array('rp foo', 'RepeatCommand'),
  114. array('rp foo bar', null),
  115. array('rt', null),
  116. array('rt foo', 'RepeatCommand'),
  117. array('rt foo bar', null),
  118. array('rd', null),
  119. array('rd foo', 'RepeatCommand'),
  120. array('rd foo bar', null),
  121. array('whois', null),
  122. array('whois foo', 'WhoisCommand'),
  123. array('whois foo bar', null),
  124. /* array('fav', null),
  125. array('fav foo', 'FavCommand'),
  126. array('fav foo bar', null),*/
  127. array('nudge', null),
  128. array('nudge foo', 'NudgeCommand'),
  129. array('nudge foo bar', null),
  130. array('stats', 'StatsCommand'),
  131. array('stats foo', null),
  132. array('invite', null),
  133. array('invite foo', 'InviteCommand'),
  134. array('invite foo bar', null),
  135. array('track', null),
  136. array('track foo', 'SearchSubTrackCommand'),
  137. array('track off', 'SearchSubTrackOffCommand'),
  138. array('track foo bar', null),
  139. array('track off foo', null),
  140. array('untrack', null),
  141. array('untrack foo', 'SearchSubUntrackCommand'),
  142. array('untrack all', 'SearchSubTrackOffCommand'),
  143. array('untrack foo bar', null),
  144. array('untrack all foo', null),
  145. array('tracking', 'SearchSubTrackingCommand'),
  146. array('tracking foo', null),
  147. array('tracks', 'SearchSubTrackingCommand'),
  148. array('tracks foo', null),
  149. );
  150. return $sets;
  151. }
  152. }