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
68660025
Unverified
Commit
68660025
authored
Jul 06, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make more use of the TestHelpers functions.
parent
75f72d54
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
37 deletions
+20
-37
ConversationTest.php
tests/Unit/ConversationTest.php
+6
-6
ChatTest.php
tests/Unit/Entities/ChatTest.php
+5
-5
MessageTest.php
tests/Unit/Entities/MessageTest.php
+9
-26
No files found.
tests/Unit/ConversationTest.php
View file @
68660025
...
...
@@ -57,7 +57,7 @@ class ConversationTest extends TestCase
public
function
testConversationThatExistsPropertiesSetCorrectly
()
{
$info
=
TestHelpers
::
startFakeConversation
(
'command'
);
$info
=
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
$info
[
'user_id'
],
$info
[
'chat_id'
],
'command'
);
$this
->
assertAttributeEquals
(
$info
[
'user_id'
],
'user_id'
,
$conversation
);
$this
->
assertAttributeEquals
(
$info
[
'chat_id'
],
'chat_id'
,
$conversation
);
...
...
@@ -81,7 +81,7 @@ class ConversationTest extends TestCase
public
function
testNewConversationThatWontExistWithoutCommand
()
{
TestHelpers
::
startFakeConversation
(
null
);
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
0
,
0
);
$this
->
assertFalse
(
$conversation
->
exists
());
$this
->
assertNull
(
$conversation
->
getCommand
());
...
...
@@ -89,7 +89,7 @@ class ConversationTest extends TestCase
public
function
testNewConversationThatWillExistWithCommand
()
{
$info
=
TestHelpers
::
startFakeConversation
(
'command'
);
$info
=
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
$info
[
'user_id'
],
$info
[
'chat_id'
],
'command'
);
$this
->
assertTrue
(
$conversation
->
exists
());
$this
->
assertEquals
(
'command'
,
$conversation
->
getCommand
());
...
...
@@ -97,7 +97,7 @@ class ConversationTest extends TestCase
public
function
testStopConversation
()
{
$info
=
TestHelpers
::
startFakeConversation
(
'command'
);
$info
=
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
$info
[
'user_id'
],
$info
[
'chat_id'
],
'command'
);
$this
->
assertTrue
(
$conversation
->
exists
());
$conversation
->
stop
();
...
...
@@ -108,7 +108,7 @@ class ConversationTest extends TestCase
public
function
testCancelConversation
()
{
$info
=
TestHelpers
::
startFakeConversation
(
'command'
);
$info
=
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
$info
[
'user_id'
],
$info
[
'chat_id'
],
'command'
);
$this
->
assertTrue
(
$conversation
->
exists
());
$conversation
->
cancel
();
...
...
@@ -119,7 +119,7 @@ class ConversationTest extends TestCase
public
function
testUpdateConversationNotes
()
{
$info
=
TestHelpers
::
startFakeConversation
(
'command'
);
$info
=
TestHelpers
::
startFakeConversation
();
$conversation
=
new
Conversation
(
$info
[
'user_id'
],
$info
[
'chat_id'
],
'command'
);
$conversation
->
notes
=
'newnote'
;
$conversation
->
update
();
...
...
tests/Unit/Entities/ChatTest.php
View file @
68660025
...
...
@@ -10,7 +10,8 @@
namespace
Tests\Unit
;
use
\Longman\TelegramBot\Entities\Chat
;
use
Longman\TelegramBot\Entities\Chat
;
use
Tests\TestHelpers
;
/**
* @package TelegramTest
...
...
@@ -35,14 +36,13 @@ class ChatTest extends TestCase
public
function
testChatType
()
{
$this
->
chat
=
new
Chat
(
json_decode
(
'{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"}'
,
true
));
$this
->
chat
=
TestHelpers
::
getFakeChatObject
();
$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
->
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
());
}
}
tests/Unit/Entities/MessageTest.php
View file @
68660025
...
...
@@ -10,7 +10,7 @@
namespace
Tests\Unit
;
use
\Longman\TelegramBot\Entities\Message
;
use
Tests\TestHelpers
;
/**
* @package TelegramTest
...
...
@@ -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
()
{
// /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
->
getCommand
());
$this
->
assertEquals
(
'/help'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
''
,
$this
->
message
->
getText
(
true
));
// 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
->
getCommand
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /command@bot
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
'/help@testbot'
),
'testbot'
);
$this
->
message
=
TestHelpers
::
getFakeMessageObject
([
'text'
=>
'/help@testbot'
]);
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
''
,
$this
->
message
->
getText
(
true
));
// /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
->
getCommand
());
$this
->
assertEquals
(
'/help some text'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /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'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
'/help@testbot some text'
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /commmad\n 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
->
message
=
TestHelpers
::
getFakeMessageObject
([
'text'
=>
"/help
\n
some text"
]);
$this
->
assertEquals
(
'/help'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help
\n
some text"
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
' some text'
,
$this
->
message
->
getText
(
true
));
// /command@bot\nsome text
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
"/help@testbot
\n
some text"
),
'testbot'
);
$this
->
message
=
TestHelpers
::
getFakeMessageObject
([
'text'
=>
"/help@testbot
\n
some text"
]
);
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help@testbot
\n
some text"
,
$this
->
message
->
getText
());
$this
->
assertEquals
(
'some text'
,
$this
->
message
->
getText
(
true
));
// /command@bot \nsome text
$this
->
message
=
new
Message
(
$this
->
generateMessage
(
"/help@testbot
\n
some text"
),
'testbot'
);
$this
->
message
=
TestHelpers
::
getFakeMessageObject
([
'text'
=>
"/help@testbot
\n
some text"
]
);
$this
->
assertEquals
(
'/help@testbot'
,
$this
->
message
->
getFullCommand
());
$this
->
assertEquals
(
'help'
,
$this
->
message
->
getCommand
());
$this
->
assertEquals
(
"/help@testbot
\n
some text"
,
$this
->
message
->
getText
());
...
...
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