From 73cbdf011bc69776144c69b9a077efbcbe23127e Mon Sep 17 00:00:00 2001 From: davidpersson Date: Thu, 16 Apr 2009 10:30:36 +0200 Subject: [PATCH 01/17] Removing prepending of "Error: " in ShellDispatcher::stderr --- cake/console/cake.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 823e6fc00..0866d53b6 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -436,7 +436,7 @@ class ShellDispatcher { * @access public */ function stderr($string) { - fwrite($this->stderr, 'Error: '. $string); + fwrite($this->stderr, $string); } /** * Parses command line options From 4faa9d3b21de78c4d637673014894423d64e67f0 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Thu, 16 Apr 2009 10:53:12 +0200 Subject: [PATCH 02/17] Adding newline param to Shell::err The signature of ::err is now identical to ::out Adding tests for ::err --- cake/console/libs/shell.php | 5 +++-- cake/tests/cases/console/libs/shell.test.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index bac6c347b..b298fcaaa 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -358,9 +358,10 @@ class Shell extends Object { * Outputs to the stderr filehandle. * * @param string $string Error text to output. + * @param boolean $newline If true, the outputs gets an added newline. * @access public */ - function err($string) { + function err($string, $newline = true) { if (is_array($string)) { $str = ''; foreach ($string as $message) { @@ -368,7 +369,7 @@ class Shell extends Object { } $string = $str; } - return $this->Dispatch->stderr($string."\n"); + return $this->Dispatch->stderr($string . ($newline ? "\n" : '')); } /** * Outputs a series of minus characters to the standard output, acts as a visual separator. diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index bfd15a95b..8d03541fc 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -160,6 +160,19 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(1, 'stdout', array("Just\na\ntest\n", true)); $this->Shell->out(array('Just', 'a', 'test')); } +/** + * testErr method + * + * @return void + * @access public + */ + function testErr() { + $this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n")); + $this->Shell->err('Just a test'); + + $this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n\n")); + $this->Shell->err(array('Just', 'a', 'test')); + } /** * testIn method * From 82641e535f581260c7b614aa3ac56d0349de2c49 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Thu, 16 Apr 2009 11:00:47 +0200 Subject: [PATCH 03/17] Updating formatting of output in Shell:error Renaming $msg param to $message The $message param is now optional The method now exits the app with status code 1 --- cake/console/libs/shell.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index b298fcaaa..01855bceb 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -387,18 +387,20 @@ class Shell extends Object { } } /** - * Displays a formatted error message and exits the application + * Displays a formatted error message + * and exits the application with status code 1 * - * @param string $title Title of the error message - * @param string $msg Error message + * @param string $title Title of the error + * @param string $message An optional error message * @access public */ - function error($title, $msg) { - $out = "$title\n"; - $out .= "$msg\n"; - $out .= "\n"; - $this->err($out); - $this->_stop(); + function error($title, $message = null) { + $this->err(sprintf(__('Error: %s', true), $title)); + + if (!empty($message)) { + $this->err($message); + } + $this->_stop(1); } /** * Will check the number args matches otherwise throw an error From 0ee8889e6d9fb26873a0d8a87832f8c201757d9d Mon Sep 17 00:00:00 2001 From: davidpersson Date: Fri, 24 Apr 2009 21:04:07 +0200 Subject: [PATCH 04/17] Adding Shell::nl method Updating out to not use newline feature of SD::stdout Updating out, err and hr methods to utilize the new method Rewording parameters of out, err and hr Changing handling of multiple messages Adding tests for nl, hr and error Updating tests for out and err Updating docblocks --- cake/console/libs/shell.php | 66 +++++----- cake/tests/cases/console/libs/shell.test.php | 131 +++++++++++++++---- 2 files changed, 141 insertions(+), 56 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 01855bceb..a0a194d70 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -338,53 +338,59 @@ class Shell extends Object { } } /** - * Outputs to the stdout filehandle. + * Outputs a single or multiple messages to stdout. * - * @param string $string String to output. - * @param boolean $newline If true, the outputs gets an added newline. + * @param mixed $message A string or a an array of strings to output + * @param mixed $after Appended to message, if true a newline is used * @access public */ - function out($string, $newline = true) { - if (is_array($string)) { - $str = ''; - foreach ($string as $message) { - $str .= $message ."\n"; - } - $string = $str; + function out($message, $after = true) { + if (is_array($message)) { + $message = implode($this->nl(), $message); } - return $this->Dispatch->stdout($string, $newline); + $this->Dispatch->stdout($message . $this->nl($after), false); } /** - * Outputs to the stderr filehandle. + * Outputs a single or multiple error messages to stderr. * - * @param string $string Error text to output. - * @param boolean $newline If true, the outputs gets an added newline. + * @param mixed $message A string or a an array of strings to output + * @param mixed $after Appended to message, if true a newline is used * @access public */ - function err($string, $newline = true) { - if (is_array($string)) { - $str = ''; - foreach ($string as $message) { - $str .= $message ."\n"; - } - $string = $str; + function err($message, $after = true) { + if (is_array($message)) { + $message = implode($this->nl(), $message); } - return $this->Dispatch->stderr($string . ($newline ? "\n" : '')); + $this->Dispatch->stderr($message . $this->nl($after)); + } +/** + * Returns a single or multiple linefeeds sequences. + * + * @param mixed $format If true returns a linefeed sequence, if false null, + * if a string is given that is returned, + * if an integer is given it is used as a multiplier to return multiple linefeed sequences + * @access public + * @return string + */ + function nl($format = true) { + if (is_string($format)) { + return $format; + } + if (is_integer($format)) { + return str_repeat("\n", $format); + } + return $format ? "\n" : null; } /** * Outputs a series of minus characters to the standard output, acts as a visual separator. * - * @param boolean $newline If true, the outputs gets an added newline. + * @param mixed $surround If true, the outputs gets surrounded by newlines. * @access public */ - function hr($newline = false) { - if ($newline) { - $this->out("\n"); - } + function hr($surround = false) { + $this->out(null, $surround); $this->out('---------------------------------------------------------------'); - if ($newline) { - $this->out("\n"); - } + $this->out(null, $surround); } /** * Displays a formatted error message diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index 8d03541fc..6144842a4 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -48,6 +48,23 @@ Mock::generatePartial( * @subpackage cake.tests.cases.console.libs */ class TestShell extends Shell { +/** + * stopped property + * + * @var integer + * @access public + */ + var $stopped; +/** + * stop method + * + * @param integer $status + * @access protected + * @return void + */ + function _stop($status = 0) { + $this->stopped = $status; + } } /** * TestAppleTask class @@ -147,32 +164,6 @@ class ShellTest extends CakeTestCase { Configure::write('pluginPaths', $_back['pluginPaths']); Configure::write('modelPaths', $_back['modelPaths']); } -/** - * testOut method - * - * @return void - * @access public - */ - function testOut() { - $this->Shell->Dispatch->expectAt(0, 'stdout', array('Just a test', true)); - $this->Shell->out('Just a test'); - - $this->Shell->Dispatch->expectAt(1, 'stdout', array("Just\na\ntest\n", true)); - $this->Shell->out(array('Just', 'a', 'test')); - } -/** - * testErr method - * - * @return void - * @access public - */ - function testErr() { - $this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n")); - $this->Shell->err('Just a test'); - - $this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n\n")); - $this->Shell->err(array('Just', 'a', 'test')); - } /** * testIn method * @@ -210,6 +201,94 @@ class ShellTest extends CakeTestCase { $result = $this->Shell->in('Just a test?', 'y/n', 'n'); $this->assertEqual($result, 'n'); } +/** + * testOut method + * + * @return void + * @access public + */ + function testOut() { + $this->Shell->Dispatch->expectAt(0, 'stdout', array("Just a test\n", false)); + $this->Shell->out('Just a test'); + + $this->Shell->Dispatch->expectAt(1, 'stdout', array("Just\na\ntest\n", false)); + $this->Shell->out(array('Just', 'a', 'test')); + + $this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false)); + $this->Shell->out(array('Just', 'a', 'test'), 2); + } +/** + * testErr method + * + * @return void + * @access public + */ + function testErr() { + $this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n")); + $this->Shell->err('Just a test'); + + $this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n")); + $this->Shell->err(array('Just', 'a', 'test')); + + $this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n")); + $this->Shell->err(array('Just', 'a', 'test'), 2); + } +/** + * testNl + * + * @access public + * @return void + */ + function testNl() { + $this->assertEqual($this->Shell->nl(), "\n"); + $this->assertEqual($this->Shell->nl(true), "\n"); + $this->assertEqual($this->Shell->nl(false), ""); + $this->assertEqual($this->Shell->nl(2), "\n\n"); + $this->assertEqual($this->Shell->nl(1), "\n"); + $this->assertEqual($this->Shell->nl("custom\n"), "custom\n"); + } +/** + * testHr + * + * @access public + * @return void + */ + function testHr() { + $bar = '---------------------------------------------------------------'; + + $this->Shell->Dispatch->expectAt(0, 'stdout', array('', false)); + $this->Shell->Dispatch->expectAt(1, 'stdout', array($bar . "\n", false)); + $this->Shell->Dispatch->expectAt(2, 'stdout', array('', false)); + $this->Shell->hr(); + + $this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false)); + $this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false)); + $this->Shell->Dispatch->expectAt(5, 'stdout', array("\n", false)); + $this->Shell->hr(true); + + $this->Shell->Dispatch->expectAt(3, 'stdout', array("\n\n", false)); + $this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false)); + $this->Shell->Dispatch->expectAt(5, 'stdout', array("\n\n", false)); + $this->Shell->hr(2); + } +/** + * testError + * + * @access public + * @return void + */ + function testError() { + $this->Shell->Dispatch->expectAt(0, 'stderr', array("Error: Foo Not Found\n")); + $this->Shell->error('Foo Not Found'); + $this->assertIdentical($this->Shell->stopped, 1); + + $this->Shell->stopped = null; + + $this->Shell->Dispatch->expectAt(1, 'stderr', array("Error: Foo Not Found\n")); + $this->Shell->Dispatch->expectAt(2, 'stderr', array("Searched all...\n")); + $this->Shell->error('Foo Not Found', 'Searched all...'); + $this->assertIdentical($this->Shell->stopped, 1); + } /** * testLoadTasks method * From 4b89dd2209a7a5ee9c5833ce15f0c31351a12497 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Thu, 30 Apr 2009 19:25:58 +0200 Subject: [PATCH 05/17] Refactoring ShellDispatcher::dispatch Updating dispatch method to use is_a fixes #5318 Adding _getShell method to ease testing Updating status code handling in the constructor Adding and updating tests --- cake/console/cake.php | 255 ++++++++++-------- cake/tests/cases/console/cake.test.php | 350 ++++++++++++++++++++++++- 2 files changed, 484 insertions(+), 121 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 0866d53b6..22683ad8b 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -120,15 +120,21 @@ class ShellDispatcher { /** * Constructor * - * @param array $args the argv. + * The execution of the script is stopped after dispatching the request with + * a status code of either 0 or 1 according to the result of the dispatch. + * + * @param array $args the argv + * @return void + * @access public */ function __construct($args = array()) { set_time_limit(0); + $this->__initConstants(); $this->parseParams($args); $this->_initEnvironment(); $this->__buildPaths(); - $this->_stop($this->dispatch()); + $this->_stop($this->dispatch() === false ? 1 : 0); } /** * Defines core configuration. @@ -269,118 +275,145 @@ class ShellDispatcher { /** * Dispatches a CLI request * + * @return boolean * @access public */ function dispatch() { - if (isset($this->args[0])) { - $plugin = null; - $shell = $this->args[0]; - if (strpos($shell, '.') !== false) { - list($plugin, $shell) = explode('.', $this->args[0]); - } - - $this->shell = $shell; - $this->shiftArgs(); - $this->shellName = Inflector::camelize($this->shell); - $this->shellClass = $this->shellName . 'Shell'; - - if ($this->shell === 'help') { - $this->help(); - } else { - $loaded = false; - foreach ($this->shellPaths as $path) { - $this->shellPath = $path . $this->shell . '.php'; - - $isPlugin = ($plugin && strpos($path, DS . $plugin . DS . 'vendors' . DS . 'shells' . DS) !== false); - if (($isPlugin && file_exists($this->shellPath)) || (!$plugin && file_exists($this->shellPath))) { - $loaded = true; - break; - } - } - - if ($loaded) { - if (!class_exists('Shell')) { - require CONSOLE_LIBS . 'shell.php'; - } - require $this->shellPath; - if (class_exists($this->shellClass)) { - $command = null; - if (isset($this->args[0])) { - $command = $this->args[0]; - } - $this->shellCommand = Inflector::variable($command); - $shell = new $this->shellClass($this); - - if (strtolower(get_parent_class($shell)) == 'shell') { - $shell->initialize(); - $shell->loadTasks(); - - foreach ($shell->taskNames as $task) { - if (strtolower(get_parent_class($shell)) == 'shell') { - $shell->{$task}->initialize(); - $shell->{$task}->loadTasks(); - } - } - - $task = Inflector::camelize($command); - if (in_array($task, $shell->taskNames)) { - $this->shiftArgs(); - $shell->{$task}->startup(); - if (isset($this->args[0]) && $this->args[0] == 'help') { - if (method_exists($shell->{$task}, 'help')) { - $shell->{$task}->help(); - $this->_stop(); - } else { - $this->help(); - } - } - return $shell->{$task}->execute(); - } - } - - $classMethods = get_class_methods($shell); - - $privateMethod = $missingCommand = false; - if ((in_array($command, $classMethods) || in_array(strtolower($command), $classMethods)) && strpos($command, '_', 0) === 0) { - $privateMethod = true; - } - - if (!in_array($command, $classMethods) && !in_array(strtolower($command), $classMethods)) { - $missingCommand = true; - } - - $protectedCommands = array( - 'initialize','in','out','err','hr', - 'createfile', 'isdir','copydir','object','tostring', - 'requestaction','log','cakeerror', 'shelldispatcher', - '__initconstants','__initenvironment','__construct', - 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs' - ); - - if (in_array(strtolower($command), $protectedCommands)) { - $missingCommand = true; - } - - if ($missingCommand && method_exists($shell, 'main')) { - $shell->startup(); - return $shell->main(); - } elseif (!$privateMethod && method_exists($shell, $command)) { - $this->shiftArgs(); - $shell->startup(); - return $shell->{$command}(); - } else { - $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); - } - } else { - $this->stderr('Class '.$this->shellClass.' could not be loaded'); - } - } else { - $this->help(); - } - } - } else { + if (!$arg = array_shift($this->args)) { $this->help(); + return false; } + if ($arg == 'help') { + $this->help(); + return true; + } + + if (strpos($arg, '.') !== false) { + list($plugin, $shell) = explode('.', $arg); + } else { + $plugin = null; + $shell = $arg; + } + $this->shell = $shell; + $this->shellName = Inflector::camelize($shell); + $this->shellClass = $this->shellName . 'Shell'; + + if ($arg = array_shift($this->args)) { + $this->shellCommand = Inflector::variable($arg); + } + + $Shell = $this->_getShell($plugin); + + if (!$Shell) { + $message = sprintf(__('Class `%s` could not be loaded', true), $this->shellClass); + $this->stderr($message . "\n"); + return false; + } + + if (is_a($Shell, 'Shell')) { + $Shell->initialize(); + $Shell->loadTasks(); + + foreach ($Shell->taskNames as $task) { + if (is_a($Shell->{$task}, 'Shell')) { + $Shell->{$task}->initialize(); + $Shell->{$task}->loadTasks(); + } + } + + $task = Inflector::camelize($this->shellCommand); + + if (in_array($task, $Shell->taskNames)) { + $this->shiftArgs(); + $Shell->{$task}->startup(); + + if (isset($this->args[0]) && $this->args[0] == 'help') { + if (method_exists($Shell->{$task}, 'help')) { + $Shell->{$task}->help(); + } else { + $this->help(); + } + return true; + } + return $Shell->{$task}->execute(); + } + + } + + $classMethods = get_class_methods($Shell); + + $privateMethod = $missingCommand = false; + if ((in_array($arg, $classMethods) || in_array(strtolower($arg), $classMethods)) + && $arg[0] == '_') { + $privateMethod = true; + } + + if (!in_array($arg, $classMethods) && !in_array(strtolower($arg), $classMethods)) { + $missingCommand = true; + } + + $protectedCommands = array( + 'initialize','in','out','err','hr', + 'createfile', 'isdir','copydir','object','tostring', + 'requestaction','log','cakeerror', 'shelldispatcher', + '__initconstants','__initenvironment','__construct', + 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs' + ); + + if (in_array(strtolower($arg), $protectedCommands)) { + $missingCommand = true; + } + + if ($missingCommand && method_exists($Shell, 'main')) { + $Shell->startup(); + return $Shell->main(); + } elseif (!$privateMethod && method_exists($Shell, $arg)) { + $this->shiftArgs(); + $Shell->startup(); + return $Shell->{$arg}(); + } + + $message = sprintf(__('Unknown %1$s command `%2$s`. For usage try `cake %3$s help`.', true), + $this->shellName, $this->shellCommand, $this->shell); + $this->stderr($message . "\n"); + return false; + } +/** + * Get shell to use, either plugin shell or application shell + * + * All paths in the shellPaths property are searched. + * shell, shellPath and shellClass properties are taken into account. + * + * @param string $plugin Optionally the name of a plugin + * @return mixed False if no shell could be found or an object on success + * @access protected + */ + function _getShell($plugin = null) { + foreach ($this->shellPaths as $path) { + $this->shellPath = $path . $this->shell . '.php'; + $pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS; + + if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) { + $loaded = true; + break; + } + } + if (!isset($loaded)) { + return false; + } + + if (!class_exists('Shell')) { + require CONSOLE_LIBS . 'shell.php'; + } + + if (!class_exists($this->shellClass)) { + require $this->shellPath; + } + if (!class_exists($this->shellClass)) { + return false; + } + $Shell = new $this->shellClass($this); + return $Shell; } /** * Prompts the user for input, and returns it. @@ -480,7 +513,7 @@ class ShellDispatcher { $this->params = array_merge($this->params, $params); } /** - * Helper for recursively paraing params + * Helper for recursively parsing params * * @return array params * @access private @@ -559,6 +592,7 @@ class ShellDispatcher { } else { sort($shells); foreach ($shells as $shell) { + if ($shell !== 'shell.php') { $this->stdout("\t " . str_replace('.php', '', $shell)); } @@ -568,7 +602,6 @@ class ShellDispatcher { } $this->stdout("\nTo run a command, type 'cake shell_name [args]'"); $this->stdout("To get help on a specific command, type 'cake shell_name help'"); - $this->_stop(); } /** * Stop execution of the current script diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 9ec2e57dd..2c87d6628 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -34,6 +34,8 @@ if (!class_exists('ShellDispatcher')) { require CAKE . 'console' . DS . 'cake.php'; ob_end_clean(); } + +require_once CONSOLE_LIBS . 'shell.php'; /** * TestShellDispatcher class * @@ -69,6 +71,13 @@ class TestShellDispatcher extends ShellDispatcher { * @access public */ var $stopped = null; +/** + * TestShell + * + * @var mixed + * @access public + */ + var $TestShell; /** * _initEnvironment method * @@ -107,6 +116,30 @@ class TestShellDispatcher extends ShellDispatcher { */ function _stop($status = 0) { $this->stopped = 'Stopped with status: ' . $status; + return $status; + } +/** + * getShell + * + * @param mixed $plugin + * @access public + * @return mixed + */ + function getShell($plugin = null) { + return $this->_getShell($plugin); + } +/** + * _getShell + * + * @param mixed $plugin + * @access protected + * @return mixed + */ + function _getShell($plugin = null) { + if (isset($this->TestShell)) { + return $this->TestShell; + } + return parent::_getShell($plugin); } } /** @@ -115,7 +148,7 @@ class TestShellDispatcher extends ShellDispatcher { * @package cake * @subpackage cake.tests.cases.libs */ -class ShellDispatcherTest extends UnitTestCase { +class ShellDispatcherTest extends CakeTestCase { /** * setUp method * @@ -419,20 +452,317 @@ class ShellDispatcherTest extends UnitTestCase { $this->assertIdentical(array_diff($expected, $result), array()); } /** - * testDispatch method + * Verify loading of (plugin-) shells * * @access public * @return void */ - function testDispatch() { - $Dispatcher =& new TestShellDispatcher(array('sample')); - $this->assertPattern('/This is the main method called from SampleShell/', $Dispatcher->stdout); + function testGetShell() { + $this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded'); + $this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded'); - $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.example')); - $this->assertPattern('/This is the main method called from TestPluginTwo.ExampleShell/', $Dispatcher->stdout); + $Dispatcher =& new TestShellDispatcher(); - $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.welcome', 'say_hello')); - $this->assertPattern('/This is the say_hello method called from TestPluginTwo.WelcomeShell/', $Dispatcher->stdout); + $Dispatcher->shell = 'sample'; + $Dispatcher->shellName = 'Sample'; + $Dispatcher->shellClass = 'SampleShell'; + + $result = $Dispatcher->getShell(); + $this->assertIsA($result, 'SampleShell'); + + $Dispatcher =& new TestShellDispatcher(); + + $Dispatcher->shell = 'example'; + $Dispatcher->shellName = 'Example'; + $Dispatcher->shellClass = 'ExampleShell'; + + $result = $Dispatcher->getShell('test_plugin'); + $this->assertIsA($result, 'ExampleShell'); + } +/** + * Verify correct dispatch of Shell subclasses with a main method + * + * @access public + * @return void + */ + function testDispatchShellWithMain() { + Mock::generate('Shell', 'MockWithMainShell', array('main', '_secret')); + + $Dispatcher =& new TestShellDispatcher(); + + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('initialize'); + $Shell->expectOnce('loadTasks'); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main', 'initdb')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectNever('hr'); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main', 'hr')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main', 'dispatch')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main', 'idontexist')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainShell(); + $Shell->expectNever('startup'); + $Shell->expectNever('main'); + $Shell->expectNever('_secret'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main', '_secret')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + } +/** + * Verify correct dispatch of Shell subclasses without a main method + * + * @access public + * @return void + */ + function testDispatchShellWithoutMain() { + Mock::generate('Shell', 'MockWithoutMainShell', array('initDb', '_secret')); + + $Dispatcher =& new TestShellDispatcher(); + + $Shell = new MockWithoutMainShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectOnce('initialize'); + $Shell->expectOnce('loadTasks'); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('initDb'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main', 'initdb')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + /* Currently fails when it should not */ + /* $Shell = new MockWithoutMainShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectNever('startup'); + $Shell->expectNever('hr'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main', 'hr')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); */ + + $Shell = new MockWithoutMainShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main', 'dispatch')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainShell(); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main', 'idontexist')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainShell(); + $Shell->expectNever('startup'); + $Shell->expectNever('_secret'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main', '_secret')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + } +/** + * Verify correct dispatch of custom classes with a main method + * + * @access public + * @return void + */ + function testDispatchNotAShellWithMain() { + Mock::generate('Object', 'MockWithMainNotAShell', + array('main', 'initialize', 'loadTasks', 'startup', '_secret')); + + $Dispatcher =& new TestShellDispatcher(); + + $Shell = new MockWithMainNotAShell(); + $Shell->setReturnValue('main', true); + $Shell->expectNever('initialize'); + $Shell->expectNever('loadTasks'); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainNotAShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a', 'initdb')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainNotAShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a', 'hr')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainNotAShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a', 'dispatch')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainNotAShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('main'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a', 'idontexist')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithMainNotAShell(); + $Shell->expectNever('startup'); + $Shell->expectNever('main'); + $Shell->expectNever('_secret'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_with_main_not_a', '_secret')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + } +/** + * Verify correct dispatch of custom classes without a main method + * + * @access public + * @return void + */ + function testDispatchNotAShellWithoutMain() { + Mock::generate('Object', 'MockWithoutMainNotAShell', + array('initDb', 'initialize', 'loadTasks', 'startup', '_secret')); + + $Dispatcher =& new TestShellDispatcher(); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectNever('initialize'); + $Shell->expectNever('loadTasks'); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('initDb'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a', 'initdb')); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a', 'hr')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->setReturnValue('initDb', true); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a', 'dispatch')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->expectNever('startup'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a', 'idontexist')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); + + $Shell = new MockWithoutMainNotAShell(); + $Shell->expectNever('startup'); + $Shell->expectNever('_secret'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->parseParams(array('mock_without_main_not_a', '_secret')); + $result = $Dispatcher->dispatch(); + $this->assertFalse($result); } /** * testHelpCommand method @@ -476,7 +806,7 @@ class ShellDispatcherTest extends UnitTestCase { $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:"; $expected .= "\n\t sample"; $expected .= "\n/"; - $this->assertPattern($expected, $Dispatcher->stdout); + $this->assertPattern($expected, $Dispatcher->stdout); } } ?> \ No newline at end of file From ebe1cd258a09adf06e54aec2b3b0ae3dd22836ff Mon Sep 17 00:00:00 2001 From: davidpersson Date: Fri, 1 May 2009 03:47:33 +0200 Subject: [PATCH 06/17] Updating shiftArgs to return shifted arg If no args were available the method was returning false and now returns null. If args were available the method was returning true it now returns the shifted argument instead. --- cake/console/cake.php | 13 ++++-------- cake/tests/cases/console/cake.test.php | 29 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 22683ad8b..1129b9a25 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -279,7 +279,7 @@ class ShellDispatcher { * @access public */ function dispatch() { - if (!$arg = array_shift($this->args)) { + if (!$arg = $this->shiftArgs()) { $this->help(); return false; } @@ -298,7 +298,7 @@ class ShellDispatcher { $this->shellName = Inflector::camelize($shell); $this->shellClass = $this->shellName . 'Shell'; - if ($arg = array_shift($this->args)) { + if ($arg = $this->shiftArgs()) { $this->shellCommand = Inflector::variable($arg); } @@ -546,16 +546,11 @@ class ShellDispatcher { /** * Removes first argument and shifts other arguments up * - * @return boolean False if there are no arguments + * @return mixed Null if there are no arguments otherwise the shifted argument * @access public */ function shiftArgs() { - if (empty($this->args)) { - return false; - } - unset($this->args[0]); - $this->args = array_values($this->args); - return true; + return array_shift($this->args); } /** * Shows console help diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 2c87d6628..45b160a8b 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -764,6 +764,35 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertFalse($result); } +/** + * Verify shifting of arguments + * + * @access public + * @return void + */ + function testShiftArgs() { + $Dispatcher =& new TestShellDispatcher(); + + $Dispatcher->args = array('a', 'b', 'c'); + $this->assertEqual($Dispatcher->shiftArgs(), 'a'); + $this->assertIdentical($Dispatcher->args, array('b', 'c')); + + $Dispatcher->args = array('a' => 'b', 'c', 'd'); + $this->assertEqual($Dispatcher->shiftArgs(), 'b'); + $this->assertIdentical($Dispatcher->args, array('c', 'd')); + + $Dispatcher->args = array('a', 'b' => 'c', 'd'); + $this->assertEqual($Dispatcher->shiftArgs(), 'a'); + $this->assertIdentical($Dispatcher->args, array('b' => 'c', 'd')); + + $Dispatcher->args = array(0 => 'a', 2 => 'b', 30 => 'c'); + $this->assertEqual($Dispatcher->shiftArgs(), 'a'); + $this->assertIdentical($Dispatcher->args, array(0 => 'b', 1 => 'c')); + + $Dispatcher->args = array(); + $this->assertNull($Dispatcher->shiftArgs()); + $this->assertIdentical($Dispatcher->args, array()); + } /** * testHelpCommand method * From 1d8f57d37a5bdd7b4d6f077e78e7ac4d88b9257b Mon Sep 17 00:00:00 2001 From: davidpersson Date: Fri, 1 May 2009 12:08:56 +0200 Subject: [PATCH 07/17] Second pass at dispatch refactor Updating command dispatching Fixing incorrect arg handling Moving assignments out of conditionals Updating tests to reset args Adding dispatch task test --- cake/console/cake.php | 71 ++++++++--------- cake/tests/cases/console/cake.test.php | 102 ++++++++++++++++++------- 2 files changed, 105 insertions(+), 68 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 1129b9a25..72236b84a 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -279,7 +279,9 @@ class ShellDispatcher { * @access public */ function dispatch() { - if (!$arg = $this->shiftArgs()) { + $arg = $this->shiftArgs(); + + if (!$arg) { $this->help(); return false; } @@ -298,18 +300,23 @@ class ShellDispatcher { $this->shellName = Inflector::camelize($shell); $this->shellClass = $this->shellName . 'Shell'; - if ($arg = $this->shiftArgs()) { + $arg = null; + + if (isset($this->args[0])) { + $arg = $this->args[0]; $this->shellCommand = Inflector::variable($arg); } $Shell = $this->_getShell($plugin); if (!$Shell) { - $message = sprintf(__('Class `%s` could not be loaded', true), $this->shellClass); - $this->stderr($message . "\n"); + $title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass); + $this->stderr($title . "\n"); return false; } + $methods = array(); + if (is_a($Shell, 'Shell')) { $Shell->initialize(); $Shell->loadTasks(); @@ -321,7 +328,7 @@ class ShellDispatcher { } } - $task = Inflector::camelize($this->shellCommand); + $task = Inflector::camelize($arg); if (in_array($task, $Shell->taskNames)) { $this->shiftArgs(); @@ -337,45 +344,27 @@ class ShellDispatcher { } return $Shell->{$task}->execute(); } + $methods = get_class_methods('Shell'); + } + $methods = array_diff(get_class_methods($Shell), $methods); + $added = in_array(strtolower($arg), array_map('strtolower', $methods)); + $private = $arg[0] == '_' && method_exists($Shell, $arg); + if (!$private) { + if ($added) { + $this->shiftArgs(); + $Shell->startup(); + return $Shell->{$arg}(); + } + if (method_exists($Shell, 'main')) { + $Shell->startup(); + return $Shell->main(); + } } - $classMethods = get_class_methods($Shell); - - $privateMethod = $missingCommand = false; - if ((in_array($arg, $classMethods) || in_array(strtolower($arg), $classMethods)) - && $arg[0] == '_') { - $privateMethod = true; - } - - if (!in_array($arg, $classMethods) && !in_array(strtolower($arg), $classMethods)) { - $missingCommand = true; - } - - $protectedCommands = array( - 'initialize','in','out','err','hr', - 'createfile', 'isdir','copydir','object','tostring', - 'requestaction','log','cakeerror', 'shelldispatcher', - '__initconstants','__initenvironment','__construct', - 'dispatch','__bootstrap','getinput','stdout','stderr','parseparams','shiftargs' - ); - - if (in_array(strtolower($arg), $protectedCommands)) { - $missingCommand = true; - } - - if ($missingCommand && method_exists($Shell, 'main')) { - $Shell->startup(); - return $Shell->main(); - } elseif (!$privateMethod && method_exists($Shell, $arg)) { - $this->shiftArgs(); - $Shell->startup(); - return $Shell->{$arg}(); - } - - $message = sprintf(__('Unknown %1$s command `%2$s`. For usage try `cake %3$s help`.', true), - $this->shellName, $this->shellCommand, $this->shell); - $this->stderr($message . "\n"); + $title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg); + $message = sprintf(__('For usage try `cake %s help`', true), $this->shell); + $this->stderr($title . "\n" . $message . "\n"); return false; } /** diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 45b160a8b..914890223 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -498,9 +498,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main')); + $Dispatcher->args = array('mock_with_main'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array()); $Shell = new MockWithMainShell(); $Shell->setReturnValue('main', true); @@ -508,9 +509,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main', 'initdb')); + $Dispatcher->args = array('mock_with_main', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('initdb')); $Shell = new MockWithMainShell(); $Shell->setReturnValue('main', true); @@ -519,9 +521,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main', 'hr')); + $Dispatcher->args = array('mock_with_main', 'hr'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('hr')); $Shell = new MockWithMainShell(); $Shell->setReturnValue('main', true); @@ -529,9 +532,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main', 'dispatch')); + $Dispatcher->args = array('mock_with_main', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('dispatch')); $Shell = new MockWithMainShell(); $Shell->setReturnValue('main', true); @@ -539,9 +543,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main', 'idontexist')); + $Dispatcher->args = array('mock_with_main', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('idontexist')); $Shell = new MockWithMainShell(); $Shell->expectNever('startup'); @@ -549,7 +554,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main', '_secret')); + $Dispatcher->args = array('mock_with_main', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); } @@ -571,9 +576,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main')); + $Dispatcher->args = array('mock_without_main'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); + $this->assertEqual($Dispatcher->args, array()); $Shell = new MockWithoutMainShell(); $Shell->setReturnValue('initDb', true); @@ -581,27 +587,28 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('initDb'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main', 'initdb')); + $Dispatcher->args = array('mock_without_main', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array()); - /* Currently fails when it should not */ - /* $Shell = new MockWithoutMainShell(); + $Shell = new MockWithoutMainShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('startup'); $Shell->expectNever('hr'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main', 'hr')); + $Dispatcher->args = array('mock_without_main', 'hr'); $result = $Dispatcher->dispatch(); - $this->assertFalse($result); */ + $this->assertFalse($result); + $this->assertEqual($Dispatcher->args, array('hr')); $Shell = new MockWithoutMainShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main', 'dispatch')); + $Dispatcher->args = array('mock_without_main', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -609,7 +616,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main', 'idontexist')); + $Dispatcher->args = array('mock_without_main', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -618,7 +625,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main', '_secret')); + $Dispatcher->args = array('mock_without_main', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); } @@ -642,9 +649,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a')); + $Dispatcher->args = array('mock_with_main_not_a'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array()); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); @@ -652,9 +660,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a', 'initdb')); + $Dispatcher->args = array('mock_with_main_not_a', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('initdb')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); @@ -662,9 +671,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a', 'hr')); + $Dispatcher->args = array('mock_with_main_not_a', 'hr'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('hr')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); @@ -672,9 +682,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a', 'dispatch')); + $Dispatcher->args = array('mock_with_main_not_a', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('dispatch')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); @@ -682,9 +693,10 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a', 'idontexist')); + $Dispatcher->args = array('mock_with_main_not_a', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array('idontexist')); $Shell = new MockWithMainNotAShell(); $Shell->expectNever('startup'); @@ -692,7 +704,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_with_main_not_a', '_secret')); + $Dispatcher->args = array('mock_with_main_not_a', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); } @@ -715,7 +727,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a')); + $Dispatcher->args = array('mock_without_main_not_a'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -725,16 +737,17 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectOnce('initDb'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a', 'initdb')); + $Dispatcher->args = array('mock_without_main_not_a', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array()); $Shell = new MockWithoutMainNotAShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a', 'hr')); + $Dispatcher->args = array('mock_without_main_not_a', 'hr'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -743,7 +756,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a', 'dispatch')); + $Dispatcher->args = array('mock_without_main_not_a', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -751,7 +764,7 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a', 'idontexist')); + $Dispatcher->args = array('mock_without_main_not_a', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); @@ -760,10 +773,45 @@ class ShellDispatcherTest extends CakeTestCase { $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; - $Dispatcher->parseParams(array('mock_without_main_not_a', '_secret')); + $Dispatcher->args = array('mock_without_main_not_a', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); } +/** + * Verify that a task is called instead of the shell if the first arg equals + * the name of the task + * + * @access public + * @return void + */ + function testDispatchTask() { + Mock::generate('Shell', 'MockWeekShell', array('main')); + Mock::generate('Shell', 'MockOnSundayTask', array('execute')); + + $Dispatcher =& new TestShellDispatcher(); + + $Shell = new MockWeekShell(); + $Shell->expectOnce('initialize'); + $Shell->expectOnce('loadTasks'); + $Shell->expectNever('startup'); + $Shell->expectNever('main'); + + $Task = new MockOnSundayTask(); + $Task->setReturnValue('execute', true); + $Task->expectOnce('initialize'); + $Task->expectOnce('loadTasks'); + $Task->expectOnce('startup'); + $Task->expectOnce('execute'); + + $Shell->MockOnSunday =& $Task; + $Shell->taskNames = array('MockOnSunday'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->args = array('mock_week', 'mock_on_sunday'); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); + $this->assertEqual($Dispatcher->args, array()); + } /** * Verify shifting of arguments * From 06d3aee348ac3bdcccb6d4f6fc735c6c1e811e2b Mon Sep 17 00:00:00 2001 From: davidpersson Date: Sat, 2 May 2009 23:34:39 +0200 Subject: [PATCH 08/17] Fixing help not getting called Adding tests --- cake/console/cake.php | 2 +- cake/tests/cases/console/cake.test.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 72236b84a..d62b88002 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -344,7 +344,7 @@ class ShellDispatcher { } return $Shell->{$task}->execute(); } - $methods = get_class_methods('Shell'); + $methods = array_diff(get_class_methods('Shell'), array('help')); } $methods = array_diff(get_class_methods($Shell), $methods); $added = in_array(strtolower($arg), array_map('strtolower', $methods)); diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 914890223..26d8faf5f 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -514,6 +514,17 @@ class ShellDispatcherTest extends CakeTestCase { $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array('initdb')); + $Shell = new MockWithMainShell(); + $Shell->setReturnValue('main', true); + $Shell->expectOnce('startup'); + $Shell->expectOnce('help'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->args = array('mock_with_main', 'help'); + $result = $Dispatcher->dispatch(); + $this->assertNull($result); + $this->assertEqual($Dispatcher->args, array()); + $Shell = new MockWithMainShell(); $Shell->setReturnValue('main', true); $Shell->expectNever('hr'); @@ -811,6 +822,19 @@ class ShellDispatcherTest extends CakeTestCase { $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array()); + + $Shell = new MockWeekShell(); + $Task = new MockOnSundayTask(); + $Task->expectNever('execute'); + $Task->expectOnce('help'); + + $Shell->MockOnSunday =& $Task; + $Shell->taskNames = array('MockOnSunday'); + $Dispatcher->TestShell =& $Shell; + + $Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help'); + $result = $Dispatcher->dispatch(); + $this->assertTrue($result); } /** * Verify shifting of arguments From a6f25f5c64a4cf3cd227b81b9ed49b4fa2d9edbd Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Jul 2009 21:45:30 +0000 Subject: [PATCH 09/17] Removing ending html tags, they were being generated before the page ended. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8256 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/lib/cake_reporter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cake/tests/lib/cake_reporter.php b/cake/tests/lib/cake_reporter.php index f2688b440..b5e93bf22 100644 --- a/cake/tests/lib/cake_reporter.php +++ b/cake/tests/lib/cake_reporter.php @@ -91,7 +91,6 @@ class CakeHtmlReporter extends SimpleReporter { echo "" . $this->getFailCount() . " fails and "; echo "" . $this->getExceptionCount() . " exceptions."; echo "\n"; - echo "\n\n"; } /** * Paints the test failure with a breadcrumbs From f53181bc967ef4c9e7c46f3a2eade9e48ae6ad56 Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 27 Jul 2009 16:57:58 +0000 Subject: [PATCH 10/17] fixes #6467, cake bake on windows drive. thanks burzum git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8257 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/cake.php | 14 ++++++++------ cake/tests/cases/console/cake.test.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index 823e6fc00..2e114a343 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -446,13 +446,15 @@ class ShellDispatcher { */ function parseParams($params) { $this->__parseParams($params); - $defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot'); - $params = array_merge($defaults, array_intersect_key($this->params, $defaults)); - - $isWin = array_filter(array_map('strpos', $params, array('\\'))); - + $isWin = false; + foreach ($defaults as $default => $value) { + if (strpos($params[$default], '\\') !== false) { + $isWin = true; + break; + } + } $params = str_replace('\\', '/', $params); if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) { @@ -464,7 +466,7 @@ class ShellDispatcher { } } - if ($params['app'][0] == '/' || preg_match('/([a-zA-Z])(:)/i', $params['app'], $matches)) { + if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) { $params['root'] = dirname($params['app']); } elseif (strpos($params['app'], '/')) { $params['root'] .= '/' . dirname($params['app']); diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 9ec2e57dd..6eda913f8 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.php @@ -396,6 +396,25 @@ class ShellDispatcherTest extends UnitTestCase { $Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->parseParams($params); $this->assertEqual($expected, $Dispatcher->params); + + + $params = array( + 'cake.php', + '-working', + 'D:\www', + 'bake', + 'my_app', + ); + $expected = array( + 'working' => 'D:\www', + 'app' => 'www', + 'root' => 'D:', + 'webroot' => 'webroot' + ); + + $Dispatcher->params = $Dispatcher->args = array(); + $Dispatcher->parseParams($params); + $this->assertEqual($expected, $Dispatcher->params); } /** * testBuildPaths method From 9da7b6ef552ef1de1b1dfdb540c3ff8aeeb586f0 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Tue, 28 Jul 2009 09:49:27 +0000 Subject: [PATCH 11/17] Bringing Router coverage up to 94.45%, minor router refactorings git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8258 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 19 ++++---- cake/tests/cases/libs/router.test.php | 69 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index 9ce2df977..45dc5c12a 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -311,9 +311,9 @@ class Router extends Object { /** * Builds a route regular expression * - * @param string $route An empty string, or a route string "/" - * @param array $default NULL or an array describing the default route - * @param array $params An array matching the named elements in the route to regular expressions which that element should match. + * @param string $route An empty string, or a route string "/" + * @param array $default NULL or an array describing the default route + * @param array $params An array matching the named elements in the route to regular expressions which that element should match. * @return array * @see routes * @access public @@ -533,10 +533,7 @@ class Router extends Object { function compile($i) { $route = $this->routes[$i]; - if (!list($pattern, $names) = $this->writeRoute($route[0], $route[1], $route[2])) { - unset($this->routes[$i]); - return array(); - } + list($pattern, $names) = $this->writeRoute($route[0], $route[1], $route[2]); $this->routes[$i] = array( $route[0], $pattern, $names, array_merge(array('plugin' => null, 'controller' => null), (array)$route[1]), @@ -1271,9 +1268,9 @@ class Router extends Object { return $param; } - $return = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $param); - return $return; + return preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $param); } + foreach ($param as $key => $value) { if (is_string($value)) { $return[$key] = preg_replace('/^(?:[\\t ]*(?:-!)+)/', '', $value); @@ -1346,7 +1343,9 @@ class Router extends Object { continue; } $param = $_this->stripEscape($param); - if ((!isset($options['named']) || !empty($options['named'])) && strpos($param, $_this->named['separator']) !== false) { + + $separatorIsPresent = strpos($param, $_this->named['separator']) !== false; + if ((!isset($options['named']) || !empty($options['named'])) && $separatorIsPresent) { list($key, $val) = explode($_this->named['separator'], $param, 2); $hasRule = isset($rules[$key]); $passIt = (!$hasRule && !$greedy) || ($hasRule && !Router::matchNamed($key, $val, $rules[$key], $context)); diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 99d0e220d..cf2dd221e 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1670,5 +1670,74 @@ class RouterTest extends CakeTestCase { $this->assertEqual(Router::stripPlugin($url), $url); $this->assertEqual(Router::stripPlugin($url, null), $url); } +/** + * testCurentRoute + * + * This test needs some improvement and actual requestAction() usage + * + * @return void + * @access public + */ + function testCurentRoute() { + $url = array('controller' => 'pages', 'action' => 'display', 'government'); + Router::connect('/government', $url); + Router::parse('/government'); + $route = Router::currentRoute(); + $this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]); + } +/** + * testRequestRoute + * + * @return void + * @access public + */ + function testRequestRoute() { + $url = array('controller' => 'products', 'action' => 'display', 5); + Router::connect('/government', $url); + Router::parse('/government'); + $route = Router::requestRoute(); + $this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]); + + // test that the first route is matched + $newUrl = array('controller' => 'products', 'action' => 'display', 6); + Router::connect('/government', $url); + Router::parse('/government'); + $route = Router::requestRoute(); + $this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]); + + // test that an unmatched route does not change the current route + $newUrl = array('controller' => 'products', 'action' => 'display', 6); + Router::connect('/actor', $url); + Router::parse('/government'); + $route = Router::requestRoute(); + $this->assertEqual(array_merge($url, array('plugin' => false)), $route[3]); + } +/** + * testGetParams + * + * @return void + * @access public + */ + function testGetParams() { + $paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot'); + $params = array('param1' => '1', 'param2' => '2'); + Router::setRequestInfo(array($params, $paths)); + $expected = array( + 'plugin' => false, 'controller' => false, 'action' => false, + 'param1' => '1', 'param2' => '2' + ); + $this->assertEqual(Router::getparams(), $expected); + $this->assertEqual(Router::getparam('controller'), false); + $this->assertEqual(Router::getparam('param1'), '1'); + $this->assertEqual(Router::getparam('param2'), '2'); + + Router::reload(); + + $params = array('controller' => 'pages', 'action' => 'display'); + Router::setRequestInfo(array($params, $paths)); + $expected = array('plugin' => false, 'controller' => 'pages', 'action' => 'display'); + $this->assertEqual(Router::getparams(), $expected); + $this->assertEqual(Router::getparams(true), $expected); + } } ?> \ No newline at end of file From 47cd941b530f0c892fb93b8a4d2311d3f5c1d5b3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 28 Jul 2009 12:40:31 +0000 Subject: [PATCH 12/17] Applying optimization patch to PaginatorHelper and test refactorings to PaginatorHelper test case. Thanks Phally. Fixes #6526 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8259 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/paginator.php | 30 +- .../libs/view/helpers/paginator.test.php | 426 ++++++++++++++++-- 2 files changed, 404 insertions(+), 52 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 4cb57c406..2a8f37433 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -491,15 +491,12 @@ class PaginatorHelper extends AppHelper { $end = $params['page'] + ($modulus - $params['page']) + 1; } - if ($first) { - if ($start > (int)$first) { - if ($start == $first + 1) { - $out .= $this->first($first, array('tag' => $tag, 'after' => $separator, 'separator' => $separator)); - } else { - $out .= $this->first($first, array('tag' => $tag, 'separator' => $separator)); - } - } elseif ($start == 2) { - $out .= $this->Html->tag($tag, $this->link(1, array('page' => 1), $options)) . $separator; + if ($first && $start > 1) { + $offset = ($start <= (int)$first) ? $start - 1 : $first; + if ($offset < $start - 1) { + $out .= $this->first($offset, array('tag' => $tag, 'separator' => $separator)); + } else { + $out .= $this->first($offset, array('tag' => $tag, 'after' => $separator, 'separator' => $separator)); } } @@ -525,15 +522,12 @@ class PaginatorHelper extends AppHelper { $out .= $after; - if ($last) { - if ($end <= $params['pageCount'] - (int)$last) { - if ($end + 1 == $params['pageCount']) { - $out .= $this->last($last, array('tag' => $tag, 'before' => $separator, 'separator' => $separator)); - } else { - $out .= $this->last($last, array('tag' => $tag, 'separator' => $separator)); - } - } elseif ($end == $params['pageCount'] - 1) { - $out .= $separator . $this->Html->tag($tag, $this->link($params['pageCount'], array('page' => $params['pageCount']), $options)); + if ($last && $end < $params['pageCount']) { + $offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last; + if ($offset <= $last && $params['pageCount'] - $end > $offset) { + $out .= $this->last($offset, array('tag' => $tag, 'separator' => $separator)); + } else { + $out .= $this->last($offset, array('tag' => $tag, 'before' => $separator, 'separator' => $separator)); } } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 83a798420..d3145596c 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -745,29 +745,116 @@ class PaginatorHelperTest extends CakeTestCase { 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) ); $result = $this->Paginator->numbers(); - $expected = '4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '8', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', + ); + $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('tag' => 'li')); - $expected = '
  • 4
  • |
  • 5
  • |
  • 6
  • |
  • 7
  • |
  • 8
  • |
  • 9
  • |
  • 10
  • |
  • 11
  • |
  • 12
  • '; - $this->assertEqual($result, $expected); + $expected = array( + array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li', + ' | ', + array('li' => array('class' => 'current')), '8', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li', + ); + $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('tag' => 'li', 'separator' => false)); - $expected = '
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • '; - $this->assertEqual($result, $expected); + $expected = array( + array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li', + array('li' => array('class' => 'current')), '8', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/li', + array('li' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/li', + ); + $this->assertTags($result, $expected); $result = $this->Paginator->numbers(true); - $expected = 'first | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | last'; - $this->assertEqual($result, $expected); - + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), 'first', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '8', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:15')), 'last', '/a', '/span', + ); + $this->assertTags($result, $expected); + $this->Paginator->params['paging'] = array('Client' => array( 'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, 'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()), 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) ); $result = $this->Paginator->numbers(); - $expected = '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array('class' => 'current')), '1', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ); + $this->assertTags($result, $expected); + $this->Paginator->params['paging'] = array('Client' => array( 'page' => 14, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, @@ -775,8 +862,26 @@ class PaginatorHelperTest extends CakeTestCase { 'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) ); $result = $this->Paginator->numbers(); - $expected = '7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '14', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 2, 'current' => 3, 'count' => 27, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 9, @@ -785,12 +890,48 @@ class PaginatorHelperTest extends CakeTestCase { ); $result = $this->Paginator->numbers(array('first' => 1)); - $expected = '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ); + $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('last' => 1)); - $expected = '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, @@ -799,8 +940,29 @@ class PaginatorHelperTest extends CakeTestCase { ); $result = $this->Paginator->numbers(array('first' => 1)); - $expected = '1...7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '15', '/span', + + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 10, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15, @@ -809,8 +971,30 @@ class PaginatorHelperTest extends CakeTestCase { ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); - $expected = '1...6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '10', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:11')), '11', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:12')), '12', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:13')), '13', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:14')), '14', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:15')), '15', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 6, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, @@ -819,8 +1003,30 @@ class PaginatorHelperTest extends CakeTestCase { ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); - $expected = '1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10...42'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '6', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:10')), '10', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 37, 'current' => 15, 'count' => 623, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 42, @@ -829,8 +1035,30 @@ class PaginatorHelperTest extends CakeTestCase { ); $result = $this->Paginator->numbers(array('first' => 1, 'last' => 1)); - $expected = '1...33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:33')), '33', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:34')), '34', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:35')), '35', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:36')), '36', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '37', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:38')), '38', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:39')), '39', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:40')), '40', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:41')), '41', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:42')), '42', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array( 'Client' => array( @@ -856,8 +1084,14 @@ class PaginatorHelperTest extends CakeTestCase { ); $options = array('modulus' => 10); $result = $this->Paginator->numbers($options); - $expected = '1 | 2 | 3'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array('class' => 'current')), '1', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ); + $this->assertTags($result, $expected); $this->Paginator->params['paging'] = array('Client' => array( 'page' => 2, 'current' => 10, 'count' => 31, 'prevPage' => true, 'nextPage' => true, 'pageCount' => 4, @@ -865,8 +1099,17 @@ class PaginatorHelperTest extends CakeTestCase { 'options' => array('page' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array())) ); $result = $this->Paginator->numbers(); - $expected = '1 | 2 | 3 | 4'; - $this->assertEqual($result, $expected); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span', + ); + $this->assertTags($result, $expected); + $this->Paginator->params['paging'] = array('Client' => array( 'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, @@ -890,11 +1133,7 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Paginator->params['paging'] = array('Client' => array( - 'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, - 'defaults' => array('limit' => 10), - 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array())) - ); + $this->Paginator->params['paging']['Client']['page'] = 3; $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); $expected = array( @@ -927,6 +1166,125 @@ class PaginatorHelperTest extends CakeTestCase { array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', ); $this->assertTags($result, $expected); + + $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - ')); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' - ', + array('span' => array('class' => 'current')), '3', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $this->Paginator->params['paging']['Client']['page'] = 4893; + $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4891')), '4891', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4892')), '4892', '/a', '/span', + ' - ', + array('span' => array('class' => 'current')), '4893', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $this->Paginator->params['paging']['Client']['page'] = 58; + $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:56')), '56', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:57')), '57', '/a', '/span', + ' - ', + array('span' => array('class' => 'current')), '58', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:59')), '59', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:60')), '60', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $this->Paginator->params['paging']['Client']['page'] = 5; + $result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - ')); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + ' - ', + array('span' => array('class' => 'current')), '5', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4893')), '4893', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4895')), '4895', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); } /** * testFirstAndLast method From f88cc56cfe01b9441845d8121828d9815fa6e67e Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Tue, 28 Jul 2009 20:01:42 +0000 Subject: [PATCH 13/17] Coding standards fixes git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8260 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/schema.php | 2 +- cake/console/libs/shell.php | 2 +- cake/console/libs/tasks/controller.php | 14 +++---- cake/console/libs/tasks/model.php | 8 ++-- cake/console/libs/tasks/project.php | 6 +-- cake/console/libs/tasks/test.php | 2 +- cake/console/libs/templates/views/form.ctp | 6 +-- cake/console/libs/templates/views/home.ctp | 2 +- cake/console/libs/templates/views/index.ctp | 4 +- cake/console/libs/templates/views/view.ctp | 18 ++++----- cake/libs/controller/components/cookie.php | 14 +++---- cake/libs/http_socket.php | 6 +-- .../libs/model/datasources/dbo/dbo_mysqli.php | 37 ++++++++----------- cake/libs/model/schema.php | 4 +- cake/libs/view/errors/missing_action.ctp | 6 +-- .../view/errors/missing_component_class.ctp | 6 +-- .../view/errors/missing_component_file.ctp | 4 +- cake/libs/view/errors/missing_controller.ctp | 6 +-- .../libs/view/errors/missing_helper_class.ctp | 4 +- cake/libs/view/errors/missing_helper_file.ctp | 6 +-- cake/libs/view/errors/missing_layout.ctp | 6 +-- cake/libs/view/errors/missing_model.ctp | 4 +- cake/libs/view/errors/missing_scaffolddb.ctp | 4 +- cake/libs/view/errors/missing_table.ctp | 4 +- cake/libs/view/errors/missing_view.ctp | 4 +- cake/libs/view/errors/private_action.ctp | 4 +- cake/libs/view/errors/scaffold_error.ctp | 2 +- cake/libs/view/scaffolds/edit.ctp | 4 +- cake/libs/view/scaffolds/index.ctp | 4 +- cake/libs/view/scaffolds/view.ctp | 16 ++++---- cake/tests/cases/libs/http_socket.test.php | 4 +- cake/tests/cases/libs/sanitize.test.php | 4 +- 32 files changed, 106 insertions(+), 111 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 698164d05..c04a399cb 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -199,7 +199,7 @@ class SchemaShell extends Shell { } } $db =& ConnectionManager::getDataSource($this->Schema->connection); - $contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:i:s') . " : ". time()."\n\n"; + $contents = "#" . $Schema->name . " sql generated on: " . date('Y-m-d H:i:s') . " : " . time() . "\n\n"; $contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema); if ($write) { if (strpos($write, '.sql') === false) { diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 47bbfac1f..eed6bff8e 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -297,7 +297,7 @@ class Shell extends Object { } if (!isset($this->{$taskName})) { - $this->err("Task '".$taskName."' could not be loaded"); + $this->err("Task '" . $taskName . "' could not be loaded"); $this->_stop(); } } diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 2531dacca..736522a84 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -273,7 +273,7 @@ class ControllerTask extends Shell { $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n"; } $actions .= "\t\t}\n"; - $actions .= "\t\t\$this->set('".$singularName."', \$this->{$currentModelName}->read(null, \$id));\n"; + $actions .= "\t\t\$this->set('" . $singularName . "', \$this->{$currentModelName}->read(null, \$id));\n"; $actions .= "\t}\n"; $actions .= "\n"; @@ -284,7 +284,7 @@ class ControllerTask extends Shell { $actions .= "\t\t\t\$this->{$currentModelName}->create();\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { - $actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".$singularHumanName." has been saved', true));\n"; + $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n"; $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n"; } else { $actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action'=>'index'));\n"; @@ -313,7 +313,7 @@ class ControllerTask extends Shell { } } if (!empty($compact)) { - $actions .= "\t\t\$this->set(compact(".join(', ', $compact)."));\n"; + $actions .= "\t\t\$this->set(compact(" . join(', ', $compact) . "));\n"; } $actions .= "\t}\n"; $actions .= "\n"; @@ -332,10 +332,10 @@ class ControllerTask extends Shell { $actions .= "\t\tif (!empty(\$this->data)) {\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { - $actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".$singularHumanName." has been saved', true));\n"; + $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n"; $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n"; } else { - $actions .= "\t\t\t\t\$this->flash(__('The ".$singularHumanName." has been saved.', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\t\$this->flash(__('The " . $singularHumanName . " has been saved.', true), array('action'=>'index'));\n"; } $actions .= "\t\t\t} else {\n"; if ($wannaUseSession) { @@ -365,7 +365,7 @@ class ControllerTask extends Shell { } } if (!empty($compact)) { - $actions .= "\t\t\$this->set(compact(".join(',', $compact)."));\n"; + $actions .= "\t\t\$this->set(compact(" . join(',', $compact) . "));\n"; } $actions .= "\t}\n"; $actions .= "\n"; @@ -484,7 +484,7 @@ class ControllerTask extends Shell { $this->out("\nBaking unit test for $className..."); $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($path . $filename, $content); } /** diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 2c98659da..779d088f8 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -733,7 +733,7 @@ class ModelTask extends Shell { $this->out("\nBaking unit test for $className..."); $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($path . $filename, $content); } return false; @@ -905,7 +905,7 @@ class ModelTask extends Shell { $col = "\t\t'indexes' => array("; $props = array(); foreach ((array)$value as $key => $index) { - $props[] = "'{$key}' => array(".join(', ', $schema->__values($index)).")"; + $props[] = "'{$key}' => array(" . join(', ', $schema->__values($index)) . ")"; } $col .= join(', ', $props); } @@ -925,9 +925,9 @@ class ModelTask extends Shell { $pluginPath = 'plugins' . DS . Inflector::underscore($this->plugin) . DS; $path = APP . $pluginPath . 'tests' . DS . 'fixtures' . DS; } - $filename = Inflector::underscore($model).'_fixture.php'; + $filename = Inflector::underscore($model) . '_fixture.php'; $header = '$Id'; - $content = ""; + $content = ""; $this->out("\nBaking test fixture for $model..."); if ($this->createFile($path . $filename, $content)) { return str_replace("\t\t", "\t\t\t", $records); diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index 1d73e515f..f7a0c3021 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -153,7 +153,7 @@ class ProjectTask extends Shell { $this->out(sprintf(__("Created: %s in %s", true), $app, $path)); $this->hr(); } else { - $this->err(" '".$app."' could not be created properly"); + $this->err(" '" . $app . "' could not be created properly"); return false; } @@ -219,7 +219,7 @@ class ProjectTask extends Shell { $File =& new File($path . 'webroot' . DS . 'index.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { - $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents); + $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents); if (!$File->write($result)) { return false; } @@ -230,7 +230,7 @@ class ProjectTask extends Shell { $File =& new File($path . 'webroot' . DS . 'test.php'); $contents = $File->read(); if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_CORE_INCLUDE_PATH\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) { - $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '".CAKE_CORE_INCLUDE_PATH."');", $contents); + $result = str_replace($match[0], "\t\tdefine('CAKE_CORE_INCLUDE_PATH', '" . CAKE_CORE_INCLUDE_PATH . "');", $contents); if (!$File->write($result)) { return false; } diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index f959d21da..416d3bd22 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -181,7 +181,7 @@ class TestTask extends Shell { } $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content); } /** diff --git a/cake/console/libs/templates/views/form.ctp b/cake/console/libs/templates/views/form.ctp index 78ebdda7b..fda3eddc9 100644 --- a/cake/console/libs/templates/views/form.ctp +++ b/cake/console/libs/templates/views/form.ctp @@ -25,7 +25,7 @@
    create('{$modelClass}');?>\n";?>
    - ";?> + ";?> $data) { foreach ($data as $alias => $details) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { - echo "\t\t
  • link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; - echo "\t\t
  • link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; + echo "\t\t
  • link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; + echo "\t\t
  • link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; $done[] = $details['controller']; } } diff --git a/cake/console/libs/templates/views/home.ctp b/cake/console/libs/templates/views/home.ctp index 39020d488..5b3dc316f 100644 --- a/cake/console/libs/templates/views/home.ctp +++ b/cake/console/libs/templates/views/home.ctp @@ -1,5 +1,5 @@ Sweet, \"".Inflector::humanize($app)."\" got Baked by CakePHP!\n"; +$output = "

    Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP!

    \n"; $output .=" 0): diff --git a/cake/console/libs/templates/views/index.ctp b/cake/console/libs/templates/views/index.ctp index af2c5acb5..49c69dbab 100644 --- a/cake/console/libs/templates/views/index.ctp +++ b/cake/console/libs/templates/views/index.ctp @@ -88,8 +88,8 @@ echo "\n"; foreach ($associations as $type => $data) { foreach ($data as $alias => $details) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { - echo "\t\t
  • link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; - echo "\t\t
  • link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; + echo "\t\t
  • link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; + echo "\t\t
  • link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; $done[] = $details['controller']; } } diff --git a/cake/console/libs/templates/views/view.ctp b/cake/console/libs/templates/views/view.ctp index a25b7574c..e390bb02e 100644 --- a/cake/console/libs/templates/views/view.ctp +++ b/cake/console/libs/templates/views/view.ctp @@ -32,14 +32,14 @@ foreach ($fields as $field) { foreach ($associations['belongsTo'] as $alias => $details) { if ($field === $details['foreignKey']) { $isKey = true; - echo "\t\t>\n"; + echo "\t\t>\n"; echo "\t\t>\n\t\t\tlink(\${$singularVar}['{$alias}']['{$details['displayField']}'], array('controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}['{$alias}']['{$details['primaryKey']}'])); ?>\n\t\t\t \n\t\t\n"; break; } } } if ($isKey !== true) { - echo "\t\t>\n"; + echo "\t\t>\n"; echo "\t\t>\n\t\t\t\n\t\t\t \n\t\t\n"; } } @@ -58,8 +58,8 @@ foreach ($fields as $field) { foreach ($associations as $type => $data) { foreach ($data as $alias => $details) { if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) { - echo "\t\t
  • link(__('List ".Inflector::humanize($details['controller'])."', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; - echo "\t\t
  • link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; + echo "\t\t
  • link(__('List " . Inflector::humanize($details['controller']) . "', true), array('controller' => '{$details['controller']}', 'action' => 'index')); ?>
  • \n"; + echo "\t\t
  • link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add')); ?>
  • \n"; $done[] = $details['controller']; } } @@ -71,12 +71,12 @@ foreach ($fields as $field) { if (!empty($associations['hasOne'])) : foreach ($associations['hasOne'] as $alias => $details): ?> @@ -110,7 +110,7 @@ foreach ($relations as $alias => $details): \n"; + echo "\t\t\n"; } ?> ";?> @@ -143,7 +143,7 @@ echo "\t\n"; \n\n";?>
      -
    • link(__('New ".Inflector::humanize(Inflector::underscore($alias))."', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?>
    • +
    • link(__('New " . Inflector::humanize(Inflector::underscore($alias)) . "', true), array('controller' => '{$details['controller']}', 'action' => 'add'));?>";?>
    diff --git a/cake/libs/controller/components/cookie.php b/cake/libs/controller/components/cookie.php index 524453c96..56713f5c4 100644 --- a/cake/libs/controller/components/cookie.php +++ b/cake/libs/controller/components/cookie.php @@ -203,10 +203,10 @@ class CookieComponent extends Object { if (count($name) > 1) { $this->__values[$name[0]][$name[1]] = $value; - $this->__write("[".$name[0]."][".$name[1]."]", $value); + $this->__write("[" . $name[0] . "][" . $name[1] . "]", $value); } else { $this->__values[$name[0]] = $value; - $this->__write("[".$name[0]."]", $value); + $this->__write("[" . $name[0] . "]", $value); } } else { foreach ($key as $names => $value) { @@ -214,10 +214,10 @@ class CookieComponent extends Object { if (count($name) > 1) { $this->__values[$name[0]][$name[1]] = $value; - $this->__write("[".$name[0]."][".$name[1]."]", $value); + $this->__write("[" . $name[0] . "][" . $name[1] . "]", $value); } else { $this->__values[$name[0]] = $value; - $this->__write("[".$name[0]."]", $value); + $this->__write("[" . $name[0] . "]", $value); } } } @@ -278,17 +278,17 @@ class CookieComponent extends Object { $name = $this->__cookieVarNames($key); if (count($name) > 1) { if (isset($this->__values[$name[0]])) { - $this->__delete("[".$name[0]."][".$name[1]."]"); + $this->__delete("[" . $name[0] . "][" . $name[1] . "]"); unset($this->__values[$name[0]][$name[1]]); } } else { if (isset($this->__values[$name[0]])) { if (is_array($this->__values[$name[0]])) { foreach ($this->__values[$name[0]] as $key => $value) { - $this->__delete("[".$name[0]."][".$key."]"); + $this->__delete("[" . $name[0] . "][" . $key . "]"); } } - $this->__delete("[".$name[0]."]"); + $this->__delete("[" . $name[0] . "]"); unset($this->__values[$name[0]]); } } diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 79a96cd32..544de704f 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -202,10 +202,10 @@ class HttpSocket extends CakeSocket { } if (isset($this->request['auth']['user']) && isset($this->request['auth']['pass'])) { - $this->request['header']['Authorization'] = $this->request['auth']['method'] ." ". base64_encode($this->request['auth']['user'] .":".$this->request['auth']['pass']); + $this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['auth']['user'] . ":" . $this->request['auth']['pass']); } if (isset($this->request['uri']['user']) && isset($this->request['uri']['pass'])) { - $this->request['header']['Authorization'] = $this->request['auth']['method'] ." ". base64_encode($this->request['uri']['user'] .":".$this->request['uri']['pass']); + $this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['uri']['user'] . ":" . $this->request['uri']['pass']); } if (is_array($this->request['body'])) { @@ -812,7 +812,7 @@ class HttpSocket extends CakeSocket { return false; } - preg_match_all("/(.+):(.+)(?:(?lineBreak."|\$)/Uis", $header, $matches, PREG_SET_ORDER); + preg_match_all("/(.+):(.+)(?:(?lineBreak . "|\$)/Uis", $header, $matches, PREG_SET_ORDER); $header = array(); foreach ($matches as $match) { diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index c0d238079..4663567ca 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -105,9 +105,8 @@ class DboMysqli extends DboMysqlBase { function _execute($sql) { if (preg_match('/^\s*call/i', $sql)) { return $this->_executeProcedure($sql); - } else { - return mysqli_query($this->connection, $sql); } + return mysqli_query($this->connection, $sql); } /** * Executes given SQL statement (procedure call). @@ -140,15 +139,15 @@ class DboMysqli extends DboMysqlBase { if (!$result) { return array(); - } else { - $tables = array(); - - while ($line = mysqli_fetch_array($result)) { - $tables[] = $line[0]; - } - parent::listSources($tables); - return $tables; } + + $tables = array(); + + while ($line = mysqli_fetch_array($result)) { + $tables[] = $line[0]; + } + parent::listSources($tables); + return $tables; } /** * Returns an array of the fields in given table name. @@ -201,14 +200,15 @@ class DboMysqli extends DboMysqlBase { if ($parent != null) { return $parent; } - - if ($data === null) { + if ($data === null || (is_array($data) && empty($data))) { return 'NULL'; } - if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { return "''"; } + if (empty($column)) { + $column = $this->introspectType($data); + } switch ($column) { case 'boolean': @@ -217,9 +217,6 @@ class DboMysqli extends DboMysqlBase { case 'integer' : case 'float' : case null : - if ($data === '') { - return 'NULL'; - } if ((is_int($data) || is_float($data) || $data === '0') || ( is_numeric($data) && strpos($data, ',') === false && $data[0] != '0' && strpos($data, 'e') === false)) { @@ -278,7 +275,6 @@ class DboMysqli extends DboMysqlBase { if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) { return $id[0]['insertID']; } - return null; } /** @@ -337,11 +333,11 @@ class DboMysqli extends DboMysqlBase { function length($real) { $col = str_replace(array(')', 'unsigned'), '', $real); $limit = null; - + if (strpos($col, '(') !== false) { list($col, $limit) = explode('(', $col); } - + if ($limit != null) { return intval($limit); } @@ -389,9 +385,8 @@ class DboMysqli extends DboMysqlBase { $i++; } return $resultRow; - } else { - return false; } + return false; } /** * Gets the database encoding diff --git a/cake/libs/model/schema.php b/cake/libs/model/schema.php index d3e2811ab..23c2f4816 100644 --- a/cake/libs/model/schema.php +++ b/cake/libs/model/schema.php @@ -338,7 +338,7 @@ class CakeSchema extends Object { $col = "\t\t'indexes' => array("; $props = array(); foreach ((array)$value as $key => $index) { - $props[] = "'{$key}' => array(".join(', ', $this->__values($index)).")"; + $props[] = "'{$key}' => array(" . join(', ', $this->__values($index)) . ")"; } $col .= join(', ', $props); } @@ -446,7 +446,7 @@ class CakeSchema extends Object { if (is_array($values)) { foreach ($values as $key => $val) { if (is_array($val)) { - $vals[] = "'{$key}' => array('".join("', '", $val)."')"; + $vals[] = "'{$key}' => array('" . join("', '", $val) . "')"; } else if (!is_numeric($key)) { $val = var_export($val, true); $vals[] = "'{$key}' => {$val}"; diff --git a/cake/libs/view/errors/missing_action.ctp b/cake/libs/view/errors/missing_action.ctp index 857ac206c..0de1c6cc3 100644 --- a/cake/libs/view/errors/missing_action.ctp +++ b/cake/libs/view/errors/missing_action.ctp @@ -25,11 +25,11 @@

    : - ".$action."", "".$controller."");?> + " . $action . "", "" . $controller . "");?>

    : - ".$controller."::", "".$action."()", APP_DIR.DS."controllers".DS.Inflector::underscore($controller).".php");?> + " . $controller . "::", "" . $action . "()", APP_DIR . DS . "controllers" . DS . Inflector::underscore($controller) . ".php");?>

     <?php
    @@ -47,5 +47,5 @@ class  extends AppController {
     

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_component_class.ctp b/cake/libs/view/errors/missing_component_class.ctp index 49af6e3a3..ec154de02 100644 --- a/cake/libs/view/errors/missing_component_class.ctp +++ b/cake/libs/view/errors/missing_component_class.ctp @@ -25,11 +25,11 @@

    : - ". $component ."Component", "". $controller ."Controller");?> + " . $component . "Component", "" . $controller . "Controller");?>

    : - ". $component ."Component", APP_DIR.DS."controllers".DS."components".DS.$file);?> + " . $component . "Component", APP_DIR . DS . "controllers" . DS . "components" . DS . $file);?>

     <?php
    @@ -40,5 +40,5 @@ class Component extends Object {

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_component_file.ctp b/cake/libs/view/errors/missing_component_file.ctp index e4eb675b9..3b8b874fb 100644 --- a/cake/libs/view/errors/missing_component_file.ctp +++ b/cake/libs/view/errors/missing_component_file.ctp @@ -29,7 +29,7 @@

    : - ". $component ."Component", APP_DIR.DS."controllers".DS."components".DS.$file);?> + " . $component . "Component", APP_DIR . DS . "controllers" . DS . "components" . DS . $file);?>

     <?php
    @@ -40,5 +40,5 @@ class Component extends Object {

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_controller.ctp b/cake/libs/view/errors/missing_controller.ctp index 829cc53ca..676747284 100644 --- a/cake/libs/view/errors/missing_controller.ctp +++ b/cake/libs/view/errors/missing_controller.ctp @@ -25,11 +25,11 @@

    : - ".$controller."");?> + " . $controller . "");?>

    : - ".$controller."", APP_DIR.DS."controllers".DS.Inflector::underscore($controller).".php");?> + " . $controller . "", APP_DIR . DS . "controllers" . DS . Inflector::underscore($controller) . ".php");?>

     <?php
    @@ -41,5 +41,5 @@ class  extends AppController {
     

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_helper_class.ctp b/cake/libs/view/errors/missing_helper_class.ctp index d94d1ab1d..e1f464cdd 100644 --- a/cake/libs/view/errors/missing_helper_class.ctp +++ b/cake/libs/view/errors/missing_helper_class.ctp @@ -29,7 +29,7 @@

    : - +

     <?php
    @@ -40,5 +40,5 @@ class  extends AppHelper {
     

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_helper_file.ctp b/cake/libs/view/errors/missing_helper_file.ctp index 7affb0fd4..34d6d5dc7 100644 --- a/cake/libs/view/errors/missing_helper_file.ctp +++ b/cake/libs/view/errors/missing_helper_file.ctp @@ -25,11 +25,11 @@

    : - +

    : - +

     <?php
    @@ -40,5 +40,5 @@ class  extends AppHelper {
     

    : - +

    diff --git a/cake/libs/view/errors/missing_layout.ctp b/cake/libs/view/errors/missing_layout.ctp index c41c59d45..cb8445a44 100644 --- a/cake/libs/view/errors/missing_layout.ctp +++ b/cake/libs/view/errors/missing_layout.ctp @@ -25,13 +25,13 @@

    : - ". $file ."");?> + " . $file . "");?>

    : - ". $file ."");?> + " . $file . "");?>

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_model.ctp b/cake/libs/view/errors/missing_model.ctp index 49cf8f7a4..c2d64e95f 100644 --- a/cake/libs/view/errors/missing_model.ctp +++ b/cake/libs/view/errors/missing_model.ctp @@ -29,7 +29,7 @@

    : - ". $model . "", APP_DIR.DS."models".DS.Inflector::underscore($model).".php");?> + " . $model . "", APP_DIR . DS . "models" . DS . Inflector::underscore($model) . ".php");?>

     <?php
    @@ -42,5 +42,5 @@ class  extends AppModel {
     

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_scaffolddb.ctp b/cake/libs/view/errors/missing_scaffolddb.ctp index 2477d3207..443199224 100644 --- a/cake/libs/view/errors/missing_scaffolddb.ctp +++ b/cake/libs/view/errors/missing_scaffolddb.ctp @@ -29,9 +29,9 @@

    : - +

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_table.ctp b/cake/libs/view/errors/missing_table.ctp index 341897680..1bdc59f69 100644 --- a/cake/libs/view/errors/missing_table.ctp +++ b/cake/libs/view/errors/missing_table.ctp @@ -25,9 +25,9 @@

    : - ". $table ."", "". $model ."");?> + " . $table . "", "" . $model . "");?>

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/missing_view.ctp b/cake/libs/view/errors/missing_view.ctp index 184573751..737da88c0 100644 --- a/cake/libs/view/errors/missing_view.ctp +++ b/cake/libs/view/errors/missing_view.ctp @@ -25,7 +25,7 @@

    : - ". $controller."Controller::", "". $action ."()");?> + " . $controller . "Controller::", "". $action . "()");?>

    : @@ -33,5 +33,5 @@

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/private_action.ctp b/cake/libs/view/errors/private_action.ctp index f172c50aa..6d9e92c70 100644 --- a/cake/libs/view/errors/private_action.ctp +++ b/cake/libs/view/errors/private_action.ctp @@ -25,9 +25,9 @@

    : - ". $controller ."::", "". $action ."()");?> + " . $controller . "::", "" . $action . "()");?>

    : - +

    \ No newline at end of file diff --git a/cake/libs/view/errors/scaffold_error.ctp b/cake/libs/view/errors/scaffold_error.ctp index d20843cbd..9ce156af7 100644 --- a/cake/libs/view/errors/scaffold_error.ctp +++ b/cake/libs/view/errors/scaffold_error.ctp @@ -29,7 +29,7 @@

    : - +

     <?php
    diff --git a/cake/libs/view/scaffolds/edit.ctp b/cake/libs/view/scaffolds/edit.ctp
    index fd537d239..6705b4bf4 100644
    --- a/cake/libs/view/scaffolds/edit.ctp
    +++ b/cake/libs/view/scaffolds/edit.ctp
    @@ -40,8 +40,8 @@
     		foreach ($associations as $_type => $_data) {
     			foreach ($_data as $_alias => $_details) {
     				if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
    -					echo "\t\t
  • ".$html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' =>'index'))."
  • \n"; - echo "\t\t
  • ".$html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' =>'add'))."
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' =>'index')) . "
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' =>'add')) . "
  • \n"; $done[] = $_details['controller']; } } diff --git a/cake/libs/view/scaffolds/index.ctp b/cake/libs/view/scaffolds/index.ctp index 5d18fef54..c5b9e0e7f 100644 --- a/cake/libs/view/scaffolds/index.ctp +++ b/cake/libs/view/scaffolds/index.ctp @@ -86,8 +86,8 @@ echo "\n"; foreach ($associations as $_type => $_data) { foreach ($_data as $_alias => $_details) { if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { - echo "\t\t
  • ".$html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index'))."
  • \n"; - echo "\t\t
  • ".$html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add'))."
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "
  • \n"; $done[] = $_details['controller']; } } diff --git a/cake/libs/view/scaffolds/view.ctp b/cake/libs/view/scaffolds/view.ctp index 0c5ef7420..a497ca673 100644 --- a/cake/libs/view/scaffolds/view.ctp +++ b/cake/libs/view/scaffolds/view.ctp @@ -37,14 +37,14 @@ foreach ($scaffoldFields as $_field) { foreach ($associations['belongsTo'] as $_alias => $_details) { if ($_field === $_details['foreignKey']) { $isKey = true; - echo "\t\t".Inflector::humanize($_alias)."\n"; + echo "\t\t" . Inflector::humanize($_alias) . "\n"; echo "\t\t\n\t\t\t" . $html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t \n"; break; } } } if ($isKey !== true) { - echo "\t\t".Inflector::humanize($_field)."\n"; + echo "\t\t" . Inflector::humanize($_field) . "\n"; echo "\t\t\n\t\t\t{${$singularVar}[$modelClass][$_field]}\n \t\t\n"; } } @@ -63,8 +63,8 @@ foreach ($scaffoldFields as $_field) { foreach ($associations as $_type => $_data) { foreach ($_data as $_alias => $_details) { if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { - echo "\t\t
  • ".$html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index'))."
  • \n"; - echo "\t\t
  • ".$html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add'))."
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "
  • \n"; + echo "\t\t
  • " . $html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "
  • \n"; $done[] = $_details['controller']; } } @@ -87,8 +87,8 @@ foreach ($associations['hasOne'] as $_alias => $_details): ?> if ($i++ % 2 == 0) { $class = ' class="altrow"'; } - echo "\t\t".Inflector::humanize($_field)."\n"; - echo "\t\t\n\t" .${$singularVar}[$_alias][$_field] ."\n \n"; + echo "\t\t" . Inflector::humanize($_field) . "\n"; + echo "\t\t\n\t" . ${$singularVar}[$_alias][$_field] . "\n \n"; } ?> @@ -122,7 +122,7 @@ $otherSingularVar = Inflector::variable($_alias); ".Inflector::humanize($_field)."\n"; + echo "\t\t" . Inflector::humanize($_field) . "\n"; } ?> Actions @@ -137,7 +137,7 @@ $otherSingularVar = Inflector::variable($_alias); echo "\t\t\n"; foreach ($otherFields as $_field) { - echo "\t\t\t".${$otherSingularVar}[$_field]."\n"; + echo "\t\t\t" . ${$otherSingularVar}[$_field] . "\n"; } echo "\t\t\t\n"; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index cb6a79891..b3fa948b1 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -399,12 +399,12 @@ class HttpSocketTest extends CakeTestCase { $this->Socket->setReturnValue('read', false); $this->Socket->_mock->_call_counts['read'] = 0; $number = mt_rand(0, 9999999); - $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    Hello, your lucky number is ".$number."

    "; + $serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    Hello, your lucky number is " . $number . "

    "; $this->Socket->setReturnValueAt(0, 'read', $serverResponse); $this->Socket->expect('write', array("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n")); $this->Socket->expectCallCount('read', 2); $response = $this->Socket->request($request); - $this->assertIdentical($response, "

    Hello, your lucky number is ".$number."

    "); + $this->assertIdentical($response, "

    Hello, your lucky number is " . $number . "

    "); $this->Socket->reset(); $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

    This is a cookie test!

    "; diff --git a/cake/tests/cases/libs/sanitize.test.php b/cake/tests/cases/libs/sanitize.test.php index e564f9a92..1899f16c7 100644 --- a/cake/tests/cases/libs/sanitize.test.php +++ b/cake/tests/cases/libs/sanitize.test.php @@ -298,8 +298,8 @@ class SanitizeTest extends CakeTestCase { $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); - $string = ''."\n".''."\n".''."\n".''; - $expected = "\n".''."\n".''."\n".''; + $string = '' . "\n" . '' . "\n" . '' . "\n" . ''; + $expected = "\n" . '' . "\n" . ''."\n".''; $result = Sanitize::stripScripts($string); $this->assertEqual($result, $expected); From f710ae7fbe7837d4401cca1a95395ae7c729929d Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Tue, 28 Jul 2009 20:08:24 +0000 Subject: [PATCH 14/17] Minor refactorings + fix for dbo mysqli related to previous commit git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8261 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysqli.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 4663567ca..b0adf8d2e 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -204,7 +204,7 @@ class DboMysqli extends DboMysqlBase { return 'NULL'; } if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { - return "''"; + return "''"; } if (empty($column)) { $column = $this->introspectType($data); @@ -212,11 +212,14 @@ class DboMysqli extends DboMysqlBase { switch ($column) { case 'boolean': - $data = $this->boolean((bool)$data); + return $this->boolean((bool)$data); break; case 'integer' : case 'float' : case null : + if ($data === '') { + return 'NULL'; + } if ((is_int($data) || is_float($data) || $data === '0') || ( is_numeric($data) && strpos($data, ',') === false && $data[0] != '0' && strpos($data, 'e') === false)) { From 01d22ffd2eee8aa3686fe3c3fdb5420048d0df76 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 30 Jul 2009 15:01:22 -0700 Subject: [PATCH 15/17] fixing up some App::import calls --- cake/console/libs/bake.php | 2 +- cake/console/libs/schema.php | 2 +- cake/console/libs/tasks/fixture.php | 4 ++-- cake/console/libs/tasks/model.php | 3 +-- cake/console/libs/tasks/view.php | 2 +- cake/console/libs/templates/skel/app_helper.php | 2 +- cake/dispatcher.php | 2 +- cake/libs/configure.php | 14 +++++++------- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index af35877b6..bc15e6360 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -157,7 +157,7 @@ class BakeShell extends Shell { $object = new $model(); $modelExists = true; } else { - App::import('Model'); + App::import('Model', 'Model', false); $object = new Model(array('name' => $name, 'ds' => $this->connection)); } diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 033c2a01c..60d959721 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -27,7 +27,7 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ App::import('File'); -App::import('Model', 'CakeSchema'); +App::import('Model', 'CakeSchema', false); /** * Schema is a command-line database management utility for automating programmer chores. diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index eca3b9da6..58a5455d0 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -74,7 +74,7 @@ class FixtureTask extends Shell { parent::__construct($dispatch); $this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS; if (!class_exists('CakeSchema')) { - App::import('Model', 'CakeSchema'); + App::import('Model', 'CakeSchema', false); } } @@ -384,7 +384,7 @@ class FixtureTask extends Shell { while (!$condition) { $condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10'); } - App::import('Core', 'Model'); + App::import('Model', 'Model', false); $modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection)); $records = $modelObject->find('all', array( 'conditions' => $condition, diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 8d3840158..f9d7937b2 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -20,7 +20,7 @@ * @since CakePHP(tm) v 1.2 * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -App::import('Model', 'ConnectionManager'); +App::import('Model', 'Model', false); /** * Task class for creating and updating model files. @@ -82,7 +82,6 @@ class ModelTask extends Shell { * @return void **/ function startup() { - App::import('Core', 'Model'); parent::startup(); } diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 515d0e7a8..18e86b995 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -20,7 +20,7 @@ * @since CakePHP(tm) v 1.2 * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -App::import('Core', 'Controller'); +App::import('Controller', 'Controller', false); /** * Task class for creating and updating view files. diff --git a/cake/console/libs/templates/skel/app_helper.php b/cake/console/libs/templates/skel/app_helper.php index 05b94944d..66762cb58 100644 --- a/cake/console/libs/templates/skel/app_helper.php +++ b/cake/console/libs/templates/skel/app_helper.php @@ -26,7 +26,7 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -App::import('Core', 'Helper'); +App::import('Helper', 'Helper', false); /** * This is a placeholder class. diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 838151861..1d1dca562 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -226,7 +226,7 @@ class Dispatcher extends Object { if (!isset($methods[strtolower($params['action'])])) { if ($controller->scaffold !== false) { - App::import('Core', 'Scaffold'); + App::import('Controller', 'Scaffold', false); return new Scaffold($controller, $params); } return $this->cakeError('missingAction', array(array( diff --git a/cake/libs/configure.php b/cake/libs/configure.php index ccf6e4a48..37d5ceea2 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -844,7 +844,7 @@ class App extends Object { } } - if (!App::import($tempType, $plugin . $class)) { + if (!App::import($tempType, $plugin . $class, $parent)) { return false; } } @@ -866,7 +866,7 @@ class App extends Object { if ($name != null && !class_exists($name . $ext['class'])) { if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) { if ($_this->__load($load)) { - $_this->__overload($type, $name . $ext['class']); + $_this->__overload($type, $name . $ext['class'], $parent); if ($_this->return) { $value = include $load; @@ -908,7 +908,7 @@ class App extends Object { if ($directory !== null) { $_this->__cache = true; $_this->__map($directory . $file, $name . $ext['class'], $type, $plugin); - $_this->__overload($type, $name . $ext['class']); + $_this->__overload($type, $name . $ext['class'], $parent); if ($_this->return) { $value = include $directory . $file; @@ -1058,8 +1058,8 @@ class App extends Object { * @param string $name Class name to overload * @access private */ - function __overload($type, $name) { - if (($type === 'Model' || $type === 'Helper') && strtolower($name) != 'schema') { + function __overload($type, $name, $parent) { + if (($type === 'Model' || $type === 'Helper') && $parent !== false) { Overloadable::overload($name); } } @@ -1088,10 +1088,10 @@ class App extends Object { switch ($load) { case 'model': if (!class_exists('Model')) { - App::import('Model', 'Model', false, App::core('models')); + require LIBS . 'model' . DS . 'model.php'; } if (!class_exists('AppModel')) { - App::import($type, 'AppModel', false, App::path('models')); + App::import($type, 'AppModel', false); } if ($plugin) { if (!class_exists($plugin . 'AppModel')) { From 729d8fddea94741e8339bf16ab128599db7a241a Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 31 Jul 2009 11:48:30 -0400 Subject: [PATCH 16/17] Applying PHP 5.3 compatibility patch from Mark Story. Please update your config/core.php, webroot/index.php and webroot/test.php accordingly. --- app/config/core.php | 5 +++++ app/webroot/index.php | 7 +++++++ app/webroot/test.php | 9 ++++++++- cake/bootstrap.php | 3 +++ cake/console/libs/templates/skel/config/core.php | 5 +++++ cake/console/libs/templates/skel/webroot/index.php | 7 +++++++ cake/console/libs/templates/skel/webroot/test.php | 9 ++++++++- cake/libs/configure.php | 2 +- cake/libs/debugger.php | 2 +- 9 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/config/core.php b/app/config/core.php index 01b8d563d..28ee3f5d6 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -184,6 +184,11 @@ */ Configure::write('Acl.classname', 'DbAcl'); Configure::write('Acl.database', 'default'); +/** + * If you are on PHP 5.3 uncomment this line and correct your server timezone + * to fix the date & time related errors. + */ + //date_default_timezone_set('UTC'); /** * * Cache Engine Configuration diff --git a/app/webroot/index.php b/app/webroot/index.php index 526cecba3..083812fdd 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -52,6 +52,13 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', ROOT); } +/** + * PHP 5.3 raises many notices in bootstrap. + */ + if (!defined('E_DEPRECATED')) { + define('E_DEPRECATED', 8192); + } + error_reporting(E_ALL & ~E_DEPRECATED); /** * Editing below this line should NOT be necessary. diff --git a/app/webroot/test.php b/app/webroot/test.php index 1e9a044ac..725469d93 100644 --- a/app/webroot/test.php +++ b/app/webroot/test.php @@ -24,7 +24,14 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -error_reporting(E_ALL); +/** + * PHP 5.3 raises many notices in bootstrap. + */ +if (!defined('E_DEPRECATED')) { + define('E_DEPRECATED', 8192); +} +error_reporting(E_ALL & ~E_DEPRECATED); + set_time_limit(0); ini_set('memory_limit','128M'); ini_set('display_errors', 1); diff --git a/cake/bootstrap.php b/cake/bootstrap.php index c50974478..88d1526d7 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -22,6 +22,9 @@ if (!defined('PHP5')) { define('PHP5', (PHP_VERSION >= 5)); } +if (!defined('E_DEPRECATED')) { + define('PHP5', (PHP_VERSION >= 5)); +} require CORE_PATH . 'cake' . DS . 'basics.php'; $TIME_START = getMicrotime(); require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php'; diff --git a/cake/console/libs/templates/skel/config/core.php b/cake/console/libs/templates/skel/config/core.php index dfcba1ea5..fbd02e74a 100644 --- a/cake/console/libs/templates/skel/config/core.php +++ b/cake/console/libs/templates/skel/config/core.php @@ -170,6 +170,11 @@ */ Configure::write('Acl.classname', 'DbAcl'); Configure::write('Acl.database', 'default'); +/** + * If you are on PHP 5.3 uncomment this line and correct your server timezone + * to fix the date & time related errors. + */ + //date_default_timezone_set('UTC'); /** * * Cache Engine Configuration diff --git a/cake/console/libs/templates/skel/webroot/index.php b/cake/console/libs/templates/skel/webroot/index.php index 59484d983..efdc5b680 100644 --- a/cake/console/libs/templates/skel/webroot/index.php +++ b/cake/console/libs/templates/skel/webroot/index.php @@ -57,6 +57,13 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', ROOT); } +/** + * PHP 5.3 raises many notices in bootstrap. + */ + if (!defined('E_DEPRECATED')) { + define('E_DEPRECATED', 8192); + } + error_reporting(E_ALL & ~E_DEPRECATED); /** * Editing below this line should not be necessary. diff --git a/cake/console/libs/templates/skel/webroot/test.php b/cake/console/libs/templates/skel/webroot/test.php index 1e9a044ac..725469d93 100644 --- a/cake/console/libs/templates/skel/webroot/test.php +++ b/cake/console/libs/templates/skel/webroot/test.php @@ -24,7 +24,14 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -error_reporting(E_ALL); +/** + * PHP 5.3 raises many notices in bootstrap. + */ +if (!defined('E_DEPRECATED')) { + define('E_DEPRECATED', 8192); +} +error_reporting(E_ALL & ~E_DEPRECATED); + set_time_limit(0); ini_set('memory_limit','128M'); ini_set('display_errors', 1); diff --git a/cake/libs/configure.php b/cake/libs/configure.php index f73499d22..7fc6d3492 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -110,7 +110,7 @@ class Configure extends Object { if (isset($config['debug'])) { if ($_this->debug) { - error_reporting(E_ALL); + error_reporting(E_ALL & ~E_DEPRECATED); if (function_exists('ini_set')) { ini_set('display_errors', 1); diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index bab67ae80..6c11e2768 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -252,7 +252,7 @@ class Debugger extends Object { * @access public */ function handleError($code, $description, $file = null, $line = null, $context = null) { - if (error_reporting() == 0 || $code === 2048) { + if (error_reporting() == 0 || $code === 2048 || $code === 8192) { return; } From 7847044711720333815524e10a6ef15a3f3e5e3d Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 1 Aug 2009 08:36:57 -0400 Subject: [PATCH 17/17] Moving error flags to core bootstrap to avoid extra changes in user files, fixing error in previous commit. --- app/webroot/index.php | 7 ------- cake/bootstrap.php | 4 +++- cake/console/libs/templates/skel/webroot/index.php | 7 ------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/webroot/index.php b/app/webroot/index.php index 083812fdd..526cecba3 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -52,13 +52,6 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', ROOT); } -/** - * PHP 5.3 raises many notices in bootstrap. - */ - if (!defined('E_DEPRECATED')) { - define('E_DEPRECATED', 8192); - } - error_reporting(E_ALL & ~E_DEPRECATED); /** * Editing below this line should NOT be necessary. diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 88d1526d7..1aafb6237 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -23,8 +23,10 @@ if (!defined('PHP5')) { define('PHP5', (PHP_VERSION >= 5)); } if (!defined('E_DEPRECATED')) { - define('PHP5', (PHP_VERSION >= 5)); + define('E_DEPRECATED', 8192); } +error_reporting(E_ALL & ~E_DEPRECATED); + require CORE_PATH . 'cake' . DS . 'basics.php'; $TIME_START = getMicrotime(); require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php'; diff --git a/cake/console/libs/templates/skel/webroot/index.php b/cake/console/libs/templates/skel/webroot/index.php index 37b6fee49..6c8cecdd9 100644 --- a/cake/console/libs/templates/skel/webroot/index.php +++ b/cake/console/libs/templates/skel/webroot/index.php @@ -62,13 +62,6 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', ROOT); } -/** - * PHP 5.3 raises many notices in bootstrap. - */ - if (!defined('E_DEPRECATED')) { - define('E_DEPRECATED', 8192); - } - error_reporting(E_ALL & ~E_DEPRECATED); /** * Editing below this line should not be necessary.