pictcode / lib / Cake / Test / Case / Console / Command / CompletionShellTest.php @ 0b1b8047
履歴 | 表示 | アノテート | ダウンロード (6.519 KB)
1 | 635eef61 | spyder1211 | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * CompletionShellTest file
|
||
4 | *
|
||
5 | * PHP 5
|
||
6 | *
|
||
7 | * CakePHP : Rapid Development Framework (http://cakephp.org)
|
||
8 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
9 | *
|
||
10 | * Licensed under The MIT License
|
||
11 | * For full copyright and license information, please see the LICENSE.txt
|
||
12 | * Redistributions of files must retain the above copyright notice.
|
||
13 | *
|
||
14 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
15 | * @link http://cakephp.org CakePHP Project
|
||
16 | * @package Cake.Test.Case.Console.Command
|
||
17 | * @since CakePHP v 2.5
|
||
18 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
19 | */
|
||
20 | |||
21 | App::uses('CompletionShell', 'Console/Command'); |
||
22 | App::uses('ConsoleOutput', 'Console'); |
||
23 | App::uses('ConsoleInput', 'Console'); |
||
24 | App::uses('Shell', 'Console'); |
||
25 | App::uses('CommandTask', 'Console/Command/Task'); |
||
26 | |||
27 | /**
|
||
28 | * Class TestCompletionStringOutput
|
||
29 | *
|
||
30 | * @package Cake.Test.Case.Console.Command
|
||
31 | */
|
||
32 | class TestCompletionStringOutput extends ConsoleOutput { |
||
33 | |||
34 | public $output = ''; |
||
35 | |||
36 | protected function _write($message) { |
||
37 | $this->output .= $message; |
||
38 | } |
||
39 | |||
40 | } |
||
41 | |||
42 | /**
|
||
43 | * Class CompletionShellTest
|
||
44 | *
|
||
45 | * @package Cake.Test.Case.Console.Command
|
||
46 | */
|
||
47 | class CompletionShellTest extends CakeTestCase { |
||
48 | |||
49 | /**
|
||
50 | * setUp method
|
||
51 | *
|
||
52 | * @return void
|
||
53 | */
|
||
54 | public function setUp() { |
||
55 | parent::setUp();
|
||
56 | App::build(array( |
||
57 | 'Plugin' => array( |
||
58 | CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS |
||
59 | ), |
||
60 | 'Console/Command' => array( |
||
61 | CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS |
||
62 | ) |
||
63 | ), App::RESET); |
||
64 | CakePlugin::load(array('TestPlugin', 'TestPluginTwo')); |
||
65 | |||
66 | $out = new TestCompletionStringOutput(); |
||
67 | $in = $this->getMock('ConsoleInput', array(), array(), '', false); |
||
68 | |||
69 | $this->Shell = $this->getMock( |
||
70 | 'CompletionShell',
|
||
71 | array('in', '_stop', 'clear'), |
||
72 | array($out, $out, $in) |
||
73 | ); |
||
74 | |||
75 | $this->Shell->Command = $this->getMock( |
||
76 | 'CommandTask',
|
||
77 | array('in', '_stop', 'clear'), |
||
78 | array($out, $out, $in) |
||
79 | ); |
||
80 | } |
||
81 | |||
82 | /**
|
||
83 | * tearDown
|
||
84 | *
|
||
85 | * @return void
|
||
86 | */
|
||
87 | public function tearDown() { |
||
88 | parent::tearDown();
|
||
89 | unset($this->Shell); |
||
90 | CakePlugin::unload();
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * test that the startup method supresses the shell header
|
||
95 | *
|
||
96 | * @return void
|
||
97 | */
|
||
98 | public function testStartup() { |
||
99 | $this->Shell->runCommand('main', array()); |
||
100 | $output = $this->Shell->stdout->output; |
||
101 | |||
102 | $needle = 'Welcome to CakePHP'; |
||
103 | $this->assertTextNotContains($needle, $output); |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * test that main displays a warning
|
||
108 | *
|
||
109 | * @return void
|
||
110 | */
|
||
111 | public function testMain() { |
||
112 | $this->Shell->runCommand('main', array()); |
||
113 | $output = $this->Shell->stdout->output; |
||
114 | |||
115 | $expected = "/This command is not intended to be called manually/"; |
||
116 | $this->assertRegExp($expected, $output); |
||
117 | } |
||
118 | |||
119 | /**
|
||
120 | * test commands method that list all available commands
|
||
121 | *
|
||
122 | * @return void
|
||
123 | */
|
||
124 | public function testCommands() { |
||
125 | $this->Shell->runCommand('commands', array()); |
||
126 | $output = $this->Shell->stdout->output; |
||
127 | |||
128 | $expected = "TestPlugin.example TestPlugin.test_plugin TestPluginTwo.example TestPluginTwo.welcome acl api bake command_list completion console i18n schema server test testsuite upgrade sample\n"; |
||
129 | $this->assertEquals($expected, $output); |
||
130 | } |
||
131 | |||
132 | /**
|
||
133 | * test that options without argument returns the default options
|
||
134 | *
|
||
135 | * @return void
|
||
136 | */
|
||
137 | public function testOptionsNoArguments() { |
||
138 | $this->Shell->runCommand('options', array()); |
||
139 | $output = $this->Shell->stdout->output; |
||
140 | |||
141 | $expected = "--help -h --verbose -v --quiet -q\n"; |
||
142 | $this->assertEquals($expected, $output); |
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * test that options with a nonexisting command returns the default options
|
||
147 | *
|
||
148 | * @return void
|
||
149 | */
|
||
150 | public function testOptionsNonExistingCommand() { |
||
151 | $this->Shell->runCommand('options', array('options', 'foo')); |
||
152 | $output = $this->Shell->stdout->output; |
||
153 | |||
154 | $expected = "--help -h --verbose -v --quiet -q\n"; |
||
155 | $this->assertEquals($expected, $output); |
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * test that options with a existing command returns the proper options
|
||
160 | *
|
||
161 | * @return void
|
||
162 | */
|
||
163 | public function testOptions() { |
||
164 | $this->Shell->runCommand('options', array('options', 'bake')); |
||
165 | $output = $this->Shell->stdout->output; |
||
166 | |||
167 | $expected = "--help -h --verbose -v --quiet -q --connection -c --theme -t\n"; |
||
168 | $this->assertEquals($expected, $output); |
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * test that subCommands with a existing CORE command returns the proper sub commands
|
||
173 | *
|
||
174 | * @return void
|
||
175 | */
|
||
176 | public function testSubCommandsCorePlugin() { |
||
177 | $this->Shell->runCommand('subCommands', array('subCommands', 'CORE.bake')); |
||
178 | $output = $this->Shell->stdout->output; |
||
179 | |||
180 | $expected = "controller db_config fixture model plugin project test view\n"; |
||
181 | $this->assertEquals($expected, $output); |
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * test that subCommands with a existing APP command returns the proper sub commands (in this case none)
|
||
186 | *
|
||
187 | * @return void
|
||
188 | */
|
||
189 | public function testSubCommandsAppPlugin() { |
||
190 | $this->Shell->runCommand('subCommands', array('subCommands', 'app.sample')); |
||
191 | $output = $this->Shell->stdout->output; |
||
192 | |||
193 | $expected = ''; |
||
194 | $this->assertEquals($expected, $output); |
||
195 | } |
||
196 | |||
197 | /**
|
||
198 | * test that subCommands with a existing plugin command returns the proper sub commands
|
||
199 | *
|
||
200 | * @return void
|
||
201 | */
|
||
202 | public function testSubCommandsPlugin() { |
||
203 | $this->Shell->runCommand('subCommands', array('subCommands', 'TestPluginTwo.welcome')); |
||
204 | $output = $this->Shell->stdout->output; |
||
205 | |||
206 | $expected = "say_hello\n"; |
||
207 | $this->assertEquals($expected, $output); |
||
208 | } |
||
209 | |||
210 | /**
|
||
211 | * test that subcommands without arguments returns nothing
|
||
212 | *
|
||
213 | * @return void
|
||
214 | */
|
||
215 | public function testSubCommandsNoArguments() { |
||
216 | $this->Shell->runCommand('subCommands', array()); |
||
217 | $output = $this->Shell->stdout->output; |
||
218 | |||
219 | $expected = ''; |
||
220 | $this->assertEquals($expected, $output); |
||
221 | } |
||
222 | |||
223 | /**
|
||
224 | * test that subcommands with a nonexisting command returns nothing
|
||
225 | *
|
||
226 | * @return void
|
||
227 | */
|
||
228 | public function testSubCommandsNonExistingCommand() { |
||
229 | $this->Shell->runCommand('subCommands', array('subCommands', 'foo')); |
||
230 | $output = $this->Shell->stdout->output; |
||
231 | |||
232 | $expected = ''; |
||
233 | $this->assertEquals($expected, $output); |
||
234 | } |
||
235 | |||
236 | /**
|
||
237 | * test that subcommands returns the available subcommands for the given command
|
||
238 | *
|
||
239 | * @return void
|
||
240 | */
|
||
241 | public function testSubCommands() { |
||
242 | $this->Shell->runCommand('subCommands', array('subCommands', 'bake')); |
||
243 | $output = $this->Shell->stdout->output; |
||
244 | |||
245 | $expected = "controller db_config fixture model plugin project test view\n"; |
||
246 | $this->assertEquals($expected, $output); |
||
247 | } |
||
248 | |||
249 | /**
|
||
250 | * test that fuzzy returns nothing
|
||
251 | *
|
||
252 | * @return void
|
||
253 | */
|
||
254 | public function testFuzzy() { |
||
255 | $this->Shell->runCommand('fuzzy', array()); |
||
256 | $output = $this->Shell->stdout->output; |
||
257 | |||
258 | $expected = ''; |
||
259 | $this->assertEquals($expected, $output); |
||
260 | } |
||
261 | } |