/
CommandListShellTest.php
140 lines (119 loc) · 3.8 KB
/
CommandListShellTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* CommandListShellTest file
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @since 2.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Shell;
use Cake\Console\ConsoleIo;
use Cake\Core\App;
use Cake\Core\Plugin;
use Cake\Shell\CommandListShell;
use Cake\Shell\Task\CommandTask;
use Cake\TestSuite\Stub\ConsoleOutput;
use Cake\TestSuite\TestCase;
/**
* Class CommandListShellTest
*
*/
class CommandListShellTest extends TestCase
{
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
Plugin::load(['TestPlugin', 'TestPluginTwo']);
$this->out = new ConsoleOutput();
$io = new ConsoleIo($this->out);
$this->Shell = $this->getMock(
'Cake\Shell\CommandListShell',
['in', 'err', '_stop', 'clear'],
[$io]
);
$this->Shell->Command = $this->getMock(
'Cake\Shell\Task\CommandTask',
['in', '_stop', 'err', 'clear'],
[$io]
);
}
/**
* tearDown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($this->Shell);
Plugin::unload();
}
/**
* test that main finds core shells.
*
* @return void
*/
public function testMain()
{
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);
$expected = "/\[.*TestPlugin.*\] example/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*TestPluginTwo.*\] example, welcome/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*CORE.*\] i18n, orm_cache, plugin, server/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*app.*\] i18m, sample/";
$this->assertRegExp($expected, $output);
}
/**
* If there is an app shell with the same name as a core shell,
* tests that the app shell is the one displayed and the core one is hidden.
*
* @return void
*/
public function testMainAppPriority()
{
rename(APP . 'Shell' . DS . 'I18mShell.php', APP . 'Shell' . DS . 'I18nShell.php');
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);
$expected = "/\[.*CORE.*\] orm_cache, plugin, server/";
$this->assertRegExp($expected, $output);
$expected = "/\[.*app.*\] i18n, sample/";
$this->assertRegExp($expected, $output);
rename(APP . 'Shell' . DS . 'I18nShell.php', APP . 'Shell' . DS . 'I18mShell.php');
}
/**
* test xml output.
*
* @return void
*/
public function testMainXml()
{
$this->Shell->params['xml'] = true;
$this->Shell->main();
$output = $this->out->messages();
$output = implode("\n", $output);
$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"';
$this->assertContains($find, $output);
$find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"';
$this->assertContains($find, $output);
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
$this->assertContains($find, $output);
}
}