Commit e8a663c9 authored by Jack'lul's avatar Jack'lul Committed by GitHub

Merge pull request #6 from noplanman/no_default_commands_fix_tests

No default commands fix tests
parents 89d2f73b e0c1889a
......@@ -404,8 +404,6 @@ class Telegram
$this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false);
}
$this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false);
$type = $message->getType();
if ($type === 'command') {
$command = $message->getCommand();
......@@ -850,7 +848,7 @@ class Telegram
return $this;
}
/**
* Run provided commands
*
......
......@@ -38,8 +38,6 @@ class CommandTestCase extends TestCase
public function setUp()
{
$this->telegram = new Telegram('apikey', 'testbot');
$this->telegram->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands');
$this->telegram->addCommandsPath(BASE_PATH . '/../examples/Commands');
// Add custom commands dedicated to do some tests.
$this->telegram->addCommandsPath(__DIR__ . '/CustomTestCommands');
......
<?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\Tests\Unit\Commands\UserCommands;
use Longman\TelegramBot\Tests\Unit\Commands\CommandTestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
use Longman\TelegramBot\Commands\UserCommands\EchoCommand;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class EchoCommandTest extends CommandTestCase
{
/**
* setUp
*/
public function setUp()
{
parent::setUp();
$this->command = new EchoCommand($this->telegram);
}
public function testEchoCommandProperties()
{
$this->assertAttributeEquals('echo', 'name', $this->command);
$this->assertAttributeEquals('Show text', 'description', $this->command);
$this->assertAttributeEquals('/echo <text>', 'usage', $this->command);
}
public function testEchoCommandExecuteWithoutParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo'))
->execute()
->getResult()
->getText();
$this->assertEquals('Command usage: /echo <text>', $text);
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo '))
->execute()
->getResult()
->getText();
$this->assertEquals('Command usage: /echo <text>', $text);
}
public function testEchoCommandExecuteWithParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/echo Message!'))
->execute()
->getResult()
->getText();
$this->assertEquals('Message!', $text);
}
}
<?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\Tests\Unit\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommands\HelpCommand;
use Longman\TelegramBot\Tests\Unit\Commands\CommandTestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class HelpCommandTest extends CommandTestCase
{
/**
* setUp
*/
public function setUp()
{
parent::setUp();
$this->command = new HelpCommand($this->telegram);
}
public function testHelpCommandProperties()
{
$this->assertAttributeEquals('help', 'name', $this->command);
$this->assertAttributeEquals('Show bot commands help', 'description', $this->command);
$this->assertAttributeEquals('/help or /help <command>', 'usage', $this->command);
}
public function testHelpCommandExecuteWithoutParameter()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help'))
->execute()
->getResult()
->getText();
$this->assertContains(
'testbot v. ' . $this->telegram->getVersion() . "\n\nCommands List:",
$text
);
}
public function testHelpCommandExecuteWithParameterInvalidCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help invalidcommand'))
->execute()
->getResult()
->getText();
$this->assertEquals('No help available: Command /invalidcommand not found', $text);
}
public function testHelpCommandExecuteWithParameterValidCommand()
{
$text = $this->command
->setUpdate(TestHelpers::getFakeUpdateCommandObject('/help echo'))
->execute()
->getResult()
->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);
}
}
......@@ -148,10 +148,4 @@ class TelegramTest extends TestCase
$this->assertInternalType('array', $commands);
$this->assertNotCount(0, $commands);
}
public function testGetHelpCommandObject()
{
$command = $this->telegram->getCommandObject('help');
$this->assertInstanceOf('Longman\TelegramBot\Commands\UserCommands\HelpCommand', $command);
}
}
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