gnu-social/tests/Core/CommandInterperterTest.php

200 lines
6.2 KiB
PHP
Raw Normal View History

<?php
2019-07-13 00:31:14 +09:00
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
namespace Tests\Unit;
if (!defined('INSTALLDIR')) {
define('INSTALLDIR', dirname(dirname(__DIR__)));
}
2019-07-25 09:29:20 +09:00
if (!defined('PUBLICDIR')) {
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
}
2019-07-13 00:31:14 +09:00
if (!defined('GNUSOCIAL')) {
define('GNUSOCIAL', true);
}
if (!defined('STATUSNET')) { // Compatibility
define('STATUSNET', true);
}
2019-07-13 00:31:14 +09:00
use CommandInterpreter;
use PHPUnit\Framework\TestCase;
use User;
2019-08-23 21:36:02 +09:00
require_once INSTALLDIR . '/lib/util/common.php';
2020-06-24 21:08:11 +09:00
final class CommandInterperterTest extends TestCase
{
/**
* @dataProvider commandInterpreterCases
2020-06-24 21:08:11 +09:00
*
2019-07-13 00:31:14 +09:00
* @param $input
* @param $expectedType
* @param string $comment
2020-06-24 21:08:11 +09:00
* @throws \EmptyPkeyValueException
* @throws \ServerException
*/
2019-07-13 00:31:14 +09:00
public function testCommandInterpreter($input, $expectedType, $comment = '')
{
$inter = new CommandInterpreter();
$cmd = $inter->handle_command(User::getById(1), $input);
$type = $cmd ? get_class($cmd) : null;
2020-06-24 21:08:11 +09:00
static::assertSame(strtolower($expectedType), strtolower($type), $comment);
}
2020-06-24 21:08:11 +09:00
public static function commandInterpreterCases()
{
2020-06-24 21:08:11 +09:00
$sets = [
['help', 'HelpCommand'],
['help me bro', null, 'help does not accept multiple params'],
['HeLP', 'HelpCommand', 'case check'],
['HeLP Me BRO!', null, 'case & non-params check'],
2020-06-24 21:08:11 +09:00
['login', 'LoginCommand'],
['login to savings!', null, 'login does not accept params'],
2020-06-24 21:08:11 +09:00
['lose', null, 'lose must have at least 1 parameter'],
['lose foobar', 'LoseCommand', 'lose requires 1 parameter'],
['lose foobar', 'LoseCommand', 'check for space norm'],
['lose more weight', null, 'lose does not accept multiple params'],
2020-06-24 21:08:11 +09:00
['subscribers', 'SubscribersCommand'],
['subscribers foo', null, 'subscribers does not take params'],
2020-06-24 21:08:11 +09:00
['subscriptions', 'SubscriptionsCommand'],
['subscriptions foo', null, 'subscriptions does not take params'],
2020-06-24 21:08:11 +09:00
['groups', 'GroupsCommand'],
['groups foo', null, 'groups does not take params'],
2020-06-24 21:08:11 +09:00
['off', 'OffCommand', 'off accepts 0 or 1 params'],
['off foo', 'OffCommand', 'off accepts 0 or 1 params'],
['off foo bar', null, 'off accepts 0 or 1 params'],
2020-06-24 21:08:11 +09:00
['stop', 'OffCommand', 'stop accepts 0 params'],
['stop foo', null, 'stop accepts 0 params'],
2020-06-24 21:08:11 +09:00
['quit', 'OffCommand', 'quit accepts 0 params'],
['quit foo', null, 'quit accepts 0 params'],
2020-06-24 21:08:11 +09:00
['on', 'OnCommand', 'on accepts 0 or 1 params'],
['on foo', 'OnCommand', 'on accepts 0 or 1 params'],
['on foo bar', null, 'on accepts 0 or 1 params'],
2020-06-24 21:08:11 +09:00
['join', null],
['join foo', 'JoinCommand'],
['join foo bar', null],
2020-06-24 21:08:11 +09:00
['drop', null],
['drop foo', 'DropCommand'],
['drop foo bar', null],
2020-06-24 21:08:11 +09:00
['follow', null],
['follow foo', 'SubCommand'],
['follow foo bar', null],
2020-06-24 21:08:11 +09:00
['sub', null],
['sub foo', 'SubCommand'],
['sub foo bar', null],
2020-06-24 21:08:11 +09:00
['leave', null],
['leave foo', 'UnsubCommand'],
['leave foo bar', null],
2020-06-24 21:08:11 +09:00
['unsub', null],
['unsub foo', 'UnsubCommand'],
['unsub foo bar', null],
2020-06-24 21:08:11 +09:00
['leave', null],
['leave foo', 'UnsubCommand'],
['leave foo bar', null],
2020-06-24 21:08:11 +09:00
['d', null],
['d foo', null],
['d foo bar', 'MessageCommand'],
2020-06-24 21:08:11 +09:00
['dm', null],
['dm foo', null],
['dm foo bar', 'MessageCommand'],
2020-06-24 21:08:11 +09:00
['r', null],
['r foo', null],
['r foo bar', 'ReplyCommand'],
2020-06-24 21:08:11 +09:00
['reply', null],
['reply foo', null],
['reply foo bar', 'ReplyCommand'],
2020-06-24 21:08:11 +09:00
['repeat', null],
['repeat foo', 'RepeatCommand'],
['repeat foo bar', null],
2020-06-24 21:08:11 +09:00
['rp', null],
['rp foo', 'RepeatCommand'],
['rp foo bar', null],
2020-06-24 21:08:11 +09:00
['rt', null],
['rt foo', 'RepeatCommand'],
['rt foo bar', null],
2020-06-24 21:08:11 +09:00
['rd', null],
['rd foo', 'RepeatCommand'],
['rd foo bar', null],
2020-06-24 21:08:11 +09:00
['whois', null],
['whois foo', 'WhoisCommand'],
['whois foo bar', null],
2019-07-13 00:31:14 +09:00
/* array('fav', null),
array('fav foo', 'FavCommand'),
array('fav foo bar', null),*/
2020-06-24 21:08:11 +09:00
['nudge', null],
['nudge foo', 'NudgeCommand'],
['nudge foo bar', null],
2020-06-24 21:08:11 +09:00
['stats', 'StatsCommand'],
['stats foo', null],
2020-06-24 21:08:11 +09:00
['invite', null],
['invite foo', 'InviteCommand'],
['invite foo bar', null],
2020-06-24 21:08:11 +09:00
['track', null],
['track foo', 'SearchSubTrackCommand'],
['track off', 'SearchSubTrackOffCommand'],
['track foo bar', null],
['track off foo', null],
2020-06-24 21:08:11 +09:00
['untrack', null],
['untrack foo', 'SearchSubUntrackCommand'],
['untrack all', 'SearchSubTrackOffCommand'],
['untrack foo bar', null],
['untrack all foo', null],
2020-06-24 21:08:11 +09:00
['tracking', 'SearchSubTrackingCommand'],
['tracking foo', null],
2020-06-24 21:08:11 +09:00
['tracks', 'SearchSubTrackingCommand'],
['tracks foo', null],
2020-06-24 21:08:11 +09:00
];
return $sets;
}
}