2009-06-17 02:34:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ProjectTask Test file
|
|
|
|
*
|
|
|
|
* Test Case for project generation shell task
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2009-06-17 02:34:16 +00:00
|
|
|
* Copyright 2006-2009, Cake Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2009-06-17 02:34:16 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
* @since CakePHP v 1.3.0
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2009-06-17 02:34:16 +00:00
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Shell', 'Shell', false);
|
2009-06-17 02:34:16 +00:00
|
|
|
|
|
|
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
|
|
|
define('DISABLE_AUTO_DISPATCH', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('ShellDispatcher')) {
|
|
|
|
ob_start();
|
|
|
|
$argv = false;
|
|
|
|
require CAKE . 'console' . DS . 'cake.php';
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
2010-01-17 00:41:52 +00:00
|
|
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
|
2009-06-17 02:34:16 +00:00
|
|
|
|
|
|
|
Mock::generatePartial(
|
|
|
|
'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
|
|
|
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
|
|
);
|
|
|
|
Mock::generatePartial(
|
|
|
|
'ProjectTask', 'MockProjectTask',
|
|
|
|
array('in', '_stop', 'err', 'out', 'createFile')
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ProjectTask Test class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
|
|
|
class ProjectTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-17 02:34:16 +00:00
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* startTest method
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function startTest() {
|
2009-06-17 02:34:16 +00:00
|
|
|
$this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
|
2009-07-07 03:11:57 +00:00
|
|
|
$this->Dispatcher->shellPaths = App::path('shells');
|
2009-06-17 02:34:16 +00:00
|
|
|
$this->Task =& new MockProjectTask($this->Dispatcher);
|
|
|
|
$this->Task->Dispatch =& $this->Dispatcher;
|
2009-06-17 03:05:48 +00:00
|
|
|
$this->Task->path = TMP . 'tests' . DS;
|
2009-06-17 02:34:16 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-17 02:34:16 +00:00
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* endTest method
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function endTest() {
|
2009-06-17 02:34:16 +00:00
|
|
|
ClassRegistry::flush();
|
2009-06-30 22:30:39 +00:00
|
|
|
|
|
|
|
$Folder =& new Folder($this->Task->path . 'bake_test_app');
|
|
|
|
$Folder->delete();
|
2009-06-17 02:34:16 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-17 03:05:48 +00:00
|
|
|
/**
|
2009-07-01 00:44:09 +00:00
|
|
|
* creates a test project that is used for testing project task.
|
2009-06-17 03:05:48 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _setupTestProject() {
|
2009-07-26 05:52:05 +00:00
|
|
|
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
|
2009-06-17 03:05:48 +00:00
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
|
|
$this->Task->setReturnValueAt(1, 'in', 'n');
|
|
|
|
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
|
2009-07-01 00:44:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-01 00:44:09 +00:00
|
|
|
/**
|
|
|
|
* test bake() method and directory creation.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBake() {
|
2009-07-01 00:44:09 +00:00
|
|
|
$this->_setupTestProject();
|
2009-06-17 03:05:48 +00:00
|
|
|
|
|
|
|
$path = $this->Task->path . 'bake_test_app';
|
|
|
|
$this->assertTrue(is_dir($path), 'No project dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-16 23:04:33 +00:00
|
|
|
/**
|
|
|
|
* test bake() method with -empty flag, directory creation and empty files.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeEmptyFlag() {
|
2009-11-16 23:04:33 +00:00
|
|
|
$this->Task->params['empty'] = true;
|
|
|
|
$this->_setupTestProject();
|
|
|
|
$path = $this->Task->path . 'bake_test_app';
|
|
|
|
$this->assertTrue(is_dir($path), 'No project dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
|
|
|
|
|
|
|
$this->assertTrue(is_file($path . DS . 'controllers' . DS .'components' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'locale' . DS . 'eng' . DS . 'LC_MESSAGES' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'plugins' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'shells' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'views' . DS . 'errors' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'views' . DS . 'scaffolds' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
$this->assertTrue(is_file($path . DS . 'webroot' . DS . 'js' . DS . 'empty'), 'No empty file in dir %s');
|
|
|
|
}
|
|
|
|
|
2009-06-30 22:30:39 +00:00
|
|
|
/**
|
|
|
|
* test generation of Security.salt
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSecuritySaltGeneration() {
|
2009-07-01 00:44:09 +00:00
|
|
|
$this->_setupTestProject();
|
|
|
|
|
2009-06-30 22:30:39 +00:00
|
|
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
|
$result = $this->Task->securitySalt($path);
|
|
|
|
$this->assertTrue($result);
|
2009-07-01 00:44:09 +00:00
|
|
|
|
2009-06-30 22:30:39 +00:00
|
|
|
$file =& new File($path . 'config' . DS . 'core.php');
|
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-01-25 16:14:18 +00:00
|
|
|
/**
|
2010-01-25 18:42:41 +00:00
|
|
|
* test generation of Security.cipherSeed
|
2010-01-25 16:14:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2010-04-05 03:19:38 +00:00
|
|
|
*/
|
|
|
|
public function testSecurityCipherSeedGeneration() {
|
2010-01-25 16:14:18 +00:00
|
|
|
$this->_setupTestProject();
|
|
|
|
|
|
|
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
|
$result = $this->Task->securityCipherSeed($path);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$file =& new File($path . 'config' . DS . 'core.php');
|
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
|
|
|
}
|
|
|
|
|
2009-11-10 01:10:24 +00:00
|
|
|
/**
|
|
|
|
* Test that index.php is generated correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testIndexPhpGeneration() {
|
2009-11-10 01:10:24 +00:00
|
|
|
$this->_setupTestProject();
|
2009-11-16 23:04:33 +00:00
|
|
|
|
2009-11-10 01:10:24 +00:00
|
|
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
|
$this->Task->corePath($path);
|
|
|
|
|
|
|
|
$file =& new File($path . 'webroot' . DS . 'index.php');
|
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
2009-11-10 14:17:54 +00:00
|
|
|
|
|
|
|
$file =& new File($path . 'webroot' . DS . 'test.php');
|
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
2009-11-10 01:10:24 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 00:44:09 +00:00
|
|
|
/**
|
2009-10-07 04:46:13 +00:00
|
|
|
* test getPrefix method, and that it returns Routing.prefix or writes to config file.
|
2009-07-01 00:44:09 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetPrefix() {
|
2009-10-07 04:46:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
|
|
|
$result = $this->Task->getPrefix();
|
2009-07-01 00:44:09 +00:00
|
|
|
$this->assertEqual($result, 'admin_');
|
|
|
|
|
2009-10-07 04:46:13 +00:00
|
|
|
Configure::write('Routing.prefixes', null);
|
2009-07-01 00:44:09 +00:00
|
|
|
$this->_setupTestProject();
|
|
|
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
|
|
|
$this->Task->setReturnValue('in', 'super_duper_admin');
|
|
|
|
|
2009-10-07 04:46:13 +00:00
|
|
|
$result = $this->Task->getPrefix();
|
2009-07-01 00:44:09 +00:00
|
|
|
$this->assertEqual($result, 'super_duper_admin_');
|
2009-10-07 04:46:13 +00:00
|
|
|
|
|
|
|
$file =& new File($this->Task->configPath . 'core.php');
|
|
|
|
$file->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test cakeAdmin() writing core.php
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testCakeAdmin() {
|
2009-10-07 04:46:13 +00:00
|
|
|
$file =& new File(CONFIGS . 'core.php');
|
|
|
|
$contents = $file->read();;
|
|
|
|
$file =& new File(TMP . 'tests' . DS . 'core.php');
|
|
|
|
$file->write($contents);
|
|
|
|
|
|
|
|
Configure::write('Routing.prefixes', null);
|
|
|
|
$this->Task->configPath = TMP . 'tests' . DS;
|
|
|
|
$result = $this->Task->cakeAdmin('my_prefix');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertEqual(Configure::read('Routing.prefixes'), array('my_prefix'));
|
|
|
|
$file->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test getting the prefix with more than one prefix setup
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetPrefixWithMultiplePrefixes() {
|
2009-10-07 04:46:13 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
|
|
|
|
$this->_setupTestProject();
|
|
|
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
|
|
|
|
$this->Task->setReturnValue('in', 2);
|
|
|
|
|
|
|
|
$result = $this->Task->getPrefix();
|
|
|
|
$this->assertEqual($result, 'ninja_');
|
2009-07-01 00:44:09 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-01 02:23:48 +00:00
|
|
|
/**
|
|
|
|
* Test execute method with one param to destination folder.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecute() {
|
2009-07-26 05:52:05 +00:00
|
|
|
$this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
|
2009-07-01 02:23:48 +00:00
|
|
|
$this->Task->params['working'] = TMP . 'tests' . DS;
|
|
|
|
|
|
|
|
$path = $this->Task->path . 'bake_test_app';
|
|
|
|
$this->Task->setReturnValue('in', 'y');
|
|
|
|
$this->Task->setReturnValueAt(0, 'in', $path);
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$this->assertTrue(is_dir($path), 'No project dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
|
|
|
|
}
|
2009-06-17 02:34:16 +00:00
|
|
|
}
|