File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ require_once dirname ( __FILE__ ) . '/TinyTestCase.php ' ;
4+
5+ class Tiny_Cli_Test extends Tiny_TestCase {
6+
7+
8+ public function set_up () {
9+ parent ::set_up ();
10+ }
11+
12+ public function test_will_register_command_on_cli_init_hook () {
13+ $ this ->wp ->defaults ();
14+
15+ if (!defined ('WP_CLI ' )) {
16+ define ('WP_CLI ' , true );
17+ }
18+
19+ $ tiny_cli = new Tiny_Cli (null );
20+
21+ $ add_action_calls = $ this ->wp ->getCalls ('add_action ' );
22+ $ cli_init_found = false ;
23+
24+ foreach ($ add_action_calls as $ call ) {
25+ if ($ call [0 ] === 'cli_init ' && $ call [1 ] === array ($ tiny_cli , 'register_command ' )) {
26+ $ cli_init_found = true ;
27+ break ;
28+ }
29+ }
30+
31+ $ this ->assertTrue ($ cli_init_found , 'register_command should be hooked to cli_init ' );
32+ }
33+
34+ public function test_will_not_hook_if_cli_is_unavailable () {
35+ $ this ->wp ->defaults ();
36+
37+ $ add_action_calls = $ this ->wp ->getCalls ('add_action ' );
38+ $ cli_init_found = false ;
39+
40+ foreach ($ add_action_calls as $ call ) {
41+ if ($ call [0 ] === 'cli_init ' ) {
42+ $ cli_init_found = true ;
43+ break ;
44+ }
45+ }
46+
47+ $ this ->assertFalse ($ cli_init_found , 'No cli_init hooks should be registered when WP_CLI is not available ' );
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments