CommandInterperterTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/common.php';
  10. class CommandInterpreterTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @dataProvider commandInterpreterCases
  14. */
  15. public function testCommandInterpreter($input, $expectedType, $comment='')
  16. {
  17. $inter = new CommandInterpreter();
  18. $cmd = $inter->handle_command(null, $input);
  19. $type = $cmd ? get_class($cmd) : null;
  20. $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
  21. }
  22. static public function commandInterpreterCases()
  23. {
  24. $sets = array(
  25. array('help', 'HelpCommand'),
  26. array('help me bro', null, 'help does not accept multiple params'),
  27. array('HeLP', 'HelpCommand', 'case check'),
  28. array('HeLP Me BRO!', null, 'case & non-params check'),
  29. array('login', 'LoginCommand'),
  30. array('login to savings!', null, 'login does not accept params'),
  31. array('lose', null, 'lose must have at least 1 parameter'),
  32. array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
  33. array('lose foobar', 'LoseCommand', 'check for space norm'),
  34. array('lose more weight', null, 'lose does not accept multiple params'),
  35. array('subscribers', 'SubscribersCommand'),
  36. array('subscribers foo', null, 'subscribers does not take params'),
  37. array('subscriptions', 'SubscriptionsCommand'),
  38. array('subscriptions foo', null, 'subscriptions does not take params'),
  39. array('groups', 'GroupsCommand'),
  40. array('groups foo', null, 'groups does not take params'),
  41. array('off', 'OffCommand', 'off accepts 0 or 1 params'),
  42. array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
  43. array('off foo bar', null, 'off accepts 0 or 1 params'),
  44. array('stop', 'OffCommand', 'stop accepts 0 params'),
  45. array('stop foo', null, 'stop accepts 0 params'),
  46. array('quit', 'OffCommand', 'quit accepts 0 params'),
  47. array('quit foo', null, 'quit accepts 0 params'),
  48. array('on', 'OnCommand', 'on accepts 0 or 1 params'),
  49. array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
  50. array('on foo bar', null, 'on accepts 0 or 1 params'),
  51. array('join', null),
  52. array('join foo', 'JoinCommand'),
  53. array('join foo bar', null),
  54. array('drop', null),
  55. array('drop foo', 'DropCommand'),
  56. array('drop foo bar', null),
  57. array('follow', null),
  58. array('follow foo', 'SubCommand'),
  59. array('follow foo bar', null),
  60. array('sub', null),
  61. array('sub foo', 'SubCommand'),
  62. array('sub foo bar', null),
  63. array('leave', null),
  64. array('leave foo', 'UnsubCommand'),
  65. array('leave foo bar', null),
  66. array('unsub', null),
  67. array('unsub foo', 'UnsubCommand'),
  68. array('unsub foo bar', null),
  69. array('leave', null),
  70. array('leave foo', 'UnsubCommand'),
  71. array('leave foo bar', null),
  72. array('d', null),
  73. array('d foo', null),
  74. array('d foo bar', 'MessageCommand'),
  75. array('dm', null),
  76. array('dm foo', null),
  77. array('dm foo bar', 'MessageCommand'),
  78. array('r', null),
  79. array('r foo', null),
  80. array('r foo bar', 'ReplyCommand'),
  81. array('reply', null),
  82. array('reply foo', null),
  83. array('reply foo bar', 'ReplyCommand'),
  84. array('repeat', null),
  85. array('repeat foo', 'RepeatCommand'),
  86. array('repeat foo bar', null),
  87. array('rp', null),
  88. array('rp foo', 'RepeatCommand'),
  89. array('rp foo bar', null),
  90. array('rt', null),
  91. array('rt foo', 'RepeatCommand'),
  92. array('rt foo bar', null),
  93. array('rd', null),
  94. array('rd foo', 'RepeatCommand'),
  95. array('rd foo bar', null),
  96. array('whois', null),
  97. array('whois foo', 'WhoisCommand'),
  98. array('whois foo bar', null),
  99. /* array('fav', null),
  100. array('fav foo', 'FavCommand'),
  101. array('fav foo bar', null),*/
  102. array('nudge', null),
  103. array('nudge foo', 'NudgeCommand'),
  104. array('nudge foo bar', null),
  105. array('stats', 'StatsCommand'),
  106. array('stats foo', null),
  107. array('invite', null),
  108. array('invite foo', 'InviteCommand'),
  109. array('invite foo bar', null),
  110. array('track', null),
  111. array('track foo', 'SearchSubTrackCommand'),
  112. array('track off', 'SearchSubTrackOffCommand'),
  113. array('track foo bar', null),
  114. array('track off foo', null),
  115. array('untrack', null),
  116. array('untrack foo', 'SearchSubUntrackCommand'),
  117. array('untrack all', 'SearchSubTrackOffCommand'),
  118. array('untrack foo bar', null),
  119. array('untrack all foo', null),
  120. array('tracking', 'SearchSubTrackingCommand'),
  121. array('tracking foo', null),
  122. array('tracks', 'SearchSubTrackingCommand'),
  123. array('tracks foo', null),
  124. );
  125. return $sets;
  126. }
  127. }