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
ce42f431
Unverified
Commit
ce42f431
authored
Oct 04, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add InlineKeyboard tests and fix createFromParams method.
parent
9eb50bb0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
11 deletions
+118
-11
Keyboard.php
src/Entities/Keyboard.php
+6
-2
InlineKeyboardTest.php
tests/unit/Entities/InlineKeyboardTest.php
+103
-0
KeyboardTest.php
tests/unit/Entities/KeyboardTest.php
+9
-9
No files found.
src/Entities/Keyboard.php
View file @
ce42f431
...
...
@@ -88,7 +88,7 @@ class Keyboard extends Entity
$data
=
reset
(
$args
);
if
(
!
array_key_exists
(
$keyboard_type
,
$data
))
{
if
(
!
array_key_exists
(
$keyboard_type
,
(
array
)
$data
))
{
$new_keyboard
=
[];
foreach
(
$args
as
$row
)
{
if
(
is_array
(
$row
))
{
...
...
@@ -105,7 +105,11 @@ class Keyboard extends Entity
}
}
}
else
{
$new_row
=
[
new
$button_class
(
$row
)];
$button
=
$row
;
if
(
!
(
$button
instanceof
$button_class
))
{
$button
=
new
$button_class
(
$button
);
}
$new_row
=
[
$button
];
}
$new_keyboard
[]
=
$new_row
;
}
...
...
tests/unit/Entities/InlineKeyboardTest.php
0 → 100644
View file @
ce42f431
<?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
;
use
Longman\TelegramBot\Entities\InlineKeyboard
;
use
Longman\TelegramBot\Entities\InlineKeyboardButton
;
/**
* @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
InlineKeyboardTest
extends
TestCase
{
private
function
getRandomButton
(
$text
)
{
$random_params
=
[
'url'
,
'callback_data'
,
'switch_inline_query'
];
$param
=
$random_params
[
array_rand
(
$random_params
,
1
)];
$data
=
[
'text'
=>
$text
,
$param
=>
'random_param'
,
];
return
new
InlineKeyboardButton
(
$data
);
}
public
function
testNothing
(){
}
public
function
testInlineKeyboardSingleButtonSinleRow
()
{
$inline_keyboard
=
(
new
InlineKeyboard
(
$this
->
getRandomButton
(
'Button Text 1'
)
))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 1'
,
$inline_keyboard
[
0
][
0
]
->
getText
());
$inline_keyboard
=
(
new
InlineKeyboard
(
[
$this
->
getRandomButton
(
'Button Text 2'
)]
))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 2'
,
$inline_keyboard
[
0
][
0
]
->
getText
());
}
public
function
testInlineKeyboardSingleButtonMultipleRows
()
{
$keyboard
=
(
new
InlineKeyboard
(
$this
->
getRandomButton
(
'Button Text 1'
),
$this
->
getRandomButton
(
'Button Text 2'
),
$this
->
getRandomButton
(
'Button Text 3'
)
))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 1'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 2'
,
$keyboard
[
1
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 3'
,
$keyboard
[
2
][
0
]
->
getText
());
$keyboard
=
(
new
InlineKeyboard
(
[
$this
->
getRandomButton
(
'Button Text 4'
)],
[
$this
->
getRandomButton
(
'Button Text 5'
)],
[
$this
->
getRandomButton
(
'Button Text 6'
)]
))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 4'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 5'
,
$keyboard
[
1
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 6'
,
$keyboard
[
2
][
0
]
->
getText
());
}
public
function
testInlineKeyboardMultipleButtonsSingleRow
()
{
$keyboard
=
(
new
InlineKeyboard
([
$this
->
getRandomButton
(
'Button Text 1'
),
$this
->
getRandomButton
(
'Button Text 2'
)
]))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 1'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 2'
,
$keyboard
[
0
][
1
]
->
getText
());
}
public
function
testInlineKeyboardMultipleButtonsMultipleRows
()
{
$keyboard
=
(
new
InlineKeyboard
(
[
$this
->
getRandomButton
(
'Button Text 1'
),
$this
->
getRandomButton
(
'Button Text 2'
)
],
[
$this
->
getRandomButton
(
'Button Text 3'
),
$this
->
getRandomButton
(
'Button Text 4'
)
]
))
->
getProperty
(
'inline_keyboard'
);
self
::
assertSame
(
'Button Text 1'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 2'
,
$keyboard
[
0
][
1
]
->
getText
());
self
::
assertSame
(
'Button Text 3'
,
$keyboard
[
1
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text 4'
,
$keyboard
[
1
][
1
]
->
getText
());
}
}
tests/unit/Entities/KeyboardTest.php
View file @
ce42f431
...
...
@@ -43,20 +43,20 @@ class KeyboardTest extends TestCase
self
::
assertSame
(
'Button Text 3'
,
$keyboard
[
2
][
0
]
->
getText
());
$keyboard
=
(
new
Keyboard
(
[
'Button Text
1
'
],
[
'Button Text
2
'
],
[
'Button Text
3
'
]
[
'Button Text
4
'
],
[
'Button Text
5
'
],
[
'Button Text
6
'
]
))
->
getProperty
(
'keyboard'
);
self
::
assertSame
(
'Button Text
1
'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
2
'
,
$keyboard
[
1
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
3
'
,
$keyboard
[
2
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
4
'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
5
'
,
$keyboard
[
1
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
6
'
,
$keyboard
[
2
][
0
]
->
getText
());
}
public
function
testKeyboardMultipleButtonsSingleRow
()
{
$keyboard
=
(
new
Keyboard
([
'Button Text
3'
,
'Button Text 4
'
]))
->
getProperty
(
'keyboard'
);
self
::
assertSame
(
'Button Text
3
'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
4
'
,
$keyboard
[
0
][
1
]
->
getText
());
$keyboard
=
(
new
Keyboard
([
'Button Text
1'
,
'Button Text 2
'
]))
->
getProperty
(
'keyboard'
);
self
::
assertSame
(
'Button Text
1
'
,
$keyboard
[
0
][
0
]
->
getText
());
self
::
assertSame
(
'Button Text
2
'
,
$keyboard
[
0
][
1
]
->
getText
());
}
public
function
testKeyboardMultipleButtonsMultipleRows
()
...
...
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