| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* ProjectTask Test file
|
|
|
4 |
*
|
|
|
5 |
* Test Case for project generation shell task
|
|
|
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.Task
|
|
|
17 |
* @since CakePHP v 1.3.0
|
|
|
18 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
App::uses('ShellDispatcher', 'Console');
|
|
|
22 |
App::uses('ConsoleOutput', 'Console');
|
|
|
23 |
App::uses('ConsoleInput', 'Console');
|
|
|
24 |
App::uses('Shell', 'Console');
|
|
|
25 |
App::uses('ProjectTask', 'Console/Command/Task');
|
|
|
26 |
App::uses('Folder', 'Utility');
|
|
|
27 |
App::uses('File', 'Utility');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* ProjectTask Test class
|
|
|
31 |
*
|
|
|
32 |
* @package Cake.Test.Case.Console.Command.Task
|
|
|
33 |
*/
|
|
|
34 |
class ProjectTaskTest extends CakeTestCase {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* setUp method
|
|
|
38 |
*
|
|
|
39 |
* @return void
|
|
|
40 |
*/
|
|
|
41 |
public function setUp() {
|
|
|
42 |
parent::setUp();
|
|
|
43 |
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
44 |
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
45 |
|
|
|
46 |
$this->Task = $this->getMock('ProjectTask',
|
|
|
47 |
array('in', 'err', 'createFile', '_stop'),
|
|
|
48 |
array($out, $out, $in)
|
|
|
49 |
);
|
|
|
50 |
$this->Task->path = TMP . 'tests' . DS;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* tearDown method
|
|
|
55 |
*
|
|
|
56 |
* @return void
|
|
|
57 |
*/
|
|
|
58 |
public function tearDown() {
|
|
|
59 |
parent::tearDown();
|
|
|
60 |
|
|
|
61 |
$Folder = new Folder($this->Task->path . 'bake_test_app');
|
|
|
62 |
$Folder->delete();
|
|
|
63 |
unset($this->Task);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* creates a test project that is used for testing project task.
|
|
|
68 |
*
|
|
|
69 |
* @return void
|
|
|
70 |
*/
|
|
|
71 |
protected function _setupTestProject() {
|
|
|
72 |
$skel = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
|
|
|
73 |
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
|
|
74 |
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* test bake() method and directory creation.
|
|
|
79 |
*
|
|
|
80 |
* @return void
|
|
|
81 |
*/
|
|
|
82 |
public function testBake() {
|
|
|
83 |
$this->_setupTestProject();
|
|
|
84 |
$path = $this->Task->path . 'bake_test_app';
|
|
|
85 |
|
|
|
86 |
$this->assertTrue(is_dir($path), 'No project dir %s');
|
|
|
87 |
$dirs = array(
|
|
|
88 |
'Config',
|
|
|
89 |
'Config' . DS . 'Schema',
|
|
|
90 |
'Console',
|
|
|
91 |
'Console' . DS . 'Command',
|
|
|
92 |
'Console' . DS . 'Templates',
|
|
|
93 |
'Console' . DS . 'Command' . DS . 'Task',
|
|
|
94 |
'Controller',
|
|
|
95 |
'Controller' . DS . 'Component',
|
|
|
96 |
'Locale',
|
|
|
97 |
'Model',
|
|
|
98 |
'Model' . DS . 'Behavior',
|
|
|
99 |
'Model' . DS . 'Datasource',
|
|
|
100 |
'Plugin',
|
|
|
101 |
'Test',
|
|
|
102 |
'Test' . DS . 'Case',
|
|
|
103 |
'Test' . DS . 'Case' . DS . 'Controller',
|
|
|
104 |
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
|
|
|
105 |
'Test' . DS . 'Case' . DS . 'Model',
|
|
|
106 |
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
|
|
|
107 |
'Test' . DS . 'Fixture',
|
|
|
108 |
'Vendor',
|
|
|
109 |
'View',
|
|
|
110 |
'View' . DS . 'Helper',
|
|
|
111 |
'tmp',
|
|
|
112 |
'tmp' . DS . 'cache',
|
|
|
113 |
'tmp' . DS . 'cache' . DS . 'models',
|
|
|
114 |
'tmp' . DS . 'cache' . DS . 'persistent',
|
|
|
115 |
'tmp' . DS . 'cache' . DS . 'views',
|
|
|
116 |
'tmp' . DS . 'logs',
|
|
|
117 |
'tmp' . DS . 'sessions',
|
|
|
118 |
'tmp' . DS . 'tests',
|
|
|
119 |
'webroot',
|
|
|
120 |
'webroot' . DS . 'css',
|
|
|
121 |
'webroot' . DS . 'files',
|
|
|
122 |
'webroot' . DS . 'img',
|
|
|
123 |
'webroot' . DS . 'js',
|
|
|
124 |
|
|
|
125 |
);
|
|
|
126 |
foreach ($dirs as $dir) {
|
|
|
127 |
$this->assertTrue(is_dir($path . DS . $dir), 'Missing ' . $dir);
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* test bake with an absolute path.
|
|
|
133 |
*
|
|
|
134 |
* @return void
|
|
|
135 |
*/
|
|
|
136 |
public function testExecuteWithAbsolutePath() {
|
|
|
137 |
$path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app';
|
|
|
138 |
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
|
|
|
139 |
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
|
|
140 |
$this->Task->execute();
|
|
|
141 |
|
|
|
142 |
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
|
|
|
143 |
$File = new File($path . DS . 'webroot' . DS . 'index.php');
|
|
|
144 |
$contents = $File->read();
|
|
|
145 |
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
|
|
|
146 |
$File = new File($path . DS . 'webroot' . DS . 'test.php');
|
|
|
147 |
$contents = $File->read();
|
|
|
148 |
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
/**
|
|
|
152 |
* test bake with CakePHP on the include path. The constants should remain commented out.
|
|
|
153 |
*
|
|
|
154 |
* @return void
|
|
|
155 |
*/
|
|
|
156 |
public function testExecuteWithCakeOnIncludePath() {
|
|
|
157 |
if (!function_exists('ini_set')) {
|
|
|
158 |
$this->markTestAsSkipped('Not access to ini_set, cannot proceed.');
|
|
|
159 |
}
|
|
|
160 |
$restore = ini_get('include_path');
|
|
|
161 |
ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . $restore);
|
|
|
162 |
|
|
|
163 |
$path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app';
|
|
|
164 |
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
|
|
|
165 |
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
|
|
166 |
$this->Task->execute();
|
|
|
167 |
|
|
|
168 |
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
|
|
|
169 |
$contents = file_get_contents($path . DS . 'webroot' . DS . 'index.php');
|
|
|
170 |
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
|
|
|
171 |
|
|
|
172 |
$contents = file_get_contents($path . DS . 'webroot' . DS . 'test.php');
|
|
|
173 |
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
|
|
|
174 |
|
|
|
175 |
ini_set('include_path', $restore);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* test bake() method with -empty flag, directory creation and empty files.
|
|
|
180 |
*
|
|
|
181 |
* @return void
|
|
|
182 |
*/
|
|
|
183 |
public function testBakeEmptyFlag() {
|
|
|
184 |
$this->Task->params['empty'] = true;
|
|
|
185 |
$this->_setupTestProject();
|
|
|
186 |
$path = $this->Task->path . 'bake_test_app';
|
|
|
187 |
|
|
|
188 |
$empty = array(
|
|
|
189 |
'Console' . DS . 'Command' . DS . 'Task' => 'empty',
|
|
|
190 |
'Controller' . DS . 'Component' => 'empty',
|
|
|
191 |
'Lib' => 'empty',
|
|
|
192 |
'Model' . DS . 'Behavior' => 'empty',
|
|
|
193 |
'Model' . DS . 'Datasource' => 'empty',
|
|
|
194 |
'Plugin' => 'empty',
|
|
|
195 |
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior' => 'empty',
|
|
|
196 |
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component' => 'empty',
|
|
|
197 |
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' => 'empty',
|
|
|
198 |
'Test' . DS . 'Fixture' => 'empty',
|
|
|
199 |
'Vendor' => 'empty',
|
|
|
200 |
'View' . DS . 'Elements' => 'empty',
|
|
|
201 |
'View' . DS . 'Scaffolds' => 'empty',
|
|
|
202 |
'tmp' . DS . 'cache' . DS . 'models' => 'empty',
|
|
|
203 |
'tmp' . DS . 'cache' . DS . 'persistent' => 'empty',
|
|
|
204 |
'tmp' . DS . 'cache' . DS . 'views' => 'empty',
|
|
|
205 |
'tmp' . DS . 'logs' => 'empty',
|
|
|
206 |
'tmp' . DS . 'sessions' => 'empty',
|
|
|
207 |
'tmp' . DS . 'tests' => 'empty',
|
|
|
208 |
'webroot' . DS . 'js' => 'empty',
|
|
|
209 |
'webroot' . DS . 'files' => 'empty'
|
|
|
210 |
);
|
|
|
211 |
|
|
|
212 |
foreach ($empty as $dir => $file) {
|
|
|
213 |
$this->assertTrue(is_file($path . DS . $dir . DS . $file), sprintf('Missing %s file in %s', $file, $dir));
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
/**
|
|
|
218 |
* test generation of Security.salt
|
|
|
219 |
*
|
|
|
220 |
* @return void
|
|
|
221 |
*/
|
|
|
222 |
public function testSecuritySaltGeneration() {
|
|
|
223 |
$this->_setupTestProject();
|
|
|
224 |
|
|
|
225 |
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
226 |
$result = $this->Task->securitySalt($path);
|
|
|
227 |
$this->assertTrue($result);
|
|
|
228 |
|
|
|
229 |
$File = new File($path . 'Config' . DS . 'core.php');
|
|
|
230 |
$contents = $File->read();
|
|
|
231 |
$this->assertNotRegExp('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* test generation of Security.cipherSeed
|
|
|
236 |
*
|
|
|
237 |
* @return void
|
|
|
238 |
*/
|
|
|
239 |
public function testSecurityCipherSeedGeneration() {
|
|
|
240 |
$this->_setupTestProject();
|
|
|
241 |
|
|
|
242 |
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
243 |
$result = $this->Task->securityCipherSeed($path);
|
|
|
244 |
$this->assertTrue($result);
|
|
|
245 |
|
|
|
246 |
$File = new File($path . 'Config' . DS . 'core.php');
|
|
|
247 |
$contents = $File->read();
|
|
|
248 |
$this->assertNotRegExp('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**
|
|
|
252 |
* test generation of cache prefix
|
|
|
253 |
*
|
|
|
254 |
* @return void
|
|
|
255 |
*/
|
|
|
256 |
public function testCachePrefixGeneration() {
|
|
|
257 |
$this->_setupTestProject();
|
|
|
258 |
|
|
|
259 |
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
260 |
$result = $this->Task->cachePrefix($path);
|
|
|
261 |
$this->assertTrue($result);
|
|
|
262 |
|
|
|
263 |
$File = new File($path . 'Config' . DS . 'core.php');
|
|
|
264 |
$contents = $File->read();
|
|
|
265 |
$this->assertRegExp('/\$prefix = \'.+\';/', $contents, '$prefix is not defined');
|
|
|
266 |
$this->assertNotRegExp('/\$prefix = \'myapp_\';/', $contents, 'Default cache prefix left behind. %s');
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
/**
|
|
|
270 |
* Test that index.php is generated correctly.
|
|
|
271 |
*
|
|
|
272 |
* @return void
|
|
|
273 |
*/
|
|
|
274 |
public function testIndexPhpGeneration() {
|
|
|
275 |
$this->_setupTestProject();
|
|
|
276 |
|
|
|
277 |
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
278 |
$this->Task->corePath($path);
|
|
|
279 |
|
|
|
280 |
$File = new File($path . 'webroot' . DS . 'index.php');
|
|
|
281 |
$contents = $File->read();
|
|
|
282 |
$this->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
|
|
|
283 |
$File = new File($path . 'webroot' . DS . 'test.php');
|
|
|
284 |
$contents = $File->read();
|
|
|
285 |
$this->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/**
|
|
|
289 |
* test getPrefix method, and that it returns Routing.prefix or writes to config file.
|
|
|
290 |
*
|
|
|
291 |
* @return void
|
|
|
292 |
*/
|
|
|
293 |
public function testGetPrefix() {
|
|
|
294 |
Configure::write('Routing.prefixes', array('admin'));
|
|
|
295 |
$result = $this->Task->getPrefix();
|
|
|
296 |
$this->assertEquals('admin_', $result);
|
|
|
297 |
|
|
|
298 |
Configure::write('Routing.prefixes', null);
|
|
|
299 |
$this->_setupTestProject();
|
|
|
300 |
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'Config' . DS;
|
|
|
301 |
$this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
|
|
|
302 |
|
|
|
303 |
$result = $this->Task->getPrefix();
|
|
|
304 |
$this->assertEquals('super_duper_admin_', $result);
|
|
|
305 |
|
|
|
306 |
$File = new File($this->Task->configPath . 'core.php');
|
|
|
307 |
$File->delete();
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
/**
|
|
|
311 |
* test cakeAdmin() writing core.php
|
|
|
312 |
*
|
|
|
313 |
* @return void
|
|
|
314 |
*/
|
|
|
315 |
public function testCakeAdmin() {
|
|
|
316 |
$File = new File(APP . 'Config' . DS . 'core.php');
|
|
|
317 |
$contents = $File->read();
|
|
|
318 |
$File = new File(TMP . 'tests' . DS . 'core.php');
|
|
|
319 |
$File->write($contents);
|
|
|
320 |
|
|
|
321 |
Configure::write('Routing.prefixes', null);
|
|
|
322 |
$this->Task->configPath = TMP . 'tests' . DS;
|
|
|
323 |
$result = $this->Task->cakeAdmin('my_prefix');
|
|
|
324 |
$this->assertTrue($result);
|
|
|
325 |
|
|
|
326 |
$this->assertEquals(Configure::read('Routing.prefixes'), array('my_prefix'));
|
|
|
327 |
$File->delete();
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
/**
|
|
|
331 |
* test getting the prefix with more than one prefix setup
|
|
|
332 |
*
|
|
|
333 |
* @return void
|
|
|
334 |
*/
|
|
|
335 |
public function testGetPrefixWithMultiplePrefixes() {
|
|
|
336 |
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
|
|
|
337 |
$this->_setupTestProject();
|
|
|
338 |
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'Config' . DS;
|
|
|
339 |
$this->Task->expects($this->once())->method('in')->will($this->returnValue(2));
|
|
|
340 |
|
|
|
341 |
$result = $this->Task->getPrefix();
|
|
|
342 |
$this->assertEquals('ninja_', $result);
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
/**
|
|
|
346 |
* Test execute method with one param to destination folder.
|
|
|
347 |
*
|
|
|
348 |
* @return void
|
|
|
349 |
*/
|
|
|
350 |
public function testExecute() {
|
|
|
351 |
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel';
|
|
|
352 |
$this->Task->params['working'] = TMP . 'tests' . DS;
|
|
|
353 |
|
|
|
354 |
$path = $this->Task->path . 'bake_test_app';
|
|
|
355 |
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($path));
|
|
|
356 |
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
|
|
357 |
|
|
|
358 |
$this->Task->execute();
|
|
|
359 |
$this->assertTrue(is_dir($path), 'No project dir');
|
|
|
360 |
$this->assertTrue(is_dir($path . DS . 'Controller'), 'No controllers dir ');
|
|
|
361 |
$this->assertTrue(is_dir($path . DS . 'Controller' . DS . 'Component'), 'No components dir ');
|
|
|
362 |
$this->assertTrue(is_dir($path . DS . 'Model'), 'No models dir');
|
|
|
363 |
$this->assertTrue(is_dir($path . DS . 'View'), 'No views dir');
|
|
|
364 |
$this->assertTrue(is_dir($path . DS . 'View' . DS . 'Helper'), 'No helpers dir');
|
|
|
365 |
$this->assertTrue(is_dir($path . DS . 'Test'), 'No tests dir');
|
|
|
366 |
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Case'), 'No cases dir');
|
|
|
367 |
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Fixture'), 'No fixtures dir');
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
/**
|
|
|
371 |
* test console path
|
|
|
372 |
*
|
|
|
373 |
* @return void
|
|
|
374 |
*/
|
|
|
375 |
public function testConsolePath() {
|
|
|
376 |
$this->_setupTestProject();
|
|
|
377 |
|
|
|
378 |
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
379 |
$result = $this->Task->consolePath($path);
|
|
|
380 |
$this->assertTrue($result);
|
|
|
381 |
|
|
|
382 |
$File = new File($path . 'Console' . DS . 'cake.php');
|
|
|
383 |
$contents = $File->read();
|
|
|
384 |
$this->assertNotRegExp('/__CAKE_PATH__/', $contents, 'Console path placeholder left behind.');
|
|
|
385 |
}
|
|
|
386 |
}
|