]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
authorEvan Prodromou <evan@status.net>
Mon, 21 Feb 2011 21:36:12 +0000 (16:36 -0500)
committerEvan Prodromou <evan@status.net>
Mon, 21 Feb 2011 21:36:12 +0000 (16:36 -0500)
classes/Notice.php
classes/Profile.php
doc-src/im
lib/commandinterpreter.php
tests/CommandInterperterTest.php [new file with mode: 0644]

index 4522d1fc3889b4648afb6e8434afddfd0fbe8bd8..c9cca8a96952b7724f62827dc2261584831af3d4 100644 (file)
@@ -1333,7 +1333,7 @@ class Notice extends Memcached_DataObject
             $groups = $this->getGroups();
 
             foreach ($groups as $group) {
-                $ctx->attention[] = $group->uri;
+                $ctx->attention[] = $group->getUri();
             }
 
             // XXX: deprecated; use ActivityVerb::SHARE instead
index 397b96bbc18c3850a2d7a4ea2eed20f71b1705cc..e9b9c7a51a488494b77e89443e66bbc888ea06a0 100644 (file)
@@ -752,6 +752,10 @@ class Profile extends Memcached_DataObject
                 throw new Exception("Can't save role '$name' for profile '{$this->id}'");
             }
 
+            if ($name == 'owner') {
+                User::blow('user:site_owner');
+            }
+
             Event::handle('EndGrantRole', array($this, $name));
         }
 
@@ -780,6 +784,10 @@ class Profile extends Memcached_DataObject
                 throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id));
             }
 
+            if ($name == 'owner') {
+                User::blow('user:site_owner');
+            }
+
             Event::handle('EndRevokeRole', array($this, $name));
 
             return true;
index 896c1218798ea1d72b041da651f2c0cb0d08dd40..9932632188afbe4216e1ae204d5bc4d1363b8394 100644 (file)
@@ -32,19 +32,40 @@ Commands
 You can do some minor management of your account through Jabber. These are the
 currently-implemented commands:
 
-* **on**: Turn on notifications. You'll receive copies of messages by people
-  you subscribe to.
-* **off**: Turn off notifications. You'll no longer receive Jabber
-  notifications.
-* **stop**: Same as 'off'
-* **quit**: Same as 'off'
-* **help**: Show this help. List available Jabber/XMPP commands
-* **follow &lt;nickname&gt;**: Subscribe to &lt;nickname&gt;
-* **sub &lt;nickname&gt;**: Same as follow
-* **leave &lt;nickname&gt;**: Unsubscribe from &lt;nickname&gt;
-* **unsub &lt;nickname&gt;**: Same as leave
-* **d &lt;nickname&gt; &lt;text&gt;**: Send direct message to &lt;nickname&gt; with message body &lt;text&gt;
-* **get &lt;nickname&gt;**: Get last notice from &lt;nickname&gt;
-* **last &lt;nickname&gt;**: Same as 'get'
-* **whois &lt;nickname&gt;**: Get Profile info on &lt;nickname&gt;
-* **fav &lt;nickname&gt;**: Add user's last notice as a favorite
+* **on** - turn on notifications
+* **off** - turn off notifications
+* **help** - show this help
+* **follow &lt;nickname&gt;** - subscribe to user
+* **groups** - lists the groups you have joined
+* **subscriptions** - list the people you follow
+* **subscribers** - list the people that follow you
+* **leave &lt;nickname&gt;** - unsubscribe from user
+* **d &lt;nickname&gt; &lt;text&gt;** - direct message to user
+* **get &lt;nickname&gt;** - get last notice from user
+* **whois &lt;nickname&gt;** - get profile info on user
+* **lose &lt;nickname&gt;** - force user to stop following you
+* **fav &lt;nickname&gt;** - add user's last notice as a 'fave'
+* **fav #&lt;notice_id&gt;** - add notice with the given id as a 'fave'
+* **repeat #&lt;notice_id&gt;** - repeat a notice with a given id
+* **repeat &lt;nickname&gt;** - repeat the last notice from user
+* **reply #&lt;notice_id&gt;** - reply to notice with a given id
+* **reply &lt;nickname&gt;** - reply to the last notice from user
+* **join &lt;group&gt;** - join group
+* **login** - Get a link to login to the web interface
+* **drop &lt;group&gt;** - leave group
+* **stats** - get your stats
+* **stop** - same as 'off'
+* **quit** - same as 'off'
+* **sub &lt;nickname&gt;** - same as 'follow'
+* **unsub &lt;nickname&gt;** - same as 'leave'
+* **last &lt;nickname&gt;** - same as 'get'
+* **on &lt;nickname&gt;** - not yet implemented.
+* **off &lt;nickname&gt;** - not yet implemented.
+* **nudge &lt;nickname&gt;** - remind a user to update.
+* **invite &lt;phone number&gt;** - not yet implemented.
+* **track &lt;word&gt;** - not yet implemented.
+* **untrack &lt;word&gt;** - not yet implemented.
+* **track off** - not yet implemented.
+* **untrack all** - not yet implemented.
+* **tracks** - not yet implemented.
+* **tracking** - not yet implemented.
index f2caf48bdb47d5ff9cf01714429c3002bdb17234..fe426f1fcd3a41f6b4a6515a2fcaaf10079f561e 100644 (file)
@@ -42,8 +42,9 @@ class CommandInterpreter
             case 'help':
                 if ($arg) {
                     $result = null;
+                } else {
+                    $result = new HelpCommand($user);
                 }
