CommandInterperterTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. use User;
  32. require_once INSTALLDIR . '/lib/util/common.php';
  33. final class CommandInterperterTest extends TestCase
  34. {
  35. /**
  36. * @dataProvider commandInterpreterCases
  37. *
  38. * @param $input
  39. * @param $expectedType
  40. * @param string $comment
  41. * @throws \EmptyPkeyValueException
  42. * @throws \ServerException
  43. */
  44. public function testCommandInterpreter($input, $expectedType, $comment = '')
  45. {
  46. $inter = new CommandInterpreter();
  47. $cmd = $inter->handle_command(User::getById(1), $input);
  48. $type = $cmd ? get_class($cmd) : null;
  49. static::assertSame(strtolower($expectedType), strtolower($type), $comment);
  50. }
  51. public static function commandInterpreterCases()
  52. {
  53. $sets = [
  54. ['help', 'HelpCommand'],
  55. ['help me bro', null, 'help does not accept multiple params'],
  56. ['HeLP', 'HelpCommand', 'case check'],
  57. ['HeLP Me BRO!', null, 'case & non-params check'],
  58. ['login', 'LoginCommand'],
  59. ['login to savings!', null, 'login does not accept params'],
  60. ['lose', null, 'lose must have at least 1 parameter'],
  61. ['lose foobar', 'LoseCommand', 'lose requires 1 parameter'],
  62. ['lose foobar', 'LoseCommand', 'check for space norm'],
  63. ['lose more weight', null, 'lose does not accept multiple params'],
  64. ['subscribers', 'SubscribersCommand'],
  65. ['subscribers foo', null, 'subscribers does not take params'],
  66. ['subscriptions', 'SubscriptionsCommand'],
  67. ['subscriptions foo', null, 'subscriptions does not take params'],
  68. ['groups', 'GroupsCommand'],
  69. ['groups foo', null, 'groups does not take params'],
  70. ['off', 'OffCommand', 'off accepts 0 or 1 params'],
  71. ['off foo', 'OffCommand', 'off accepts 0 or 1 params'],
  72. ['off foo bar', null, 'off accepts 0 or 1 params'],
  73. ['stop', 'OffCommand', 'stop accepts 0 params'],
  74. ['stop foo', null, 'stop accepts 0 params'],
  75. ['quit', 'OffCommand', 'quit accepts 0 params'],
  76. ['quit foo', null, 'quit accepts 0 params'],
  77. ['on', 'OnCommand', 'on accepts 0 or 1 params'],
  78. ['on foo', 'OnCommand', 'on accepts 0 or 1 params'],
  79. ['on foo bar', null, 'on accepts 0 or 1 params'],
  80. ['join', null],
  81. ['join foo', 'JoinCommand'],
  82. ['join foo bar', null],
  83. ['drop', null],
  84. ['drop foo', 'DropCommand'],
  85. ['drop foo bar', null],
  86. ['follow', null],
  87. ['follow foo', 'SubCommand'],
  88. ['follow foo bar', null],
  89. ['sub', null],
  90. ['sub foo', 'SubCommand'],
  91. ['sub foo bar', null],
  92. ['leave', null],
  93. ['leave foo', 'UnsubCommand'],
  94. ['leave foo bar', null],
  95. ['unsub', null],
  96. ['unsub foo', 'UnsubCommand'],
  97. ['unsub foo bar', null],
  98. ['leave', null],
  99. ['leave foo', 'UnsubCommand'],
  100. ['leave foo bar', null],
  101. ['d', null],
  102. ['d foo', null],
  103. ['d foo bar', 'MessageCommand'],
  104. ['dm', null],
  105. ['dm foo', null],
  106. ['dm foo bar', 'MessageCommand'],
  107. ['r', null],
  108. ['r foo', null],
  109. ['r foo bar', 'ReplyCommand'],
  110. ['reply', null],
  111. ['reply foo', null],
  112. ['reply foo bar', 'ReplyCommand'],
  113. ['repeat', null],
  114. ['repeat foo', 'RepeatCommand'],
  115. ['repeat foo bar', null],
  116. ['rp', null],
  117. ['rp foo', 'RepeatCommand'],
  118. ['rp foo bar', null],
  119. ['rt', null],
  120. ['rt foo', 'RepeatCommand'],
  121. ['rt foo bar', null],
  122. ['rd', null],
  123. ['rd foo', 'RepeatCommand'],
  124. ['rd foo bar', null],
  125. ['whois', null],
  126. ['whois foo', 'WhoisCommand'],
  127. ['whois foo bar', null],
  128. /* array('fav', null),
  129. array('fav foo', 'FavCommand'),
  130. array('fav foo bar', null),*/
  131. ['nudge', null],
  132. ['nudge foo', 'NudgeCommand'],
  133. ['nudge foo bar', null],
  134. ['stats', 'StatsCommand'],
  135. ['stats foo', null],
  136. ['invite', null],
  137. ['invite foo', 'InviteCommand'],
  138. ['invite foo bar', null],
  139. ['track', null],
  140. ['track foo', 'SearchSubTrackCommand'],
  141. ['track off', 'SearchSubTrackOffCommand'],
  142. ['track foo bar', null],
  143. ['track off foo', null],
  144. ['untrack', null],
  145. ['untrack foo', 'SearchSubUntrackCommand'],
  146. ['untrack all', 'SearchSubTrackOffCommand'],
  147. ['untrack foo bar', null],
  148. ['untrack all foo', null],
  149. ['tracking', 'SearchSubTrackingCommand'],
  150. ['tracking foo', null],
  151. ['tracks', 'SearchSubTrackingCommand'],
  152. ['tracks foo', null],
  153. ];
  154. return $sets;
  155. }
  156. }