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