CommandInterperterTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. $user = new User(); // fake user
  19. $user->limit(1);
  20. $user->find();
  21. $cmd = $inter->handle_command($user, $input);
  22. $type = $cmd ? get_class($cmd) : null;
  23. $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
  24. }
  25. static public function commandInterpreterCases()
  26. {
  27. $sets = array(
  28. array('help', 'HelpCommand'),
  29. array('help me bro', null, 'help does not accept multiple params'),
  30. array('HeLP', 'HelpCommand', 'case check'),
  31. array('HeLP Me BRO!', null, 'case & non-params check'),
  32. array('login', 'LoginCommand'),
  33. array('login to savings!', null, 'login does not accept params'),
  34. array('lose', null, 'lose must have at least 1 parameter'),
  35. array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
  36. array('lose foobar', 'LoseCommand', 'check for space norm'),
  37. array('lose more weight', null, 'lose does not accept multiple params'),
  38. array('subscribers', 'SubscribersCommand'),
  39. array('subscribers foo', null, 'subscribers does not take params'),
  40. array('subscriptions', 'SubscriptionsCommand'),
  41. array('subscriptions foo', null, 'subscriptions does not take params'),
  42. array('groups', 'GroupsCommand'),
  43. array('groups foo', null, 'groups does not take params'),
  44. array('off', 'OffCommand', 'off accepts 0 or 1 params'),
  45. array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
  46. array('off foo bar', null, 'off accepts 0 or 1 params'),
  47. array('stop', 'OffCommand', 'stop accepts 0 params'),
  48. array('stop foo', null, 'stop accepts 0 params'),
  49. array('quit', 'OffCommand', 'quit accepts 0 params'),
  50. array('quit foo', null, 'quit accepts 0 params'),
  51. array('on', 'OnCommand', 'on accepts 0 or 1 params'),
  52. array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
  53. array('on foo bar', null, 'on accepts 0 or 1 params'),
  54. array('join', null),
  55. array('join foo', 'JoinCommand'),
  56. array('join foo bar', null),
  57. array('drop', null),
  58. array('drop foo', 'DropCommand'),
  59. array('drop foo bar', null),
  60. array('follow', null),
  61. array('follow foo', 'SubCommand'),
  62. array('follow foo bar', null),
  63. array('sub', null),
  64. array('sub foo', 'SubCommand'),
  65. array('sub foo bar', null),
  66. array('leave', null),
  67. array('leave foo', 'UnsubCommand'),
  68. array('leave foo bar', null),
  69. array('unsub', null),
  70. array('unsub foo', 'UnsubCommand'),
  71. array('unsub foo bar', null),
  72. array('leave', null),
  73. array('leave foo', 'UnsubCommand'),
  74. array('leave foo bar', null),
  75. array('d', null),
  76. array('d foo', null),
  77. array('d foo bar', 'MessageCommand'),
  78. array('dm', null),
  79. array('dm foo', null),
  80. array('dm foo bar', 'MessageCommand'),
  81. array('r', null),
  82. array('r foo', null),
  83. array('r foo bar', 'ReplyCommand'),
  84. array('reply', null),
  85. array('reply foo', null),
  86. array('reply foo bar', 'ReplyCommand'),
  87. array('repeat', null),
  88. array('repeat foo', 'RepeatCommand'),
  89. array('repeat foo bar', null),
  90. array('rp', null),
  91. array('rp foo', 'RepeatCommand'),
  92. array('rp foo bar', null),
  93. array('rt', null),
  94. array('rt foo', 'RepeatCommand'),
  95. array('rt foo bar', null),
  96. array('rd', null),
  97. array('rd foo', 'RepeatCommand'),
  98. array('rd foo bar', null),
  99. array('whois', null),
  100. array('whois foo', 'WhoisCommand'),
  101. array('whois foo bar', null),
  102. /* array('fav', null),
  103. array('fav foo', 'FavCommand'),
  104. array('fav foo bar', null),*/
  105. array('nudge', null),
  106. array('nudge foo', 'NudgeCommand'),
  107. array('nudge foo bar', null),
  108. array('stats', 'StatsCommand'),
  109. array('stats foo', null),
  110. array('invite', null),
  111. array('invite foo', 'InviteCommand'),
  112. array('invite foo bar', null),
  113. array('track', null),
  114. array('track foo', 'TrackCommand'),
  115. array('track off', 'TrackOffCommand'),
  116. array('track foo bar', null),
  117. array('track off foo', null),
  118. array('untrack', null),
  119. array('untrack foo', 'UntrackCommand'),
  120. array('untrack all', 'TrackOffCommand'),
  121. array('untrack foo bar', null),
  122. array('untrack all foo', null),
  123. array('tracking', 'TrackingCommand'),
  124. array('tracking foo', null),
  125. array('tracks', 'TrackingCommand'),
  126. array('tracks foo', null),
  127. );
  128. return $sets;
  129. }
  130. }