Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
27cc9e9c
Unverified
Commit
27cc9e9c
authored
Oct 11, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tryMention for Chat entity and add extra Chat tests.
parent
01b137cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
12 deletions
+44
-12
Chat.php
src/Entities/Chat.php
+1
-1
ChatTest.php
tests/unit/Entities/ChatTest.php
+43
-11
No files found.
src/Entities/Chat.php
View file @
27cc9e9c
...
...
@@ -52,7 +52,7 @@ class Chat extends Entity
public
function
tryMention
(
$escape_markdown
=
false
)
{
if
(
$this
->
isPrivateChat
())
{
return
$this
->
tryMention
(
$escape_markdown
);
return
parent
::
tryMention
(
$escape_markdown
);
}
return
$this
->
getTitle
();
...
...
tests/unit/Entities/ChatTest.php
View file @
27cc9e9c
...
...
@@ -19,20 +19,52 @@ namespace Longman\TelegramBot\Tests\Unit;
*/
class
ChatTest
extends
TestCase
{
/**
* @var \Longman\TelegramBot\Entities\Chat
*/
private
$chat
;
public
function
testChatType
()
{
$this
->
chat
=
TestHelpers
::
getFakeChatObject
();
$this
->
assertEquals
(
'private'
,
$this
->
chat
->
getType
());
$chat
=
TestHelpers
::
getFakeChatObject
();
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
]);
$this
->
assertEquals
(
'group'
,
$this
->
chat
->
getType
());
// First and Last name.
$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'
]);
$this
->
assertEquals
(
'channel'
,
$this
->
chat
->
getType
());
// Non-private chat should return title.
$chat
=
TestHelpers
::
getFakeChatObject
([
'id'
=>
-
123
,
'type'
=>
null
,
'title'
=>
'My group chat'
]);
self
::
assertSame
(
'My group chat'
,
$chat
->
tryMention
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment