Skip to content
Permalink
Browse files

Fixed failing tests to reflect new config files.

  • Loading branch information...
renan committed Nov 5, 2012
1 parent 1df42f8 commit 711eae985838bdafd42d871680f7d15fbaf6f810
@@ -89,12 +89,11 @@ public function startup() {
}
if ($this->command) {
if (!config('database')) {
$this->out(__d('cake_console', 'Your database configuration was not found. Take a moment to create one.'), true);
if (Configure::check('Datasource') === null) {
$this->out(__d('cake_console', 'Your datasources configuration was not found. Take a moment to create one.'), true);
$this->args = null;
return $this->DbConfig->execute();
}
require_once (APP . 'Config/database.php');
if (!in_array($this->command, array('initdb'))) {
$collection = new ComponentCollection();
@@ -64,7 +64,7 @@ public function execute() {
}
$response = false;
while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'boostrap.php')) {
$prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
$response = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($response) === 'n') {
@@ -79,14 +79,14 @@ public function execute() {
if ($this->securitySalt($path) === true) {
$this->out(__d('cake_console', ' * Random hash key created for \'Security.salt\''));
} else {
$this->err(__d('cake_console', 'Unable to generate random hash for \'Security.salt\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
$this->err(__d('cake_console', 'Unable to generate random hash for \'Security.salt\', you should change it in %s', APP . 'Config' . DS . 'app.php'));
$success = false;
}
if ($this->securityCipherSeed($path) === true) {
$this->out(__d('cake_console', ' * Random seed created for \'Security.cipherSeed\''));
} else {
$this->err(__d('cake_console', 'Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
$this->err(__d('cake_console', 'Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', APP . 'Config' . DS . 'app.php'));
$success = false;
}
@@ -97,13 +97,6 @@ public function execute() {
$success = false;
}
if ($this->consolePath($path) === true) {
$this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
} else {
$this->err(__d('cake_console', 'Unable to set console path for app/Console.'));
$success = false;
}
$hardCode = false;
if ($this->cakeOnIncludePath()) {
$this->out(__d('cake_console', '<info>CakePHP is on your `include_path`. CAKE_CORE_INCLUDE_PATH will be set, but commented out.</info>'));
@@ -114,10 +107,9 @@ public function execute() {
}
$success = $this->corePath($path, $hardCode) === true;
if ($success) {
$this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
$this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
$this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in Config/paths.php', CAKE_CORE_INCLUDE_PATH));
} else {
$this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' . DS . 'index.php'));
$this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'Config' . DS . 'paths.php'));
$success = false;
}
if ($success && $hardCode) {
@@ -226,28 +218,6 @@ public function bake($path, $skel = null, $skip = array('empty')) {
}
}
/**
* Generates the correct path to the CakePHP libs that are generating the project
* and points app/console/cake.php to the right place
*
* @param string $path Project path.
* @return boolean success
*/
public function consolePath($path) {
$File = new File($path . 'Console/cake.php');
$contents = $File->read();
if (preg_match('/(__CAKE_PATH__)/', $contents, $match)) {
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " \$ds . '" : "'";
$replacement = $root . str_replace(DS, "' . \$ds . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
$result = str_replace($match[0], $replacement, $contents);
if ($File->write($result)) {
return true;
}
return false;
}
return false;
}
/**
* Generates and writes 'Security.salt'
*
@@ -302,7 +272,7 @@ public function securityCipherSeed($path) {
*/
public function cachePrefix($dir) {
$app = basename($dir);
$File = new File($dir . 'Config/core.php');
$File = new File($dir . 'Config/cache.php');
$contents = $File->read();
if (preg_match('/(\$prefix = \'myapp_\';)/', $contents, $match)) {
$result = str_replace($match[0], '$prefix = \'' . $app . '_\';', $contents);
@@ -352,7 +322,7 @@ protected function _replaceCorePath($filename, $hardCode) {
}
/**
* Enables Configure::read('Routing.prefixes') in /app/Config/core.php
* Enables Configure::read('Routing.prefixes') in /app/Config/routes.php
*
* @param string $name Name to use as admin routing
* @return boolean Success
@@ -402,15 +372,15 @@ public function getPrefix() {
}
if ($this->interactive) {
$this->hr();
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/core.php to use prefix routing.'));
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/routes.php to use prefix routing.'));
$this->out(__d('cake_console', 'What would you like the prefix route to be?'));
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller'));
while (!$admin) {
$admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
}
if ($this->cakeAdmin($admin) !== true) {
$this->out(__d('cake_console', '<error>Unable to write to</error> /app/Config/core.php.'));
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/core.php to use prefix routing.'));
$this->out(__d('cake_console', '<error>Unable to write to</error> /app/Config/routes.php.'));
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/routes.php to use prefix routing.'));
$this->_stop();
}
return $admin . '_';
@@ -111,7 +111,7 @@
* Leaving this constant undefined will result in it being defined in Cake/bootstrap.php
*/
//TODO include_path support.
define('CAKE_CORE_INCLUDE_PATH', __CAKE_PATH__);
//define('CAKE_CORE_INCLUDE_PATH', __CAKE_PATH__);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
@@ -97,6 +97,8 @@ public function testBake() {
'Test/TestCase/Controller/Component',
'Test/TestCase/Model',
'Test/TestCase/Model/Behavior',
'Test/TestCase/View',
'Test/TestCase/View/Helper',
'Test/Fixture',
'Vendor',
'View',
@@ -114,7 +116,6 @@ public function testBake() {
'webroot/files',
'webroot/img',
'webroot/js',
);
foreach ($dirs as $dir) {
$this->assertTrue(is_dir($path . DS . $dir), 'Missing ' . $dir);
@@ -133,10 +134,7 @@ public function testExecuteWithAbsolutePath() {
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$File = new File($path . DS . 'webroot/index.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
$File = new File($path . DS . 'webroot/test.php');
$File = new File($path . DS . 'Config/paths.php');
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
}
@@ -159,10 +157,7 @@ public function testExecuteWithCakeOnIncludePath() {
$this->Task->execute();
$this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
$contents = file_get_contents($path . DS . 'webroot/index.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
$contents = file_get_contents($path . DS . 'webroot/test.php');
$contents = file_get_contents($path . DS . 'Config/paths.php');
$this->assertRegExp('#//define\(\'CAKE_CORE_INCLUDE_PATH#', $contents);
ini_set('include_path', $restore);
@@ -253,14 +248,14 @@ public function testCachePrefixGeneration() {
$result = $this->Task->cachePrefix($path);
$this->assertTrue($result);
$File = new File($path . 'Config/core.php');
$File = new File($path . 'Config/cache.php');
$contents = $File->read();
$this->assertRegExp('/\$prefix = \'.+\';/', $contents, '$prefix is not defined');
$this->assertNotRegExp('/\$prefix = \'myapp_\';/', $contents, 'Default cache prefix left behind. %s');
}
/**
* Test that index.php is generated correctly.
* Test that Config/paths.php is generated correctly.
*
* @return void
*/
@@ -270,10 +265,7 @@ public function testIndexPhpGeneration() {
$path = $this->Task->path . 'bake_test_app/';
$this->Task->corePath($path);
$File = new File($path . 'webroot/index.php');
$contents = $File->read();
$this->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
$File = new File($path . 'webroot/test.php');
$File = new File($path . 'Config/paths.php');
$contents = $File->read();
$this->assertNotRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents);
}
@@ -296,7 +288,7 @@ public function testGetPrefix() {
$result = $this->Task->getPrefix();
$this->assertEquals('super_duper_admin_', $result);
$File = new File($this->Task->configPath . 'core.php');
$File = new File($this->Task->configPath . 'routes.php');
$File->delete();
}
@@ -359,21 +351,4 @@ public function testExecute() {
$this->assertTrue(is_dir($path . DS . 'Test/TestCase'), 'No cases dir');
$this->assertTrue(is_dir($path . DS . 'Test/Fixture'), 'No fixtures dir');
}
/**
* test console path
*
* @return void
*/
public function testConsolePath() {
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app/';
$result = $this->Task->consolePath($path);
$this->assertTrue($result);
$File = new File($path . 'Console/cake.php');
$contents = $File->read();
$this->assertNotRegExp('/__CAKE_PATH__/', $contents, 'Console path placeholder left behind.');
}
}

0 comments on commit 711eae9

Please sign in to comment.
You can’t perform that action at this time.