From 5ffc84d28a82de9b12eb85c71de1fed760472143 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 12 Dec 2010 21:14:30 -0500 Subject: [PATCH 01/15] Calling parent constructors in helpers that have it omitted. Fixes #1359 --- cake/libs/view/helpers/js.php | 1 + cake/libs/view/helpers/paginator.php | 1 + 2 files changed, 2 insertions(+) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 546792c68..5c3571bef 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -501,6 +501,7 @@ class JsBaseEngineHelper extends AppHelper { * @return void */ function __construct() { + parent::__construct(); $this->useNative = function_exists('json_encode'); } diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index f3bb2cdb0..ca5f45541 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -88,6 +88,7 @@ class PaginatorHelper extends AppHelper { * @return void */ function __construct($config = array()) { + parent::__construct($config); $ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js'; $this->helpers[] = $ajaxProvider; $this->_ajaxHelperClass = $ajaxProvider; From e410509684a9aaeaa1fd7107459d80c4b290d220 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 13 Dec 2010 22:00:37 -0500 Subject: [PATCH 02/15] Fixing TestTask not being able to find plugin objects when baking test skeletons interactively. Test case added. Fixes #1361 --- cake/console/libs/tasks/test.php | 15 +++++++++++- .../cases/console/libs/tasks/test.test.php | 23 ++++++++++++++++++- cake/tests/cases/libs/model/db_acl.test.php | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index d90a1eb4a..ed9c7e433 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -181,7 +181,20 @@ class TestTask extends BakeTask { * @access public */ function getClassName($objectType) { - $options = App::objects(strtolower($objectType)); + $type = strtolower($objectType); + if ($this->plugin) { + $path = Inflector::pluralize($type); + if ($type === 'helper') { + $path = 'views' . DS . $path; + } elseif ($type === 'component') { + $path = 'controllers' . DS . $path; + } elseif ($type === 'behavior') { + $path = 'models' . DS . $path; + } + $options = App::objects($type, App::pluginPath($this->plugin) . $path, false); + } else { + $options = App::objects($type); + } $this->out(sprintf(__('Choose a %s class', true), $objectType)); $keys = array(); foreach ($options as $key => $option) { diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index e660cdea8..b6f1e8c2a 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -44,7 +44,7 @@ Mock::generatePartial( ); Mock::generatePartial( 'TestTask', 'MockTestTask', - array('in', '_stop', 'err', 'out', 'createFile', 'isLoadableClass') + array('in', '_stop', 'err', 'out', 'hr', 'createFile', 'isLoadableClass') ); /** @@ -278,6 +278,7 @@ class TestTaskTest extends CakeTestCase { */ function endTest() { ClassRegistry::flush(); + App::build(); } /** @@ -560,6 +561,26 @@ class TestTaskTest extends CakeTestCase { $this->Task->bake('Helper', 'Form'); } +/** + * test interactive with plugins lists from the plugin + * + * @return void + */ + function testInteractiveWithPlugin() { + $testApp = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS; + App::build(array( + 'plugins' => array($testApp) + ), true); + + $this->Task->plugin = 'TestPlugin'; + $path = $testApp . 'test_plugin' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'other_helper.test.php'; + $this->Task->setReturnValueAt(0, 'in', 5); //helper + $this->Task->setReturnValueAt(1, 'in', 1); //OtherHelper + $this->Task->expectAt(0, 'createFile', array($path, '*')); + $this->Task->expectAt(9, 'out', array('1. OtherHelper')); + $this->Task->execute(); + } + /** * Test filename generation for each type + plugins * diff --git a/cake/tests/cases/libs/model/db_acl.test.php b/cake/tests/cases/libs/model/db_acl.test.php index 73e9cf6a6..b970d2332 100644 --- a/cake/tests/cases/libs/model/db_acl.test.php +++ b/cake/tests/cases/libs/model/db_acl.test.php @@ -211,7 +211,8 @@ class DbAroUserTest extends CakeTestModel { * @access public */ var $useTable = 'auth_users'; - /** + +/** * bindNode method * * @param mixed $ref From 53a687049ce78e2d2211f51ca89e72d06edd5e40 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 13 Dec 2010 23:23:02 -0500 Subject: [PATCH 03/15] Fixing encoding of address aliases. They are now mime-encoded like other headers. Tests added. Fixes #1360 --- cake/libs/controller/components/email.php | 5 +++-- .../libs/controller/components/email.test.php | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 2aa96c3e0..83ee15df2 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -774,14 +774,15 @@ class EmailComponent extends Object{ * @access private */ function _formatAddress($string, $smtp = false) { - $hasAlias = preg_match('/((.*)\s)?<(.+)>/', $string, $matches); + $hasAlias = preg_match('/((.*))?\s?<(.+)>/', $string, $matches); if ($smtp && $hasAlias) { return $this->_strip('<' . $matches[3] . '>'); } elseif ($smtp) { return $this->_strip('<' . $string . '>'); } + if ($hasAlias && !empty($matches[2])) { - return $this->_strip($matches[2] . ' <' . $matches[3] . '>'); + return $this->_encode($matches[2]) . $this->_strip(' <' . $matches[3] . '>'); } return $this->_strip($string); } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index ed80c1b2b..0dbb72d0e 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -1216,6 +1216,9 @@ HTMLBLOC; $result = $this->Controller->EmailTest->formatAddress('alias '); $this->assertEqual($result, 'alias '); + + $result = $this->Controller->EmailTest->formatAddress('alias'); + $this->assertEqual($result, 'alias '); $result = $this->Controller->EmailTest->formatAddress('email@example.com'); $this->assertEqual($result, 'email@example.com'); @@ -1232,4 +1235,21 @@ HTMLBLOC; $result = $this->Controller->EmailTest->formatAddress('alias name ', true); $this->assertEqual($result, ''); } + +/** + * test formatting addresses with multibyte chars + * + * @return void + */ + function testFormatAddressMultibyte() { + $this->Controller->EmailTest->charset = 'UTF-8'; + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest '); + $this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdCA=?= '); + + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest'); + $this->assertEqual($result, '=?UTF-8?B?w4TDlsOcVGVzdA==?= '); + + $result = $this->Controller->EmailTest->formatAddress('ÄÖÜTest ', true); + $this->assertEqual($result, ''); + } } From 7416e58759856f5c4944eb9d4442aa9f3f7d0525 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 14 Dec 2010 20:55:34 -0800 Subject: [PATCH 04/15] Allowed comma-delimited list in smtp $to var to be consistent with standard mail delivery. Fixes #1353 --- 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 83ee15df2..3bb1357ac 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -893,7 +893,7 @@ class EmailComponent extends Object{ } if (!is_array($this->to)) { - $tos = array($this->to); + $tos = array_map('trim', explode(',', $this->to)); } else { $tos = $this->to; } From a7c7436d8ec758795e0cf38b6062befd12933134 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 18 Dec 2010 19:31:10 -0200 Subject: [PATCH 05/15] Passing viewVars to cache views, avoiding cake:nocache problems. --- cake/libs/view/helpers/cache.php | 2 ++ cake/libs/view/view.php | 1 + .../cases/libs/view/helpers/cache.test.php | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index adea15cc5..52ebd75b9 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -233,6 +233,7 @@ class CacheHelper extends AppHelper { $controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\')); $controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\'); $controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\')); + $controller->viewVars = $this->viewVars = unserialize(stripslashes(\'' . addslashes(serialize($this->viewVars)) . '\')); $controller->theme = $this->theme = \'' . $this->theme . '\'; Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));'; @@ -253,6 +254,7 @@ class CacheHelper extends AppHelper { $this->loaded[$camelBackedHelper] =& ${$camelBackedHelper}; $this->{$helper} =& $loadedHelpers[$helper]; } + extract($this->viewVars, EXTR_SKIP); ?>'; $content = preg_replace("/(<\\?xml)/", "",$content); $file .= $content; diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index fd1999e9a..dbf7b5f9b 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -751,6 +751,7 @@ class View extends Object { $cache->controllerName = $this->name; $cache->layout = $this->layout; $cache->cacheAction = $this->cacheAction; + $cache->viewVars = $this->viewVars; $cache->cache($___viewFn, $out, $cached); } } diff --git a/cake/tests/cases/libs/view/helpers/cache.test.php b/cake/tests/cases/libs/view/helpers/cache.test.php index 3a42ec0fa..d2d6b43ee 100644 --- a/cake/tests/cases/libs/view/helpers/cache.test.php +++ b/cake/tests/cases/libs/view/helpers/cache.test.php @@ -308,6 +308,42 @@ class CacheHelperTest extends CakeTestCase { $this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents); } +/** + * test cache of view vars + * + * @access public + * @return void + */ + function testCacheViewVars() { + $this->Controller->cache_parsing(); + $this->Controller->params = array( + 'controller' => 'cache_test', + 'action' => 'cache_parsing', + 'url' => array(), + 'pass' => array(), + 'named' => array() + ); + $this->Controller->cacheAction = 21600; + $this->Controller->here = '/cacheTest/cache_parsing'; + $this->Controller->action = 'cache_parsing'; + + $View = new View($this->Controller); + $result = $View->render('index'); + $this->assertNoPattern('/cake:nocache/', $result); + $this->assertNoPattern('/php echo/', $result); + + $filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php'; + $this->assertTrue(file_exists($filename)); + + $contents = file_get_contents($filename); + $this->assertPattern('/\$this\-\>viewVars.*variable/', $contents); + $this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents); + $this->assertPattern('/php echo \$variable/', $contents); + $this->assertPattern('/variableValue/', $contents); + + @unlink($filename); + } + /** * test cacheAction set to a boolean * From 5d2b4c758dd2de4ac470e25416f35bcb9a3c16cb Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 18 Dec 2010 19:41:57 -0200 Subject: [PATCH 06/15] Minor optimization in cache views. --- cake/libs/view/helpers/cache.php | 10 +++++----- cake/tests/cases/libs/view/helpers/cache.test.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index 52ebd75b9..e2e911b8c 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -225,15 +225,15 @@ class CacheHelper extends AppHelper { $file .= '$controller =& new ' . $this->controllerName . 'Controller(); $controller->plugin = $this->plugin = \''.$this->plugin.'\'; - $controller->helpers = $this->helpers = unserialize(\'' . serialize($this->helpers) . '\'); + $controller->helpers = $this->helpers = ' . var_export($this->helpers, true) . '; $controller->base = $this->base = \'' . $this->base . '\'; $controller->layout = $this->layout = \'' . $this->layout. '\'; $controller->webroot = $this->webroot = \'' . $this->webroot . '\'; $controller->here = $this->here = \'' . $this->here . '\'; - $controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\')); - $controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\'); - $controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\')); - $controller->viewVars = $this->viewVars = unserialize(stripslashes(\'' . addslashes(serialize($this->viewVars)) . '\')); + $controller->params = $this->params = ' . var_export($this->params, true) . '; + $controller->action = $this->action = ' . var_export($this->action, true) . '; + $controller->data = $this->data = ' . var_export($this->data, true) . '; + $controller->viewVars = $this->viewVars = ' . var_export($this->viewVars, true) . '; $controller->theme = $this->theme = \'' . $this->theme . '\'; Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));'; diff --git a/cake/tests/cases/libs/view/helpers/cache.test.php b/cake/tests/cases/libs/view/helpers/cache.test.php index d2d6b43ee..45edea332 100644 --- a/cake/tests/cases/libs/view/helpers/cache.test.php +++ b/cake/tests/cases/libs/view/helpers/cache.test.php @@ -336,7 +336,7 @@ class CacheHelperTest extends CakeTestCase { $this->assertTrue(file_exists($filename)); $contents = file_get_contents($filename); - $this->assertPattern('/\$this\-\>viewVars.*variable/', $contents); + $this->assertPattern('/\$this\-\>viewVars/', $contents); $this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents); $this->assertPattern('/php echo \$variable/', $contents); $this->assertPattern('/variableValue/', $contents); From 04929ae1df80420bb53d6257c6125e3fe51ca70d Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Dec 2010 20:40:19 -0500 Subject: [PATCH 07/15] Applying patch from 'Thorsten Buss'. Fixes issues in DboSource, where mismatching types on join columns could result in incorrect query generation. Fixes #708 --- cake/libs/model/datasources/datasource.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 94b5d5cef..5de46be8a 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -503,6 +503,7 @@ class DataSource extends Object { foreach ($keys as $key) { $val = null; + $type = null; if (strpos($query, $key) !== false) { switch ($key) { @@ -526,6 +527,7 @@ class DataSource extends Object { $val = ''; } } + $type = $model->getColumnType($model->primaryKey); break; case '{$__cakeForeignKey__$}': foreach ($model->__associations as $id => $name) { @@ -533,6 +535,8 @@ class DataSource extends Object { if ($assocName === $association) { if (isset($assoc['foreignKey'])) { $foreignKey = $assoc['foreignKey']; + $assocModel = $model->$assocName; + $type = $assocModel->getColumnType($assocModel->primaryKey); if (isset($data[$model->alias][$foreignKey])) { $val = $data[$model->alias][$foreignKey]; @@ -561,7 +565,7 @@ class DataSource extends Object { if (empty($val) && $val !== '0') { return false; } - $query = str_replace($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query); + $query = str_replace($key, $this->value($val, $type), $query); } } return $query; From 56415f20cb95f3b68b434aa21e610eec0e75405e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 26 Dec 2010 13:02:43 -0500 Subject: [PATCH 08/15] Fixing issue where CakeLog would log suppressed errors even when error reporting was disabled. Fixes #1403 --- cake/libs/cake_log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/cake_log.php b/cake/libs/cake_log.php index efac12bcf..d84931587 100644 --- a/cake/libs/cake_log.php +++ b/cake/libs/cake_log.php @@ -253,7 +253,7 @@ class CakeLog { * @return void */ function handleError($code, $description, $file = null, $line = null, $context = null) { - if ($code === 2048 || $code === 8192) { + if ($code === 2048 || $code === 8192 || error_reporting() === 0) { return; } switch ($code) { From c5c638e8f59dc264774cde1862c3e5034f6bd09e Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 27 Dec 2010 10:40:21 -0500 Subject: [PATCH 09/15] Fixing option documentation. --- cake/libs/view/helpers/paginator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index ca5f45541..df41d5ba1 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -707,7 +707,7 @@ class PaginatorHelper extends AppHelper { * ### Options: * * - `tag` The tag wrapping tag you want to use, defaults to 'span' - * - `before` Content to insert before the link/tag + * - `after` Content to insert after the link/tag * - `model` The model to use defaults to PaginatorHelper::defaultModel() * - `separator` Content between the generated links, defaults to ' | ' * From 5092013304eba4d05789c6fc2aa8d7c575764f9c Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 27 Dec 2010 15:12:27 -0500 Subject: [PATCH 10/15] Making EmailComponent register and un-register its view object, when rendering email templates. This allows helpers to use the view to do additional processing. Fixes #442 --- cake/libs/controller/components/email.php | 4 +++- cake/tests/cases/libs/controller/components/email.test.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 3bb1357ac..c5ff866d5 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -458,7 +458,7 @@ class EmailComponent extends Object{ App::import('View', $this->Controller->view); } - $View = new $viewClass($this->Controller, false); + $View = new $viewClass($this->Controller); $View->layout = $this->layout; $msg = array(); @@ -496,6 +496,7 @@ class EmailComponent extends Object{ $msg[] = '--alt-' . $this->__boundary . '--'; $msg[] = ''; + ClassRegistry::removeObject('view'); return $msg; } @@ -525,6 +526,7 @@ class EmailComponent extends Object{ } $msg = array_merge($msg, $content); + ClassRegistry::removeObject('view'); return $msg; } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 0dbb72d0e..72c14ace6 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -538,6 +538,8 @@ MSGBLOC; * @return void */ function testTemplates() { + ClassRegistry::flush(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; $this->Controller->EmailTest->from = 'noreply@example.com'; $this->Controller->EmailTest->subject = 'Cake SMTP test'; @@ -629,6 +631,9 @@ HTMLBLOC; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '
'; $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin')); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + + $result = ClassRegistry::getObject('view'); + $this->assertFalse($result); } /** From a7061510c13cbccf3a02e7a331d66d697d98af8a Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 31 Dec 2010 13:05:04 -0500 Subject: [PATCH 11/15] Applying patch from 'rynop'. Fixing FixtureTask so it includes the datasource if its not the default one. Updating tests. Fixes #1419 --- cake/console/libs/tasks/fixture.php | 17 +++++++----- .../cases/console/libs/tasks/fixture.test.php | 26 ++++++++++++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index 54b2ca684..124d61f78 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -161,7 +161,9 @@ class FixtureTask extends BakeTask { if (!class_exists('CakeSchema')) { App::import('Model', 'CakeSchema', false); } - $table = $schema = $records = $import = $modelImport = $recordImport = null; + $table = $schema = $records = $import = $modelImport = null; + $importBits = array(); + if (!$useTable) { $useTable = Inflector::tableize($model); } elseif ($useTable != Inflector::tableize($model)) { @@ -170,16 +172,17 @@ class FixtureTask extends BakeTask { if (!empty($importOptions)) { if (isset($importOptions['schema'])) { - $modelImport = "'model' => '{$importOptions['schema']}'"; + $modelImport = true; + $importBits[] = "'model' => '{$importOptions['schema']}'"; } if (isset($importOptions['records'])) { - $recordImport = "'records' => true"; + $importBits[] = "'records' => true"; } - if ($modelImport && $recordImport) { - $modelImport .= ', '; + if ($this->connection != 'default') { + $importBits[] .= "'connection' => '{$this->connection}'"; } - if (!empty($modelImport) || !empty($recordImport)) { - $import = sprintf("array(%s%s)", $modelImport, $recordImport); + if (!empty($importBits)) { + $import = sprintf("array(%s)", implode(', ', $importBits)); } } diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index 0c456ee5c..45920d393 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -135,6 +135,17 @@ class FixtureTaskTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test that connection gets set to the import options when a different connection is used. + * + * @return void + */ + function testImportOptionsAlternateConnection() { + $this->Task->connection = 'test'; + $result = $this->Task->bake('Article', false, array('schema' => 'Article')); + $this->assertPattern("/'connection' => 'test'/", $result); + } + /** * test generating a fixture with database conditions. * @@ -287,15 +298,24 @@ class FixtureTaskTest extends CakeTestCase { $this->assertPattern('/var \$fields = array\(/', $result); $result = $this->Task->bake('Article', 'comments', array('records' => true)); - $this->assertPattern("/var \\\$import \= array\('records' \=\> true\);/", $result); + $this->assertPattern( + "/var \\\$import \= array\('records' \=\> true, 'connection' => 'test_suite'\);/", + $result + ); $this->assertNoPattern('/var \$records/', $result); $result = $this->Task->bake('Article', 'comments', array('schema' => 'Article')); - $this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\);/", $result); + $this->assertPattern( + "/var \\\$import \= array\('model' \=\> 'Article', 'connection' => 'test_suite'\);/", + $result + ); $this->assertNoPattern('/var \$fields/', $result); $result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true)); - $this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true\);/", $result); + $this->assertPattern( + "/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true, 'connection' => 'test_suite'\);/", + $result + ); $this->assertNoPattern('/var \$fields/', $result); $this->assertNoPattern('/var \$records/', $result); } From 5768bfe5c77709f987f7e6b27f1a0ce88b2b8010 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 31 Dec 2010 16:35:44 -0500 Subject: [PATCH 12/15] Fixing failing test caused by missing space. --- 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 dbaceee23..bfdbb9ccd 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -339,14 +339,14 @@ class TimeHelperTest extends CakeTestCase { if (date('Y', $time) == date('Y')) { $this->assertEqual(date('M jS, H:i', $time), $this->Time->niceShort($time)); } else { - $this->assertEqual(date('M jSY, H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual(date('M jS Y, H:i', $time), $this->Time->niceShort($time)); } $time = time(); - $this->assertEqual('Today, '.date('H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual('Today, ' . date('H:i', $time), $this->Time->niceShort($time)); $time = time() - DAY; - $this->assertEqual('Yesterday, '.date('H:i', $time), $this->Time->niceShort($time)); + $this->assertEqual('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time)); } /** From 6e2ffafe54862710d3ae27e726de058b70b83a27 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Jan 2011 22:48:09 -0500 Subject: [PATCH 13/15] Fixing Set::filter() not predictably filtering in a recursive fashion. While a minor change in behavior, more predictable and uniform behavior is worth it. Fixes #1431 --- cake/libs/set.php | 16 ++++++++++++++-- cake/tests/cases/libs/set.test.php | 14 +++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index 3d4e89f02..289c5af59 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -68,10 +68,22 @@ class Set { * @static */ function filter($var, $isArray = false) { - if (is_array($var) && (!empty($var) || $isArray)) { - return array_filter($var, array('Set', 'filter')); + foreach ((array)$var as $k => $v) { + if (!empty($v) && is_array($v)) { + $var[$k] = array_filter($v, array('Set', '_filter')); + } } + return array_filter($var, array('Set', '_filter')); + } +/** + * Set::filter callback function + * + * @param array $var Array to filter. + * @return boolean + * @access protected + */ + function _filter($var) { if ($var === 0 || $var === '0' || !empty($var)) { return true; } diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 3018c351a..9f0d9a596 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -88,8 +88,20 @@ class SetTest extends CakeTestCase { */ function testFilter() { $result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false))); - $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be', false)); + $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be')); $this->assertIdentical($result, $expected); + + $result = Set::filter(array(1, array(false))); + $expected = array(1); + $this->assertEqual($expected, $result); + + $result = Set::filter(array(1, array(false, false))); + $expected = array(1); + $this->assertEqual($expected, $result); + + $result = Set::filter(array(1, array('empty', false))); + $expected = array(1, array('empty')); + $this->assertEqual($expected, $result); } /** From f45f2e4096fc045cfa2c86e4ba757ecf2fd52fa0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Jan 2011 22:53:56 -0500 Subject: [PATCH 14/15] Making niceShort() compare the original dateString and userOffset. This fixes issues where timezone differences would cause the incorrect short form to be displayed. Fixes #1331 --- cake/libs/view/helpers/time.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index 0e04c6338..1f4d0be1c 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -226,9 +226,9 @@ class TimeHelper extends AppHelper { $y = $this->isThisYear($date) ? '' : ' %Y'; - if ($this->isToday($date)) { + if ($this->isToday($dateString, $userOffset)) { $ret = sprintf(__('Today, %s',true), strftime("%H:%M", $date)); - } elseif ($this->wasYesterday($date)) { + } elseif ($this->wasYesterday($dateString, $userOffset)) { $ret = sprintf(__('Yesterday, %s',true), strftime("%H:%M", $date)); } else { $format = $this->convertSpecifiers("%b %eS{$y}, %H:%M", $date); From 8754d11aed8c5b88fb94dcd50db765cb4c0c46b5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 6 Jan 2011 23:08:54 -0500 Subject: [PATCH 15/15] Adding EmailComponent::_getSocket() so EmailComponent + smtp is easier to test. Fixing issue where hosts with portnames could cause smtp emails to fail. Added tests, fixed an existing test to not depend on a local mailserver. Fixes #1433 --- cake/libs/controller/components/email.php | 16 ++- .../libs/controller/components/email.test.php | 103 +++++++++++++----- 2 files changed, 87 insertions(+), 32 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index c5ff866d5..78698b056 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -837,6 +837,18 @@ class EmailComponent extends Object{ return @mail($to, $this->_encode($this->subject), $message, $header, $this->additionalParams); } + +/** + * Helper method to get socket, overridden in tests + * + * @param array $config Config data for the socket. + * @return void + * @access protected + */ + function _getSocket($config) { + $this->__smtpConnection =& new CakeSocket($config); + } + /** * Sends out email via SMTP * @@ -853,7 +865,7 @@ class EmailComponent extends Object{ 'timeout' => 30 ); $this->smtpOptions = array_merge($defaults, $this->smtpOptions); - $this->__smtpConnection =& new CakeSocket($this->smtpOptions); + $this->_getSocket($this->smtpOptions); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); @@ -867,7 +879,7 @@ class EmailComponent extends Object{ if (isset($this->smtpOptions['client'])) { $host = $this->smtpOptions['client']; } elseif (!empty($httpHost)) { - $host = $httpHost; + list($host) = explode(':', $httpHost); } else { $host = 'localhost'; } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 72c14ace6..de1be084e 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -20,6 +20,9 @@ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ App::import('Component', 'Email'); +App::import('Core', 'CakeSocket'); + +Mock::generate('CakeSocket', 'MockEmailSocket'); /** * EmailTestComponent class @@ -29,6 +32,7 @@ App::import('Component', 'Email'); */ class EmailTestComponent extends EmailComponent { + var $smtpSend = ''; /** * smtpSend method override for testing * @@ -39,6 +43,19 @@ class EmailTestComponent extends EmailComponent { return parent::_smtpSend($data, $code); } +/** + * undocumented function + * + * @return void + */ + function _smtpSend($data, $code = '250') { + if ($this->_debug) { + $this->smtpSend .= $data . "\n"; + return true; + } + return parent::_smtpSend($data, $code); + } + /** * Convenience setter method for testing. * @@ -49,6 +66,18 @@ class EmailTestComponent extends EmailComponent { $this->__smtpConnection = $socket; } +/** + * Allows mocks to be used with tests. + * + * @param array $config + * @return void + */ + function _getSocket($config) { + if (empty($this->__smtpConnection)) { + parent::_getSocket($config); + } + } + /** * Convenience getter method for testing. * @@ -408,46 +437,60 @@ TEMPDOC; * @return void */ function testSmtpSendMultipleTo() { - if ($this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { - return; - } $this->Controller->EmailTest->reset(); $this->Controller->EmailTest->to = array('postmaster@localhost', 'root@localhost'); $this->Controller->EmailTest->from = 'noreply@example.com'; $this->Controller->EmailTest->subject = 'Cake SMTP multiple To test'; $this->Controller->EmailTest->replyTo = 'noreply@example.com'; $this->Controller->EmailTest->template = null; - - $this->Controller->EmailTest->delivery = 'smtp'; - $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); - $this->Controller->EmailTest->_debug = true; $this->Controller->EmailTest->sendAs = 'text'; - $expect = <<Host: localhost -Port: 25 -Timeout: 30 -To: postmaster@localhost, root@localhost -From: noreply@example.com -Subject: Cake SMTP multiple To test -Header: + $this->Controller->EmailTest->delivery = 'smtp'; + + $socket = new MockEmailSocket(); + $socket->setReturnValue('connect', true); + $this->Controller->EmailTest->setConnectionSocket($socket); -To: postmaster@localhost, root@localhost -From: noreply@example.com -Reply-To: noreply@example.com -Subject: Cake SMTP multiple To test -X-Mailer: CakePHP Email Component -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 7bitParameters: - -Message: - -This is the body of the message - - -TEMPDOC; $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); - $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + + $this->assertPattern('/EHLO localhost\n/', $this->Controller->EmailTest->smtpSend); + $this->assertPattern('/MAIL FROM: \n/', $this->Controller->EmailTest->smtpSend); + $this->assertPattern('/RCPT TO: \n/', $this->Controller->EmailTest->smtpSend); + $this->assertPattern('/RCPT TO: \n/', $this->Controller->EmailTest->smtpSend); + $this->assertPattern( + '/To: postmaster@localhost, root@localhost[\n\r]/', + $this->Controller->EmailTest->smtpSend + ); + } + +/** + * test sending smtp from a host using a port. + * + * @return void + */ + function testSmtpSendHostWithPort() { + $bkp = env('HTTP_HOST'); + $_SERVER['HTTP_HOST'] = 'localhost:8080'; + + $this->Controller->EmailTest->reset(); + $this->Controller->EmailTest->to = array('root@localhost'); + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP host test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'smtp'; + $this->Controller->EmailTest->sendAs = 'text'; + $this->Controller->EmailTest->_debug = true; + + $socket = new MockEmailSocket(); + $socket->setReturnValue('connect', true); + + $this->Controller->EmailTest->setConnectionSocket($socket); + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); + + $this->assertPattern('/EHLO localhost\n/', $this->Controller->EmailTest->smtpSend); + + $_SERVER['HTTP_HOST'] = $bkp; } /**