updating cake.test.php, fixes #4638. updating cake.php, fixes #4648 (with tests), updated Cache

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6870 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-05-14 19:43:55 +00:00
parent 72c37d429e
commit 18b627636b
6 changed files with 219 additions and 187 deletions

View file

@ -145,12 +145,15 @@ class ShellDispatcher {
ini_set('implicit_flush', true);
ini_set('max_execution_time', 0);
}
define('PHP5', (phpversion() >= 5));
define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('DISABLE_DEFAULT_ERROR_HANDLING', false);
define('CAKEPHP_SHELL', true);
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('PHP5', (phpversion() >= 5));
define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('DISABLE_DEFAULT_ERROR_HANDLING', false);
define('CAKEPHP_SHELL', true);
}
}
/**
* Defines current working environment.
@ -204,8 +207,8 @@ class ShellDispatcher {
define('ROOT', $this->params['root']);
define('APP_DIR', $this->params['app']);
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('WWW_ROOT', 'webroot');
define('APP_PATH', $this->params['working'] . DS);
define('WWW_ROOT', APP_PATH . $this->params['webroot']);
$includes = array(
CORE_PATH . 'cake' . DS . 'basics.php',
@ -213,8 +216,10 @@ class ShellDispatcher {
CORE_PATH . 'cake' . DS . 'libs' . DS . 'object.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'file.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'cache.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'class_registry.php',
CORE_PATH . 'cake' . DS . 'console' . DS . 'error.php'
);
@ -229,12 +234,8 @@ class ShellDispatcher {
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
} else {
include_once APP_PATH . 'config' . DS . 'core.php';
}
require CORE_PATH . 'cake' . DS . 'libs' . DS . 'class_registry.php';
Configure::write('debug', 1);
return true;
}
@ -441,8 +442,10 @@ class ShellDispatcher {
$app = 'app';
$root = dirname(dirname(dirname(__FILE__)));
$this->params = str_replace("\\", '/', $this->params);
if (!empty($this->params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
if ($this->params['app']{0} == '/' || preg_match('/([a-z])(:)(\\\\)/i', substr($this->params['app'], 0, 3))) {
if (empty($this->params['app'])) {
$root = dirname($this->params['working']);
$app = basename($this->params['working']);
} else {
@ -452,13 +455,17 @@ class ShellDispatcher {
}
if (!empty($this->params['app'])) {
if ($this->params['app']{0} == '/') {
if($this->params['app']{0} == '/' || preg_match('/([a-z])(:)/i', $this->params['app'])) {
$root = dirname($this->params['app']);
}
$app = basename($this->params['app']);
unset($this->params['app']);
}
if (empty($this->params['webroot'])) {
$this->params['webroot'] = 'webroot';
}
$working = str_replace(DS . DS, DS, $root . DS . $app);
$this->params = array_merge($this->params, array('app'=> $app, 'root'=> $root, 'working'=> $working));
@ -515,9 +522,9 @@ class ShellDispatcher {
*/
function help() {
$this->stdout("Current Paths:");
$this->stdout(" -app: ". $this->params['app']);
$this->stdout(" -working: " . $this->params['working']);
$this->stdout(" -root: " . ROOT);
$this->stdout(" -app: ". APP);
$this->stdout(" -root: " . $this->params['root']);
$this->stdout(" -core: " . CORE_PATH);
$this->stdout("");
$this->stdout("Changing Paths:");

View file

@ -65,16 +65,11 @@ class ProjectTask extends Shell {
}
}
if($project) {
if($project{0} == '/' || $project{0} == DS) {
$this->Dispatch->parseParams(array('-working', $project, '-app', false));
} else {
$this->Dispatch->parseParams(array('-app', $project));
}
if ($project) {
$this->Dispatch->parseParams(array('-app', $project));
$project = $this->params['working'];
}
$project = $this->params['working'];
if (empty($this->params['skel'])) {
$this->params['skel'] = '';
if (is_dir(CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel') === true) {
@ -82,38 +77,21 @@ class ProjectTask extends Shell {
}
}
while (!$project) {
$project = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['working'] . DS . "myapp", null, $this->params['working'] . DS . 'myapp');
}
if ($project) {
$response = false;
while ($response == false && is_dir($project) === true && config('core') === true) {
while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
$response = $this->in('A project already exists in this location: '.$project.' Overwrite?', array('y','n'), 'n');
if (low($response) === 'n') {
$response = false;
while (!$response) {
$response = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['root'] . DS . "myapp\n[Q]uit", null, 'Q');
if (strtoupper($response) === 'Q') {
$this->out(__('Bake Aborted.', true));
exit();
}
$this->params['working'] = null;
$this->params['app'] = null;
$this->execute($response);
return true;
}
if (strtolower($response) === 'n') {
$response = $project = false;
}
}
}
while (!$project) {
$project = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['root'] . DS . "myapp", null, $this->params['root'] . DS . 'myapp');
$this->execute($project);
return true;
}
if($this->bake($project)) {
$this->params['app'] = basename($project);
$this->params['working'] = $project;
$path = Folder::slashTerm($project);
if ($this->createHome($path)) {
$this->out(__('Welcome page created', true));
@ -158,6 +136,7 @@ class ProjectTask extends Shell {
if(!$skel) {
$skel = $this->params['skel'];
}
while (!$skel) {
$skel = $this->in(sprintf(__("What is the path to the directory layout you wish to copy?\nExample: %s"), APP, null, ROOT . DS . 'myapp' . DS));
if ($skel == '') {
@ -201,9 +180,8 @@ class ProjectTask extends Shell {
} elseif (low($looksGood) == 'q' || low($looksGood) == 'quit') {
$this->out('Bake Aborted.');
} else {
$this->params['working'] = null;
$this->params['app'] = null;
$this->execute(false);
return false;
}
}
/**

View file

@ -100,30 +100,27 @@ class Cache extends Object {
function config($name = 'default', $settings = array()) {
$_this =& Cache::getInstance();
if (is_array($name)) {
extract($name);
$settings = $name;
}
if (isset($_this->__config[$name])) {
$settings = array_merge($_this->__config[$name], $settings);
} elseif (!empty($settings)) {
if (!empty($settings)) {
$_this->__name == null;
$_this->__config[$name] = $settings;
} elseif (isset($_this->__config[$name])) {
$settings = array_merge($_this->__config[$name], $settings);
} elseif ($_this->__name !== null && isset($_this->__config[$_this->__name])) {
$name = $_this->__name;
$settings = $_this->__config[$_this->__name];
} else {
$name = 'default';
if(!empty($_this->__config['default'])) {
$settings = $_this->__config['default'];
} else {
$settings = array('engine'=>'File');
}
return false;
}
$engine = 'File';
if (!empty($settings['engine'])) {
$engine = $settings['engine'];
if (empty($settings['engine'])) {
return false;
}
$engine = $settings['engine'];
if ($name !== $_this->__name) {
if ($_this->engine($engine, $settings) === false) {
return false;
@ -334,6 +331,7 @@ class Cache extends Object {
if (!$engine && isset($_this->__config[$_this->__name]['engine'])) {
$engine = $_this->__config[$_this->__name]['engine'];
}
if (isset($_this->_Engine[$engine]) && !is_null($_this->_Engine[$engine])) {
return $_this->_Engine[$engine]->settings();
}
@ -361,7 +359,6 @@ class Cache extends Object {
* @subpackage cake.cake.libs
*/
class CacheEngine extends Object {
/**
* settings of current engine instance
*

View file

@ -207,9 +207,7 @@ class Configure extends Object {
* @return array List of directories or files in directory
*/
function __list($path, $suffix = false, $extension = false) {
if (!class_exists('folder')) {
uses('folder');
}
App::import('Folder');
$items = array();
$Folder =& new Folder($path);
$contents = $Folder->read(false, true);
@ -278,9 +276,7 @@ class Configure extends Object {
if (!class_exists('Debugger')) {
require LIBS . 'debugger.php';
}
if (!class_exists('CakeLog')) {
uses('cake_log');
}
App::import('CakeLog');
Configure::write('log', LOG_NOTICE);
} else {
error_reporting(0);
@ -542,9 +538,7 @@ class Configure extends Object {
}
if ($write === true) {
if (!class_exists('File')) {
uses('File');
}
App::import('File');
$fileClass = new File($file);
if ($fileClass->writable()) {
@ -642,7 +636,6 @@ class Configure extends Object {
if ($_this->read('Cache.disable') !== true) {
$cache = Cache::settings();
if (empty($cache)) {
trigger_error('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', E_USER_WARNING);
list($engine, $cache) = Cache::config('default', array('engine' => 'File'));
@ -654,7 +647,7 @@ class Configure extends Object {
$config = Cache::config('_cake_core_' , array_merge($cache, $settings));
}
}
if (empty($_this->controllerPaths)) {
if (empty($_this->modelPaths)) {
$_this->buildPaths(compact('modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths', 'vendorPaths'));
}
}
@ -900,9 +893,7 @@ class App extends Object {
continue;
}
if (!isset($_this->__paths[$path])) {
if (!class_exists('Folder')) {
uses('Folder');
}
$_this->import('Folder');
$Folder =& new Folder();
$directories = $Folder->tree($path, false, 'dir');
$_this->__paths[$path] = $directories;

View file

@ -30,11 +30,12 @@ if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
}
ob_start();
$argv = false;
require CAKE . 'console' . DS . 'cake.php';
$out = ob_get_clean();
if (!class_exists('ShellDispatcher')) {
ob_start();
$argv = false;
require CAKE . 'console' . DS . 'cake.php';
ob_end_clean();
}
class TestShellDispatcher extends ShellDispatcher {
@ -58,18 +59,21 @@ class ShellDispatcherTest extends UnitTestCase {
function testParseParams() {
$Dispatcher =& new TestShellDispatcher();
$params = array('/cake/1.2.x.x/cake/console/cake.php',
'bake',
'-app',
'new',
'-working',
'/var/www/htdocs'
);
$params = array(
'/cake/1.2.x.x/cake/console/cake.php',
'bake',
'-app',
'new',
'-working',
'/var/www/htdocs'
);
$expected = array('app' => 'new',
'working' => '/var/www/htdocs/new',
'root' => '/var/www/htdocs'
);
$expected = array(
'app' => 'new',
'webroot' => 'webroot',
'working' => '/var/www/htdocs/new',
'root' => '/var/www/htdocs'
);
$Dispatcher->parseParams($params);
@ -78,103 +82,121 @@ class ShellDispatcherTest extends UnitTestCase {
$params = array('cake.php');
$expected = array('app' => 'app',
'working' => ROOT . DS . 'app',
'root' => ROOT,
);
$expected = array(
'app' => 'app',
'webroot' => 'webroot',
'working' => ROOT . DS . 'app',
'root' => ROOT,
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array('cake.php',
'-app',
'new',
);
$params = array(
'cake.php',
'-app',
'new',
);
$expected = array('app' => 'new',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$expected = array(
'app' => 'new',
'webroot' => 'webroot',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array('./cake.php',
'bake',
'-app',
'new',
'-working',
' /cake/1.2.x.x/cake/console'
);
$params = array(
'./cake.php',
'bake',
'-app',
'new',
'-working',
'/cake/1.2.x.x/cake/console'
);
$expected = array('app' => 'new',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$expected = array(
'app' => 'new',
'webroot' => 'webroot',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array('./console/cake.php',
'bake',
'-app',
'new',
'-working',
' /cake/1.2.x.x/cake'
);
$params = array(
'./console/cake.php',
'bake',
'-app',
'new',
'-working',
'/cake/1.2.x.x/cake'
);
$expected = array('app' => 'new',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$expected = array(
'app' => 'new',
'webroot' => 'webroot',
'working' => ROOT . DS . 'new',
'root' => ROOT
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array('./console/cake.php',
'bake',
'-app',
'new',
'-dry',
'-working',
' /cake/1.2.x.x/cake'
);
$params = array(
'./console/cake.php',
'bake',
'-app',
'new',
'-dry',
'-working',
'/cake/1.2.x.x/cake'
);
$expected = array('app' => 'new',
'working' => ROOT . DS . 'new',
'root' => ROOT,
'dry' => 1
);
$expected = array(
'app' => 'new',
'webroot' => 'webroot',
'working' => ROOT . DS . 'new',
'root' => ROOT,
'dry' => 1
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array('./console/cake.php',
'-working',
'/cake/1.2.x.x/cake',
'schema',
'run',
'create',
'-dry',
'-f',
'-name',
'DbAcl'
);
$expected = array('app' => 'app',
'working' => ROOT . DS . 'app',
'root' => ROOT,
'dry' => 1,
'f' => 1,
'name' => 'DbAcl'
);
$params = array(
'./console/cake.php',
'-working',
'/cake/1.2.x.x/cake',
'schema',
'run',
'create',
'-dry',
'-f',
'-name',
'DbAcl'
);
$expected = array(
'app' => 'app',
'webroot' => 'webroot',
'working' => ROOT . DS . 'app',
'root' => ROOT,
'dry' => 1,
'f' => 1,
'name' => 'DbAcl'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
@ -183,22 +205,26 @@ class ShellDispatcherTest extends UnitTestCase {
$expected = array('./console/cake.php', 'schema', 'run', 'create');
$this->assertEqual($expected, $Dispatcher->args);
$params = array('/cake/1.2.x.x/cake/console/cake.php',
'-working',
'/cake/1.2.x.x/app',
'schema',
'run',
'create',
'-dry',
'-name',
'DbAcl'
);
$expected = array('app' => 'app',
'working' => '/cake/1.2.x.x/app',
'root' => '/cake/1.2.x.x',
'dry' => 1,
'name' => 'DbAcl'
);
$params = array(
'/cake/1.2.x.x/cake/console/cake.php',
'-working',
'/cake/1.2.x.x/app',
'schema',
'run',
'create',
'-dry',
'-name',
'DbAcl'
);
$expected = array(
'app' => 'app',
'webroot' => 'webroot',
'working' => '/cake/1.2.x.x/app',
'root' => '/cake/1.2.x.x',
'dry' => 1,
'name' => 'DbAcl'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
@ -207,18 +233,41 @@ class ShellDispatcherTest extends UnitTestCase {
$expected = array('/cake/1.2.x.x/cake/console/cake.php', 'schema', 'run', 'create');
$this->assertEqual($expected, $Dispatcher->args);
$params = array('cake.php',
'-working',
'C:\wamp\www\cake\app',
'bake',
'-app',
'C:\wamp\www\apps\cake\app',
);
$params = array(
'cake.php',
'-working',
'C:/wamp/www/cake/app',
'bake',
'-app',
'C:/wamp/www/apps/cake/app',
);
$expected = array('app' => 'C:\wamp\www\apps\cake\app',
'working' => 'C:\wamp\www\cake\app',
'root' => ROOT
);
$expected = array(
'app' => 'app',
'webroot' => 'webroot',
'working' => 'C:/wamp/www/apps/cake/app',
'root' => 'C:/wamp/www/apps/cake'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$params = array(
'cake.php',
'-working',
'C:\wamp\www\cake\app',
'bake',
'-app',
'C:\wamp\www\apps\cake\app',
);
$expected = array(
'app' => 'app',
'webroot' => 'webroot',
'working' => 'C:/wamp/www/apps/cake/app',
'root' => 'C:/wamp/www/apps/cake'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
@ -226,4 +275,4 @@ class ShellDispatcherTest extends UnitTestCase {
}
}
?>
?>

View file

@ -38,6 +38,7 @@ class ConfigureTest extends UnitTestCase {
function setUp() {
$this->Configure =& Configure::getInstance();
$this->Configure->write('Cache.disable', true);
}
function testListCoreObjects() {
@ -98,6 +99,15 @@ class ConfigureTest extends UnitTestCase {
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths')) {
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths');
}
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map')) {
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map');
}
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map')) {
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map');
}
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map')) {
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map');
}
}
}