Make more use of the TestHelpers functions.

parent 75f72d54
...@@ -57,7 +57,7 @@ class ConversationTest extends TestCase ...@@ -57,7 +57,7 @@ class ConversationTest extends TestCase
public function testConversationThatExistsPropertiesSetCorrectly() public function testConversationThatExistsPropertiesSetCorrectly()
{ {
$info = TestHelpers::startFakeConversation('command'); $info = TestHelpers::startFakeConversation();
$conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
$this->assertAttributeEquals($info['user_id'], 'user_id', $conversation); $this->assertAttributeEquals($info['user_id'], 'user_id', $conversation);
$this->assertAttributeEquals($info['chat_id'], 'chat_id', $conversation); $this->assertAttributeEquals($info['chat_id'], 'chat_id', $conversation);
...@@ -81,7 +81,7 @@ class ConversationTest extends TestCase ...@@ -81,7 +81,7 @@ class ConversationTest extends TestCase
public function testNewConversationThatWontExistWithoutCommand() public function testNewConversationThatWontExistWithoutCommand()
{ {
TestHelpers::startFakeConversation(null); TestHelpers::startFakeConversation();
$conversation = new Conversation(0, 0); $conversation = new Conversation(0, 0);
$this->assertFalse($conversation->exists()); $this->assertFalse($conversation->exists());
$this->assertNull($conversation->getCommand()); $this->assertNull($conversation->getCommand());
...@@ -89,7 +89,7 @@ class ConversationTest extends TestCase ...@@ -89,7 +89,7 @@ class ConversationTest extends TestCase
public function testNewConversationThatWillExistWithCommand() public function testNewConversationThatWillExistWithCommand()
{ {
$info = TestHelpers::startFakeConversation('command'); $info = TestHelpers::startFakeConversation();
$conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
$this->assertTrue($conversation->exists()); $this->assertTrue($conversation->exists());
$this->assertEquals('command', $conversation->getCommand()); $this->assertEquals('command', $conversation->getCommand());
...@@ -97,7 +97,7 @@ class ConversationTest extends TestCase ...@@ -97,7 +97,7 @@ class ConversationTest extends TestCase
public function testStopConversation() public function testStopConversation()
{ {
$info = TestHelpers::startFakeConversation('command'); $info = TestHelpers::startFakeConversation();
$conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
$this->assertTrue($conversation->exists()); $this->assertTrue($conversation->exists());
$conversation->stop(); $conversation->stop();
...@@ -108,7 +108,7 @@ class ConversationTest extends TestCase ...@@ -108,7 +108,7 @@ class ConversationTest extends TestCase
public function testCancelConversation() public function testCancelConversation()
{ {
$info = TestHelpers::startFakeConversation('command'); $info = TestHelpers::startFakeConversation();
$conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
$this->assertTrue($conversation->exists()); $this->assertTrue($conversation->exists());
$conversation->cancel(); $conversation->cancel();
...@@ -119,7 +119,7 @@ class ConversationTest extends TestCase ...@@ -119,7 +119,7 @@ class ConversationTest extends TestCase
public function testUpdateConversationNotes() public function testUpdateConversationNotes()
{ {
$info = TestHelpers::startFakeConversation('command'); $info = TestHelpers::startFakeConversation();
$conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
$conversation->notes = 'newnote'; $conversation->notes = 'newnote';
$conversation->update(); $conversation->update();
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
namespace Tests\Unit; namespace Tests\Unit;
use \Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Tests\TestHelpers;
/** /**
* @package TelegramTest * @package TelegramTest
...@@ -35,14 +36,13 @@ class ChatTest extends TestCase ...@@ -35,14 +36,13 @@ class ChatTest extends TestCase
public function testChatType() public function testChatType()
{ {
$this->chat = TestHelpers::getFakeChatObject();
$this->chat = new Chat(json_decode('{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"}',true));
$this->assertEquals('private', $this->chat->getType()); $this->assertEquals('private', $this->chat->getType());
$this->chat = new Chat(json_decode('{"id":-123,"title":"ChatTitle","first_name":null,"last_name":null,"username":"null"}',true)); $this->chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => null]);
$this->assertEquals('group', $this->chat->getType()); $this->assertEquals('group', $this->chat->getType());
$this->chat = new Chat(json_decode('{"id":-123,"type":"channel","title":"ChatTitle","first_name":null,"last_name":null,"username":"null"}',true)); $this->chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'channel']);
$this->assertEquals('channel', $this->chat->getType()); $this->assertEquals('channel', $this->chat->getType());
} }
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
namespace Tests\Unit; namespace Tests\Unit;
use \Longman\TelegramBot\Entities\Message; use Tests\TestHelpers;
/** /**
* @package TelegramTest * @package TelegramTest
...@@ -33,75 +33,58 @@ class MessageTest extends TestCase ...@@ -33,75 +33,58 @@ class MessageTest extends TestCase
{ {
} }
protected function generateMessage($string) {
$string = str_replace("\n", "\\n", $string);
$json = '{"message_id":961,"from":{"id":123,"first_name":"john","username":"john"},"chat":{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"},"date":1435920612,"text":"'.$string.'"}';
//$json = utf8_encode($json);
return json_decode($json, true);
}
public function testTextAndCommandRecognise() { public function testTextAndCommandRecognise() {
// /command // /command
$this->message = new Message($this->generateMessage('/help'), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => '/help']);
$this->assertEquals('/help', $this->message->getFullCommand()); $this->assertEquals('/help', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals('/help', $this->message->getText()); $this->assertEquals('/help', $this->message->getText());
$this->assertEquals('', $this->message->getText(true)); $this->assertEquals('', $this->message->getText(true));
// text // text
$this->message = new Message($this->generateMessage('some text'), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => 'some text']);
$this->assertEquals('', $this->message->getFullCommand()); $this->assertEquals('', $this->message->getFullCommand());
$this->assertEquals('', $this->message->getCommand()); $this->assertEquals('', $this->message->getCommand());
$this->assertEquals('some text', $this->message->getText()); $this->assertEquals('some text', $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true)); $this->assertEquals('some text', $this->message->getText(true));
// /command@bot // /command@bot
$this->message = TestHelpers::getFakeMessageObject(['text' => '/help@testbot']);
$this->message = new Message($this->generateMessage('/help@testbot'), 'testbot');
$this->assertEquals('/help@testbot', $this->message->getFullCommand()); $this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals('/help@testbot', $this->message->getText()); $this->assertEquals('/help@testbot', $this->message->getText());
$this->assertEquals('', $this->message->getText(true)); $this->assertEquals('', $this->message->getText(true));
// /commmad text // /commmad text
$this->message = new Message($this->generateMessage('/help some text'), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => '/help some text']);
$this->assertEquals('/help', $this->message->getFullCommand()); $this->assertEquals('/help', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals('/help some text', $this->message->getText()); $this->assertEquals('/help some text', $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true)); $this->assertEquals('some text', $this->message->getText(true));
// /command@bot some text // /command@bot some text
$this->message = new Message($this->generateMessage('/help@testbot some text'), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => '/help@testbot some text']);
$this->assertEquals('/help@testbot', $this->message->getFullCommand()); $this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals('/help@testbot some text', $this->message->getText()); $this->assertEquals('/help@testbot some text', $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true)); $this->assertEquals('some text', $this->message->getText(true));
// /commmad\n text // /commmad\n text
$this->message = TestHelpers::getFakeMessageObject(['text' => "/help\n some text"]);
//$array = $this->generateMessage("/help\n some text");
////print_r($this->generateMessage('/help@testbot'));
//echo 'value:';
//print_r($array);
$this->message = new Message($this->generateMessage("/help\n some text"), 'testbot');
$this->assertEquals('/help', $this->message->getFullCommand()); $this->assertEquals('/help', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help\n some text", $this->message->getText()); $this->assertEquals("/help\n some text", $this->message->getText());
$this->assertEquals(' some text', $this->message->getText(true)); $this->assertEquals(' some text', $this->message->getText(true));
// /command@bot\nsome text // /command@bot\nsome text
$this->message = new Message($this->generateMessage("/help@testbot\nsome text"), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => "/help@testbot\nsome text"]);
$this->assertEquals('/help@testbot', $this->message->getFullCommand()); $this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help@testbot\nsome text", $this->message->getText()); $this->assertEquals("/help@testbot\nsome text", $this->message->getText());
$this->assertEquals('some text', $this->message->getText(true)); $this->assertEquals('some text', $this->message->getText(true));
// /command@bot \nsome text // /command@bot \nsome text
$this->message = new Message($this->generateMessage("/help@testbot \nsome text"), 'testbot'); $this->message = TestHelpers::getFakeMessageObject(['text' => "/help@testbot \nsome text"]);
$this->assertEquals('/help@testbot', $this->message->getFullCommand()); $this->assertEquals('/help@testbot', $this->message->getFullCommand());
$this->assertEquals('help', $this->message->getCommand()); $this->assertEquals('help', $this->message->getCommand());
$this->assertEquals("/help@testbot \nsome text", $this->message->getText()); $this->assertEquals("/help@testbot \nsome text", $this->message->getText());
......
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