-                $result = new HelpCommand($user);
                 break;
             case 'login':
                 if ($arg) {
@@ -120,49 +121,51 @@ class CommandInterpreter
             case 'join':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new JoinCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new JoinCommand($user, $other);
+                    }
                 }
                 break;
             case 'drop':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new DropCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new DropCommand($user, $other);
+                    }
                 }
                 break;
             case 'follow':
             case 'sub':
                 if (!$arg) {
                     $result = null;
-                }
-
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new SubCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new SubCommand($user, $other);
+                    }
                 }
                 break;
             case 'leave':
             case 'unsub':
                 if (!$arg) {
                     $result = null;
-                }
-
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new UnsubCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new UnsubCommand($user, $other);
+                    }
                 }
                 break;
             case 'get':
@@ -207,96 +210,105 @@ class CommandInterpreter
             case 'rd':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new RepeatCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new RepeatCommand($user, $other);
+                    }
                 }
                 break;
             case 'whois':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new WhoisCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new WhoisCommand($user, $other);
+                    }
                 }
                 break;
             case 'fav':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new FavCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new FavCommand($user, $other);
+                    }
                 }
                 break;
             case 'nudge':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new NudgeCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new NudgeCommand($user, $other);
+                    }
                 }
                 break;
             case 'stats':
                 if ($arg) {
                     $result = null;
+                } else {
+                    $result = new StatsCommand($user);
                 }
