2009-06-17 02:34:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ProjectTask Test file
|
|
|
|
*
|
|
|
|
* Test Case for project generation shell task
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2010-10-24 20:58:22 +00:00
|
|
|
* Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-10-24 20:58:22 +00:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
2009-06-17 02:34:16 +00:00
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-07 05:55:05 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Shell', 'Console');
|
2011-03-07 05:55:05 +00:00
|
|
|
App::uses('ProjectTask', 'Console/Command/Task');
|
|
|
|
App::uses('Folder', 'Utility');
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('File', 'Utility');
|
2009-06-17 02:34:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ProjectTask Test class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
2009-06-17 02:34:16 +00:00
|
|
|
*/
|
|
|
|
class ProjectTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-17 02:34:16 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setup method
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
|
|
|
$this->Task = $this->getMock('ProjectTask',
|
2010-06-10 04:59:19 +00:00
|
|
|
array('in', 'err', 'createFile', '_stop'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-10 04:59:19 +00:00
|
|
|
);
|
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
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* teardown method
|
2009-06-17 02:34:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2009-06-30 22:30:39 +00:00
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
$Folder = new Folder($this->Task->path . 'bake_test_app');
|
2009-06-30 22:30:39 +00:00
|
|
|
$Folder->delete();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
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() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$skel = CAKE . 'Console' . DS . 'templates' . DS . 'skel';
|
2010-06-10 04:59:19 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
2009-06-17 03:05:48 +00:00
|
|
|
$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';
|
2010-10-17 23:01:44 +00:00
|
|
|
|
2009-06-17 03:05:48 +00:00
|
|
|
$this->assertTrue(is_dir($path), 'No project dir %s');
|
2010-10-17 23:01:44 +00:00
|
|
|
$dirs = array(
|
2011-05-13 08:06:45 +00:00
|
|
|
'Config',
|
2011-05-15 04:10:09 +00:00
|
|
|
'Config' . DS . 'Schema',
|
2011-04-12 02:45:51 +00:00
|
|
|
'Console',
|
|
|
|
'Console' . DS . 'Command',
|
|
|
|
'Console' . DS . 'Command' . DS . 'Task',
|
2011-04-17 10:35:21 +00:00
|
|
|
'Controller',
|
|
|
|
'Model',
|
2011-04-12 02:45:51 +00:00
|
|
|
'View',
|
|
|
|
'View' . DS . 'Helper',
|
2011-05-15 04:10:09 +00:00
|
|
|
'Test',
|
2011-04-17 10:35:21 +00:00
|
|
|
'Test' . DS . 'Case',
|
2011-05-15 04:10:09 +00:00
|
|
|
'Test' . DS . 'Case' . DS . 'Model',
|
|
|
|
'Test' . DS . 'Fixture',
|
2010-10-17 23:01:44 +00:00
|
|
|
'tmp',
|
|
|
|
'webroot',
|
|
|
|
'webroot' . DS . 'js',
|
|
|
|
'webroot' . DS . 'css',
|
|
|
|
);
|
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
$this->assertTrue(is_dir($path . DS . $dir), 'Missing ' . $dir);
|
|
|
|
}
|
2009-06-17 03:05:48 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-05-22 12:49:51 +00:00
|
|
|
/**
|
|
|
|
* test bake with an absolute path.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExecuteWithAbsolutePath() {
|
2011-05-30 19:14:21 +00:00
|
|
|
$this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app';
|
2011-05-22 12:49:51 +00:00
|
|
|
$this->Task->params['skel'] = CAKE . 'Console' . DS . 'templates' . DS . 'skel';
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
|
|
|
$this->Task->execute();
|
|
|
|
|
|
|
|
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
|
|
|
|
}
|
|
|
|
|
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';
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-17 23:01:44 +00:00
|
|
|
$empty = array(
|
2011-04-12 02:45:51 +00:00
|
|
|
'Console' . DS . 'Command' . DS . 'Task',
|
2011-04-17 10:35:21 +00:00
|
|
|
'Controller' . DS . 'Component',
|
|
|
|
'Model' . DS . 'Behavior',
|
2011-04-12 02:45:51 +00:00
|
|
|
'View' . DS . 'Helper',
|
2011-05-15 04:10:09 +00:00
|
|
|
'View' . DS . 'Errors',
|
|
|
|
'View' . DS . 'Scaffolds',
|
2011-04-17 10:35:21 +00:00
|
|
|
'Test' . DS . 'Case' . DS . 'Model',
|
2011-05-15 04:10:09 +00:00
|
|
|
'Test' . DS . 'Case' . DS . 'Controller',
|
|
|
|
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
|
|
|
|
'Test' . DS . 'Fixture',
|
2010-10-17 23:01:44 +00:00
|
|
|
'webroot' . DS . 'js'
|
|
|
|
);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-17 23:01:44 +00:00
|
|
|
foreach ($empty as $dir) {
|
|
|
|
$this->assertTrue(is_file($path . DS . $dir . DS . 'empty'), 'Missing empty file in ' . $dir);
|
|
|
|
}
|
2009-11-16 23:04:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-05-13 08:06:45 +00:00
|
|
|
$file = new File($path . 'Config' . DS . 'core.php');
|
2009-06-30 22:30:39 +00:00
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
/**
|
|
|
|
* test generation of Security.cipherSeed
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecurityCipherSeedGeneration() {
|
|
|
|
$this->_setupTestProject();
|
2010-01-25 16:14:18 +00:00
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
|
$result = $this->Task->securityCipherSeed($path);
|
|
|
|
$this->assertTrue($result);
|
2010-01-25 16:14:18 +00:00
|
|
|
|
2011-05-13 08:06:45 +00:00
|
|
|
$file = new File($path . 'Config' . DS . 'core.php');
|
2010-06-10 04:59:19 +00:00
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
|
|
|
|
}
|
2010-01-25 16:14:18 +00:00
|
|
|
|
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);
|
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
$file = new File($path . 'webroot' . DS . 'index.php');
|
2009-11-10 01:10:24 +00:00
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
|
2009-11-10 14:17:54 +00:00
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
$file = new File($path . 'webroot' . DS . 'test.php');
|
2009-11-10 14:17:54 +00:00
|
|
|
$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();
|
2011-05-13 08:06:45 +00:00
|
|
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'Config' . DS;
|
2010-06-10 04:59:19 +00:00
|
|
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
|
2009-07-01 00:44:09 +00:00
|
|
|
|
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
|
|
|
|
2010-06-10 04:59:19 +00:00
|
|
|
$file = new File($this->Task->configPath . 'core.php');
|
2009-10-07 04:46:13 +00:00
|
|
|
$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() {
|
2011-04-17 11:13:02 +00:00
|
|
|
$file = new File(APP . 'Config' . DS . 'core.php');
|
2009-10-07 04:46:13 +00:00
|
|
|
$contents = $file->read();;
|
2010-06-10 04:59:19 +00:00
|
|
|
$file = new File(TMP . 'tests' . DS . 'core.php');
|
2009-10-07 04:46:13 +00:00
|
|
|
$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();
|
2011-05-13 08:06:45 +00:00
|
|
|
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'Config' . DS;
|
2010-06-10 04:59:19 +00:00
|
|
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue(2));
|
2009-10-07 04:46:13 +00:00
|
|
|
|
|
|
|
$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() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->Task->params['skel'] = CAKE . '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';
|
2010-06-10 04:59:19 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($path));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
2009-07-01 02:23:48 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
2010-12-06 04:32:34 +00:00
|
|
|
$this->assertTrue(is_dir($path), 'No project dir');
|
2011-04-12 02:45:51 +00:00
|
|
|
$this->assertTrue(is_dir($path . DS . 'Controller'), 'No controllers dir ');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'Controller' . DS .'Component'), 'No components dir ');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'Model'), 'No models dir');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'View'), 'No views dir');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'View' . DS . 'Helper'), 'No helpers dir');
|
2011-05-15 04:10:09 +00:00
|
|
|
$this->assertTrue(is_dir($path . DS . 'Test'), 'No tests dir');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Case'), 'No cases dir');
|
|
|
|
$this->assertTrue(is_dir($path . DS . 'Test' . DS . 'Fixture'), 'No fixtures dir');
|
2010-10-18 02:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test console path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testConsolePath() {
|
|
|
|
$this->_setupTestProject();
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-18 02:38:32 +00:00
|
|
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
|
|
|
$result = $this->Task->consolePath($path);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2011-04-12 02:45:51 +00:00
|
|
|
$file = new File($path . 'Console' . DS . 'cake.php');
|
2010-10-18 02:38:32 +00:00
|
|
|
$contents = $file->read();
|
|
|
|
$this->assertNoPattern('/__CAKE_PATH__/', $contents, 'Console path placeholder left behind.');
|
2009-07-01 02:23:48 +00:00
|
|
|
}
|
2009-06-17 02:34:16 +00:00
|
|
|
}
|