From 3c88d817352d2217c6725cf09f48fa5eefe89379 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 1 Jan 2010 23:34:11 -0500 Subject: [PATCH 01/22] Adding tests for model method validation with multiple parameters and addition of original validation rule to method params. Closes #149 --- .../libs/model/model_validation.test.php | 50 +++++++++++++++++++ cake/tests/cases/libs/model/models.php | 10 ++++ 2 files changed, 60 insertions(+) diff --git a/cake/tests/cases/libs/model/model_validation.test.php b/cake/tests/cases/libs/model/model_validation.test.php index a35e4898d..54aa474e3 100644 --- a/cake/tests/cases/libs/model/model_validation.test.php +++ b/cake/tests/cases/libs/model/model_validation.test.php @@ -73,6 +73,56 @@ class ModelValidationTest extends BaseModelTest { ); $this->assertEqual($TestModel->invalidFields(), $expected); + + $TestModel->validate['title'] = array( + 'rule' => array('customValidatorWithSixParams', 'one', 'two', null, 'four'), + 'required' => true + ); + $TestModel->create(array('title' => 'foo')); + $TestModel->invalidFields(); + $expected = array( + 'data' => array( + 'title' => 'foo' + ), + 'one' => 'one', + 'two' => 'two', + 'three' => null, + 'four' => 'four', + 'five' => array( + 'rule' => array(1 => 'one', 2 => 'two', 3 => null, 4 => 'four'), + 'on' => null, + 'last' => false, + 'allowEmpty' => false, + 'required' => true + ), + 'six' => 6 + ); + $this->assertEqual($TestModel->validatorParams, $expected); + + $TestModel->validate['title'] = array( + 'rule' => array('customValidatorWithSixParams', 'one', array('two'), null, 'four', array('five' => 5)), + 'required' => true + ); + $TestModel->create(array('title' => 'foo')); + $TestModel->invalidFields(); + $expected = array( + 'data' => array( + 'title' => 'foo' + ), + 'one' => 'one', + 'two' => array('two'), + 'three' => null, + 'four' => 'four', + 'five' => array('five' => 5), + 'six' => array( + 'rule' => array(1 => 'one', 2 => array('two'), 3 => null, 4 => 'four', 5 => array('five' => 5)), + 'on' => null, + 'last' => false, + 'allowEmpty' => false, + 'required' => true + ) + ); + $this->assertEqual($TestModel->validatorParams, $expected); } /** * Tests validation parameter fieldList in invalidFields diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 33ca715fa..cb2089679 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -1939,6 +1939,16 @@ class ValidationTest1 extends CakeTestModel { function customValidatorWithMessage($data) { return 'This field will *never* validate! Muhahaha!'; } +/** + * Test validation with many parameters + * + * @return void + */ + function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) { + $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); + return true; + } } /** * ValidationTest2 class From 026eeb645b6959115bacd0bf690db9edfb5ac167 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 1 Jan 2010 23:58:07 -0500 Subject: [PATCH 02/22] Correcting and improving doc block for Model::__construct. --- cake/libs/model/model.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index f0e0a6e9c..c7fd52c6c 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -333,9 +333,34 @@ class Model extends Overloadable { /** * Constructor. Binds the model's database table to the object. * - * @param integer $id Set this ID for this model on startup + * If `$id` is an array it can be used to pass several options into the model. + * + * - id - The id to start the model on. + * - table - The table to use for this model. + * - ds - The connection name this model is connected to. + * - name - The name of the model eg. Post. + * - alias - The alias of the model, this is used for registering the instance in the `ClassRegistry`. + * eg. `ParentThread` + * + * ### Overriding Model's __construct method. + * + * When overriding Model::__construct() be careful to include and pass in all 3 of the + * arguments to `parent::__construct($id, $table, $ds);` + * + * ### Dynamically creating models + * + * You can dynamically create model instances using the the $id array syntax. + * + * {{{ + * $Post = new Model(array('table' => 'posts', 'name' => 'Post', 'ds' => 'connection2')); + * }}} + * + * Would create a model attached to the posts table on connection2. Dynamic model creation is useful + * when you want a model object that contains no associations or attached behaviors. + * + * @param mixed $id Set this ID for this model on startup, can also be an array of options, see above. * @param string $table Name of database table to use. - * @param object $ds DataSource connection object. + * @param string $ds DataSource connection name. */ function __construct($id = false, $table = null, $ds = null) { parent::__construct(); From 730153b1516f368a73dcae8efcfa025b9187b062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Perras?= Date: Thu, 7 Jan 2010 17:49:57 -0500 Subject: [PATCH 03/22] Adding isset() checks for CakeSchema::compare() when diff'ing db indexes. Allows for slightly better interoperability between schemas generated with CakePHP 1.2 and with 1.3 --- cake/libs/model/schema.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/schema.php b/cake/libs/model/schema.php index d607dbf57..d1a455290 100644 --- a/cake/libs/model/schema.php +++ b/cake/libs/model/schema.php @@ -168,7 +168,7 @@ class CakeSchema extends Object { * Reads database and creates schema tables * * Options - * + * * - 'connection' - the db connection to use * - 'name' - name of the schema * - 'models' - a list of models to use, or false to ignore models @@ -428,8 +428,12 @@ class CakeSchema extends Object { if (isset($old[$table]['indexes']) && isset($new[$table]['indexes'])) { $diff = $this->_compareIndexes($new[$table]['indexes'], $old[$table]['indexes']); if ($diff) { - $tables[$table]['drop']['indexes'] = $diff['drop']; - $tables[$table]['add']['indexes'] = $diff['add']; + if (isset($tables[$table]['drop']['indexes']) && isset($diff['drop'])) { + $tables[$table]['drop']['indexes'] = $diff['drop']; + } + if (isset($tables[$table]['add']['indexes']) && isset($diff['add'])) { + $tables[$table]['add']['indexes'] = $diff['add']; + } } } } From 11a5403aaf4049b4a3e605b14057ba17ff093990 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 8 Jan 2010 18:35:01 -0500 Subject: [PATCH 04/22] Removing unused variables from inflections.php. These variables are artifacts from previous refactorings and have been non-functional for quite sometime. Fixes #163 --- app/config/inflections.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/app/config/inflections.php b/app/config/inflections.php index ed8c08b3d..07ca6d2a8 100644 --- a/app/config/inflections.php +++ b/app/config/inflections.php @@ -53,18 +53,5 @@ * $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i') */ $singularRules = array(); -/** - * This is a key only array of singular words that should not be inflected. - * You should not have to change this value below if you do change it use same format - * as the $uninflectedPlural above. - */ - $uninflectedSingular = $uninflectedPlural; -/** - * This is a key => value array of singular irregular words. - * Most of the time this will be a reverse of the above $irregularPlural array - * You should not have to change this value below if you do change it use same format - * - * $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother') - */ - $irregularSingular = array_flip($irregularPlural); + ?> \ No newline at end of file From f11068b831ef73b32a6ee345aeb4a21abfd3dc46 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 13:26:47 -0500 Subject: [PATCH 05/22] Trimming trailing whitespace from files. Refs #201 --- cake/config/config.php | 2 +- cake/console/libs/tasks/model.php | 2 +- cake/tests/cases/libs/view/helpers/js.test.php | 2 +- cake/tests/lib/code_coverage_manager.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cake/config/config.php b/cake/config/config.php index 754b623ae..d633f71a6 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -20,4 +20,4 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ return $config['Cake.version'] = '1.3.0-alpha'; -?> +?> \ No newline at end of file diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 08ddb3b97..92827c646 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -915,4 +915,4 @@ class ModelTask extends Shell { $this->Fixture->bake($className, $useTable); } } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index 97c6a8b4a..1e3a16437 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -772,4 +772,4 @@ class JsBaseEngineTestCase extends CakeTestCase { } } -?> +?> \ No newline at end of file diff --git a/cake/tests/lib/code_coverage_manager.php b/cake/tests/lib/code_coverage_manager.php index 946842901..5ddeaab84 100644 --- a/cake/tests/lib/code_coverage_manager.php +++ b/cake/tests/lib/code_coverage_manager.php @@ -801,4 +801,4 @@ class CodeCoverageManager { return false; } } -?> +?> \ No newline at end of file From 813a7779e0f897fa61690be1429dd24a19973108 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 13:28:09 -0500 Subject: [PATCH 06/22] Removing inflections.php from skel directory. --- .../templates/skel/config/inflections.php | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 cake/console/templates/skel/config/inflections.php diff --git a/cake/console/templates/skel/config/inflections.php b/cake/console/templates/skel/config/inflections.php deleted file mode 100644 index 085462b3b..000000000 --- a/cake/console/templates/skel/config/inflections.php +++ /dev/null @@ -1,56 +0,0 @@ - value array of regex used to match words. - * If key matches then the value is returned. - * - * $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice'); - */ - $pluralRules = array(); - -/** - * This is a key only array of plural words that should not be inflected. - * Notice the last comma - * - * $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox'); - */ - $uninflectedPlural = array(); - -/** - * This is a key => value array of plural irregular words. - * If key matches then the value is returned. - * - * $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers') - */ - $irregularPlural = array(); - -/** - * This is a key => value array of regex used to match words. - * If key matches then the value is returned. - * - * $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i') - */ - $singularRules = array(); - -?> \ No newline at end of file From 1a8c3fd40588b532429cc38c5408cbfc4b00e627 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 16:17:34 -0500 Subject: [PATCH 07/22] Fixing infinite loops caused by stale caches. --- cake/tests/cases/libs/object.test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/object.test.php b/cake/tests/cases/libs/object.test.php index e54ba9150..8d722a0d6 100644 --- a/cake/tests/cases/libs/object.test.php +++ b/cake/tests/cases/libs/object.test.php @@ -662,7 +662,9 @@ class ObjectTest extends CakeTestCase { 'models' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS), 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), 'controllers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS) - ), true); + )); + App::objects('plugin', null, false); + Router::reload(); $result = $this->object->requestAction('/tests_apps/index', array('return')); $expected = 'This is the TestsAppsController index view'; @@ -716,6 +718,9 @@ class ObjectTest extends CakeTestCase { $result = $this->object->requestAction(array('controller'=>'request_action', 'action'=>'paginate_request_action'), array('pass' => array(5), 'named' => array('param' => 'value'))); $this->assertTrue($result); + + App::build(); + App::objects('plugin', null, false); } /** From 4f5ce7f94cbbe1e99306e26c5dbedf49f28dc80e Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 16:18:19 -0500 Subject: [PATCH 08/22] Adding additional plugin 'shortcut' dispatching tests. --- cake/tests/cases/dispatcher.test.php | 37 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index 2b99cd827..2917dc49d 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -1516,17 +1516,10 @@ class DispatcherTest extends CakeTestCase { $controller = $Dispatcher->dispatch($url, array('return' => 1)); - $expected = 'my_plugin'; - $this->assertIdentical($controller->plugin, $expected); - - $expected = 'MyPlugin'; - $this->assertIdentical($controller->name, $expected); - - $expected = 'add'; - $this->assertIdentical($controller->action, $expected); - - $expected = array('param' => 'value', 'param2' => 'value2'); - $this->assertEqual($controller->params['named'], $expected); + $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->name, 'MyPlugin'); + $this->assertIdentical($controller->action, 'add'); + $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2')); Router::reload(); @@ -1678,6 +1671,8 @@ class DispatcherTest extends CakeTestCase { App::build(array( 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) ), true); + App::objects('plugin', null, false); + $Dispatcher =& new TestDispatcher(); $Dispatcher->base = false; @@ -1687,6 +1682,21 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($controller->params['plugin'], 'test_plugin'); $this->assertEqual($controller->params['action'], 'index'); $this->assertFalse(isset($controller->params['pass'][0])); + + $url = '/test_plugin/tests/index'; + $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $this->assertEqual($controller->params['controller'], 'tests'); + $this->assertEqual($controller->params['plugin'], 'test_plugin'); + $this->assertEqual($controller->params['action'], 'index'); + $this->assertFalse(isset($controller->params['pass'][0])); + + $url = '/test_plugin/tests/index/some_param'; + $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $this->assertEqual($controller->params['controller'], 'tests'); + $this->assertEqual($controller->params['plugin'], 'test_plugin'); + $this->assertEqual($controller->params['action'], 'index'); + $this->assertEqual($controller->params['pass'][0], 'some_param'); + App::build(); } @@ -1985,7 +1995,7 @@ class DispatcherTest extends CakeTestCase { 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), ), true); - $dispatcher =& new Dispatcher(); + $dispatcher =& new TestDispatcher(); $dispatcher->base = false; $url = '/'; @@ -2119,7 +2129,7 @@ class DispatcherTest extends CakeTestCase { 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); - $dispatcher =& new Dispatcher(); + $dispatcher =& new TestDispatcher(); $dispatcher->base = false; $url = 'test_cached_pages/cache_form'; @@ -2139,6 +2149,7 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($result, $expected); $filename = $this->__cachePath($dispatcher->here); + @unlink($filename); ClassRegistry::flush(); } From 1f5d579ab614f4d4b566d7720ad55dbcf8d80b1d Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 16:19:23 -0500 Subject: [PATCH 09/22] Removing the ability to set layout, and viewPath with Request parameters. This feature was untested and undocumented. Furthermore, it should not be the responsibility of the dispatcher to set these parameters. --- cake/dispatcher.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index ef63a3243..4dda2be43 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -167,16 +167,6 @@ class Dispatcher extends Object { if (!empty($this->params['bare'])) { $controller->autoLayout = false; } - if (array_key_exists('layout', $this->params)) { - if (empty($this->params['layout'])) { - $controller->autoLayout = false; - } else { - $controller->layout = $this->params['layout']; - } - } - if (isset($this->params['viewPath'])) { - $controller->viewPath = $this->params['viewPath']; - } return $this->_invoke($controller, $this->params); } From 2441849fa008cb9aa2f77cd695c8a6f79f72c6a8 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 16 Jan 2010 03:26:26 +0530 Subject: [PATCH 10/22] Replacing constant CIPHER_SEED with Configure class variable 'Security.cipher_seed' and renaming Security class method 'checkSessionKey' to 'checkSecurityKeys' --- app/config/core.php | 7 ++++++- cake/console/templates/default/views/home.ctp | 2 +- cake/console/templates/skel/config/core.php | 7 ++++++- cake/libs/controller/components/auth.php | 2 +- cake/libs/debugger.php | 8 ++++++-- cake/libs/security.php | 6 +----- cake/libs/view/pages/home.ctp | 2 +- cake/tests/test_app/views/pages/home.ctp | 2 +- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/config/core.php b/app/config/core.php index 903c0205a..c127be2d1 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -74,7 +74,7 @@ * The value of the define determines the names of the routes * and their associated controller actions: * - * Set to an array of prefixes you want to use in your application. Use for + * Set to an array of prefixes you want to use in your application. Use for * admin or other prefixed routes. * * Routing.prefixes = array('admin', 'manager'); @@ -197,6 +197,11 @@ */ Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi'); +/** + * A random numeric string (digits only) used to encrypt/decrypt strings. + */ + Configure::write('Security.cipher_seed', '76859309657453542496749683645'); + /** * Apply timestamps with the last modified time to static assets (js, css, images). * Will append a querystring parameter containing the time the file was modified. This is diff --git a/cake/console/templates/default/views/home.ctp b/cake/console/templates/default/views/home.ctp index 0e478c4f1..eeaec4a24 100644 --- a/cake/console/templates/default/views/home.ctp +++ b/cake/console/templates/default/views/home.ctp @@ -3,7 +3,7 @@ $output = "

Sweet, \"" . Inflector::humanize($app) . "\" got Baked by CakePHP $output .=" 0): - Debugger::checkSessionKey(); + Debugger::checkSecurityKeys(); endif; ?>

diff --git a/cake/console/templates/skel/config/core.php b/cake/console/templates/skel/config/core.php index a8b506d14..15ec7aec3 100644 --- a/cake/console/templates/skel/config/core.php +++ b/cake/console/templates/skel/config/core.php @@ -85,7 +85,7 @@ /** * Uncomment the define below to use CakePHP prefix routes. * - * Set to an array of prefixes you want to use in your application. Use for + * Set to an array of prefixes you want to use in your application. Use for * admin or other prefixed routes. * * Routing.prefixes = array('admin', 'manager'); @@ -206,6 +206,11 @@ */ Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi'); +/** + * A random numeric string (digits only) used to encrypt/decrypt strings. + */ + Configure::write('Security.cipher_seed', '76859309657453542496749683645'); + /** * Compress CSS output by removing comments, whitespace, repeating tags, etc. * This requires a/var/cache directory to be writable by the web server for caching. diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index b391b972b..bdbeb7146 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -278,7 +278,7 @@ class AuthComponent extends Object { $this->_set($settings); if (Configure::read() > 0) { App::import('Debugger'); - Debugger::checkSessionKey(); + Debugger::checkSecurityKeys(); } } diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index f7c04f013..ff01586cc 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -664,15 +664,19 @@ class Debugger extends Object { } /** - * Verifies that the application's salt value has been changed from the default value. + * Verifies that the application's salt and cipher seed value has been changed from the default value. * * @access public * @static */ - function checkSessionKey() { + function checkSecurityKeys() { if (Configure::read('Security.salt') == 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') { trigger_error(__('Please change the value of \'Security.salt\' in app/config/core.php to a salt value specific to your application', true), E_USER_NOTICE); } + + if (Configure::read('Security.cipher_seed') == '76859309657453542496749683645') { + trigger_error(__('Please change the value of \'Security.cipher_seed\' in app/config/core.php to a numeric (digits only) seed value specific to your application', true), E_USER_NOTICE); + } } /** diff --git a/cake/libs/security.php b/cake/libs/security.php index b93f9934e..5bfc387bf 100644 --- a/cake/libs/security.php +++ b/cake/libs/security.php @@ -174,11 +174,7 @@ class Security extends Object { return ''; } - if (!defined('CIPHER_SEED')) { - //This is temporary will change later - define('CIPHER_SEED', '76859309657453542496749683645'); - } - srand(CIPHER_SEED); + srand(Configure::read('Security.cipher_seed')); $out = ''; for ($i = 0; $i < strlen($text); $i++) { diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index 37951f8c9..adb658685 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -25,7 +25,7 @@ endif; echo $this->Html->link(__('Read the changelog', true), 'http://code.cakephp.org/wiki/changelog/1_3_0-alpha'); if (Configure::read() > 0): - Debugger::checkSessionKey(); + Debugger::checkSecurityKeys(); endif; ?>

diff --git a/cake/tests/test_app/views/pages/home.ctp b/cake/tests/test_app/views/pages/home.ctp index b9b6f00ed..1d394b49f 100644 --- a/cake/tests/test_app/views/pages/home.ctp +++ b/cake/tests/test_app/views/pages/home.ctp @@ -2,7 +2,7 @@ 0): - Debugger::checkSessionKey(); + Debugger::checkSecurityKeys(); endif; ?>

From 476ef19fff9235d118183e948b9e9f9319a348e1 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Jan 2010 17:16:51 -0500 Subject: [PATCH 11/22] Removing gettests from jsHelper test case. --- cake/tests/cases/libs/view/helpers/js.test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index 1e3a16437..525ea7b1c 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -279,9 +279,6 @@ class JsHelperTestCase extends CakeTestCase { @unlink(WWW_ROOT . $filename[1]); } - function getTests() { - return array('start', 'startCase', 'testLinkWithMock', 'endCase', 'end'); - } /** * test link() From 3bd4cc07a6af7d102cfafc90ae3195d58dbd0836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Fri, 15 Jan 2010 17:40:49 -0430 Subject: [PATCH 12/22] Fixes to make TimeHelper and test cases more compatible with PHP 4 --- cake/libs/view/helpers/time.php | 3 + .../cases/libs/view/helpers/time.test.php | 65 +++++++++---------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index e4b9f7cb6..1431fd52c 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -174,6 +174,9 @@ class TimeHelper extends AppHelper { if ($userOffset !== null) { return $this->convert($date, $userOffset); } + if ($date === -1) { + return false; + } return $date; } diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 7b70d4ed7..d90fd4562 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -86,34 +86,34 @@ class TimeHelperTest extends CakeTestCase { * @return void */ function testTimeAgoInWords() { - $result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 3 days'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +3 days'), array('end' => '8 years'), true); $this->assertEqual($result, '4 months, 2 weeks, 3 days'); - $result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 2 days'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +2 days'), array('end' => '8 years'), true); $this->assertEqual($result, '4 months, 2 weeks, 2 days'); - $result = $this->Time->timeAgoInWords(strtotime('4 months, 2 weeks, 1 day'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+4 months +2 weeks +1 day'), array('end' => '8 years'), true); $this->assertEqual($result, '4 months, 2 weeks, 1 day'); - $result = $this->Time->timeAgoInWords(strtotime('3 months, 2 weeks, 1 day'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+3 months +2 weeks +1 day'), array('end' => '8 years'), true); $this->assertEqual($result, '3 months, 2 weeks, 1 day'); - $result = $this->Time->timeAgoInWords(strtotime('3 months, 2 weeks'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+3 months +2 weeks'), array('end' => '8 years'), true); $this->assertEqual($result, '3 months, 2 weeks'); - $result = $this->Time->timeAgoInWords(strtotime('3 months, 1 week, 6 days'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+3 months +1 week +6 days'), array('end' => '8 years'), true); $this->assertEqual($result, '3 months, 1 week, 6 days'); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 weeks, 1 day'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 weeks +1 day'), array('end' => '8 years'), true); $this->assertEqual($result, '2 months, 2 weeks, 1 day'); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 weeks'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 weeks'), array('end' => '8 years'), true); $this->assertEqual($result, '2 months, 2 weeks'); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 1 week, 6 days'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +1 week +6 days'), array('end' => '8 years'), true); $this->assertEqual($result, '2 months, 1 week, 6 days'); - $result = $this->Time->timeAgoInWords(strtotime('1 month, 1 week, 6 days'), array('end' => '8 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('+1 month +1 week +6 days'), array('end' => '8 years'), true); $this->assertEqual($result, '1 month, 1 week, 6 days'); for($i = 0; $i < 200; $i ++) { @@ -157,8 +157,8 @@ class TimeHelperTest extends CakeTestCase { $relative_date .= ($relative_date ? ', -' : '-') . $seconds . ' second' . ($seconds != 1 ? 's' : ''); } - if (date('j/n/y', strtotime($relative_date)) != '1/1/70') { - $result = $this->Time->timeAgoInWords(strtotime($relative_date), array('end' => '8 years'), true); + if (date('j/n/y', strtotime(str_replace(',','',$relative_date))) != '1/1/70') { + $result = $this->Time->timeAgoInWords(strtotime(str_replace(',','',$relative_date)), array('end' => '8 years'), true); if ($relative_date == '0 seconds') { $relative_date = '0 seconds ago'; } @@ -211,9 +211,8 @@ class TimeHelperTest extends CakeTestCase { $relative_date .= ($relative_date ? ', ' : '') . $seconds . ' second' . ($seconds != 1 ? 's' : ''); } - if (date('j/n/y', strtotime($relative_date)) != '1/1/70') { - // echo $relative_date."
"; - $result = $this->Time->timeAgoInWords(strtotime($relative_date), array('end' => '8 years'), true); + if (date('j/n/y', strtotime(str_replace(',','',$relative_date))) != '1/1/70') { + $result = $this->Time->timeAgoInWords(strtotime(str_replace(',','',$relative_date)), array('end' => '8 years'), true); if ($relative_date == '0 seconds') { $relative_date = '0 seconds ago'; } @@ -223,7 +222,7 @@ class TimeHelperTest extends CakeTestCase { } } - $result = $this->Time->timeAgoInWords(strtotime('-2 years, -5 months, -2 days'), array('end' => '3 years'), true); + $result = $this->Time->timeAgoInWords(strtotime('-2 years -5 months -2 days'), array('end' => '3 years'), true); $this->assertEqual($result, '2 years, 5 months, 2 days ago'); $result = $this->Time->timeAgoInWords('2007-9-25'); @@ -235,44 +234,44 @@ class TimeHelperTest extends CakeTestCase { $result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d', true); $this->assertEqual($result, 'on 2007-09-25'); - $result = $this->Time->timeAgoInWords(strtotime('-2 weeks, -2 days'), 'Y-m-d', false); + $result = $this->Time->timeAgoInWords(strtotime('-2 weeks -2 days'), 'Y-m-d', false); $this->assertEqual($result, '2 weeks, 2 days ago'); - $result = $this->Time->timeAgoInWords(strtotime('2 weeks, 2 days'), 'Y-m-d', true); + $result = $this->Time->timeAgoInWords(strtotime('+2 weeks +2 days'), 'Y-m-d', true); $this->assertPattern('/^2 weeks, [1|2] day(s)?$/', $result); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month')); - $this->assertEqual($result, 'on ' . date('j/n/y', strtotime('2 months, 2 days'))); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '1 month')); + $this->assertEqual($result, 'on ' . date('j/n/y', strtotime('+2 months +2 days'))); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month')); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '3 month')); $this->assertPattern('/2 months/', $result); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 12 days'), array('end' => '3 month')); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +12 days'), array('end' => '3 month')); $this->assertPattern('/2 months, 1 week/', $result); - $result = $this->Time->timeAgoInWords(strtotime('3 months, 5 days'), array('end' => '4 month')); + $result = $this->Time->timeAgoInWords(strtotime('+3 months +5 days'), array('end' => '4 month')); $this->assertEqual($result, '3 months, 5 days'); - $result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month')); + $result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '3 month')); $this->assertEqual($result, '2 months, 2 days ago'); - $result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month')); + $result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '3 month')); $this->assertEqual($result, '2 months, 2 days ago'); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month')); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '3 month')); $this->assertPattern('/2 months/', $result); - $result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month', 'format' => 'Y-m-d')); - $this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('2 months, 2 days'))); + $result = $this->Time->timeAgoInWords(strtotime('+2 months +2 days'), array('end' => '1 month', 'format' => 'Y-m-d')); + $this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('+2 months +2 days'))); - $result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '1 month', 'format' => 'Y-m-d')); - $this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('-2 months, -2 days'))); + $result = $this->Time->timeAgoInWords(strtotime('-2 months -2 days'), array('end' => '1 month', 'format' => 'Y-m-d')); + $this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('-2 months -2 days'))); - $result = $this->Time->timeAgoInWords(strtotime('-13 months, -5 days'), array('end' => '2 years')); + $result = $this->Time->timeAgoInWords(strtotime('-13 months -5 days'), array('end' => '2 years')); $this->assertEqual($result, '1 year, 1 month, 5 days ago'); - $fourHours = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => -4)); - $result = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => 4)); + $fourHours = $this->Time->timeAgoInWords(strtotime('-5 days -2 hours'), array('userOffset' => -4)); + $result = $this->Time->timeAgoInWords(strtotime('-5 days -2 hours'), array('userOffset' => 4)); $this->assertEqual($fourHours, $result); $result = $this->Time->timeAgoInWords(strtotime('-2 hours')); From 1acc4c879ad4fb03f1c962540bfb81121f0c879b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 18:15:38 -0500 Subject: [PATCH 13/22] Removing debug() from scaffold test. --- cake/tests/cases/libs/controller/scaffold.test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 7604792b2..af4d3d0ff 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -500,7 +500,6 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertPattern('/input name="data\[ScaffoldMock\]\[published\]" type="text" maxlength="1" value="Y" id="ScaffoldMockPublished"/', $result); $this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); $this->assertPattern('/

  • ]*>Delete<\/a>\s*<\/li>/', $result); - debug($result); } /** From 826dbc466ff8f451fb11e6dde08c307a3e61869d Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 18:26:06 -0500 Subject: [PATCH 14/22] Fixing failing test caused by merge with 1.2 --- cake/libs/model/cake_schema.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 152d9cd33..82b2e8913 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -486,10 +486,13 @@ class CakeSchema extends Object { if (isset($old[$table]['indexes']) && isset($new[$table]['indexes'])) { $diff = $this->_compareIndexes($new[$table]['indexes'], $old[$table]['indexes']); if ($diff) { - if (isset($tables[$table]['drop']['indexes']) && isset($diff['drop'])) { + if (!isset($tables[$table])) { + $tables[$table] = array(); + } + if (isset($diff['drop'])) { $tables[$table]['drop']['indexes'] = $diff['drop']; } - if (isset($tables[$table]['add']['indexes']) && isset($diff['add'])) { + if ($diff && isset($diff['add'])) { $tables[$table]['add']['indexes'] = $diff['add']; } } From 8cae1e850adaafb319ebc3b64fab53b188e92830 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 18:50:04 -0500 Subject: [PATCH 15/22] Fixing spacing. --- cake/libs/i18n.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index bd10c574a..2ebdd8662 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -496,15 +496,15 @@ class I18n extends Object { continue; } - $mustEscape = array($escape.',',$escape.';',$escape.'<',$escape.'>',$escape.$escape); - $replacements = array_map('crc32',$mustEscape); - $value = str_replace($mustEscape,$replacements,$value); - $value = explode(';',$value); + $mustEscape = array($escape . ',' , $escape . ';', $escape . '<', $escape . '>', $escape . $escape); + $replacements = array_map('crc32', $mustEscape); + $value = str_replace($mustEscape, $replacements, $value); + $value = explode(';', $value); $_this->__escape = $escape; foreach ($value as $i => $val) { - $val = trim($val,'"'); - $val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/',array(&$this,'__parseLiteralValue'),$val); - $val = str_replace($replacements,$mustEscape,$val); + $val = trim($val, '"'); + $val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$this, '__parseLiteralValue'), $val); + $val = str_replace($replacements, $mustEscape, $val); $value[$i] = $val; } if (count($value) == 1) { From 34fed29d05461c1ceae23fab1cec9c6a9c49fe05 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 19:19:12 -0500 Subject: [PATCH 16/22] Renaming session test case. Adding missing doc block to inflector test case. Updating Set::map reverse test to reflect changes in Model. Removing Inflector from lib group as the reset test breaks many other tests. Adding a table property to the session fixture. --- cake/tests/cases/libs/cake_session.test.php | 4 ++-- cake/tests/cases/libs/inflector.test.php | 5 +++++ cake/tests/cases/libs/set.test.php | 2 +- cake/tests/fixtures/session_fixture.php | 7 +++++++ cake/tests/groups/lib.group.php | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index 81e94d266..99811c2e2 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -22,12 +22,12 @@ if (!class_exists('CakeSession')) { } /** - * SessionTest class + * CakeSessionTest class * * @package cake * @subpackage cake.tests.cases.libs */ -class SessionTest extends CakeTestCase { +class CakeSessionTest extends CakeTestCase { /** * Fixtures used in the SessionTest diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index ac32d3385..4d911ffdc 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -381,6 +381,11 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::singularize('singulars'), 'singulars'); } +/** + * Test resetting inflection rules. + * + * @return void + */ function testCustomRuleWithReset() { $uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x'); $pluralIrregular = array('as' => 'ases'); diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 20188aff1..fd1b1aa50 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -1824,7 +1824,7 @@ class SetTest extends CakeTestCase { 'useDbConfig' => 'default', 'useTable' => false, 'displayField' => null, 'id' => false, 'data' => array(), 'table' => 'models', 'primaryKey' => 'id', '_schema' => null, 'validate' => array(), 'validationErrors' => array(), 'tablePrefix' => null, 'name' => 'Model', 'alias' => 'Model', 'tableToModel' => array(), 'logTransactions' => false, 'transactional' => false, 'cacheQueries' => false, 'belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array(), 'actsAs' => null, 'whitelist' => array(), 'cacheSources' => true, - 'findQueryType' => null, 'recursive' => 1, 'order' => null, '__exists' => null, + 'findQueryType' => null, 'recursive' => 1, 'order' => null, 'virtualFields' => array(), '__associationKeys' => array( 'belongsTo' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'counterCache'), 'hasOne' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'dependent'), diff --git a/cake/tests/fixtures/session_fixture.php b/cake/tests/fixtures/session_fixture.php index 2d8958b11..56adfe207 100644 --- a/cake/tests/fixtures/session_fixture.php +++ b/cake/tests/fixtures/session_fixture.php @@ -34,6 +34,13 @@ class SessionFixture extends CakeTestFixture { */ var $name = 'Session'; +/** + * table property. + * + * @var string + */ + // var $table = 'sessions'; + /** * fields property * diff --git a/cake/tests/groups/lib.group.php b/cake/tests/groups/lib.group.php index bae925e4f..49b3830cc 100644 --- a/cake/tests/groups/lib.group.php +++ b/cake/tests/groups/lib.group.php @@ -44,7 +44,7 @@ class LibGroupTest extends TestSuite { */ function LibGroupTest() { TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'basics'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); + // TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_session'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'debugger'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'error'); From b50b5922fd4fff06f5e1a93bdb4a181890d6bff0 Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 17 Jan 2010 11:38:45 +1100 Subject: [PATCH 17/22] Adjusting EmailComponent Boundary creation to occur for all generated email. Fixes #14. --- cake/libs/controller/components/email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 8eb16fec4..1b13a95f8 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -505,8 +505,8 @@ class EmailComponent extends Object{ } } + $this->__createBoundary(); if (!empty($this->attachments)) { - $this->__createBoundary(); $this->__header[] = 'MIME-Version: 1.0'; $this->__header[] = 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"'; $this->__header[] = 'This part of the E-mail should never be seen. If'; From c4ef4290041dfec61aa26653b5c04c76aff91893 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 19:41:52 -0500 Subject: [PATCH 18/22] Changing require to require_once to make tests less order dependent. --- cake/tests/cases/console/libs/tasks/extract.test.php | 5 ++--- cake/tests/cases/console/libs/tasks/project.test.php | 4 +--- cake/tests/cases/console/libs/tasks/test.test.php | 7 +++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index 349ffe86f..0777a733f 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -33,9 +33,8 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } -if (!class_exists('ExtractTask')) { - require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php'; -} +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php'; + Mock::generatePartial( 'ShellDispatcher', 'TestExtractTaskMockShellDispatcher', diff --git a/cake/tests/cases/console/libs/tasks/project.test.php b/cake/tests/cases/console/libs/tasks/project.test.php index 0f80b3431..37096a205 100644 --- a/cake/tests/cases/console/libs/tasks/project.test.php +++ b/cake/tests/cases/console/libs/tasks/project.test.php @@ -32,9 +32,7 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } -if (!class_exists('ProjectTask')) { - require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php'; -} +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php'; Mock::generatePartial( 'ShellDispatcher', 'TestProjectTaskMockShellDispatcher', diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index d6c9dae97..6166b300c 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -34,10 +34,9 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } -if (!class_exists('TestTask')) { - require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php'; - require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php'; -} +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php'; +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php'; + Mock::generatePartial( 'ShellDispatcher', 'TestTestTaskMockShellDispatcher', From f1276ce337524a80200ff2bae430db8acbf55a11 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 20:14:16 -0500 Subject: [PATCH 19/22] Fixing several issues in the CodeCoverageManager test case. --- .../cases/libs/code_coverage_manager.test.php | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/cake/tests/cases/libs/code_coverage_manager.test.php b/cake/tests/cases/libs/code_coverage_manager.test.php index 57510e835..b8f3a52bf 100644 --- a/cake/tests/cases/libs/code_coverage_manager.test.php +++ b/cake/tests/cases/libs/code_coverage_manager.test.php @@ -63,44 +63,55 @@ class CodeCoverageManagerTest extends CakeTestCase { * @return void */ function testNoTestCaseSupplied() { - if (PHP_SAPI != 'cli') { - $reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false)); + if ($this->skipIf(PHP_SAPI == 'cli', 'Is cli, cannot run this test %s')) { + return; + } + $reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false)); - CodeCoverageManager::init(substr(md5(microtime()), 0, 5), $reporter); - CodeCoverageManager::report(false); - $this->assertError(); + CodeCoverageManager::init(substr(md5(microtime()), 0, 5), $reporter); + CodeCoverageManager::report(false); + $this->assertError(); - CodeCoverageManager::init('tests' . DS . 'lib' . DS . basename(__FILE__), $reporter); - CodeCoverageManager::report(false); - $this->assertError(); - - $path = LIBS; - if (strpos(LIBS, ROOT) === false) { - $path = ROOT.DS.LIBS; - } - App::import('Core', 'Folder'); - $folder = new Folder(); - $folder->cd($path); - $contents = $folder->read(); + CodeCoverageManager::init('tests' . DS . 'lib' . DS . basename(__FILE__), $reporter); + CodeCoverageManager::report(false); + $this->assertError(); + } /** - * remove method + * Test that test cases don't cause errors * - * @param mixed $var - * @access public * @return void */ - function remove($var) { - return ($var != basename(__FILE__)); - } - $contents[1] = array_filter($contents[1], "remove"); - - foreach ($contents[1] as $file) { - CodeCoverageManager::init('libs' . DS . $file, $reporter); - CodeCoverageManager::report(false); - $this->assertNoErrors('libs' . DS . $file); - } + function testNoTestCaseSuppliedNoErrors() { + if ($this->skipIf(PHP_SAPI == 'cli', 'Is cli, cannot run this test %s')) { + return; } + $reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false)); + $path = LIBS; + if (strpos(LIBS, ROOT) === false) { + $path = ROOT.DS.LIBS; + } + App::import('Core', 'Folder'); + $folder = new Folder(); + $folder->cd($path); + $contents = $folder->read(); + + $contents[1] = array_filter($contents[1], array(&$this, '_basenameFilter')); + + foreach ($contents[1] as $file) { + CodeCoverageManager::init('libs' . DS . $file, $reporter); + CodeCoverageManager::report(false); + $this->assertNoErrors('libs' . DS . $file); + } + } + +/** + * Remove file names that don't share a basename with the current file. + * + * @return void + */ + function _basenameFilter($var) { + return ($var != basename(__FILE__)); } /** From 0e09fee3b1988aacb176beea461e7aaab526e7f0 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 20:14:57 -0500 Subject: [PATCH 20/22] Correcting timehelper tests to use correct timestamp for indicated times. Making timezone output more resilient. --- cake/tests/cases/libs/view/helpers/time.test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index d90fd4562..df14c1fca 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -661,7 +661,7 @@ class TimeHelperTest extends CakeTestCase { 'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS) ), true); Configure::write('Config.language', 'time_test'); - $time = 1263485619; // Thu Jan 14 11:43:39 2010 + $time = 1263487419; // Thu Jan 14 11:43:39 2010 $result = $this->Time->convertSpecifiers('%a', $time); $expected = 'jue'; @@ -751,14 +751,14 @@ class TimeHelperTest extends CakeTestCase { 'locales' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' . DS) ), true); Configure::write('Config.language', 'time_test'); - $time = 1263493768; //Thu Jan 14 13:59:28 2010 + $time = 1263495568; //Thu Jan 14 13:59:28 2010 $result = $this->Time->i18nFormat($time); $expected = '14/01/10'; $this->assertEqual($result, $expected); $result = $this->Time->i18nFormat($time, '%c'); - $expected = 'jue 14 ene 2010 13:59:28 VET'; + $expected = 'jue 14 ene 2010 13:59:28 ' . strftime('%Z'); $this->assertEqual($result, $expected); $result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x'); From 3be28fc749bcda19ff5c70de9ab1ea9b710d6782 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 20:18:20 -0500 Subject: [PATCH 21/22] Fixing errors in CakeTestCase::testAction tests case caused by changes in test suite not always forcing an output parameter. --- cake/tests/cases/libs/cake_test_case.test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index a9c472f28..8d957b56b 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -343,7 +343,6 @@ class CakeTestCaseTest extends CakeTestCase { 'method' => 'get', )); $this->assertTrue(isset($result['params']['url']['url'])); - $this->assertTrue(isset($result['params']['url']['output'])); $this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2')); $result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array( @@ -361,7 +360,6 @@ class CakeTestCaseTest extends CakeTestCase { 'blue' => 'mana' ) )); - $this->assertTrue(isset($result['params']['url']['output'])); $this->assertTrue(isset($result['params']['url']['red'])); $this->assertTrue(isset($result['params']['url']['blue'])); $this->assertTrue(isset($result['params']['url']['url'])); From 5203397a6a2631fd14077f8eb8b151950284be4a Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 16 Jan 2010 20:24:27 -0500 Subject: [PATCH 22/22] Adding error expectation to model_write test. Models using useTable = false, will still issue count queries to their datasources when exists() is called. --- cake/tests/cases/libs/model/model_write.test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 769a79f85..d55731887 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -2558,8 +2558,12 @@ class ModelWriteTest extends BaseModelTest { $TestModel =& new TheVoid(); $this->assertFalse($TestModel->exists()); + $TestModel->id = 5; + $this->expectError(); + ob_start(); $this->assertFalse($TestModel->exists()); + $output = ob_get_clean(); } /**