Fix tryMention for Chat entity and add extra Chat tests.

parent 01b137cb
...@@ -52,7 +52,7 @@ class Chat extends Entity ...@@ -52,7 +52,7 @@ class Chat extends Entity
public function tryMention($escape_markdown = false) public function tryMention($escape_markdown = false)
{ {
if ($this->isPrivateChat()) { if ($this->isPrivateChat()) {
return $this->tryMention($escape_markdown); return parent::tryMention($escape_markdown);
} }
return $this->getTitle(); return $this->getTitle();
......
...@@ -19,20 +19,52 @@ namespace Longman\TelegramBot\Tests\Unit; ...@@ -19,20 +19,52 @@ namespace Longman\TelegramBot\Tests\Unit;
*/ */
class ChatTest extends TestCase class ChatTest extends TestCase
{ {
/**
* @var \Longman\TelegramBot\Entities\Chat
*/
private $chat;
public function testChatType() public function testChatType()
{ {
$this->chat = TestHelpers::getFakeChatObject(); $chat = TestHelpers::getFakeChatObject();
$this->assertEquals('private', $this->chat->getType()); self::assertEquals('private', $chat->getType());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => null]);
self::assertEquals('group', $chat->getType());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'supergroup']);
self::assertEquals('supergroup', $chat->getType());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'channel']);
self::assertEquals('channel', $chat->getType());
}
public function testIsChatType()
{
$chat = TestHelpers::getFakeChatObject();
self::assertTrue($chat->isPrivateChat());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => null]);
self::assertTrue($chat->isGroupChat());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'supergroup']);
self::assertTrue($chat->isSuperGroup());
$chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'channel']);
self::assertTrue($chat->isChannel());
}
public function testTryMention()
{
// Username.
$chat = TestHelpers::getFakeChatObject(['id' => 1, 'first_name' => 'John', 'last_name' => 'Taylor', 'username' => 'jtaylor']);
self::assertEquals('@jtaylor', $chat->tryMention());
// First name.
$chat = TestHelpers::getFakeChatObject(['id' => 1, 'first_name' => 'John', 'last_name' => null, 'username' => null]);
self::assertEquals('John', $chat->tryMention());
$this->chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => null]); // First and Last name.
$this->assertEquals('group', $this->chat->getType()); $chat = TestHelpers::getFakeChatObject(['id' => 1, 'first_name' => 'John', 'last_name' => 'Taylor', 'username' => null]);
self::assertEquals('John Taylor', $chat->tryMention());
$this->chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => 'channel']); // Non-private chat should return title.
$this->assertEquals('channel', $this->chat->getType()); $chat = TestHelpers::getFakeChatObject(['id' => -123, 'type' => null, 'title' => 'My group chat']);
self::assertSame('My group chat', $chat->tryMention());
} }
} }
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