From 303261e23199efb3647feb622d5ed9e125dbd4cf Mon Sep 17 00:00:00 2001 From: fuga Date: Mon, 12 Aug 2013 10:28:17 +0900 Subject: [PATCH 01/13] making the config method of email-transport-classes mergable into the current config value. --- lib/Cake/Network/Email/AbstractTransport.php | 2 +- lib/Cake/Network/Email/SmtpTransport.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/Email/AbstractTransport.php b/lib/Cake/Network/Email/AbstractTransport.php index b081c0f4b..3f285a1d9 100644 --- a/lib/Cake/Network/Email/AbstractTransport.php +++ b/lib/Cake/Network/Email/AbstractTransport.php @@ -48,7 +48,7 @@ abstract class AbstractTransport { */ public function config($config = null) { if (is_array($config)) { - $this->_config = $config; + $this->_config = $config + $this->_config; } return $this->_config; } diff --git a/lib/Cake/Network/Email/SmtpTransport.php b/lib/Cake/Network/Email/SmtpTransport.php index 971a5cefd..e0b07156b 100644 --- a/lib/Cake/Network/Email/SmtpTransport.php +++ b/lib/Cake/Network/Email/SmtpTransport.php @@ -86,7 +86,7 @@ class SmtpTransport extends AbstractTransport { 'client' => null, 'tls' => false ); - $this->_config = empty($config) ? $this->_config + $default : $config + $default; + $this->_config = array_merge($default, $this->_config, $config); return $this->_config; } From 245611424fd39e727ec3e53d7fedf60187755533 Mon Sep 17 00:00:00 2001 From: fuga Date: Tue, 13 Aug 2013 17:42:52 +0900 Subject: [PATCH 02/13] Apply ADmad's patch and update testConfig method according to a new specification. --- .../Test/Case/Network/Email/CakeEmailTest.php | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index e9527280c..48ee47569 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -95,6 +95,20 @@ class EmailConfig { 'helpers' => array('Html', 'Form'), ); +/** + * test config 2 + * + * @var string + */ + public $test2 = array( + 'from' => array('some@example.com' => 'My website'), + 'to' => array('test@example.com' => 'Testname'), + 'subject' => 'Test mail subject', + 'transport' => 'Smtp', + 'host' => 'cakephp.org', + 'timeout' => 60 + ); + } /* @@ -726,12 +740,13 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($this->CakeEmail->config(), $config); $this->CakeEmail->config(array()); - $this->assertSame($transportClass->config(), array()); + $this->assertSame($transportClass->config(), $config); $config = array('test' => 'test@example.com'); $this->CakeEmail->config($config); $expected = array('test' => 'test@example.com', 'test2' => true); $this->assertSame($expected, $this->CakeEmail->config()); + $this->assertSame($expected, $transportClass->config()); } /** @@ -765,6 +780,35 @@ class CakeEmailTest extends CakeTestCase { $this->assertEquals($configs->test['helpers'], $result); } +/** + * Test updating config doesn't reset transport's config. + * + * @return void + */ + public function testConfigMerge() { + $this->CakeEmail->config('test2'); + + $expected = array( + 'host' => 'cakephp.org', + 'port' => 25, + 'timeout' => 60, + 'username' => null, + 'password' => null, + 'client' => null, + 'tls' => false + ); + $this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); + + $this->CakeEmail->config(array('log' => true)); + $result = $this->CakeEmail->transportClass()->config(); + $expected += array('log' => true); + $this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); + + $this->CakeEmail->config(array('timeout' => 45)); + $result = $this->CakeEmail->transportClass()->config(); + $this->assertEquals(45, $result['timeout']); + } + /** * testSendWithContent method * From 3bdcf7b440febde90c3eb5d0260716cba70847df Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 13 Aug 2013 13:40:59 -0400 Subject: [PATCH 03/13] Use inner join instead of a left join. In some database servers an INNER join performs better than a LEFT join. Fixes #3979 --- lib/Cake/Model/AclNode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/AclNode.php b/lib/Cake/Model/AclNode.php index 453b6f794..63bf3959c 100644 --- a/lib/Cake/Model/AclNode.php +++ b/lib/Cake/Model/AclNode.php @@ -163,7 +163,7 @@ class AclNode extends Model { 'joins' => array(array( 'table' => $table, 'alias' => "{$type}0", - 'type' => 'LEFT', + 'type' => 'INNER', 'conditions' => array( $db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"), $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght") From cb6ea82fea919eff667aa5c79debf3d09a1522d6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 13 Aug 2013 14:01:33 -0400 Subject: [PATCH 04/13] Allow CakeEmail::template() to disable layout rendering. Fix the code to act as documented. Sending template('view', null) should disable layout rendering. Fixes #3983 --- lib/Cake/Network/Email/CakeEmail.php | 5 +++++ .../Test/Case/Network/Email/CakeEmailTest.php | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 2d729427e..a40fff59b 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1573,6 +1573,11 @@ class CakeEmail { if ($this->_theme) { $View->theme = $this->_theme; } + // Convert null to false, as View needs false to disable + // the layout. + if ($layout === null) { + $layout = false; + } foreach ($types as $type) { $View->set('content', $content); diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index e9527280c..63857900a 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1048,6 +1048,26 @@ class CakeEmailTest extends CakeTestCase { $this->assertContains('To: ', $result['headers']); } +/** + * test sending and rendering with no layout + * + * @return void + */ + public function testSendRenderNoLayout() { + $this->CakeEmail->reset(); + $this->CakeEmail->transport('debug'); + + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to(array('you@cakephp.org' => 'You')); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->config(array('empty')); + $this->CakeEmail->template('default', null); + $result = $this->CakeEmail->send('message body.'); + + $this->assertContains('message body.', $result['message']); + $this->assertNotContains('This email was sent using the CakePHP Framework', $result['message']); + } + /** * testSendRender method for ISO-2022-JP * From 3f58be260e8b3fde78992a1788f61bb37052af15 Mon Sep 17 00:00:00 2001 From: Andras Kende Date: Tue, 13 Aug 2013 22:06:00 -0700 Subject: [PATCH 05/13] removed not used $i variable removed not used $i variable --- lib/Cake/Console/Templates/default/views/view.ctp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Cake/Console/Templates/default/views/view.ctp b/lib/Cake/Console/Templates/default/views/view.ctp index f5009d718..b218b7241 100644 --- a/lib/Cake/Console/Templates/default/views/view.ctp +++ b/lib/Cake/Console/Templates/default/views/view.ctp @@ -94,7 +94,6 @@ if (empty($associations['hasAndBelongsToMany'])) { $associations['hasAndBelongsToMany'] = array(); } $relations = array_merge($associations['hasMany'], $associations['hasAndBelongsToMany']); -$i = 0; foreach ($relations as $alias => $details): $otherSingularVar = Inflector::variable($alias); $otherPluralHumanName = Inflector::humanize($details['controller']); @@ -112,9 +111,7 @@ foreach ($relations as $alias => $details): "; ?> \n"; +echo "\t\n"; echo "\t\t\n"; foreach ($details['fields'] as $field) { echo "\t\t\t\n"; From d84a2d9419122917c37bfa7a496f4498df40d1c3 Mon Sep 17 00:00:00 2001 From: Andras Kende Date: Wed, 14 Aug 2013 02:16:46 -0700 Subject: [PATCH 06/13] removed $i variable, it not being used... removed $i variable, it not being used... --- lib/Cake/View/Scaffolds/view.ctp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Cake/View/Scaffolds/view.ctp b/lib/Cake/View/Scaffolds/view.ctp index 74b9726f0..5d4d3ff1e 100644 --- a/lib/Cake/View/Scaffolds/view.ctp +++ b/lib/Cake/View/Scaffolds/view.ctp @@ -21,7 +21,6 @@

