Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 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
			),
90
				'TestPluginTwo' => array(
91
				'example',
92
				'welcome'
93
			),
94
			'app' => array(
95
				'sample'
96
			),
97
		);
98
		$this->assertEquals($expected, $result);
99
	}
100
 
101
/**
102
 * Test the resulting list of commands
103
 *
104
 * @return void
105
 */
106
	public function testCommands() {
107
		$result = $this->CommandTask->commands();
108
 
109
		$expected = array(
110
			'TestPlugin.example',
111
			'TestPluginTwo.example',
112
			'TestPluginTwo.welcome',
113
			'acl',
114
			'api',
115
			'bake',
116
			'command_list',
117
			'completion',
118
			'console',
119
			'i18n',
120
			'schema',
121
			'server',
122
			'test',
123
			'testsuite',
124
			'upgrade',
125
			'sample'
126
		);
127
		$this->assertEquals($expected, $result);
128
	}
129
 
130
/**
131
 * Test the resulting list of subcommands for the given command
132
 *
133
 * @return void
134
 */
135
	public function testSubCommands() {
136
		$result = $this->CommandTask->subCommands('acl');
137
 
138
		$expected = array(
139
			'check',
140
			'create',
141
			'db_config',
142
			'delete',
143
			'deny',
144
			'getPath',
145
			'grant',
146
			'inherit',
147
			'initdb',
148
			'nodeExists',
149
			'parseIdentifier',
150
			'setParent',
151
			'view'
152
		);
153
		$this->assertEquals($expected, $result);
154
	}
155
 
156
/**
157
 * Test that unknown commands return an empty array
158
 *
159
 * @return void
160
 */
161
	public function testSubCommandsUnknownCommand() {
162
		$result = $this->CommandTask->subCommands('yoghurt');
163
 
164
		$expected = array();
165
		$this->assertEquals($expected, $result);
166
	}
167
 
168
/**
169
 * Test that getting a existing shell returns the shell instance
170
 *
171
 * @return void
172
 */
173
	public function testGetShell() {
174
		$result = $this->CommandTask->getShell('acl');
175
		$this->assertInstanceOf('AclShell', $result);
176
	}
177
 
178
/**
179
 * Test that getting a non-existing shell returns false
180
 *
181
 * @return void
182
 */
183
	public function testGetShellNonExisting() {
184
		$result = $this->CommandTask->getShell('strawberry');
185
		$this->assertFalse($result);
186
	}
187
 
188
/**
189
 * Test that getting a existing core shell with 'core.' prefix returns the correct shell instance
190
 *
191
 * @return void
192
 */
193
	public function testGetShellCore() {
194
		$result = $this->CommandTask->getShell('core.bake');
195
		$this->assertInstanceOf('BakeShell', $result);
196
	}
197
 
198
/**
199
 * Test the options array for a known command
200
 *
201
 * @return void
202
 */
203
	public function testOptions() {
204
		$result = $this->CommandTask->options('bake');
205
 
206
		$expected = array(
207
			'--help',
208
			'-h',
209
			'--verbose',
210
			'-v',
211
			'--quiet',
212
			'-q',
213
			'--connection',
214
			'-c',
215
			'--theme',
216
			'-t'
217
		);
218
		$this->assertEquals($expected, $result);
219
	}
220
 
221
/**
222
 * Test the options array for an unknown command
223
 *
224
 * @return void
225
 */
226
	public function testOptionsUnknownCommand() {
227
		$result = $this->CommandTask->options('pie');
228
 
229
		$expected = array(
230
			'--help',
231
			'-h',
232
			'--verbose',
233
			'-v',
234
			'--quiet',
235
			'-q'
236
		);
237
		$this->assertEquals($expected, $result);
238
	}
239
 
240
}