forked from GNUsocial/gnu-social
[TESTS] Fix CommandInterpreterTest
Also corrected a bad refactoring that affected Xmpp plugin test
This commit is contained in:
parent
236929a166
commit
aa7aff3f6b
@ -53,34 +53,46 @@ class DirectMessagePlugin extends Plugin
|
||||
public function onRouterInitialized(URLMapper $m)
|
||||
{
|
||||
// web front-end actions
|
||||
$m->connect('message/new',
|
||||
['action' => 'newmessage']);
|
||||
$m->connect('message/new?to=:to',
|
||||
['action' => 'newmessage'],
|
||||
['to' => '[0-9]+']);
|
||||
$m->connect(
|
||||
'message/new',
|
||||
['action' => 'newmessage']
|
||||
);
|
||||
$m->connect(
|
||||
'message/new?to=:to',
|
||||
['action' => 'newmessage'],
|
||||
['to' => '[0-9]+']
|
||||
);
|
||||
|
||||
$m->connect('message/:message',
|
||||
['action' => 'showmessage'],
|
||||
['message' => '[0-9]+']);
|
||||
$m->connect(
|
||||
'message/:message',
|
||||
['action' => 'showmessage'],
|
||||
['message' => '[0-9]+']
|
||||
);
|
||||
|
||||
// direct messages
|
||||
$m->connect('api/direct_messages.:format',
|
||||
['action' => 'ApiDirectMessage'],
|
||||
['format' => '(xml|json|rss|atom)']);
|
||||
$m->connect('api/direct_messages/sent.:format',
|
||||
['action' => 'ApiDirectMessage',
|
||||
$m->connect(
|
||||
'api/direct_messages.:format',
|
||||
['action' => 'ApiDirectMessage'],
|
||||
['format' => '(xml|json|rss|atom)']
|
||||
);
|
||||
$m->connect(
|
||||
'api/direct_messages/sent.:format',
|
||||
['action' => 'ApiDirectMessage',
|
||||
'sent' => true],
|
||||
['format' => '(xml|json|rss|atom)']);
|
||||
$m->connect('api/direct_messages/new.:format',
|
||||
['action' => 'ApiDirectMessageNew'],
|
||||
['format' => '(xml|json)']);
|
||||
['format' => '(xml|json|rss|atom)']
|
||||
);
|
||||
$m->connect(
|
||||
'api/direct_messages/new.:format',
|
||||
['action' => 'ApiDirectMessageNew'],
|
||||
['format' => '(xml|json)']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we allowed to perform a certain command over the API?
|
||||
*
|
||||
*
|
||||
* @param Command $cmd
|
||||
* @param bool &$supported
|
||||
* @return bool hook value
|
||||
@ -97,7 +109,7 @@ class DirectMessagePlugin extends Plugin
|
||||
* @param string $cmd Command being run
|
||||
* @param string $arg Rest of the message (including address)
|
||||
* @param User $user User sending the message
|
||||
* @param Command|bool &$result The resulting command object to be run.
|
||||
* @param MessageCommand|bool &$result The resulting command object to be run.
|
||||
* @return bool hook value
|
||||
*/
|
||||
public function onStartInterpretCommand(string $cmd, ?string $arg, User $user, &$result) : bool
|
||||
@ -118,29 +130,31 @@ class DirectMessagePlugin extends Plugin
|
||||
|
||||
/**
|
||||
* Show Message button in someone's left-side navigation menu
|
||||
*
|
||||
*
|
||||
* @param Menu $menu
|
||||
* @param Profile $target
|
||||
* @param Profile $scoped
|
||||
* @return void
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped = null)
|
||||
{
|
||||
if ($scoped instanceof Profile && $scoped->id == $target->id
|
||||
&& !common_config('singleuser', 'enabled')) {
|
||||
|
||||
$menu->out->menuItem(common_local_url('inbox', ['nickname' => $target->getNickname()]),
|
||||
$menu->out->menuItem(
|
||||
common_local_url('inbox', ['nickname' => $target->getNickname()]),
|
||||
// TRANS: Menu item in personal group navigation menu.
|
||||
_m('MENU','Messages'),
|
||||
_m('MENU', 'Messages'),
|
||||
// TRANS: Menu item title in personal group navigation menu.
|
||||
_('Your incoming messages'),
|
||||
$scoped->id === $target->id && $menu->actionName =='inbox');
|
||||
$scoped->id === $target->id && $menu->actionName =='inbox'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Message button in someone's profile page
|
||||
*
|
||||
*
|
||||
* @param HTMLOutputter $out
|
||||
* @param Profile $profile
|
||||
* @return bool hook flag
|
||||
@ -159,12 +173,14 @@ class DirectMessagePlugin extends Plugin
|
||||
|
||||
if (!$profile->hasBlocked($scoped)) {
|
||||
$out->elementStart('li', 'entity_send-a-message');
|
||||
$out->element('a',
|
||||
['href' => common_local_url('newmessage', ['to' => $profile->getID()]),
|
||||
$out->element(
|
||||
'a',
|
||||
['href' => common_local_url('newmessage', ['to' => $profile->getID()]),
|
||||
// TRANS: Link title for link on user profile.
|
||||
'title' => _('Send a direct message to this user.')],
|
||||
// TRANS: Link text for link on user profile.
|
||||
_m('BUTTON','Message'));
|
||||
_m('BUTTON', 'Message')
|
||||
);
|
||||
$out->elementEnd('li');
|
||||
}
|
||||
|
||||
@ -197,10 +213,12 @@ class DirectMessagePlugin extends Plugin
|
||||
$msg = Message::getKV('id', $message->id);
|
||||
$act = $msg->asActivity();
|
||||
|
||||
Notice::saveActivity($act,
|
||||
$msg->getFrom(),
|
||||
['source' => 'web',
|
||||
'scope' => NOTICE::MESSAGE_SCOPE]);
|
||||
Notice::saveActivity(
|
||||
$act,
|
||||
$msg->getFrom(),
|
||||
['source' => 'web',
|
||||
'scope' => NOTICE::MESSAGE_SCOPE]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ if (!defined('STATUSNET')) { // Compatibility
|
||||
|
||||
use CommandInterpreter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use User;
|
||||
|
||||
require_once INSTALLDIR . '/lib/util/common.php';
|
||||
|
||||
@ -47,7 +48,7 @@ final class CommandInterpreterTest extends TestCase
|
||||
{
|
||||
$inter = new CommandInterpreter();
|
||||
|
||||
$cmd = $inter->handle_command(null, $input);
|
||||
$cmd = $inter->handle_command(User::getById(1), $input);
|
||||
|
||||
$type = $cmd ? get_class($cmd) : null;
|
||||
$this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
|
||||
|
@ -71,12 +71,16 @@ final class NicknameTest extends TestCase
|
||||
} else {
|
||||
$stuff = var_export($exception, true);
|
||||
}
|
||||
$this->assertTrue($exception && $exception instanceof $expectedException,
|
||||
$this->assertTrue(
|
||||
$exception && $exception instanceof $expectedException,
|
||||
"invalid input '$input' expected to fail with $expectedException, " .
|
||||
"got $stuff");
|
||||
"got $stuff"
|
||||
);
|
||||
} else {
|
||||
$this->assertTrue($normalized == false,
|
||||
"invalid input '$input' expected to fail");
|
||||
$this->assertTrue(
|
||||
$normalized == false,
|
||||
"invalid input '$input' expected to fail"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$msg = "normalized input nickname '$input' expected to normalize to '$expected', got ";
|
||||
@ -113,12 +117,12 @@ final class NicknameTest extends TestCase
|
||||
} else {
|
||||
$text = "@{$input} awesome! :)";
|
||||
$matches = common_find_mentions_raw($text);
|
||||
$this->assertEquals(1, count($matches));
|
||||
$this->assertCount(1, $matches);
|
||||
$this->assertEquals($expected, Nickname::normalize($matches[0][0]));
|
||||
}
|
||||
}
|
||||
|
||||
static public function provider()
|
||||
public static function provider()
|
||||
{
|
||||
return array(
|
||||
array('evan', 'evan'),
|
||||
|
@ -31,16 +31,17 @@ if (!defined('STATUSNET')) { // Compatibility
|
||||
|
||||
use GNUsocial;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PluginList;
|
||||
use XmppPlugin;
|
||||
|
||||
require_once INSTALLDIR . '/lib/util/common.php';
|
||||
require_once INSTALLDIR . '/plugins/Xmpp/XmppModule.php';
|
||||
require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php';
|
||||
|
||||
final class XmppValidateTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
if (!array_key_exists('Xmpp', GNUsocial::getActiveModules())) {
|
||||
if (!PluginList::isPluginActive('Xmpp')) {
|
||||
$this->markTestSkipped('XmppPlugin is not enabled.');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user