Commit 1528fe52 authored by Marcel's avatar Marcel Committed by GitHub

Merge pull request #1 from noplanman/help_show_tests

Add tests for commands shown in help command.
parents 98bafec9 238402ef
......@@ -127,6 +127,12 @@ class CommandTest extends TestCase
$this->assertTrue($this->command_stub->isEnabled());
}
public function testDefaultCommandShownInHelp()
{
$this->assertAttributeEquals(true, 'show_in_help', $this->command_stub);
$this->assertTrue($this->command_stub->showInHelp());
}
public function testDefaultCommandNeedsMysql()
{
$this->assertAttributeEquals(false, 'need_mysql', $this->command_stub);
......
......@@ -39,6 +39,9 @@ class CommandTestCase extends TestCase
{
$this->telegram = new Telegram('apikey', 'testbot');
$this->telegram->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands');
// Add custom commands dedicated to do some tests.
$this->telegram->addCommandsPath(__DIR__ . '/CustomTestCommands');
$this->telegram->getCommandsList();
}
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
/**
* Test "/hidden" command to test $show_in_help
*/
class HiddenCommand extends UserCommand
{
/**
* @var string
*/
protected $name = 'hidden';
/**
* @var string
*/
protected $description = 'This command is hidden in help';
/**
* @var string
*/
protected $usage = '/hidden';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* @var bool
*/
protected $show_in_help = false;
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
return Request::emptyResponse();
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request;
/**
* Test "/visible" command to test $show_in_help
*/
class VisibleCommand extends UserCommand
{
/**
* @var string
*/
protected $name = 'visible';
/**
* @var string
*/
protected $description = 'This command is visible in help';
/**
* @var string
*/
protected $usage = '/visible';
/**
* @var string
*/
protected $version = '1.0.0';
/**
* @var bool
*/
protected $show_in_help = true;
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
return Request::emptyResponse();
}
}
......@@ -10,9 +10,9 @@
namespace Longman\TelegramBot\Tests\Unit\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommands\HelpCommand;
use Longman\TelegramBot\Tests\Unit\Commands\CommandTestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
use Longman\TelegramBot\Commands\UserCommands\HelpCommand;
/**
* @package TelegramTest
......@@ -71,4 +71,15 @@ class HelpCommandTest extends CommandTestCase
->getText();
$this->assertContains("Description: Show text\nUsage: /echo <text>", $text);
}
public function testHelpCommandWithHiddenCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help'))
->execute()
->getResult()
->getText();
$this->assertContains('/visible', $text);
$this->assertNotContains('/hidden', $text);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment