]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/CommandInterperterTest.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / tests / CommandInterperterTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class CommandInterpreterTest extends PHPUnit_Framework_TestCase
15 {
16
17     /**
18      * @dataProvider commandInterpreterCases
19      */
20     public function testCommandInterpreter($input, $expectedType, $comment='')
21     {
22         $inter = new CommandInterpreter();
23
24         $user = new User(); // fake user
25         $user->limit(1);
26         $user->find();
27         $cmd = $inter->handle_command($user, $input);
28
29         $type = $cmd ? get_class($cmd) : null;
30         $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
31     }
32
33     static public function commandInterpreterCases()
34     {
35         $sets = array(
36             array('help', 'HelpCommand'),
37             array('help me bro', null, 'help does not accept multiple params'),
38             array('HeLP', 'HelpCommand', 'case check'),
39             array('HeLP Me BRO!', null, 'case & non-params check'),
40
41             array('login', 'LoginCommand'),
42             array('login to savings!', null, 'login does not accept params'),
43
44             array('lose', null, 'lose must have at least 1 parameter'),
45             array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
46             array('lose        foobar', 'LoseCommand', 'check for space norm'),
47             array('lose more weight', null, 'lose does not accept multiple params'),
48
49             array('subscribers', 'SubscribersCommand'),
50             array('subscribers foo', null, 'subscribers does not take params'),
51
52             array('subscriptions', 'SubscriptionsCommand'),
53             array('subscriptions foo', null, 'subscriptions does not take params'),
54
55             array('groups', 'GroupsCommand'),
56             array('groups foo', null, 'groups does not take params'),
57
58             array('off', 'OffCommand', 'off accepts 0 or 1 params'),
59             array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
60             array('off foo bar', null, 'off accepts 0 or 1 params'),
61
62             array('stop', 'OffCommand', 'stop accepts 0 params'),
63             array('stop foo', null, 'stop accepts 0 params'),
64
65             array('quit', 'OffCommand', 'quit accepts 0 params'),
66             array('quit foo', null, 'quit accepts 0 params'),
67
68             array('on', 'OnCommand', 'on accepts 0 or 1 params'),
69             array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
70             array('on foo bar', null, 'on accepts 0 or 1 params'),
71
72             array('join', null),
73             array('join foo', 'JoinCommand'),
74             array('join foo bar', null),
75
76             array('drop', null),
77             array('drop foo', 'DropCommand'),
78             array('drop foo bar', null),
79
80             array('follow', null),
81             array('follow foo', 'SubCommand'),
82             array('follow foo bar', null),
83
84             array('sub', null),
85             array('sub foo', 'SubCommand'),
86             array('sub foo bar', null),
87
88             array('leave', null),
89             array('leave foo', 'UnsubCommand'),
90             array('leave foo bar', null),
91
92             array('unsub', null),
93             array('unsub foo', 'UnsubCommand'),
94             array('unsub foo bar', null),
95
96             array('leave', null),
97             array('leave foo', 'UnsubCommand'),
98             array('leave foo bar', null),
99
100             array('d', null),
101             array('d foo', null),
102             array('d foo bar', 'MessageCommand'),
103
104             array('dm', null),
105             array('dm foo', null),
106             array('dm foo bar', 'MessageCommand'),
107
108             array('r', null),
109             array('r foo', null),
110             array('r foo bar', 'ReplyCommand'),
111
112             array('reply', null),
113             array('reply foo', null),
114             array('reply foo bar', 'ReplyCommand'),
115
116             array('repeat', null),
117             array('repeat foo', 'RepeatCommand'),
118             array('repeat foo bar', null),
119
120             array('rp', null),
121             array('rp foo', 'RepeatCommand'),
122             array('rp foo bar', null),
123
124             array('rt', null),
125             array('rt foo', 'RepeatCommand'),
126             array('rt foo bar', null),
127
128             array('rd', null),
129             array('rd foo', 'RepeatCommand'),
130             array('rd foo bar', null),
131
132             array('whois', null),
133             array('whois foo', 'WhoisCommand'),
134             array('whois foo bar', null),
135
136 /*            array('fav', null),
137             array('fav foo', 'FavCommand'),
138             array('fav foo bar', null),*/
139
140             array('nudge', null),
141             array('nudge foo', 'NudgeCommand'),
142             array('nudge foo bar', null),
143
144             array('stats', 'StatsCommand'),
145             array('stats foo', null),
146
147             array('invite', null),
148             array('invite foo', 'InviteCommand'),
149             array('invite foo bar', null),
150
151             array('track', null),
152             array('track foo', 'TrackCommand'),
153             array('track off', 'TrackOffCommand'),
154             array('track foo bar', null),
155             array('track off foo', null),
156
157             array('untrack', null),
158             array('untrack foo', 'UntrackCommand'),
159             array('untrack all', 'TrackOffCommand'),
160             array('untrack foo bar', null),
161             array('untrack all foo', null),
162
163             array('tracking', 'TrackingCommand'),
164             array('tracking foo', null),
165
166             array('tracks', 'TrackingCommand'),
167             array('tracks foo', null),
168
169         );
170         return $sets;
171     }
172
173 }
174