$_details): ?>
" . Inflector::humanize($_field) . "\n"; From 6f74e1958b116ad032fc8e5c5a7181148f0ae9bd Mon Sep 17 00:00:00 2001 From: Phally Date: Wed, 14 Aug 2013 21:00:31 +0200 Subject: [PATCH 07/13] Makes the locale test not always pass, be verbose when it is skipped. --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 2635a754b..d634134ba 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -587,12 +587,14 @@ class CakeNumberTest extends CakeTestCase { */ public function testReadableSizeLocalized() { $restore = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, 'de_DE'); + + $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); + $result = $this->Number->toReadableSize(1321205); - $this->assertRegExp('/1[,.]26 MB/', $result); + $this->assertEquals('1,26 MB', $result); $result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 512); - $this->assertRegExp('/512[,.]00 GB/', $result); + $this->assertEquals('512,00 GB', $result); setlocale(LC_NUMERIC, $restore); } From 1459e176aca56c763084ec9b8179e315b0ae05bf Mon Sep 17 00:00:00 2001 From: Phally Date: Wed, 14 Aug 2013 21:08:25 +0200 Subject: [PATCH 08/13] Adds German locale for Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 834007621..3a9e45b74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ matrix: - PHPCS=1 before_script: + - sudo locale-gen de_DE - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi" - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test2;'; fi" - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test3;'; fi" From 559fb5805ba1ec0ac60ec2afce920e3e87514b14 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Wed, 14 Aug 2013 16:00:10 +0200 Subject: [PATCH 09/13] Fix formatting with locales using , as decimal separator No double number formatting for readable size Fixed testPrecisionLocalized for travis (when locale is missing?) Switched locale to nl_NL and fixed test Skip test when locale is not available --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 15 +++++++++++++++ lib/Cake/Utility/CakeNumber.php | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 2635a754b..0259c8485 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -596,6 +596,21 @@ class CakeNumberTest extends CakeTestCase { setlocale(LC_NUMERIC, $restore); } +/** + * test precision() with locales + * + * @return void + */ + public function testPrecisionLocalized() { + $restore = setlocale(LC_NUMERIC, 0); + + $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); + + $result = $this->Number->precision(1.234); + $this->assertEquals('1,234', $result); + setlocale(LC_NUMERIC, $restore); + } + /** * testToPercentage method * diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 95bc5231c..7d12dca03 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -84,7 +84,7 @@ class CakeNumber { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision */ public static function precision($value, $precision = 3) { - return sprintf("%01.{$precision}F", $value); + return sprintf("%01.{$precision}f", $value); } /** @@ -99,13 +99,13 @@ class CakeNumber { case $size < 1024: return __dn('cake', '%d Byte', '%d Bytes', $size, $size); case round($size / 1024) < 1024: - return __d('cake', '%d KB', self::precision($size / 1024, 0)); + return __d('cake', '%s KB', self::precision($size / 1024, 0)); case round($size / 1024 / 1024, 2) < 1024: - return __d('cake', '%.2f MB', self::precision($size / 1024 / 1024, 2)); + return __d('cake', '%s MB', self::precision($size / 1024 / 1024, 2)); case round($size / 1024 / 1024 / 1024, 2) < 1024: - return __d('cake', '%.2f GB', self::precision($size / 1024 / 1024 / 1024, 2)); + return __d('cake', '%s GB', self::precision($size / 1024 / 1024 / 1024, 2)); default: - return __d('cake', '%.2f TB', self::precision($size / 1024 / 1024 / 1024 / 1024, 2)); + return __d('cake', '%s TB', self::precision($size / 1024 / 1024 / 1024 / 1024, 2)); } } From 0e49a23065589aa51081ed8974dc6da7b540b9f4 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 14 Aug 2013 22:32:04 +0200 Subject: [PATCH 10/13] Makes the locale test not always pass, be verbose when it is skipped. --- lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php | 3 ++- lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php | 3 ++- lib/Cake/Test/Case/Model/ModelWriteTest.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index d34b80d78..882c71543 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -152,7 +152,8 @@ class MysqlTest extends CakeTestCase { $this->skipIf(DS === '\\', 'The locale is not supported in Windows and affect the others tests.'); $restore = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, 'de_DE'); + + $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); $result = $this->Dbo->value(3.141593); $this->assertEquals('3.141593', $result); diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index c0cfac57f..70336ba0a 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -340,7 +340,8 @@ class PostgresTest extends CakeTestCase { */ public function testLocalizedFloats() { $restore = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, 'de_DE'); + + $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); $result = $this->db->value(3.141593, 'float'); $this->assertEquals("3.141593", $result); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 3562b5c24..505900e7f 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -6472,7 +6472,8 @@ class ModelWriteTest extends BaseModelTest { */ public function testWriteFloatAsGerman() { $restore = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, 'de_DE'); + + $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); $model = new DataTest(); $result = $model->save(array( From 1595287290b6daa2f26c93b529c82882537b2b7e Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 15 Aug 2013 08:58:05 +0200 Subject: [PATCH 11/13] Added workaround for strtotime("0000-00-00 00:00:00") returning -62169955200 on a 64 bit system --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 3 +++ lib/Cake/Utility/CakeTime.php | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 028723b93..95370c25b 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -583,6 +583,9 @@ class CakeTimeTest extends CakeTestCase { $result = $this->Time->format('nonsense', '%d-%m-%Y', 'invalid', 'UTC'); $this->assertEquals('invalid', $result); + + $result = $this->Time->format('0000-00-00', '%d-%m-%Y', 'invalid'); + $this->assertEquals('invalid', $result); } /** diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 635d0612b..21100cc64 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -328,7 +328,12 @@ class CakeTime { } elseif ($dateString instanceof DateTime) { $date = (int)$dateString->format('U'); } else { - $date = strtotime($dateString); + // workaround for strtotime("0000-00-00 00:00:00") returning -62169955200 on a 64 bit system. + if (substr($dateString, 0, 10) === '0000-00-00') { + $date = false; + } else { + $date = strtotime($dateString); + } } if ($date === -1 || empty($date)) { From 85313e84afcbbe20045a560730097bb4d7e072f0 Mon Sep 17 00:00:00 2001 From: Floris Date: Thu, 15 Aug 2013 12:15:09 +0200 Subject: [PATCH 12/13] Minor Sanitize::escape() update If the Datasource is not going to be used, do access it. --- lib/Cake/Utility/Sanitize.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Utility/Sanitize.php b/lib/Cake/Utility/Sanitize.php index 9494ff543..d25513e32 100644 --- a/lib/Cake/Utility/Sanitize.php +++ b/lib/Cake/Utility/Sanitize.php @@ -67,10 +67,10 @@ class Sanitize { * @return string SQL safe string */ public static function escape($string, $connection = 'default') { - $db = ConnectionManager::getDataSource($connection); if (is_numeric($string) || $string === null || is_bool($string)) { return $string; } + $db = ConnectionManager::getDataSource($connection); $string = $db->value($string, 'string'); $start = 1; if ($string{0} === 'N') { From 97aaa89b3f83f760431c56dab108482cbf4f1434 Mon Sep 17 00:00:00 2001 From: Mark van Driel Date: Thu, 15 Aug 2013 17:13:31 +0200 Subject: [PATCH 13/13] Refactored the fix --- lib/Cake/Utility/CakeTime.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 21100cc64..dc546d6ce 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -316,6 +316,11 @@ class CakeTime { return false; } + $containsDummyDate = (is_string($dateString) && substr($dateString, 0, 10) === '0000-00-00'); + if ($containsDummyDate) { + return false; + } + if (is_int($dateString) || is_numeric($dateString)) { $date = intval($dateString); } elseif ( @@ -328,12 +333,7 @@ class CakeTime { } elseif ($dateString instanceof DateTime) { $date = (int)$dateString->format('U'); } else { - // workaround for strtotime("0000-00-00 00:00:00") returning -62169955200 on a 64 bit system. - if (substr($dateString, 0, 10) === '0000-00-00') { - $date = false; - } else { - $date = strtotime($dateString); - } + $date = strtotime($dateString); } if ($date === -1 || empty($date)) {