3
* ProjectTask Test file
5
* Test Case for project generation shell task
9
* CakePHP : Rapid Development Framework (http://cakephp.org)
10
* Copyright 2006-2009, Cake Software Foundation, Inc.
12
* Licensed under The MIT License
13
* Redistributions of files must retain the above copyright notice.
15
* @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
16
* @link http://cakephp.org CakePHP Project
18
* @subpackage cake.tests.cases.console.libs.tasks
19
* @since CakePHP v 1.3.0
20
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
22
App::import('Shell', 'Shell', false);
24
if (!defined('DISABLE_AUTO_DISPATCH')) {
25
define('DISABLE_AUTO_DISPATCH', true);
28
if (!class_exists('ShellDispatcher')) {
31
require CAKE . 'console' . DS . 'cake.php';
35
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
37
Mock::generatePartial(
38
'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
39
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
41
Mock::generatePartial(
42
'ProjectTask', 'MockProjectTask',
43
array('in', '_stop', 'err', 'out', 'createFile')
47
* ProjectTask Test class
50
* @subpackage cake.tests.cases.console.libs.tasks
52
class ProjectTaskTest extends CakeTestCase {
60
function startTest() {
61
$this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
62
$this->Dispatcher->shellPaths = App::path('shells');
63
$this->Task =& new MockProjectTask($this->Dispatcher);
64
$this->Task->Dispatch =& $this->Dispatcher;
65
$this->Task->path = TMP . 'tests' . DS;
75
ClassRegistry::flush();
77
$Folder =& new Folder($this->Task->path . 'bake_test_app');
82
* creates a test project that is used for testing project task.
87
function _setupTestProject() {
88
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
89
$this->Task->setReturnValueAt(0, 'in', 'y');
90
$this->Task->setReturnValueAt(1, 'in', 'n');
91
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
95
* test bake() method and directory creation.
100
function testBake() {
101
$this->_setupTestProject();
103
$path = $this->Task->path . 'bake_test_app';
104
$this->assertTrue(is_dir($path), 'No project dir %s');
105
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
106
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
107
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
108
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
109
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
110
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
111
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
112
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
113
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
117
* test bake() method with -empty flag, directory creation and empty files.
122
function testBakeEmptyFlag() {
123
$this->Task->params['empty'] = true;
124
$this->_setupTestProject();
125
$path = $this->Task->path . 'bake_test_app';
126
$this->assertTrue(is_dir($path), 'No project dir %s');
127
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
128
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
129
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
130
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
131
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
132
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
133
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
134
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
135
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
137
$this->assertTrue(is_file($path . DS . 'controllers' . DS .'components' . DS . 'empty'), 'No empty file in dir %s');
138
$this->assertTrue(is_file($path . DS . 'locale' . DS . 'eng' . DS . 'LC_MESSAGES' . DS . 'empty'), 'No empty file in dir %s');
139
$this->assertTrue(is_file($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
140
$this->assertTrue(is_file($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
141
$this->assertTrue(is_file($path . DS . 'plugins' . DS . 'empty'), 'No empty file in dir %s');
142
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
143
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file in dir %s');
144
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file in dir %s');
145
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
146
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
147
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file in dir %s');
148
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'shells' . DS . 'empty'), 'No empty file in dir %s');
149
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file in dir %s');
150
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file in dir %s');
151
$this->assertTrue(is_file($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file in dir %s');
152
$this->assertTrue(is_file($path . DS . 'views' . DS . 'errors' . DS . 'empty'), 'No empty file in dir %s');
153
$this->assertTrue(is_file($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
154
$this->assertTrue(is_file($path . DS . 'views' . DS . 'scaffolds' . DS . 'empty'), 'No empty file in dir %s');
155
$this->assertTrue(is_file($path . DS . 'webroot' . DS . 'js' . DS . 'empty'), 'No empty file in dir %s');
159
* test generation of Security.salt
164
function testSecuritySaltGeneration() {
165
$this->_setupTestProject();
167
$path = $this->Task->path . 'bake_test_app' . DS;
168
$result = $this->Task->securitySalt($path);
169
$this->assertTrue($result);
171
$file =& new File($path . 'config' . DS . 'core.php');
172
$contents = $file->read();
173
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
177
* test generation of Security.cipherSeed
182
function testSecurityCipherSeedGeneration() {
183
$this->_setupTestProject();
185
$path = $this->Task->path . 'bake_test_app' . DS;
186
$result = $this->Task->securityCipherSeed($path);
187
$this->assertTrue($result);
189
$file =& new File($path . 'config' . DS . 'core.php');
190
$contents = $file->read();
191
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
195
* Test that index.php is generated correctly.
200
function testIndexPhpGeneration() {
201
$this->_setupTestProject();
203
$path = $this->Task->path . 'bake_test_app' . DS;
204
$this->Task->corePath($path);
206
$file =& new File($path . 'webroot' . DS . 'index.php');
207
$contents = $file->read();
208
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
210
$file =& new File($path . 'webroot' . DS . 'test.php');
211
$contents = $file->read();
212
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
216
* test getPrefix method, and that it returns Routing.prefix or writes to config file.
221
function testGetPrefix() {
222
Configure::write('Routing.prefixes', array('admin'));
223
$result = $this->Task->getPrefix();
224
$this->assertEqual($result, 'admin_');
226
Configure::write('Routing.prefixes', null);
227
$this->_setupTestProject();
228
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
229
$this->Task->setReturnValue('in', 'super_duper_admin');
231
$result = $this->Task->getPrefix();
232
$this->assertEqual($result, 'super_duper_admin_');
234
$file =& new File($this->Task->configPath . 'core.php');
239
* test cakeAdmin() writing core.php
244
function testCakeAdmin() {
245
$file =& new File(CONFIGS . 'core.php');
246
$contents = $file->read();;
247
$file =& new File(TMP . 'tests' . DS . 'core.php');
248
$file->write($contents);
250
Configure::write('Routing.prefixes', null);
251
$this->Task->configPath = TMP . 'tests' . DS;
252
$result = $this->Task->cakeAdmin('my_prefix');
253
$this->assertTrue($result);
255
$this->assertEqual(Configure::read('Routing.prefixes'), array('my_prefix'));
260
* test getting the prefix with more than one prefix setup
265
function testGetPrefixWithMultiplePrefixes() {
266
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
267
$this->_setupTestProject();
268
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
269
$this->Task->setReturnValue('in', 2);
271
$result = $this->Task->getPrefix();
272
$this->assertEqual($result, 'ninja_');
276
* Test execute method with one param to destination folder.
281
function testExecute() {
282
$this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
283
$this->Task->params['working'] = TMP . 'tests' . DS;
285
$path = $this->Task->path . 'bake_test_app';
286
$this->Task->setReturnValue('in', 'y');
287
$this->Task->setReturnValueAt(0, 'in', $path);
289
$this->Task->execute();
290
$this->assertTrue(is_dir($path), 'No project dir %s');
291
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
292
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
293
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
294
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
295
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
296
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
297
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
298
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
299
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');