-                $result = new StatsCommand($user);
                 break;
             case 'invite':
                 if (!$arg) {
                     $result = null;
-                }
-                list($other, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
                 } else {
-                    $result = new InviteCommand($user, $other);
+                    list($other, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else {
+                        $result = new InviteCommand($user, $other);
+                    }
                 }
                 break;
             case 'track':
                 if (!$arg) {
                     $result = null;
-                }
-                list($word, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
-                } else if ($word == 'off') {
-                    $result = new TrackOffCommand($user);
                 } else {
-                    $result = new TrackCommand($user, $word);
+                    list($word, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else if ($word == 'off') {
+                        $result = new TrackOffCommand($user);
+                    } else {
+                        $result = new TrackCommand($user, $word);
+                    }
                 }
                 break;
             case 'untrack':
                 if (!$arg) {
                     $result = null;
-                }
-                list($word, $extra) = $this->split_arg($arg);
-                if ($extra) {
-                    $result = null;
-                } else if ($word == 'all') {
-                    $result = new TrackOffCommand($user);
                 } else {
-                    $result = new UntrackCommand($user, $word);
+                    list($word, $extra) = $this->split_arg($arg);
+                    if ($extra) {
+                        $result = null;
+                    } else if ($word == 'all') {
+                        $result = new TrackOffCommand($user);
+                    } else {
+                        $result = new UntrackCommand($user, $word);
+                    }
                 }
                 break;
             case 'tracks':
             case 'tracking':
                 if ($arg) {
                     $result = null;
+                } else {
+                    $result = new TrackingCommand($user);
                 }
-                $result = new TrackingCommand($user);
                 break;
             default:
                 $result = false;
diff --git a/tests/CommandInterperterTest.php b/tests/CommandInterperterTest.php
new file mode 100644 (file)
index 0000000..3ce1cc2
--- /dev/null
@@ -0,0 +1,174 @@
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+    print "This script must be run from the command line\n";
+    exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+define('LACONICA', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+class CommandInterpreterTest extends PHPUnit_Framework_TestCase
+{
+
+    /**
+     * @dataProvider commandInterpreterCases
+     */
+    public function testCommandInterpreter($input, $expectedType, $comment='')
+    {
+        $inter = new CommandInterpreter();
+
+        $user = new User(); // fake user
+        $user->limit(1);
+        $user->find();
+        $cmd = $inter->handle_command($user, $input);
+
+        $type = $cmd ? get_class($cmd) : null;
+        $this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
+    }
+
+    static public function commandInterpreterCases()
+    {
+        $sets = array(
+            array('help', 'HelpCommand'),
+            array('help me bro', null, 'help does not accept multiple params'),
+            array('HeLP', 'HelpCommand', 'case check'),
+            array('HeLP Me BRO!', null, 'case & non-params check'),
+
+            array('login', 'LoginCommand'),
+            array('login to savings!', null, 'login does not accept params'),
+
+            array('lose', null, 'lose must have at least 1 parameter'),
+            array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
+            array('lose        foobar', 'LoseCommand', 'check for space norm'),
+            array('lose more weight', null, 'lose does not accept multiple params'),
+
+            array('subscribers', 'SubscribersCommand'),
+            array('subscribers foo', null, 'subscribers does not take params'),
+
+            array('subscriptions', 'SubscriptionsCommand'),
+            array('subscriptions foo', null, 'subscriptions does not take params'),
+
+            array('groups', 'GroupsCommand'),
+            array('groups foo', null, 'groups does not take params'),
+
+            array('off', 'OffCommand', 'off accepts 0 or 1 params'),
+            array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
+            array('off foo bar', null, 'off accepts 0 or 1 params'),
+
+            array('stop', 'OffCommand', 'stop accepts 0 params'),
+            array('stop foo', null, 'stop accepts 0 params'),
+
+            array('quit', 'OffCommand', 'quit accepts 0 params'),
+            array('quit foo', null, 'quit accepts 0 params'),
+
+            array('on', 'OnCommand', 'on accepts 0 or 1 params'),
+            array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
+            array('on foo bar', null, 'on accepts 0 or 1 params'),
+
+            array('join', null),
+            array('join foo', 'JoinCommand'),
+            array('join foo bar', null),
+
+            array('drop', null),
+            array('drop foo', 'DropCommand'),
+            array('drop foo bar', null),
+
+            array('follow', null),
+            array('follow foo', 'SubCommand'),
+            array('follow foo bar', null),
+
+            array('sub', null),
+            array('sub foo', 'SubCommand'),
+            array('sub foo bar', null),
+
+            array('leave', null),
+            array('leave foo', 'UnsubCommand'),
+            array('leave foo bar', null),
+
+            array('unsub', null),
+            array('unsub foo', 'UnsubCommand'),
+            array('unsub foo bar', null),
+
+            array('leave', null),
+            array('leave foo', 'UnsubCommand'),
+            array('leave foo bar', null),
+
+            array('d', null),
+            array('d foo', null),
+            array('d foo bar', 'MessageCommand'),
+
+            array('dm', null),
+            array('dm foo', null),
+            array('dm foo bar', 'MessageCommand'),
+
+            array('r', null),
+            array('r foo', null),
+            array('r foo bar', 'ReplyCommand'),
+
+            array('reply', null),
+            array('reply foo', null),
+            array('reply foo bar', 'ReplyCommand'),
+
+            array('repeat', null),
+            array('repeat foo', 'RepeatCommand'),
+            array('repeat foo bar', null),
+
+            array('rp', null),
+            array('rp foo', 'RepeatCommand'),
+            array('rp foo bar', null),
+
+            array('rt', null),
+            array('rt foo', 'RepeatCommand'),
+            array('rt foo bar', null),
+
+            array('rd', null),
+            array('rd foo', 'RepeatCommand'),
+            array('rd foo bar', null),
+
+            array('whois', null),
+            array('whois foo', 'WhoisCommand'),
+            array('whois foo bar', null),
+
+            array('fav', null),
+            array('fav foo', 'FavCommand'),
+            array('fav foo bar', null),
+
+            array('nudge', null),
+            array('nudge foo', 'NudgeCommand'),
+            array('nudge foo bar', null),
+
+            array('stats', 'StatsCommand'),
+            array('stats foo', null),
+
+            array('invite', null),
+            array('invite foo', 'InviteCommand'),
+            array('invite foo bar', null),
+
+            array('track', null),
+            array('track foo', 'TrackCommand'),
+            array('track off', 'TrackOffCommand'),
+            array('track foo bar', null),
+            array('track off foo', null),
+
+            array('untrack', null),
+            array('untrack foo', 'UntrackCommand'),
+            array('untrack all', 'TrackOffCommand'),
+            array('untrack foo bar', null),
+            array('untrack all foo', null),
+
+            array('tracking', 'TrackingCommand'),
+            array('tracking foo', null),
+
+            array('tracks', 'TrackingCommand'),
+            array('tracks foo', null),
+
+        );
+        return $sets;
+    }
+
+}
+