From 3a81a9e6f28d3512ee2dc8c8cf127432a2e327a6 Mon Sep 17 00:00:00 2001 From: predominant Date: Thu, 20 May 2010 12:17:52 +1000 Subject: [PATCH 01/57] Remove unnecessary spaces. --- cake/libs/view/pages/home.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index 848ab3ad3..e61349ade 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -106,7 +106,7 @@ You can also add some CSS styles for your pages at: APP/webroot/css.');

Html->link( - sprintf('%s%s', __('new', true ), __('CakePHP 1.3 Docs', true )), + sprintf('%s%s', __('new', true), __('CakePHP 1.3 Docs', true)), 'http://book.cakephp.org/view/875/x1-3-Collection', array('target' => '_blank', 'escape' => false) ); From 82250efc3e31e7ed802c2bd6f2d032055ac93229 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 May 2010 22:58:20 -0400 Subject: [PATCH 02/57] Updating doc blocks for FormHelper::input() refs #735 --- cake/libs/view/helpers/form.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 82f3defed..5e2fb57c5 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -684,9 +684,10 @@ class FormHelper extends AppHelper { * - `after` - Content to place after the label + input. * - `between` - Content to place between the label + input. * - `format` - format template for element order. Any element that is not in the array, will not be in the output. - * Default input format order: array('before', 'label', 'between', 'input', 'after', 'error') - * Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error') - * Hidden input will not be formatted + * - Default input format order: array('before', 'label', 'between', 'input', 'after', 'error') + * - Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error') + * - Hidden input will not be formatted + * - Radio buttons cannot have the order of input and label elements controlled with these settings. * * @param string $fieldName This should be "Modelname.fieldname" * @param array $options Each type of input takes different options. From 78653347b2ad9ad2124e4ddf0be0ac81d5b5f227 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 May 2010 23:13:45 -0400 Subject: [PATCH 03/57] Removing request time output from index.php. Makes non sgml requests like json easier to do. Fixes #720 --- app/webroot/index.php | 3 --- cake/console/templates/skel/webroot/index.php | 3 --- 2 files changed, 6 deletions(-) diff --git a/app/webroot/index.php b/app/webroot/index.php index 74a356664..396775b73 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -82,6 +82,3 @@ $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(); } - if (Configure::read() > 0) { - echo ""; - } diff --git a/cake/console/templates/skel/webroot/index.php b/cake/console/templates/skel/webroot/index.php index 74a356664..396775b73 100644 --- a/cake/console/templates/skel/webroot/index.php +++ b/cake/console/templates/skel/webroot/index.php @@ -82,6 +82,3 @@ $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(); } - if (Configure::read() > 0) { - echo ""; - } From 23d4bafd39fe6334511b357e63ade319a924631b Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 21 May 2010 23:49:49 -0400 Subject: [PATCH 04/57] Fixing inflection of words ending in causes. Fixes #736 --- cake/libs/inflector.php | 2 +- cake/tests/cases/libs/inflector.test.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 83590ace9..46fc540be 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -121,7 +121,7 @@ class Inflector { '/(shoe|slave)s$/i' => '\1', '/(o)es$/i' => '\1', '/ouses$/' => 'ouse', - '/uses$/' => 'us', + '/([^a])uses$/' => '\1us', '/([m|l])ice$/i' => '\1ouse', '/(x|ch|ss|sh)es$/i' => '\1', '/(m)ovies$/i' => '\1\2ovie', diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index e50855915..c894e8a65 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -119,6 +119,8 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::singularize('genetic_analyses'), 'genetic_analysis'); $this->assertEqual(Inflector::singularize('doctor_diagnoses'), 'doctor_diagnosis'); $this->assertEqual(Inflector::singularize('parantheses'), 'paranthesis'); + $this->assertEqual(Inflector::singularize('Causes'), 'Cause'); + $this->assertEqual(Inflector::singularize('colossuses'), 'colossus'); $this->assertEqual(Inflector::singularize(''), ''); } From 29f2223c6de2d1ce99dc83625f7449d97fbe1799 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 22 May 2010 00:58:54 -0400 Subject: [PATCH 05/57] Removing hardcoded '__' for virtualField separators. Making it an instance property instead. This allows the customization of the separator if needed. Tests added for DboMysql. Refs #655, #730 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 2 +- cake/libs/model/datasources/dbo_source.php | 13 ++++++++++--- .../model/datasources/dbo/dbo_mysql.test.php | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 8648b0a2b..d06d71830 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -728,7 +728,7 @@ class DboMysql extends DboMysqlBase { while ($j < $numFields) { $column = mysql_fetch_field($results, $j); - if (!empty($column->table) && strpos($column->name, '__') === false) { + if (!empty($column->table) && strpos($column->name, $this->virtualFieldSeparator) === false) { $this->map[$index++] = array($column->table, $column->name); } else { $this->map[$index++] = array(0, $column->name); diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 40a74736e..69945aeaf 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -97,6 +97,13 @@ class DboSource extends DataSource { 'rollback' => 'ROLLBACK' ); +/** + * Separator string for virtualField composition + * + * @var string + */ + var $virtualFieldSeparator = '__'; + /** * List of table engine specific parameters used on table creating * @@ -432,10 +439,10 @@ class DboSource extends DataSource { function fetchVirtualField(&$result) { if (isset($result[0]) && is_array($result[0])) { foreach ($result[0] as $field => $value) { - if (strpos($field, '__') === false) { + if (strpos($field, $this->virtualFieldSeparator) === false) { continue; } - list($alias, $virtual) = explode('__', $field); + list($alias, $virtual) = explode($this->virtualFieldSeparator, $field); if (!ClassRegistry::isKeySet($alias)) { return; @@ -1902,7 +1909,7 @@ class DboSource extends DataSource { function _constructVirtualFields(&$model, $alias, $fields) { $virtual = array(); foreach ($fields as $field) { - $virtualField = $this->name("{$alias}__{$field}"); + $virtualField = $this->name($alias . $this->virtualFieldSeparator . $field); $expression = $this->__quoteFields($model->getVirtualField($field)); $virtual[] = '(' .$expression . ") {$this->alias} {$virtualField}"; } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index a017e7788..f79b84298 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -759,4 +759,22 @@ class DboMysqlTest extends CakeTestCase { $this->assertEqual($result, 'cp1250'); } +/** + * test that changing the virtualFieldSeparator allows for __ fields. + * + * @return void + */ + function testVirtualFieldSeparators() { + $model =& new CakeTestModel(array('table' => 'binary_tests', 'ds' => 'test_suite', 'name' => 'BinaryTest')); + $model->virtualFields = array( + 'other__field' => 'SUM(id)' + ); + + $this->db->virtualFieldSeparator = '_$_'; + $result = $this->db->fields($model, null, array('data', 'other__field')); + $expected = array('`BinaryTest`.`data`', '(SUM(id)) AS BinaryTest_$_other__field'); + $this->assertEqual($result, $expected); + + } + } From 06c1b583f8f3297153be978e1e192a3dd18e66b5 Mon Sep 17 00:00:00 2001 From: tarcisio Date: Fri, 21 May 2010 22:47:53 -0300 Subject: [PATCH 06/57] fix typo in CakeLog::config() Signed-off-by: mark_story --- 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 f05f86490..efac12bcf 100644 --- a/cake/libs/cake_log.php +++ b/cake/libs/cake_log.php @@ -91,7 +91,7 @@ class CakeLog { * * For an explaination of these parameters, see CakeLog::write() * - * @param string $key The keyname for this logger, used to revmoe the logger later. + * @param string $key The keyname for this logger, used to remove the logger later. * @param array $config Array of configuration information for the logger * @return boolean success of configuration. * @static From 7d51952801c14a88caa5ad7a1729e4de871e60ba Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 23 May 2010 02:14:07 +0530 Subject: [PATCH 07/57] Removing protected var CakeSession::_started and instead session_id() is now used to check if session is started in CakeSession::started(). This fixes issue where CakeSession::started() returned incorrect value when used across multiple objects. Closes #731 --- cake/libs/cake_session.php | 14 +++----------- cake/tests/cases/libs/cake_session.test.php | 4 ++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 97fb04571..ddefa4506 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -114,14 +114,6 @@ class CakeSession extends Object { */ var $id = null; -/** - * Session Started - * - * @var boolean - * @access protected - */ - var $_started = false; - /** * Hostname * @@ -216,7 +208,7 @@ class CakeSession extends Object { session_write_close(); } $this->__initSession(); - $this->_started = $this->__startSession(); + $this->__startSession(); return $this->started(); } @@ -227,7 +219,7 @@ class CakeSession extends Object { * @return boolean True if session has been started. */ function started() { - if (isset($_SESSION) && $this->_started) { + if (isset($_SESSION) && session_id()) { return true; } return false; @@ -795,5 +787,5 @@ class CakeSession extends Object { $return = $model->deleteAll(array($model->alias . ".expires <" => $expires), false, false); return $return; - } + } } diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index b58700bc3..c80eb3c26 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -170,6 +170,10 @@ class CakeSessionTest extends CakeTestCase { $_SESSION = null; $this->assertFalse($this->Session->started()); $this->assertTrue($this->Session->start()); + + $session = new CakeSession(null, false); + $this->assertTrue($session->started()); + unset($session); } /** From 2d449295981fbcceb9217a82e680383e0ee41c02 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 18 Apr 2010 22:22:09 -0300 Subject: [PATCH 08/57] Optimization on dbo datasource to not repeat ids in find. Fixes #601 Signed-off-by: mark_story --- cake/libs/model/datasources/dbo_source.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 69945aeaf..db5dca354 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -924,6 +924,7 @@ class DboSource extends DataSource { } if (!empty($ins)) { + $ins = array_unique($ins); $fetch = $this->fetchAssociated($model, $query, $ins); } @@ -955,10 +956,10 @@ class DboSource extends DataSource { } } if (!empty($ins)) { + $ins = array_unique($ins); if (count($ins) > 1) { $query = str_replace('{$__cakeID__$}', '(' .implode(', ', $ins) .')', $query); $query = str_replace('= (', 'IN (', $query); - $query = str_replace('= (', 'IN (', $query); } else { $query = str_replace('{$__cakeID__$}',$ins[0], $query); } @@ -1060,7 +1061,6 @@ class DboSource extends DataSource { $query = str_replace('{$__cakeID__$}', implode(', ', $ids), $query); if (count($ids) > 1) { $query = str_replace('= (', 'IN (', $query); - $query = str_replace('= (', 'IN (', $query); } return $this->fetchAll($query, $model->cacheQueries, $model->alias); } @@ -2179,7 +2179,7 @@ class DboSource extends DataSource { } } elseif (is_array($value) && !empty($value) && !$valueInsert) { $keys = array_keys($value); - if (array_keys($value) === array_values(array_keys($value))) { + if ($keys === array_values($keys)) { $count = count($value); if ($count === 1) { $data = $this->__quoteFields($key) . ' = ('; From bc3e745673385e0f48da3fa90cda5cc6fbaddf26 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Mon, 24 May 2010 22:24:58 -0300 Subject: [PATCH 09/57] Support to EHLO in SMTP server for EmailComponent. Fixes #54, #712, #737 --- cake/libs/controller/components/email.php | 16 ++++-- .../libs/controller/components/email.test.php | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 94ef82a3b..d18784abb 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -808,7 +808,7 @@ class EmailComponent extends Object{ $host = 'localhost'; } - if (!$this->_smtpSend("HELO {$host}", '250')) { + if (!$this->_smtpSend("EHLO {$host}", '250') || !$this->_smtpSend("HELO {$host}", '250')) { return false; } @@ -868,22 +868,26 @@ class EmailComponent extends Object{ } /** - * Private method for sending data to SMTP connection + * Protected method for sending data to SMTP connection * * @param string $data data to be sent to SMTP server * @param mixed $checkCode code to check for in server response, false to skip * @return bool Success - * @access private + * @access protected */ function _smtpSend($data, $checkCode = '250') { if (!is_null($data)) { $this->__smtpConnection->write($data . "\r\n"); } - if ($checkCode !== false) { + while ($checkCode !== false) { $response = $this->__smtpConnection->read(); + $response = end(explode("\r\n", rtrim($response, "\r\n"))); - if (preg_match('/^(' . $checkCode . ')/', $response, $code)) { - return $code[0]; + if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { + if ($code[2] === '-') { + continue; + } + return $code[1]; } $this->smtpError = $response; return false; diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 1267c96a7..f5de3e9d2 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -295,6 +295,61 @@ TEMPDOC; $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); } +/** + * testSmtpEhlo method + * + * @access public + * @return void + */ + function testSmtpEhlo() { + if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + return; + } + + $connection =& new CakeSocket(array('protocol'=>'smtp', 'host' => 'localhost', 'port' => 25)); + $this->Controller->EmailTest->setConnectionSocket($connection); + $this->assertTrue($connection->connect()); + $this->assertTrue($this->Controller->EmailTest->smtpSend(null, '220') !== false); + $this->skipIf($this->Controller->EmailTest->smtpSend('EHLO locahost', '250') === false, '%s do not support EHLO.'); + $connection->disconnect(); + + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP 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 +From: noreply@example.com +Subject: Cake SMTP test +Header: + +To: postmaster@localhost +From: noreply@example.com +Reply-To: noreply@example.com +Subject: Cake SMTP 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)); + } /** * testSmtpSendMultipleTo method From 64adfacd3ec9ef11c9c29218e972059bdb6be9f7 Mon Sep 17 00:00:00 2001 From: Martin Radosta Date: Wed, 19 May 2010 05:54:51 -0300 Subject: [PATCH 10/57] Making DboSource::order() accept an expression object. Fixes issues with sql parsing over quoting special SQL syntax. Tests added. Fixes #747 Signed-off-by: mark_story --- cake/libs/model/datasources/dbo_source.php | 3 +++ .../libs/model/datasources/dbo_source.test.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index db5dca354..4bd56e849 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2411,6 +2411,9 @@ class DboSource extends DataSource { } } continue; + } elseif (is_object($key) && isset($key->type) && $key->type === 'expression') { + $result[] = $key->value; + continue; } if (preg_match('/\\x20(ASC|DESC).*/i', $key, $_dir)) { diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index ead5a9d7b..73f86be55 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2966,6 +2966,19 @@ class DboSourceTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } + +/** + * test that order() will accept objects made from DboSource::expression + * + * @return void + */ + function testOrderWithExpression() { + $expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"); + $result = $this->testDb->order($expression); + $expected = " ORDER BY CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"; + $this->assertEqual($result, $expected); + } + /** * testMergeAssociations method * From 8b6c974cd0879228a5f9363450763eeaf71963cd Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 May 2010 00:01:17 -0400 Subject: [PATCH 11/57] Making FileEngine not greedily clear files in a directory that may belong to another cache configuration. Tests added. Fixes #754 --- cake/libs/cache/file.php | 4 ++++ cake/tests/cases/libs/cache/file.test.php | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index e8e8ffdad..3494c62ce 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -209,7 +209,11 @@ class FileEngine extends CacheEngine { $now = time(); $threshold = $now - $this->settings['duration']; } + $prefixLength = strlen($this->settings['prefix']); while (($entry = $dir->read()) !== false) { + if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) { + continue; + } if ($this->_setKey($entry) === false) { continue; } diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index 15ee52673..ffb571f73 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -273,6 +273,34 @@ class FileEngineTest extends CakeTestCase { Cache::config('default', array('engine' => 'File', 'path' => CACHE)); } +/** + * test that clear() doesn't wipe files not in the current engine's prefix. + * + * @return void + */ + function testClearWithPrefixes() { + $FileOne =& new FileEngine(); + $FileOne->init(array( + 'prefix' => 'prefix_one_', + 'duration' => DAY + )); + $FileTwo =& new FileEngine(); + $FileTwo->init(array( + 'prefix' => 'prefix_two_', + 'duration' => DAY + )); + + $data1 = $data2 = $expected = 'content to cache'; + $FileOne->write('key_one', $data1, DAY); + $FileTwo->write('key_two', $data2, DAY); + + $this->assertEqual($FileOne->read('key_one'), $expected); + $this->assertEqual($FileTwo->read('key_two'), $expected); + + $FileOne->clear(false); + $this->assertEqual($FileTwo->read('key_two'), $expected, 'secondary config was cleared by accident.'); + } + /** * testKeyPath method * From e02cb81a6707332bf01d8268a0073ae47d8c228f Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 29 May 2010 12:04:29 -0300 Subject: [PATCH 12/57] Reading a smtp response until EOL. Fixes #378 --- cake/libs/controller/components/email.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index d18784abb..5ee9f531f 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -880,7 +880,15 @@ class EmailComponent extends Object{ $this->__smtpConnection->write($data . "\r\n"); } while ($checkCode !== false) { - $response = $this->__smtpConnection->read(); + $response = ''; + $startTime = time(); + while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) { + $response .= $this->__smtpConnection->read(); + } + if (substr($response, -2) === "\r\n") { + $this->smtpError = 'timeout'; + return false; + } $response = end(explode("\r\n", rtrim($response, "\r\n"))); if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { From f06f0dae8be7be2cf6ed571d5e46c58959814f53 Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 30 May 2010 01:10:48 +1000 Subject: [PATCH 13/57] Numerous "Enter description here" block comments updated to have meaningful descriptions. --- app/webroot/css.php | 10 ++-- cake/console/templates/skel/webroot/css.php | 6 +-- cake/libs/model/datasources/datasource.php | 2 +- cake/libs/model/datasources/dbo/dbo_mysql.php | 4 +- .../libs/model/datasources/dbo/dbo_mysqli.php | 4 +- .../libs/model/datasources/dbo/dbo_oracle.php | 46 +++++++++---------- .../libs/model/datasources/dbo/dbo_sqlite.php | 4 +- cake/libs/view/helpers/number.php | 2 +- 8 files changed, 40 insertions(+), 38 deletions(-) diff --git a/app/webroot/css.php b/app/webroot/css.php index 445b2fb2e..aae68cba8 100644 --- a/app/webroot/css.php +++ b/app/webroot/css.php @@ -1,6 +1,6 @@ array('name' => 'inet')); /** - * Enter description here... + * Connection object * - * @var unknown_type + * @var mixed * @access protected */ var $connection; /** - * Enter description here... + * Query limit * - * @var unknown_type + * @var int * @access protected */ var $_limit = -1; /** - * Enter description here... + * Query offset * - * @var unknown_type + * @var int * @access protected */ var $_offset = 0; @@ -109,25 +109,25 @@ class DboOracle extends DboSource { var $_map; /** - * Enter description here... + * Current Row * - * @var unknown_type + * @var mixed * @access protected */ var $_currentRow; /** - * Enter description here... + * Number of rows * - * @var unknown_type + * @var int * @access protected */ var $_numRows; /** - * Enter description here... + * Query results * - * @var unknown_type + * @var mixed * @access protected */ var $_results; @@ -378,9 +378,9 @@ class DboOracle extends DboSource { } /** - * Enter description here... + * Fetch result row * - * @return unknown + * @return array * @access public */ function fetchRow() { @@ -444,10 +444,10 @@ class DboOracle extends DboSource { } /** - * Enter description here... + * Create trigger * - * @param unknown_type $table - * @return unknown + * @param string $table + * @return mixed * @access public */ function createTrigger($table) { diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index 1fdba32a8..efc660f33 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -29,9 +29,9 @@ class DboSqlite extends DboSource { /** - * Enter description here... + * Datasource Description * - * @var unknown_type + * @var string */ var $description = "SQLite DBO Driver"; diff --git a/cake/libs/view/helpers/number.php b/cake/libs/view/helpers/number.php index da8a565a6..236732a92 100644 --- a/cake/libs/view/helpers/number.php +++ b/cake/libs/view/helpers/number.php @@ -69,7 +69,7 @@ class NumberHelper extends AppHelper { * * @param float $number A floating point number. * @param integer $precision The precision of the returned number. - * @return float Enter description here... + * @return float Formatted float. * @access public * @link http://book.cakephp.org/view/1454/precision */ From 8decc683ac46f5f00e026ef2cbeb4873330f3e2e Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 30 May 2010 01:20:28 +1000 Subject: [PATCH 14/57] Numerous 'shoer description' documentation entries updated to contain useful comments. --- cake/console/libs/console.php | 2 +- cake/console/libs/i18n.php | 2 +- cake/console/templates/skel/app_controller.php | 4 ++-- cake/console/templates/skel/app_helper.php | 2 +- cake/console/templates/skel/config/acl.ini.php | 2 +- cake/console/templates/skel/config/routes.php | 2 +- cake/console/templates/skel/webroot/css.php | 2 +- cake/libs/controller/app_controller.php | 2 +- cake/libs/controller/components/cookie.php | 2 +- cake/libs/controller/components/email.php | 2 +- cake/libs/controller/components/security.php | 5 +++-- cake/libs/i18n.php | 2 +- cake/libs/l10n.php | 4 ++-- cake/libs/model/behaviors/acl.php | 2 +- cake/libs/model/behaviors/translate.php | 4 ++-- cake/libs/model/datasources/dbo/dbo_mssql.php | 2 +- cake/libs/model/datasources/dbo/dbo_oracle.php | 2 +- cake/libs/model/datasources/dbo_source.php | 2 +- cake/libs/model/db_acl.php | 2 +- cake/libs/security.php | 2 +- cake/libs/view/helpers/app_helper.php | 2 +- cake/tests/cases/libs/controller/components/acl.test.php | 2 +- 22 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cake/console/libs/console.php b/cake/console/libs/console.php index 41e4d4634..ac7b595bb 100644 --- a/cake/console/libs/console.php +++ b/cake/console/libs/console.php @@ -1,6 +1,6 @@ ; SVN FILE: $Id$ ;/** -; * Short description for file. +; * ACL Configuration ; * ; * ; * PHP versions 4 and 5 diff --git a/cake/console/templates/skel/config/routes.php b/cake/console/templates/skel/config/routes.php index 696c49a87..9e4a28c14 100644 --- a/cake/console/templates/skel/config/routes.php +++ b/cake/console/templates/skel/config/routes.php @@ -1,6 +1,6 @@ Date: Sat, 29 May 2010 12:06:36 -0300 Subject: [PATCH 15/57] Changing break; to continue; so it will process the next tables on the array, tests added. --- cake/libs/model/cake_schema.php | 2 +- .../cases/libs/model/cake_schema.test.php | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index adee3df01..7901cdf09 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -451,7 +451,7 @@ class CakeSchema extends Object { $tables = array(); foreach ($new as $table => $fields) { if ($table == 'missing') { - break; + continue; } if (!array_key_exists($table, $old)) { $tables[$table]['add'] = $fields; diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 664364e3d..c07b9d998 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -743,6 +743,45 @@ class CakeSchemaTest extends CakeTestCase { ), ); $this->assertEqual($expected, $compare); + + $tables = array( + 'missing' => array( + 'categories' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 100), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), + 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') + ) + ), + 'ratings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), + 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL), + 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), + 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') + ) + ); + $compare = $New->compare($this->Schema, $tables); + $expected = array( + 'ratings' => array( + 'add' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), + 'model' => array('type' => 'varchar', 'null' => false, 'default' => NULL), + 'value' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), + 'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM') + ) + ) + ); + $this->assertEqual($expected, $compare); } /** From 25a6a3cac84b34a3d5a93cbca0ec4e1910dc4901 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 29 May 2010 12:47:31 -0400 Subject: [PATCH 16/57] Correcting spacing in file test. Correctly constructing a File object, so testRead does not rely on the previous test to leave the object in the correct state. --- cake/tests/cases/libs/file.test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 10ff17ac0..8cb372eff 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -104,6 +104,9 @@ class FileTest extends CakeTestCase { * @return void */ function testRead() { + $file = __FILE__; + $this->File =& new File($file); + $result = $this->File->read(); $expecting = file_get_contents(__FILE__); $this->assertEqual($result, $expecting); @@ -445,7 +448,7 @@ class FileTest extends CakeTestCase { * @return void */ function _getTmpFile($paintSkip = true) { - $tmpFile = TMP.'tests'.DS.'cakephp.file.test.tmp'; + $tmpFile = TMP . 'tests' . DS . 'cakephp.file.test.tmp'; if (is_writable(dirname($tmpFile)) && (!file_exists($tmpFile) || is_writable($tmpFile))) { return $tmpFile; }; @@ -454,14 +457,14 @@ class FileTest extends CakeTestCase { $caller = 'test'; if (function_exists('debug_backtrace')) { $trace = debug_backtrace(); - $caller = $trace[1]['function'].'()'; + $caller = $trace[1]['function'] . '()'; } $assertLine = new SimpleStackTrace(array(__FUNCTION__)); $assertLine = $assertLine->traceMethod(); $shortPath = substr($tmpFile, strlen(ROOT)); $message = '[FileTest] Skipping %s because "%s" not writeable!'; - $message = sprintf(__($message, true), $caller, $shortPath).$assertLine; + $message = sprintf(__($message, true), $caller, $shortPath) . $assertLine; $this->_reporter->paintSkip($message); } return false; From 7cde3094f0c741abbe6b0b14d8894da343c9bf7b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 29 May 2010 12:50:42 -0400 Subject: [PATCH 17/57] Removing trim() that was performed when reading a file with a lock() enabled. This was causing a failure in php5. --- cake/libs/file.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cake/libs/file.php b/cake/libs/file.php index 2d41d7202..ed0e2334f 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -185,7 +185,6 @@ class File extends Object { while (!feof($this->handle)) { $data .= fgets($this->handle, 4096); } - $data = trim($data); if ($this->lock !== null) { flock($this->handle, LOCK_UN); From dea33f64520eb181c0bfcba73201858a9024d720 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 29 May 2010 13:19:12 -0400 Subject: [PATCH 18/57] Fixing pass by reference errors in php5.3. Fixes #451 --- cake/libs/model/model_behavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/model/model_behavior.php b/cake/libs/model/model_behavior.php index 77a4157ff..140a8831d 100644 --- a/cake/libs/model/model_behavior.php +++ b/cake/libs/model/model_behavior.php @@ -176,7 +176,7 @@ class ModelBehavior extends Object { case 5: return $this->{$method}($model, $params[0], $params[1], $params[2], $params[3], $params[4]); default: - array_unshift($params, $model); + $params = array_merge(array(&$model), $params); return call_user_func_array(array(&$this, $method), $params); break; } From 0180daaad372063f42e4850d0f35ccfc9ce874fb Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 29 May 2010 13:26:34 -0400 Subject: [PATCH 19/57] Updating version numbers to 1.3.1 --- cake/VERSION.txt | 3 +-- cake/config/config.php | 2 +- cake/libs/view/pages/home.ctp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cake/VERSION.txt b/cake/VERSION.txt index 4276a6cf6..271b0e83c 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -18,5 +18,4 @@ // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -1.3.0 - +1.3.1 diff --git a/cake/config/config.php b/cake/config/config.php index d01327da1..ce6f59afd 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -17,4 +17,4 @@ * @since CakePHP(tm) v 1.1.11.4062 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -return $config['Cake.version'] = '1.3.0'; +return $config['Cake.version'] = '1.3.1'; diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index e61349ade..fa2eb4a95 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -21,7 +21,7 @@ if (Configure::read() == 0): endif; ?>

- + 0): Debugger::checkSecurityKeys(); From 9cd73c345e043c878c69df40286ae407d6ba165e Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 30 May 2010 14:29:32 +1000 Subject: [PATCH 20/57] Update short description doc blocks. --- app/config/acl.ini.php | 2 +- app/config/routes.php | 2 +- cake/config/paths.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/config/acl.ini.php b/app/config/acl.ini.php index 84fce6d91..0907fbd4d 100644 --- a/app/config/acl.ini.php +++ b/app/config/acl.ini.php @@ -1,7 +1,7 @@ ; ; SVN FILE: $Id$ ;/** -; * Short description for file. +; * ACL configuration ; * ; * ; * PHP versions 4 and 5 diff --git a/app/config/routes.php b/app/config/routes.php index 3fca7f1bd..a186e49b4 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -1,6 +1,6 @@ Date: Sun, 30 May 2010 11:16:40 -0400 Subject: [PATCH 21/57] Reverting change made in [7cde309]. Readding trim() to fix issues on windows. Updating tests so they continue to pass on macos. Fixes #769 --- cake/libs/file.php | 2 +- cake/tests/cases/libs/file.test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/file.php b/cake/libs/file.php index ed0e2334f..6d01fa29f 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -192,7 +192,7 @@ class File extends Object { if ($bytes === false) { $this->close(); } - return $data; + return trim($data); } /** diff --git a/cake/tests/cases/libs/file.test.php b/cake/tests/cases/libs/file.test.php index 8cb372eff..978c68c43 100644 --- a/cake/tests/cases/libs/file.test.php +++ b/cake/tests/cases/libs/file.test.php @@ -115,7 +115,7 @@ class FileTest extends CakeTestCase { $this->File->lock = true; $result = $this->File->read(); $expecting = file_get_contents(__FILE__); - $this->assertEqual($result, $expecting); + $this->assertEqual($result, trim($expecting)); $this->File->lock = null; $data = $expecting; From 66a8890f4fcc6c8271da2181ac66deb1f7291772 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 May 2010 12:51:48 -0400 Subject: [PATCH 22/57] Fixing code formatting in test cases. --- cake/tests/cases/libs/model/datasources/dbo_source.test.php | 2 +- cake/tests/cases/libs/model/model_read.test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 73f86be55..b3b7030db 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4316,7 +4316,7 @@ class DboSourceTest extends CakeTestCase { ' WHERE Article.id = ' . $this->db->fullTableName('comments') . '.article_id' ); $conditions = array('two' => 2); - $result = $this->db->conditions($conditions,true,false,$Article); + $result = $this->db->conditions($conditions, true, false, $Article); $expected = '(1 + 1) = 2'; $this->assertEqual($expected, $result); diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 341d73b35..745858b97 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -7223,7 +7223,7 @@ class ModelReadTest extends BaseModelTest { $dbo =& $Post->getDataSource(); $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('first',array( + $result = $Post->find('first', array( 'conditions' => array('other_field' => 3), 'limit' => 1 )); @@ -7231,7 +7231,7 @@ class ModelReadTest extends BaseModelTest { $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('all',array( - 'fields' => array($dbo->calculate($Post, 'max',array('other_field'))) + 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) )); $this->assertEqual($result[0][0]['other_field'], 4); From c98a82c61c5ebc0733da89c0cbae179a2d170d97 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 May 2010 20:28:00 -0400 Subject: [PATCH 23/57] Fixing whitespace. --- cake/tests/cases/libs/model/model_read.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 745858b97..621bd6dfc 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -7230,7 +7230,7 @@ class ModelReadTest extends BaseModelTest { $this->assertEqual($result['Post']['id'], 2); $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('all',array( + $result = $Post->find('all', array( 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) )); $this->assertEqual($result[0][0]['other_field'], 4); From 7ed67e59598e71987168fba2db20362c9ffb4223 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 30 May 2010 20:30:58 -0400 Subject: [PATCH 24/57] Fixing virtualFields used in order clauses where virtualField was supplied with model alias. Tests added. Refs #768 --- cake/libs/model/datasources/dbo_source.php | 16 ++++++++-------- .../libs/model/datasources/dbo_source.test.php | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 128b0c309..29bd1fcb8 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2421,17 +2421,17 @@ class DboSource extends DataSource { $key = preg_replace('/\\x20(ASC|DESC).*/i', '', $key); } + $key = trim($key); + + if (is_object($model) && $model->isVirtualField($key)) { + $key = '(' . $this->__quoteFields($model->getVirtualField($key)) . ')'; + } + if (strpos($key, '.')) { $key = preg_replace_callback('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', array(&$this, '__quoteMatchedField'), $key); } - - $key = trim($key); - if (!preg_match('/\s/', $key) && !strpos($key,'.')) { - if (is_object($model) && $model->isVirtualField($key)) { - $key = '('.$this->__quoteFields($model->getVirtualField($key)).')'; - } else { - $key = $this->name($key); - } + if (!preg_match('/\s/', $key) && !strpos($key, '.')) { + $key = $this->name($key); } $key .= ' ' . trim($dir); $result[] = $key; diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index b3b7030db..2ba412ab4 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4353,6 +4353,11 @@ class DboSourceTest extends CakeTestCase { $result = $this->db->order($order, 'ASC', $Article); $expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC'; $this->assertEqual($expected, $result); + + $order = array('Article.two', 'Article.this_moment'); + $result = $this->db->order($order, 'ASC', $Article); + $expected = ' ORDER BY (1 + 1) ASC, (NOW()) ASC'; + $this->assertEqual($expected, $result); } /** From 74dad04323e289c2259e77d6d6e4bb696fba32b4 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 30 May 2010 23:29:21 -0300 Subject: [PATCH 25/57] Fixing read from SMTP by EmailComponent. Closes #772 --- 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 202f45384..bbc41e72d 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -885,7 +885,7 @@ class EmailComponent extends Object{ while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) { $response .= $this->__smtpConnection->read(); } - if (substr($response, -2) === "\r\n") { + if (substr($response, -2) !== "\r\n") { $this->smtpError = 'timeout'; return false; } From 8d8fce4429d0e24d575d5e1a9290b6816baa1024 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 31 May 2010 21:26:55 -0400 Subject: [PATCH 26/57] Fixing template task path replacements under windows. Fixes #771 --- cake/console/libs/tasks/template.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/console/libs/tasks/template.php b/cake/console/libs/tasks/template.php index f4338234c..84c921d25 100644 --- a/cake/console/libs/tasks/template.php +++ b/cake/console/libs/tasks/template.php @@ -54,7 +54,8 @@ class TemplateTask extends Shell { function _findThemes() { $paths = App::path('shells'); $core = array_pop($paths); - $core = preg_replace('#libs' . DS . '$#', '', $core); + $separator = DS === '/' ? '/' : '\\\\'; + $core = preg_replace('#libs' . $separator . '$#', '', $core); $paths[] = $core; $Folder =& new Folder($core . 'templates' . DS . 'default'); $contents = $Folder->read(); From 7682c5896e269797741417c5d40db2f5024d387f Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 1 Jun 2010 23:41:51 -0400 Subject: [PATCH 27/57] Changing how merged rules are cleared so it doesn't generated notice errors in PHP4. Test added. Fixes #762 --- cake/libs/inflector.php | 5 +++- cake/tests/cases/libs/inflector.test.php | 35 ++++++++++-------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 46fc540be..dc0f78f6b 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -369,7 +369,10 @@ class Inflector { } else { $_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]); } - unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)], $_this->{$var}['merged'][$rule]); + unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)]); + if (isset($_this->{$var}['merged'][$rule])) { + unset($_this->{$var}['merged'][$rule]); + } if ($type === 'plural') { $_this->_pluralized = $_this->_tableize = array(); } elseif ($type === 'singular') { diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index c894e8a65..519b39978 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -42,16 +42,6 @@ class InflectorTest extends CakeTestCase { */ var $Inflector = null; -/** - * setUp method - * - * @access public - * @return void - */ - function setUp() { - $this->Inflector = Inflector::getInstance(); - } - /** * testInstantiation method * @@ -59,7 +49,8 @@ class InflectorTest extends CakeTestCase { * @return void */ function testInstantiation() { - $this->assertEqual(Inflector::getInstance(), $this->Inflector); + $Inflector =& Inflector::getInstance(); + $this->assertEqual(Inflector::getInstance(), $Inflector); } /** @@ -339,6 +330,19 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::humanize('file_systems'), 'File Systems'); } +/** + * This test if run in isolation should not cause errors in PHP4. + * + * @return void + */ + function testRulesNoErrorPHP4() { + Inflector::rules('plural', array( + 'rules' => array(), + 'irregular' => array(), + 'uninflected' => array('pays') + )); + } + /** * testCustomPluralRule method * @@ -455,13 +459,4 @@ class InflectorTest extends CakeTestCase { $this->assertEqual(Inflector::singularize('Atlas'), 'Atlas'); } -/** - * tearDown method - * - * @access public - * @return void - */ - function tearDown() { - unset($this->Inflector); - } } From b480d80c825fdbb1fee892b1ec18f8483e832f4d Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 2 Jun 2010 18:14:58 -0300 Subject: [PATCH 28/57] Avoid undefined index if not define timeout in EmailComponent. Fixes #779 --- cake/libs/controller/components/email.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index bbc41e72d..5f42bf3cf 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -228,9 +228,7 @@ class EmailComponent extends Object{ * @access public * @link http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP */ - var $smtpOptions = array( - 'port'=> 25, 'host' => 'localhost', 'timeout' => 30 - ); + var $smtpOptions = array(); /** * Placeholder for any errors that might happen with the @@ -789,7 +787,13 @@ class EmailComponent extends Object{ function _smtp() { App::import('Core', array('CakeSocket')); - $this->__smtpConnection =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->smtpOptions)); + $defaults = array( + 'host' => 'localhost', + 'port' => 25, + 'protocol' => 'smtp', + 'timeout' => 30 + ); + $this->__smtpConnection =& new CakeSocket(array_merge($defaults, $this->smtpOptions)); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); From 3c27c4c41e853be54ebf7434b6f94ac06f99b242 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 3 Jun 2010 14:46:20 -0300 Subject: [PATCH 29/57] Ajusting smtpOption in EmailComponent. Fixes #779 --- cake/libs/controller/components/email.php | 3 ++- .../libs/controller/components/email.test.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 5f42bf3cf..dbd9ef233 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -793,7 +793,8 @@ class EmailComponent extends Object{ 'protocol' => 'smtp', 'timeout' => 30 ); - $this->__smtpConnection =& new CakeSocket(array_merge($defaults, $this->smtpOptions)); + $this->smtpOptions = array_merge($defaults, $this->smtpOptions); + $this->__smtpConnection =& new CakeSocket($this->smtpOptions); if (!$this->__smtpConnection->connect()) { $this->smtpError = $this->__smtpConnection->lastError(); diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index f5de3e9d2..512dfe97e 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -234,6 +234,30 @@ class EmailComponentTest extends CakeTestCase { return str_replace(array("\r\n", "\r"), "\n", $string); } +/** + * testSmtpConfig method + * + * @access public + * @return void + */ + function testSmtpConfig() { + $this->Controller->EmailTest->delivery = 'smtp'; + $this->Controller->EmailTest->smtpOptions = array(); + $this->Controller->EmailTest->send('anything'); + $config = array( + 'host' => 'localhost', + 'port' => 25, + 'protocol' => 'smtp', + 'timeout' => 30 + ); + $this->assertEqual($config, $this->Controller->EmailTest->smtpOptions); + + $this->Controller->EmailTest->smtpOptions = array('port' => 80); + $this->Controller->EmailTest->send('anything'); + $config['port'] = 80; + $this->assertEqual($config, $this->Controller->EmailTest->smtpOptions); + } + /** * testBadSmtpSend method * @@ -308,6 +332,7 @@ TEMPDOC; $connection =& new CakeSocket(array('protocol'=>'smtp', 'host' => 'localhost', 'port' => 25)); $this->Controller->EmailTest->setConnectionSocket($connection); + $this->Controller->EmailTest->smtpOptions['timeout'] = 10; $this->assertTrue($connection->connect()); $this->assertTrue($this->Controller->EmailTest->smtpSend(null, '220') !== false); $this->skipIf($this->Controller->EmailTest->smtpSend('EHLO locahost', '250') === false, '%s do not support EHLO.'); @@ -600,6 +625,7 @@ TEXTBLOC; function testSmtpSendSocket() { $this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost'); + $this->Controller->EmailTest->smtpOptions['timeout'] = 10; $socket =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions)); $this->Controller->EmailTest->setConnectionSocket($socket); From bd6e16be261d532da30d417e48c7f57c9be21550 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 Jun 2010 23:20:37 -0400 Subject: [PATCH 30/57] Fixing issue where join tables would be filed under 'missing' and found. Test added. Fixes #789 --- cake/libs/model/cake_schema.php | 3 +-- cake/tests/cases/libs/model/cake_schema.test.php | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 7901cdf09..a1ea24ace 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -246,7 +246,6 @@ class CakeSchema extends Object { if (is_object($Object) && $Object->useTable !== false) { $Object->setDataSource($connection); $table = $db->fullTableName($Object, false); - if (in_array($table, $currentTables)) { $key = array_search($table, $currentTables); if (empty($tables[$table])) { @@ -263,7 +262,7 @@ class CakeSchema extends Object { if (is_object($Object->$class)) { $withTable = $db->fullTableName($Object->$class, false); if (in_array($withTable, $currentTables)) { - $key = array_search($table, $currentTables); + $key = array_search($withTable, $currentTables); $tables[$withTable] = $this->__columns($Object->$class); $tables[$withTable]['indexes'] = $db->index($Object->$class); $tables[$withTable]['tableParameters'] = $db->readTableParameters($withTable); diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index c07b9d998..3a769356a 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -575,6 +575,13 @@ class CakeSchemaTest extends CakeTestCase { 'models' => array('SchemaPost') )); $this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s'); + + $read = $this->Schema->read(array( + 'connection' => 'test_suite', + 'name' => 'TestApp', + 'models' => array('SchemaComment', 'SchemaTag', 'SchemaPost') + )); + $this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing %s'); } /** From e41e89cd2a6d7e5bd71911fab14e756648126f4c Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 4 Jun 2010 00:20:14 -0400 Subject: [PATCH 31/57] Making magic select not override magic hidden. Tests added. Fixes #782 --- cake/libs/view/helpers/form.php | 2 +- .../cases/libs/view/helpers/form.test.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 5e2fb57c5..3de99f084 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -740,7 +740,7 @@ class FormHelper extends AppHelper { $options['type'] = 'hidden'; } } - if (preg_match('/_id$/', $fieldKey)) { + if (preg_match('/_id$/', $fieldKey) && $options['type'] !== 'hidden') { $options['type'] = 'select'; } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 1a3b06d22..892e2be8d 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2118,6 +2118,29 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test that input() and a non standard primary key makes a hidden input by default. + * + * @return void + */ + function testInputWithNonStandardPrimaryKeyMakesHidden() { + $this->Form->create('User'); + $this->Form->fieldset = array( + 'User' => array( + 'fields' => array( + 'model_id' => array('type' => 'integer') + ), + 'validates' => array(), + 'key' => 'model_id' + ) + ); + $result = $this->Form->input('model_id'); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'), + ); + $this->assertTags($result, $expected); + } + /** * test that overriding the magic select type widget is possible * From 26d526f6240239094aa714b86093cd36fbb9a1f3 Mon Sep 17 00:00:00 2001 From: predominant Date: Mon, 7 Jun 2010 01:20:54 +1000 Subject: [PATCH 32/57] Fix AuthComponent tests for windows newlines. --- cake/tests/cases/libs/controller/components/auth.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 618b5eb88..ba4fa181f 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -1456,7 +1456,7 @@ class AuthTest extends CakeTestCase { $Dispatcher =& new Dispatcher(); $Dispatcher->dispatch('/ajax_auth/add', array('return' => 1)); $result = ob_get_clean(); - $this->assertEqual("Ajax!\nthis is the test element", $result); + $this->assertEqual("Ajax!\nthis is the test element", str_replace("\r\n", "\n", $result)); unset($_SERVER['HTTP_X_REQUESTED_WITH']); } From d803b303886d569cff16bf975567b3d909e6a780 Mon Sep 17 00:00:00 2001 From: predominant Date: Mon, 7 Jun 2010 01:39:24 +1000 Subject: [PATCH 33/57] Fix Model validation bake tests for Windows. --- cake/tests/cases/console/libs/tasks/model.test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index a343e28a8..9eb1e4e68 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -647,8 +647,9 @@ array( //'on' => 'create', // Limit validation to 'create' or 'update' operations ), STRINGEND; - - $this->assertPattern('/' . preg_quote($expected, '/') . '/', $result); +debug($expected); +debug($result); + $this->assertPattern('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result); } /** From e47c9660f99c6b8b1748f2d712c910a7b9c60918 Mon Sep 17 00:00:00 2001 From: predominant Date: Mon, 7 Jun 2010 02:03:41 +1000 Subject: [PATCH 34/57] Remove debugging. --- cake/tests/cases/console/libs/tasks/model.test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index 9eb1e4e68..656ded486 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -647,8 +647,6 @@ array( //'on' => 'create', // Limit validation to 'create' or 'update' operations ), STRINGEND; -debug($expected); -debug($result); $this->assertPattern('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result); } From 0eea0ce0f89e195efb20727319427f960824fecb Mon Sep 17 00:00:00 2001 From: predominant Date: Mon, 7 Jun 2010 02:21:51 +1000 Subject: [PATCH 35/57] Updating version numbers to 1.3.2 --- cake/VERSION.txt | 3 ++- cake/config/config.php | 2 +- cake/libs/view/pages/home.ctp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cake/VERSION.txt b/cake/VERSION.txt index 271b0e83c..5f08ec3dc 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -18,4 +18,5 @@ // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -1.3.1 +1.3.2 + diff --git a/cake/config/config.php b/cake/config/config.php index ce6f59afd..65dd5a77c 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -17,4 +17,4 @@ * @since CakePHP(tm) v 1.1.11.4062 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -return $config['Cake.version'] = '1.3.1'; +return $config['Cake.version'] = '1.3.2'; diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index fa2eb4a95..f5a774fa3 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -21,7 +21,7 @@ if (Configure::read() == 0): endif; ?>

- + 0): Debugger::checkSecurityKeys(); From 94fc492623fbc4f6dd042cca84109dcb8cc45194 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 6 Jun 2010 22:39:04 -0400 Subject: [PATCH 36/57] Correcting how ExtractTask collects files. Test added. Fixes #775 --- cake/console/libs/tasks/extract.php | 2 +- .../cases/console/libs/tasks/extract.test.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index 8ce1be068..5dc928b04 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -488,7 +488,7 @@ class ExtractTask extends Shell { foreach ($this->__paths as $path) { $Folder = new Folder($path); $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); - $this->__files += $files; + $this->__files = array_merge($this->__files, $files); } } } diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index 29c4f2bd8..f93a9a6a7 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -155,4 +155,33 @@ class ExtractTaskTest extends CakeTestCase { $Folder = new Folder($path); $Folder->delete(); } + function getTests() { + return array('start', 'startCase', 'testExtractMultiplePaths', 'endCase', 'end'); + } + +/** + * test extract can read more than one path. + * + * @return void + */ + function testExtractMultiplePaths() { + $path = TMP . 'tests' . DS . 'extract_task_test'; + new Folder($path . DS . 'locale', true); + + $this->Task->interactive = false; + + $this->Task->params['paths'] = + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' . + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts'; + + $this->Task->params['output'] = $path . DS; + $this->Task->Dispatch->expectNever('stderr'); + $this->Task->Dispatch->expectNever('_stop'); + $this->Task->execute(); + + $result = file_get_contents($path . DS . 'default.pot'); + + $pattern = '/msgid "Add User"/'; + $this->assertPattern($pattern, $result); + } } From ccd036eed03af678ecf3f2ecff6d29e945f877dd Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 7 Jun 2010 23:10:53 -0400 Subject: [PATCH 37/57] Adding additional test cases for nld, dut, and nl. Closes #795 --- cake/tests/cases/libs/l10n.test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cake/tests/cases/libs/l10n.test.php b/cake/tests/cases/libs/l10n.test.php index 6efd3954e..4b8483d4b 100644 --- a/cake/tests/cases/libs/l10n.test.php +++ b/cake/tests/cases/libs/l10n.test.php @@ -194,6 +194,10 @@ class L10nTest extends CakeTestCase { $result = $l10n->map(array('nld', 'nl')); $expected = array('nld' => 'nl', 'nl' => 'dut'); $this->assertEqual($result, $expected); + + $result = $l10n->map(array('nld')); + $expected = array('nld' => 'nl'); + $this->assertEqual($result, $expected); $result = $l10n->map(array('eng', 'en')); $expected = array('eng' => 'en', 'en' => 'eng'); @@ -745,6 +749,18 @@ class L10nTest extends CakeTestCase { ); $this->assertEqual($result, $expected); + $result = $l10n->catalog('nl'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $this->assertEqual($result, $expected); + + $result = $l10n->catalog('nld'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $this->assertEqual($result, $expected); + + $result = $l10n->catalog('dut'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $this->assertEqual($result, $expected); + $result = $l10n->catalog(array('nb')); $expected = array( 'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr') From a9fa7ac24027feeda38ca5aa2449da2bb2582dac Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Mon, 7 Jun 2010 17:08:04 -0700 Subject: [PATCH 38/57] Fix for auth component userModel with plugins. Fixes #799 --- cake/libs/controller/components/auth.php | 2 +- .../cases/libs/controller/components/auth.test.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 153172542..fb736e8e5 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -469,7 +469,7 @@ class AuthComponent extends Object { 'loginAction' => array( 'controller' => Inflector::underscore(Inflector::pluralize($model)), 'action' => 'login', - 'plugin' => $plugin, + 'plugin' => Inflector::underscore($plugin), ), 'sessionKey' => 'Auth.' . $model, 'logoutRedirect' => $this->loginAction, diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index ba4fa181f..f077b20db 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -1431,6 +1431,16 @@ class AuthTest extends CakeTestCase { $this->assertEqual($user, $expected); $sessionKey = $this->Controller->Auth->sessionKey; $this->assertEqual('Auth.TestPluginAuthUser', $sessionKey); + + $this->Controller->Auth->loginAction = null; + $this->Controller->Auth->__setDefaults(); + $loginAction = $this->Controller->Auth->loginAction; + $expected = array( + 'controller' => 'test_plugin_auth_users', + 'action' => 'login', + 'plugin' => 'test_plugin' + ); + $this->assertEqual($loginAction, $expected); // Reverting changes Cache::delete('object_map', '_cake_core_'); From a88b8dd5b940abf8bc1aaa6a21b04171fc7b5296 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 7 Jun 2010 23:43:35 -0400 Subject: [PATCH 39/57] Making requestAction() calls that requesthandler creates not remove autoLayout. This fixes issues where ajax layout files would not be rendered. Tests added. Fixes #722 --- .../controller/components/request_handler.php | 2 +- .../components/request_handler.test.php | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 1748c787d..dbbdfe2c9 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -279,7 +279,7 @@ class RequestHandlerComponent extends Object { $msg = $statusCode[$code]; $controller->header("HTTP/1.1 {$code} {$msg}"); } - echo $this->requestAction($url, array('return')); + echo $this->requestAction($url, array('return', 'bare' => false)); $this->_stop(); } diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index abeaa0531..420ecd405 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -79,6 +79,18 @@ class RequestHandlerTestController extends Controller { echo "one: $one two: $two"; $this->autoRender = false; } + +/** + * test method for testing layout rendering when isAjax() + * + * @return void + */ + function ajax2_layout() { + if ($this->autoLayout) { + $this->layout = 'ajax2'; + } + $this->destination(); + } } /** @@ -593,6 +605,34 @@ class RequestHandlerComponentTest extends CakeTestCase { App::build(); } +/** + * test that ajax requests involving redirects don't force no layout + * this would cause the ajax layout to not be rendered. + * + * @return void + */ + function testAjaxRedirectAsRequestActionStillRenderingLayout() { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->_init(); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + ), true); + + $this->Controller->RequestHandler = new NoStopRequestHandler($this); + $this->Controller->RequestHandler->expectOnce('_stop'); + + ob_start(); + $this->Controller->RequestHandler->beforeRedirect( + $this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout') + ); + $result = ob_get_clean(); + $this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.'); + $this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.'); + + unset($_SERVER['HTTP_X_REQUESTED_WITH']); + App::build(); + } + /** * test that the beforeRedirect callback properly converts * array urls into their correct string ones, and adds base => false so @@ -605,7 +645,7 @@ class RequestHandlerComponentTest extends CakeTestCase { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0), + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')), array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') )); From 2f527cc5af6ef91a677d5255dfeb315dd726d688 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 8 Jun 2010 23:29:40 -0400 Subject: [PATCH 40/57] Adding a few tests for DboSource::fullTableName(); --- .../libs/model/datasources/dbo_source.test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 2ba412ab4..8dda31f00 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4426,4 +4426,19 @@ class DboSourceTest extends CakeTestCase { $expected = " GROUP BY (YEAR(`Article`.`created`))"; $this->assertEqual($expected, $result); } + +/** + * test the permutations of fullTableName() + * + * @return void + */ + function testFullTablePermutations() { + $Article =& ClassRegistry::init('Article'); + $result = $this->testDb->fullTableName($Article, false); + $this->assertEqual($result, 'articles'); + + $Article->tablePrefix = 'tbl_'; + $result = $this->testDb->fullTableName($Article, false); + $this->assertEqual($result, 'tbl_articles'); + } } From bca3c4ab38e0326dd4782b0536f9e3b8cd71f83e Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 8 Jun 2010 23:30:57 -0400 Subject: [PATCH 41/57] Moving init() tests into separate test methods. Adding tests for table prefixes on models being used as imports. Fixing issue where tablePrefix was not accurately used when importing model information. Fixes #765 --- .../cases/libs/cake_test_fixture.test.php | 39 +++++++++++++++++++ cake/tests/lib/cake_test_fixture.php | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/cake_test_fixture.test.php b/cake/tests/cases/libs/cake_test_fixture.test.php index 554e6119c..3b443a9c6 100644 --- a/cake/tests/cases/libs/cake_test_fixture.test.php +++ b/cake/tests/cases/libs/cake_test_fixture.test.php @@ -114,6 +114,14 @@ class FixtureImportTestModel extends Model { var $useTable = 'fixture_tests'; var $useDbConfig = 'test_suite'; } + +class FixturePrefixTest extends Model { + var $name = 'FixturePrefix'; + var $useTable = '_tests'; + var $tablePrefix = 'fixture'; + var $useDbConfig = 'test_suite'; +} + Mock::generate('DboSource', 'FixtureMockDboSource'); /** @@ -162,7 +170,14 @@ class CakeTestFixtureTest extends CakeTestCase { $Fixture->primaryKey = 'my_random_key'; $Fixture->init(); $this->assertEqual($Fixture->primaryKey, 'my_random_key'); + } +/** + * test that init() correctly sets the fixture table when the connection or model have prefixes defined. + * + * @return void + */ + function testInitDbPrefix() { $this->_initDb(); $Source =& new CakeTestFixtureTestFixture(); $Source->create($this->db); @@ -194,6 +209,30 @@ class CakeTestFixtureTest extends CakeTestCase { $Source->drop($this->db); } +/** + * test init with a model that has a tablePrefix declared. + * + * @return void + */ + function testInitModelTablePrefix() { + $this->_initDb(); + $Source =& new CakeTestFixtureTestFixture(); + $Source->create($this->db); + $Source->insert($this->db); + + $Fixture =& new CakeTestFixtureImportFixture(); + unset($Fixture->table); + $Fixture->fields = $Fixture->records = null; + $Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test_suite', 'records' => false); + $Fixture->init(); + $this->assertEqual($Fixture->table, 'fixture_tests'); + + $keys = array_flip(ClassRegistry::keys()); + $this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys)); + + $Source->drop($this->db); + } + /** * testImport * diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index efebbbe08..6c434bf8b 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -80,6 +80,7 @@ class CakeTestFixture extends Object { $db->cacheSources = false; $this->fields = $model->schema(true); $this->fields[$model->primaryKey]['key'] = 'primary'; + $this->table = $db->fullTableName($model, false); ClassRegistry::config(array('ds' => 'test_suite')); ClassRegistry::flush(); } elseif (isset($import['table'])) { @@ -97,7 +98,7 @@ class CakeTestFixture extends Object { $this->records = array(); $query = array( 'fields' => $db->fields($model, null, array_keys($this->fields)), - 'table' => $db->fullTableName($model->table), + 'table' => $db->fullTableName($model), 'alias' => $model->alias, 'conditions' => array(), 'order' => null, From ad8b70cec24164c967dc769bde1679c5822c7e8c Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 9 Jun 2010 13:48:54 -0400 Subject: [PATCH 42/57] Removing continue statement that did nothing. Adding a rollback for when validation fails and atomic has been set. Tests added. Fixes #797 --- cake/libs/model/model.php | 5 +++- .../cases/libs/model/model_write.test.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 4efe17e11..8b2dcd650 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1622,7 +1622,6 @@ class Model extends Overloadable { case ($options['validate'] === 'first'): $options['validate'] = true; $return = array(); - continue; break; default: if ($options['atomic']) { @@ -1636,6 +1635,10 @@ class Model extends Overloadable { break; } } + if ($options['atomic'] && !$validates) { + $db->rollback($this); + return false; + } return $return; } $associations = $this->getAssociated(); diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 3beb16d44..ba7b4383f 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -3034,6 +3034,34 @@ class ModelWriteTest extends BaseModelTest { ), array('validate' => 'only')); } +/** + * test saveAll with transactions and ensure there is no missing rollback. + * + * @return void + */ + function testSaveAllTransactionNoRollback() { + $this->loadFixtures('Post'); + + Mock::generate('DboSource', 'MockTransactionDboSource'); + $db = ConnectionManager::create('mock_transaction', array( + 'datasource' => 'MockTransactionDbo', + )); + $db->expectOnce('rollback'); + + $Post =& new Post(); + $Post->useDbConfig = 'mock_transaction'; + + $Post->validate = array( + 'title' => array('rule' => array('notEmpty')) + ); + + $data = array( + array('author_id' => 1, 'title' => 'New Fourth Post'), + array('author_id' => 1, 'title' => '') + ); + $Post->saveAll($data, array('atomic' => true)); + } + /** * testSaveAllTransaction method * From d5ddd8ee5f23109233387175f3c7dd6a0bd38631 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 9 Jun 2010 19:22:06 -0300 Subject: [PATCH 43/57] Fixing check of EHLO/HELO in EmailComponent. Fixes #794 --- 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 dbd9ef233..4397a5f38 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -813,7 +813,7 @@ class EmailComponent extends Object{ $host = 'localhost'; } - if (!$this->_smtpSend("EHLO {$host}", '250') || !$this->_smtpSend("HELO {$host}", '250')) { + if (!$this->_smtpSend("EHLO {$host}", '250') && !$this->_smtpSend("HELO {$host}", '250')) { return false; } From 9ee4a12a9d8ba32da80d73aafc47659b8a3815fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Jun 2010 12:48:55 -0400 Subject: [PATCH 44/57] Adding additional tests for FormHelper::input() and checkbox generation and checked attribute being set for truthy values. Close #806 --- .../cases/libs/view/helpers/form.test.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 892e2be8d..472376d71 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -313,6 +313,7 @@ class UserForm extends CakeTestModel { 'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null), 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10), 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255), + 'active' => array('type' => 'boolean', 'null' => false, 'default' => false), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); @@ -1829,6 +1830,32 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); } + +/** + * test input() with checkbox creation + * + * @return void + */ + function testInputCheckbox() { + $result = $this->Form->input('User.active', array('label' => false, 'checked' => true)); + $expected = array( + 'div' => array('class' => 'input checkbox'), + 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->input('User.active', array('label' => false, 'checked' => 1)); + $expected = array( + 'div' => array('class' => 'input checkbox'), + 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')), + '/div' + ); + $this->assertTags($result, $expected); + } + /** * test form->input() with datetime, date and time types * @@ -1952,6 +1979,7 @@ class FormHelperTest extends CakeTestCase { )); $this->assertPattern('/for\="created-month"/', $result); } + /** * Test generating checkboxes in a loop. * @@ -1972,6 +2000,7 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } } + /** * test form->input() with select type inputs. * @@ -3545,6 +3574,20 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Form->checkbox('Model.field', array('checked' => 1)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) + ); + $this->assertTags($result, $expected); + + $result = $this->Form->checkbox('Model.field', array('checked' => true)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) + ); + $this->assertTags($result, $expected); + $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; $result = $this->Form->checkbox('Contact.published', array('id' => 'theID')); From ec5ad93a68ae6064c68f4cdcb6de4ccf0fc2384f Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Jun 2010 13:54:04 -0400 Subject: [PATCH 45/57] Updating doc blocks for ModelBehavior so they better reflect the actual behaviour of the methods. Removing unused variable assignment. Fixes #810 --- cake/libs/model/model_behavior.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/model_behavior.php b/cake/libs/model/model_behavior.php index 140a8831d..2606bb49a 100644 --- a/cake/libs/model/model_behavior.php +++ b/cake/libs/model/model_behavior.php @@ -81,7 +81,7 @@ class ModelBehavior extends Object { * * @param object $model Model using this behavior * @param array $queryData Data used to execute this query, i.e. conditions, order, etc. - * @return boolean True if the operation should continue, false if it should abort + * @return mixed False if the operation should abort. Any other result will continue. * @access public */ function beforeFind(&$model, $query) { } @@ -101,7 +101,7 @@ class ModelBehavior extends Object { * Before validate callback * * @param object $model Model using this behavior - * @return boolean True if validate operation should continue, false to abort + * @return mixed False if the operation should abort. Any other result will continue. * @access public */ function beforeValidate(&$model) { } @@ -110,7 +110,7 @@ class ModelBehavior extends Object { * Before save callback * * @param object $model Model using this behavior - * @return boolean True if the operation should continue, false if it should abort + * @return mixed False if the operation should abort. Any other result will continue. * @access public */ function beforeSave(&$model) { } @@ -129,7 +129,7 @@ class ModelBehavior extends Object { * * @param object $model Model using this behavior * @param boolean $cascade If true records that depend on this record will also be deleted - * @return boolean True if the operation should continue, false if it should abort + * @return mixed False if the operation should abort. Any other result will continue. * @access public */ function beforeDelete(&$model, $cascade = true) { } @@ -483,7 +483,6 @@ class BehaviorCollection extends Object { if (empty($this->_attached)) { return true; } - $_params = $params; $options = array_merge(array('break' => false, 'breakOn' => array(null, false), 'modParams' => false), $options); $count = count($this->_attached); From e5df32e9d9cc372c79b5db6adbba97d82d7adf1e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Jun 2010 14:23:49 -0400 Subject: [PATCH 46/57] Adding omitted documentation information. --- cake/libs/controller/scaffold.php | 8 +++++- cake/libs/model/behaviors/translate.php | 33 ++++++++++++++++++------- cake/libs/view/theme.php | 5 ++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index f75237e16..27a1cd531 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -544,11 +544,17 @@ if (!class_exists('ThemeView')) { App::import('View', 'Theme'); } +/** + * ScaffoldView provides specific view file loading features for scaffolded views. + * + * @package cake.libs.view + */ class ScaffoldView extends ThemeView { /** - * Override _getViewFileName + * Override _getViewFileName Appends special scaffolding views in. * + * @param string $name name of the view file to get. * @return string action * @access protected */ diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index 39393015d..fb2d21709 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -29,6 +29,8 @@ class TranslateBehavior extends ModelBehavior { /** * Used for runtime configuration of model + * + * @var array */ var $runtime = array(); @@ -45,7 +47,8 @@ class TranslateBehavior extends ModelBehavior { * $config could be empty - and translations configured dynamically by * bindTranslation() method * - * @param array $config + * @param Model $model Model the behavior is being attached to. + * @param array $config Array of configuration information. * @return mixed * @access public */ @@ -66,8 +69,9 @@ class TranslateBehavior extends ModelBehavior { } /** - * Callback + * Cleanup Callback unbinds bound translations and deletes setting information. * + * @param Model $model Model being detached. * @return void * @access public */ @@ -80,7 +84,8 @@ class TranslateBehavior extends ModelBehavior { /** * beforeFind Callback * - * @param array $query + * @param Model $model Model find is being run on. + * @param array $query Array of Query parameters. * @return array Modified query * @access public */ @@ -205,8 +210,9 @@ class TranslateBehavior extends ModelBehavior { /** * afterFind Callback * - * @param array $results - * @param boolean $primary + * @param Model $model Model find was run on + * @param array $results Array of model results. + * @param boolean $primary Did the find originate on $model. * @return array Modified results * @access public */ @@ -250,6 +256,7 @@ class TranslateBehavior extends ModelBehavior { /** * beforeValidate Callback * + * @param Model $model Model invalidFields was called on. * @return boolean * @access public */ @@ -283,7 +290,8 @@ class TranslateBehavior extends ModelBehavior { /** * afterSave Callback * - * @param boolean $created + * @param Model $model Model the callback is called on + * @param boolean $created Whether or not the save created a record. * @return void * @access public */ @@ -327,6 +335,7 @@ class TranslateBehavior extends ModelBehavior { /** * afterDelete Callback * + * @param Model $model Model the callback was run on. * @return void * @access public */ @@ -339,6 +348,7 @@ class TranslateBehavior extends ModelBehavior { /** * Get selected locale for model * + * @param Model $model Model the locale needs to be set/get on. * @return mixed string or false * @access protected */ @@ -356,8 +366,12 @@ class TranslateBehavior extends ModelBehavior { } /** - * Get instance of model for translations + * Get instance of model for translations. * + * If the model has a translateModel property set, this will be used as the class + * name to find/use. If no translateModel property is found 'I18nModel' will be used. + * + * @param Model $model Model to get a translatemodel for. * @return object * @access public */ @@ -461,8 +475,9 @@ class TranslateBehavior extends ModelBehavior { * Unbind translation for fields, optionally unbinds hasMany association for * fake field * - * @param object instance of model - * @param mixed string with field, or array(field1, field2=>AssocName, field3), or null for unbind all original translations + * @param object $model instance of model + * @param mixed $fields string with field, or array(field1, field2=>AssocName, field3), or null for + * unbind all original translations * @return bool */ function unbindTranslation(&$model, $fields = null) { diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index f161e2685..22a06f050 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -35,7 +35,8 @@ class ThemeView extends View { /** * Constructor for ThemeView sets $this->theme. * - * @param Controller $controller + * @param Controller $controller Controller object to be rendered. + * @param boolean $register Should the view be registered in the registry. */ function __construct(&$controller, $register = true) { parent::__construct($controller, $register); @@ -45,7 +46,7 @@ class ThemeView extends View { /** * Return all possible paths to find view files in order * - * @param string $plugin + * @param string $plugin The name of the plugin views are being found for. * @param boolean $cached Set to true to force dir scan. * @return array paths * @access protected From f0d755bd8e0ae65a75923aad490781902a9be0df Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 10 Jun 2010 19:11:26 -0400 Subject: [PATCH 47/57] Adding additional tests for Helper::_parseAttributes() and fixing issue where '1' would not be interpreted as a truthy value for compact attributes. Fixes #806 --- cake/libs/view/helper.php | 9 ++--- cake/tests/cases/libs/view/helper.test.php | 34 +++++++++++++++++++ .../cases/libs/view/helpers/form.test.php | 9 +++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 376d47335..4a0f1e149 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -296,9 +296,10 @@ class Helper extends Overloadable { * * And its value is one of: * - * - 1 - * - true - * - 'true' + * - '1' (string) + * - 1 (integer) + * - true (boolean) + * - 'true' (string) * * Then the value will be reset to be identical with key's name. * If the value is not one of these 3, the parameter is not output. @@ -358,7 +359,7 @@ class Helper extends Overloadable { } if (in_array($key, $minimizedAttributes)) { - if ($value === 1 || $value === true || $value === 'true' || $value == $key) { + if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) { $attribute = sprintf($attributeFormat, $key, $key); } } else { diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index db60c94cd..114864686 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -162,6 +162,21 @@ class HelperTestPostsTag extends Model { } } +class TestHelper extends Helper { +/** + * expose a method as public + * + * @param string $options + * @param string $exclude + * @param string $insertBefore + * @param string $insertAfter + * @return void + */ + function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { + return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter); + } +} + /** * HelperTest class * @@ -720,4 +735,23 @@ class HelperTest extends CakeTestCase { Configure::write('App.www_root', $webRoot); } + +/** + * test parsing attributes. + * + * @return void + */ + function testParseAttributeCompact() { + $helper =& new TestHelper(); + $compact = array('compact', 'checked', 'declare', 'readonly', 'disabled', + 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); + + foreach ($compact as $attribute) { + foreach (array('true', true, 1, '1', $attribute) as $value) { + $attrs = array($attribute => $value); + $expected = ' ' . $attribute . '="' . $attribute . '"'; + $this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value); + } + } + } } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 472376d71..7678020db 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1854,6 +1854,15 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $result = $this->Form->input('User.active', array('label' => false, 'checked' => '1')); + $expected = array( + 'div' => array('class' => 'input checkbox'), + 'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')), + '/div' + ); + $this->assertTags($result, $expected); } /** From df3432aa86f4fbba34286e1eab5655c69f306cea Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 11 Jun 2010 09:55:39 -0400 Subject: [PATCH 48/57] Updating doc blocks in ModelBehavior. Refs #810 --- cake/libs/model/model_behavior.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/model_behavior.php b/cake/libs/model/model_behavior.php index 2606bb49a..000b3186d 100644 --- a/cake/libs/model/model_behavior.php +++ b/cake/libs/model/model_behavior.php @@ -81,7 +81,7 @@ class ModelBehavior extends Object { * * @param object $model Model using this behavior * @param array $queryData Data used to execute this query, i.e. conditions, order, etc. - * @return mixed False if the operation should abort. Any other result will continue. + * @return mixed False if the operation should abort. An array will replace the value of $query. * @access public */ function beforeFind(&$model, $query) { } @@ -92,7 +92,7 @@ class ModelBehavior extends Object { * @param object $model Model using this behavior * @param mixed $results The results of the find operation * @param boolean $primary Whether this model is being queried directly (vs. being queried as an association) - * @return mixed Result of the find operation + * @return mixed An array value will replace the value of $results - any other value will be ignored. * @access public */ function afterFind(&$model, $results, $primary) { } From d1651db9a81f97e2da376dd733bfd6202147b557 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 11 Jun 2010 10:01:02 -0400 Subject: [PATCH 49/57] Fixing typo in Scaffold that caused error messages to display incorrectly. Fixes #813 --- cake/libs/controller/scaffold.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 27a1cd531..42dcfef6c 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -223,7 +223,7 @@ class Scaffold extends Object { function __scaffoldView($params) { if ($this->controller->_beforeScaffold('view')) { - $message = __(sprintf("No id set for %s::view()", Inflector::humanize($this->modelKey), true)); + $message = __(sprintf("No id set for %s::view()", Inflector::humanize($this->modelKey)), true); if (isset($params['pass'][0])) { $this->ScaffoldModel->id = $params['pass'][0]; } elseif ($this->_validSession) { From 50144d6b5b1db2d31e1be3019e47c66a58fc50f3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 12 Jun 2010 22:50:09 -0400 Subject: [PATCH 50/57] Making FormHelper clear fields on create() as well as end() this ensures that GET forms don't leak fields. Fixes #571 --- cake/libs/view/helpers/form.php | 1 + cake/tests/cases/libs/view/helpers/form.test.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 3de99f084..4e1a209b3 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -306,6 +306,7 @@ class FormHelper extends AppHelper { unset($options['default']); $htmlAttributes = array_merge($options, $htmlAttributes); + $this->fields = array(); if (isset($this->params['_Token']) && !empty($this->params['_Token'])) { $append .= $this->hidden('_Token.key', array( 'value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand()) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 7678020db..c17c2c69a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -751,6 +751,17 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test that create() clears the fields property so it starts fresh + * + * @return void + */ + function testCreateClearingFields() { + $this->Form->fields = array('model_id'); + $this->Form->create('Contact'); + $this->assertEqual($this->Form->fields, array()); + } + /** * Tests form hash generation with model-less data * From 2db510d1c15f2627332cd87fef0538aa61f2a67f Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Jun 2010 21:47:34 -0400 Subject: [PATCH 51/57] Modifying Controller::validateErrors so it can accept and validate arbitrary model objects, not just those attached to the controller. Test cases updated, fixes #832 --- cake/libs/controller/controller.php | 7 +++++-- .../cases/libs/controller/controller.test.php | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index f3295f33a..7308418a0 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -843,8 +843,11 @@ class Controller extends Object { $errors = array(); foreach ($objects as $object) { - $this->{$object->alias}->set($object->data); - $errors = array_merge($errors, $this->{$object->alias}->invalidFields()); + if (isset($this->{$object->alias})) { + $object =& $this->{$object->alias}; + } + $object->set($object->data); + $errors = array_merge($errors, $object->invalidFields()); } return $this->validationErrors = (!empty($errors) ? $errors : false); diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 0219f2750..a517092ea 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -1228,7 +1228,7 @@ class ControllerTest extends CakeTestCase { $TestController->ControllerComment->invalidate('some_field', 'error_message'); $TestController->ControllerComment->invalidate('some_field2', 'error_message2'); - $comment = new ControllerComment; + $comment =& new ControllerComment(); $comment->set('someVar', 'data'); $result = $TestController->validateErrors($comment); $expected = array('some_field' => 'error_message', 'some_field2' => 'error_message2'); @@ -1236,6 +1236,23 @@ class ControllerTest extends CakeTestCase { $this->assertEqual($TestController->validate($comment), 2); } +/** + * test that validateErrors works with any old model. + * + * @return void + */ + function testValidateErrorsOnArbitraryModels() { + $TestController =& new TestController(); + + $Post = new ControllerPost(); + $Post->validate = array('title' => 'notEmpty'); + $Post->set('title', ''); + $result = $TestController->validateErrors($Post); + + $expected = array('title' => 'This field cannot be left blank'); + $this->assertEqual($result, $expected); + } + /** * testPostConditions method * From a1911b471475ff1107e5ffd1de09c0d4b1c092da Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 20 Jun 2010 22:05:56 -0400 Subject: [PATCH 52/57] Changing array_key_exists for the faster isset(). --- cake/dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 7ff7f5459..e4ab3ffcf 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -162,7 +162,7 @@ class Dispatcher extends Object { } else { $controller->data = null; } - if (array_key_exists('return', $this->params) && $this->params['return'] == 1) { + if (isset($this->params['return']) && $this->params['return'] == 1) { $controller->autoRender = false; } if (!empty($this->params['bare'])) { From 2a4489cdf2b8c929cb79f9f4c63a8c85a370b8f8 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 20 Jun 2010 23:53:54 -0300 Subject: [PATCH 53/57] Naming conventions to datasources with plugins. Fixes #819 --- cake/libs/model/connection_manager.php | 7 ++- .../libs/model/connection_manager.test.php | 61 +++++++++++++++++++ cake/tests/test_app/models/datasources/empty | 0 .../models/datasources/test2_other_source.php | 27 ++++++++ .../models/datasources/test2_source.php | 27 ++++++++ .../models/datasources/test_other_source.php | 27 ++++++++ 6 files changed, 147 insertions(+), 2 deletions(-) delete mode 100644 cake/tests/test_app/models/datasources/empty create mode 100644 cake/tests/test_app/models/datasources/test2_other_source.php create mode 100644 cake/tests/test_app/models/datasources/test2_source.php create mode 100644 cake/tests/test_app/plugins/test_plugin/models/datasources/test_other_source.php diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index af3365be3..723ad0994 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -272,9 +272,12 @@ class ConnectionManager extends Object { if ($plugin) { $filename = Inflector::underscore($classname); } else { - $filename = $config['datasource'] . '_source'; - $classname = Inflector::camelize(strtolower($filename)); + $filename = Inflector::underscore($config['datasource']); } + if (substr($filename, -7) != '_source') { + $filename .= '_source'; + } + $classname = Inflector::camelize(strtolower($filename)); } return compact('filename', 'classname', 'parent', 'plugin'); } diff --git a/cake/tests/cases/libs/model/connection_manager.test.php b/cake/tests/cases/libs/model/connection_manager.test.php index 049ad5276..e100a7bf3 100644 --- a/cake/tests/cases/libs/model/connection_manager.test.php +++ b/cake/tests/cases/libs/model/connection_manager.test.php @@ -276,4 +276,65 @@ class ConnectionManagerTest extends CakeTestCase { $source = ConnectionManager::create(null, $config); $this->assertEqual($source, null); } + +/** + * testConnectionData method + * + * @access public + * @return void + */ + function testConnectionData() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), + 'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS) + )); + + $expected = array( + 'filename' => 'test2_source', + 'classname' => 'Test2Source', + 'parent' => '', + 'plugin' => '' + ); + + ConnectionManager::create('connection1', array('datasource' => 'Test2')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection1']); + + ConnectionManager::create('connection2', array('datasource' => 'Test2Source')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection2']); + + ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.Test')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test_source'; + $expected['classname'] = 'TestSource'; + $expected['plugin'] = 'TestPlugin'; + $this->assertEqual($expected, $connections['connection3']); + + ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection4']); + + ConnectionManager::create('connection5', array('datasource' => 'Test2Other')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test2_other_source'; + $expected['classname'] = 'Test2OtherSource'; + $expected['plugin'] = ''; + $this->assertEqual($expected, $connections['connection5']); + + ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection6']); + + ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOther')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test_other_source'; + $expected['classname'] = 'TestOtherSource'; + $expected['plugin'] = 'TestPlugin'; + $this->assertEqual($expected, $connections['connection7']); + + ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection8']); + } } diff --git a/cake/tests/test_app/models/datasources/empty b/cake/tests/test_app/models/datasources/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/cake/tests/test_app/models/datasources/test2_other_source.php b/cake/tests/test_app/models/datasources/test2_other_source.php new file mode 100644 index 000000000..d5743f606 --- /dev/null +++ b/cake/tests/test_app/models/datasources/test2_other_source.php @@ -0,0 +1,27 @@ + Date: Mon, 21 Jun 2010 00:37:25 -0300 Subject: [PATCH 54/57] Fixing wrap for html mode in e-mails. Fixes #663 --- cake/libs/controller/components/email.php | 17 ++++++-- .../libs/controller/components/email.test.php | 41 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 4397a5f38..b341f3965 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -356,7 +356,11 @@ class EmailComponent extends Object{ } } - $message = $this->_wrap($content); + if ($this->sendAs === 'text') { + $message = $this->_wrap($content); + } else { + $message = $this->_wrap($content, 998); + } if ($this->template === null) { $message = $this->_formatMessage($message); @@ -676,10 +680,11 @@ class EmailComponent extends Object{ * Wrap the message using EmailComponent::$lineLength * * @param string $message Message to wrap + * @param integer $lineLength Max length of line * @return array Wrapped message - * @access private + * @access protected */ - function _wrap($message) { + function _wrap($message, $lineLength = null) { $message = $this->_strip($message, true); $message = str_replace(array("\r\n","\r"), "\n", $message); $lines = explode("\n", $message); @@ -690,11 +695,15 @@ class EmailComponent extends Object{ $this->lineLength = $this->_lineLength; } + if (!$lineLength) { + $lineLength = $this->lineLength; + } + foreach ($lines as $line) { if (substr($line, 0, 1) == '.') { $line = '.' . $line; } - $formatted = array_merge($formatted, explode("\n", wordwrap($line, $this->lineLength, "\n", true))); + $formatted = array_merge($formatted, explode("\n", wordwrap($line, $lineLength, "\n", true))); } $formatted[] = ''; return $formatted; diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 512dfe97e..521a3fbb9 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -109,6 +109,16 @@ class EmailTestComponent extends EmailComponent { return $this->__message; } +/** + * Convenience getter for testing. + * + * @access protected + * @return string + */ + function _getMessage() { + return $this->__message; + } + /** * Convenience method for testing. * @@ -1078,4 +1088,35 @@ HTMLBLOC; $this->assertNoPattern('/Message-ID:/', $result); } +/** + * testSendMessage method + * + * @access public + * @return void + */ + function testSendMessage() { + $this->Controller->EmailTest->delivery = 'getMessage'; + $this->Controller->EmailTest->lineLength = 70; + + $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; + $this->Controller->EmailTest->sendAs = 'text'; + $result = $this->Controller->EmailTest->send($text); + $expected = array( + 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do', + 'eiusmod tempor incididunt ut labore et dolore magna aliqua.', + '', + '' + ); + $this->assertEqual($expected, $result); + + $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; + $this->Controller->EmailTest->sendAs = 'html'; + $result = $this->Controller->EmailTest->send($text); + $expected = array( + $text, + '', + '' + ); + $this->assertEqual($expected, $result); + } } From 5945edd983597dc0bf44f6162101e7b3c3a5353f Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 21 Jun 2010 21:17:37 -0400 Subject: [PATCH 55/57] Removing strtolower call that was breaking autolinks for URL shorteners. Tests added. Fixes #838 --- cake/libs/view/helpers/text.php | 2 +- cake/tests/cases/libs/view/helpers/text.test.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 046ce7080..04e80a812 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -123,7 +123,7 @@ class TextHelper extends AppHelper { '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text); return preg_replace_callback('#(?)(?tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $options . ');'), $text); + create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . $matches[0],' . $options . ');'), $text); } /** diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index eb674d3e5..7a5470c01 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -267,15 +267,19 @@ class TextHelperTest extends CakeTestCase { $this->assertPattern('#^' . $expected . '$#', $result); $text = 'Text with a partial WWW.cakephp.org URL'; - $expected = 'Text with a partial WWW.cakephp.org URL'; + $expected = 'Text with a partial WWW.cakephp.org URL'; $result = $this->Text->autoLinkUrls($text); $this->assertPattern('#^' . $expected . '$#', $result); $text = 'Text with a partial WWW.cakephp.org © URL'; - $expected = 'Text with a partial WWW.cakephp.org © URL'; + $expected = 'Text with a partial WWW.cakephp.org © URL'; $result = $this->Text->autoLinkUrls($text, array('escape' => false)); $this->assertPattern('#^' . $expected . '$#', $result); + $text = 'Text with a url www.cot.ag/cuIb2Q and more'; + $expected = 'Text with a url www.cot.ag/cuIb2Q and more'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEqual($expected, $result); } /** From 9bbaf153f77b15f190b027065e03b78e0dc1f00e Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 23 Jun 2010 00:10:21 -0300 Subject: [PATCH 56/57] Setting cookies in a single line. Fixes #48 --- cake/libs/http_socket.php | 2 +- cake/tests/cases/libs/http_socket.test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index a5c24c9fc..6686ebbce 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -975,7 +975,7 @@ class HttpSocket extends CakeSocket { foreach ($cookies as $name => $cookie) { $header[] = $name.'='.$this->_escapeToken($cookie['value'], array(';')); } - $header = $this->_buildHeader(array('Cookie' => $header), 'pragmatic'); + $header = $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic'); return $header; } diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index 1c3d04f6c..d61d654f5 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -1375,7 +1375,7 @@ class HttpSocketTest extends CakeTestCase { 'path' => '/accounts' ) ); - $expect = "Cookie: foo=bar\r\nCookie: people=jim,jack,johnny\";\"\r\n"; + $expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"\r\n"; $result = $this->Socket->buildCookies($cookies); $this->assertEqual($result, $expect); } From 83651091cef8a677844dbb6d2d318677eaaead45 Mon Sep 17 00:00:00 2001 From: predominant Date: Thu, 24 Jun 2010 10:30:12 +1000 Subject: [PATCH 57/57] Refactor session timeouts. --- cake/libs/cake_session.php | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index ddefa4506..5c478d3ed 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -460,29 +460,13 @@ class CakeSession extends Object { */ function __initSession() { $iniSet = function_exists('ini_set'); - if ($iniSet && env('HTTPS')) { ini_set('session.cookie_secure', 1); } - - switch ($this->security) { - case 'high': - $this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins(); - if ($iniSet) { - ini_set('session.referer_check', $this->host); - } - break; - case 'medium': - $this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins(); - if ($iniSet) { - ini_set('session.referer_check', $this->host); - } - break; - case 'low': - default: - $this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins(); - break; + if ($iniSet && ($this->security === 'high' || $this->security === 'medium')) { + ini_set('session.referer_check', $this->host); } + $this->cookieLifeTime = Configure::read('Session.timeout') * Security::inactiveMins(); switch (Configure::read('Session.save')) { case 'cake':