Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16591 anikendra 1
<?php
2
/**
3
 * CakePHP : Rapid Development Framework (http://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11
 * @link          http://cakephp.org CakePHP Project
12
 * @package       Cake.Test.Case.Console.Command
13
 * @since         CakePHP v 2.5
14
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
15
 */
16
 
17
App::uses('CommandTask', 'Console/Command/Task');
18
 
19
/**
20
 * CommandTaskTest class
21
 *
22
 * @package   Cake.Test.Case.Console.Command.Task
23
 */
24
class CommandTaskTest extends CakeTestCase {
25
 
26
/**
27
 * setUp method
28
 *
29
 * @return void
30
 */
31
	public function setUp() {
32
		parent::setUp();
33
		App::build(array(
34
			'Plugin' => array(
35
				CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
36
			),
37
			'Console/Command' => array(
38
				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
39
			)
40
		), App::RESET);
41
		CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
42
 
43
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
44
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
45
 
46
		$this->CommandTask = $this->getMock(
47
			'CommandTask',
48
			array('in', '_stop', 'clear'),
49
			array($out, $out, $in)
50
		);
51
	}
52
 
53
/**
54
 * tearDown
55
 *
56
 * @return void
57
 */
58
	public function tearDown() {
59
		parent::tearDown();
60
		unset($this->CommandTask);
61
		CakePlugin::unload();
62
	}
63
 
64
/**
65
 * Test the resulting list of shells
66
 *
67
 * @return void
68
 */
69
	public function testGetShellList() {
70
		$result = $this->CommandTask->getShellList();
71
 
72
		$expected = array(
73
			'CORE' => array(
74
				'acl',
75
				'api',
76
				'bake',
77
				'command_list',
78
				'completion',
79
				'console',
80
				'i18n',
81
				'schema',
82
				'server',
83
				'test',
84
				'testsuite',
85
				'upgrade'
86
			),
87
			'TestPlugin' => array(
88
				'example',
89
				'test_plugin'
90
			),
91
			'TestPluginTwo' => array(
92
				'example',
93
				'welcome'
94
			),
95
			'app' => array(
96
				'sample'
97
			),
98
		);
99
		$this->assertEquals($expected, $result);
100
	}
101
 
102
/**
103
 * Test the resulting list of commands
104
 *
105
 * @return void
106
 */
107
	public function testCommands() {
108
		$result = $this->CommandTask->commands();
109
 
110
		$expected = array(
111
			'TestPlugin.example',
112
			'TestPlugin.test_plugin',
113
			'TestPluginTwo.example',
114
			'TestPluginTwo.welcome',
115
			'acl',
116
			'api',
117
			'bake',
118
			'command_list',
119
			'completion',
120
			'console',
121
			'i18n',
122
			'schema',
123
			'server',
124
			'test',
125
			'testsuite',
126
			'upgrade',
127
			'sample'
128
		);
129
		$this->assertEquals($expected, $result);
130
	}
131
 
132
/**
133
 * Test the resulting list of subcommands for the given command
134
 *
135
 * @return void
136
 */
137
	public function testSubCommands() {
138
		$result = $this->CommandTask->subCommands('acl');
139
 
140
		$expected = array(
141
			'check',
142
			'create',
143
			'db_config',
144
			'delete',
145
			'deny',
146
			'getPath',
147
			'grant',
148
			'inherit',
149
			'initdb',
150
			'nodeExists',
151
			'parseIdentifier',
152
			'setParent',
153
			'view'
154
		);
155
		$this->assertEquals($expected, $result);
156
	}
157
 
158
/**
159
 * Test that unknown commands return an empty array
160
 *
161
 * @return void
162
 */
163
	public function testSubCommandsUnknownCommand() {
164
		$result = $this->CommandTask->subCommands('yoghurt');
165
 
166
		$expected = array();
167
		$this->assertEquals($expected, $result);
168
	}
169
 
170
/**
171
 * Test that getting a existing shell returns the shell instance
172
 *
173
 * @return void
174
 */
175
	public function testGetShell() {
176
		$result = $this->CommandTask->getShell('acl');
177
		$this->assertInstanceOf('AclShell', $result);
178
	}
179
 
180
/**
181
 * Test that getting a non-existing shell returns false
182
 *
183
 * @return void
184
 */
185
	public function testGetShellNonExisting() {
186
		$result = $this->CommandTask->getShell('strawberry');
187
		$this->assertFalse($result);
188
	}
189
 
190
/**
191
 * Test that getting a existing core shell with 'core.' prefix returns the correct shell instance
192
 *
193
 * @return void
194
 */
195
	public function testGetShellCore() {
196
		$result = $this->CommandTask->getShell('core.bake');
197
		$this->assertInstanceOf('BakeShell', $result);
198
	}
199
 
200
/**
201
 * Test the options array for a known command
202
 *
203
 * @return void
204
 */
205
	public function testOptions() {
206
		$result = $this->CommandTask->options('bake');
207
 
208
		$expected = array(
209
			'--help',
210
			'-h',
211
			'--verbose',
212
			'-v',
213
			'--quiet',
214
			'-q',
215
			'--connection',
216
			'-c',
217
			'--theme',
218
			'-t'
219
		);
220
		$this->assertEquals($expected, $result);
221
	}
222
 
223
/**
224
 * Test the options array for an unknown command
225
 *
226
 * @return void
227
 */
228
	public function testOptionsUnknownCommand() {
229
		$result = $this->CommandTask->options('pie');
230
 
231
		$expected = array(
232
			'--help',
233
			'-h',
234
			'--verbose',
235
			'-v',
236
			'--quiet',
237
			'-q'
238
		);
239
		$this->assertEquals($expected, $result);
240
	}
241
 
242
}