File tree Expand file tree Collapse file tree 7 files changed +154
-1
lines changed Expand file tree Collapse file tree 7 files changed +154
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ abstract class Command
59
59
*/
60
60
protected $ usage = 'Command usage ' ;
61
61
62
+ /**
63
+ * Show in Help
64
+ *
65
+ * @var bool
66
+ */
67
+ protected $ show_in_help = true ;
68
+
62
69
/**
63
70
* Version
64
71
*
@@ -252,6 +259,16 @@ public function getName()
252
259
return $ this ->name ;
253
260
}
254
261
262
+ /**
263
+ * Get Show in Help
264
+ *
265
+ * @return bool
266
+ */
267
+ public function showInHelp ()
268
+ {
269
+ return $ this ->show_in_help ;
270
+ }
271
+
255
272
/**
256
273
* Check if command is enabled
257
274
*
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public function execute()
69
69
);
70
70
71
71
foreach ($ command_objs as $ command ) {
72
+ if (!$ command ->showInHelp ()) {
73
+ continue ;
74
+ }
75
+
72
76
$ text .= sprintf (
73
77
'/%s - %s ' . PHP_EOL ,
74
78
$ command ->getName (),
Original file line number Diff line number Diff line change @@ -127,6 +127,12 @@ public function testDefaultCommandIsEnabled()
127
127
$ this ->assertTrue ($ this ->command_stub ->isEnabled ());
128
128
}
129
129
130
+ public function testDefaultCommandShownInHelp ()
131
+ {
132
+ $ this ->assertAttributeEquals (true , 'show_in_help ' , $ this ->command_stub );
133
+ $ this ->assertTrue ($ this ->command_stub ->showInHelp ());
134
+ }
135
+
130
136
public function testDefaultCommandNeedsMysql ()
131
137
{
132
138
$ this ->assertAttributeEquals (false , 'need_mysql ' , $ this ->command_stub );
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ public function setUp()
39
39
{
40
40
$ this ->telegram = new Telegram ('apikey ' , 'testbot ' );
41
41
$ this ->telegram ->addCommandsPath (BASE_COMMANDS_PATH . '/UserCommands ' );
42
+
43
+ // Add custom commands dedicated to do some tests.
44
+ $ this ->telegram ->addCommandsPath (__DIR__ . '/CustomTestCommands ' );
42
45
$ this ->telegram ->getCommandsList ();
43
46
}
44
47
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * This file is part of the TelegramBot package.
4
+ *
5
+ * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+
11
+ namespace Longman \TelegramBot \Commands \UserCommands ;
12
+
13
+ use Longman \TelegramBot \Commands \UserCommand ;
14
+ use Longman \TelegramBot \Request ;
15
+
16
+ /**
17
+ * Test "/hidden" command to test $show_in_help
18
+ */
19
+ class HiddenCommand extends UserCommand
20
+ {
21
+ /**
22
+ * @var string
23
+ */
24
+ protected $ name = 'hidden ' ;
25
+
26
+ /**
27
+ * @var string
28
+ */
29
+ protected $ description = 'This command is hidden in help ' ;
30
+
31
+ /**
32
+ * @var string
33
+ */
34
+ protected $ usage = '/hidden ' ;
35
+
36
+ /**
37
+ * @var string
38
+ */
39
+ protected $ version = '1.0.0 ' ;
40
+
41
+ /**
42
+ * @var bool
43
+ */
44
+ protected $ show_in_help = false ;
45
+
46
+ /**
47
+ * Command execute method
48
+ *
49
+ * @return mixed
50
+ * @throws \Longman\TelegramBot\Exception\TelegramException
51
+ */
52
+ public function execute ()
53
+ {
54
+ return Request::emptyResponse ();
55
+ }
56
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * This file is part of the TelegramBot package.
4
+ *
5
+ * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+
11
+ namespace Longman \TelegramBot \Commands \UserCommands ;
12
+
13
+ use Longman \TelegramBot \Commands \UserCommand ;
14
+ use Longman \TelegramBot \Request ;
15
+
16
+ /**
17
+ * Test "/visible" command to test $show_in_help
18
+ */
19
+ class VisibleCommand extends UserCommand
20
+ {
21
+ /**
22
+ * @var string
23
+ */
24
+ protected $ name = 'visible ' ;
25
+
26
+ /**
27
+ * @var string
28
+ */
29
+ protected $ description = 'This command is visible in help ' ;
30
+
31
+ /**
32
+ * @var string
33
+ */
34
+ protected $ usage = '/visible ' ;
35
+
36
+ /**
37
+ * @var string
38
+ */
39
+ protected $ version = '1.0.0 ' ;
40
+
41
+ /**
42
+ * @var bool
43
+ */
44
+ protected $ show_in_help = true ;
45
+
46
+ /**
47
+ * Command execute method
48
+ *
49
+ * @return mixed
50
+ * @throws \Longman\TelegramBot\Exception\TelegramException
51
+ */
52
+ public function execute ()
53
+ {
54
+ return Request::emptyResponse ();
55
+ }
56
+ }
Original file line number Diff line number Diff line change 10
10
11
11
namespace Longman \TelegramBot \Tests \Unit \Commands \UserCommands ;
12
12
13
+ use Longman \TelegramBot \Commands \UserCommands \HelpCommand ;
13
14
use Longman \TelegramBot \Tests \Unit \Commands \CommandTestCase ;
14
15
use Longman \TelegramBot \Tests \Unit \TestHelpers ;
15
- use Longman \TelegramBot \Commands \UserCommands \HelpCommand ;
16
16
17
17
/**
18
18
* @package TelegramTest
@@ -71,4 +71,15 @@ public function testHelpCommandExecuteWithParameterValidCommand()
71
71
->getText ();
72
72
$ this ->assertContains ("Description: Show text \nUsage: /echo <text> " , $ text );
73
73
}
74
+
75
+ public function testHelpCommandWithHiddenCommand ()
76
+ {
77
+ $ text = $ this ->command
78
+ ->setUpdate (TestHelpers::getFakeUpdateCommandObject ('/help ' ))
79
+ ->execute ()
80
+ ->getResult ()
81
+ ->getText ();
82
+ $ this ->assertContains ('/visible ' , $ text );
83
+ $ this ->assertNotContains ('/hidden ' , $ text );
84
+ }
74
85
}
You can’t perform that action at this time.
0 commit comments