From 6ec0afcf5d813382964798944893ee5db7f0574c Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 25 Jun 2012 17:34:30 +0200 Subject: [PATCH 01/83] Add CakeNumber::fromReadableSize() and Validation::filesize() --- .../Console/Command/Task/ModelTaskTest.php | 4 +- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 39 +++++++++++++++++++ lib/Cake/Test/Case/Utility/ValidationTest.php | 21 +++++++++- lib/Cake/Utility/CakeNumber.php | 22 +++++++++++ lib/Cake/Utility/Validation.php | 22 +++++++++++ 5 files changed, 105 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 2e3c5d9d1..9f7479d29 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -315,7 +315,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->initValidations(); $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('23', 'y', '17', 'n')); + ->will($this->onConsecutiveCalls('24', 'y', '18', 'n')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); $expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength'); @@ -333,7 +333,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->interactive = true; $this->Task->expects($this->any())->method('in') - ->will($this->onConsecutiveCalls('999999', '23', 'n')); + ->will($this->onConsecutiveCalls('999999', '24', 'n')); $this->Task->expects($this->at(10))->method('out') ->with($this->stringContains('make a valid')); diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index bcae41d85..25737679f 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -523,4 +523,43 @@ class CakeNumberTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * testFromReadableSize + * + * @dataProvider filesizes + * @return void + */ + public function testFromReadableSize($size, $expected) { + $result = $this->Number->fromReadableSize($size); + $this->assertEquals($expected, $result); + } + +/** + * testFromReadableSize + * + * @expectedException CakeException + * @return void + */ + public function testFromReadableSizeException() { + $result = $this->Number->fromReadableSize('bogus'); + } + +/** + * filesizes dataprovider + * + * @return array + */ + public function filesizes() { + return array( + array('512B', 512), + array('1KB', 1024), + array('1.5KB', 1536), + array('1MB', 1048576), + array('1.5MB', 1572864), + array('1GB', 1073741824), + array('1.5GB', 1610612736), + array('512', 512), + ); + } + } diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index a3f98f9fd..887123cd4 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -2203,7 +2203,7 @@ class ValidationTest extends CakeTestCase { } /** - * testMimeType method + * testUploadError method * * @return void */ @@ -2214,4 +2214,23 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::uploadError(2)); $this->assertFalse(Validation::uploadError(array('error' => 2))); } + +/** + * testFileSize method + * + * @return void + */ + public function testFileSize() { + $image = CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif'; + $this->assertTrue(Validation::fileSize($image, '<', 1024)); + $this->assertTrue(Validation::fileSize(array('tmp_name' => $image), 'isless', 1024)); + $this->assertTrue(Validation::fileSize($image, '<', '1KB')); + $this->assertTrue(Validation::fileSize($image, '>=', 200)); + $this->assertTrue(Validation::fileSize($image, '==', 201)); + $this->assertTrue(Validation::fileSize($image, '==', '201B')); + + $this->assertFalse(Validation::fileSize($image, 'isgreater', 1024)); + $this->assertFalse(Validation::fileSize(array('tmp_name' => $image), '>', '1KB')); + } + } diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 3b21cbc36..d12b4f90a 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -101,6 +101,28 @@ class CakeNumber { } } +/** + * Converts filesize from human readable string to bytes + * + * @param string $size Size in human readable string like '5MB' + * @return integer Bytes + */ + public static function fromReadableSize($size) { + if (ctype_digit($size)) { + return $size * 1; + } + $units = array('KB', 'MB', 'GB', 'TB', 'PB'); + foreach ($units as $i => $unit) { + if ($unit == substr($size, -2)) { + return $size * pow(1024, $i + 1); + } + } + if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) { + return $size * 1; + } + throw new CakeException(__d('cake_dev', 'No unit type.')); + } + /** * Formats a number into a percentage string. * diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index d08c227ae..9a3805626 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -19,6 +19,7 @@ App::uses('Multibyte', 'I18n'); App::uses('File', 'Utility'); +App::uses('CakeNumber', 'Utility'); // Load multibyte if the extension is missing. if (!function_exists('mb_strlen')) { class_exists('Multibyte'); @@ -881,6 +882,27 @@ class Validation { return in_array($mime, $mimeTypes); } +/** + * Checks the filesize + * + * @param string|array $check + * @param integer|string $size Size in bytes or human readable string like '5MB' + * @param string $operator See `Validation::comparison()` + * @return boolean Success + */ + public static function fileSize($check, $operator = null, $size = null) { + if (is_array($check) && isset($check['tmp_name'])) { + $check = $check['tmp_name']; + } + + if (is_string($size)) { + $size = CakeNumber::fromReadableSize($size); + } + $filesize = filesize($check); + + return self::comparison($filesize, $operator, $size); + } + /** * Checking for upload errors * From a4c382b23a518d01d1866d2d3584d602487c952d Mon Sep 17 00:00:00 2001 From: schrolli Date: Sun, 2 Sep 2012 06:02:30 +0300 Subject: [PATCH 02/83] Update lib/Cake/Configure/IniReader.php Copied standard path from PhpReader --- lib/Cake/Configure/IniReader.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Configure/IniReader.php b/lib/Cake/Configure/IniReader.php index 900d65489..1e5180ff5 100644 --- a/lib/Cake/Configure/IniReader.php +++ b/lib/Cake/Configure/IniReader.php @@ -77,6 +77,9 @@ class IniReader implements ConfigReaderInterface { * all sections in the ini file. */ public function __construct($path, $section = null) { + if (!$path) { + $path = APP . 'Config' . DS; + } $this->_path = $path; $this->_section = $section; } From 83c05c24b325808ddaaa1dd1d8e46354139d1b1c Mon Sep 17 00:00:00 2001 From: schrolli Date: Sun, 2 Sep 2012 14:23:26 +0300 Subject: [PATCH 03/83] Update lib/Cake/Configure/IniReader.php Updated docblock and set NULL as the default value of $path --- lib/Cake/Configure/IniReader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Configure/IniReader.php b/lib/Cake/Configure/IniReader.php index 1e5180ff5..49b81b80f 100644 --- a/lib/Cake/Configure/IniReader.php +++ b/lib/Cake/Configure/IniReader.php @@ -72,11 +72,11 @@ class IniReader implements ConfigReaderInterface { * Build and construct a new ini file parser. The parser can be used to read * ini files that are on the filesystem. * - * @param string $path Path to load ini config files from. + * @param string $path Path to load ini config files from. Defaults to APP . 'Config' . DS * @param string $section Only get one section, leave null to parse and fetch * all sections in the ini file. */ - public function __construct($path, $section = null) { + public function __construct($path = null, $section = null) { if (!$path) { $path = APP . 'Config' . DS; } From 2170d87488017f3eb719289fcf11af07ee223f46 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 4 Sep 2012 01:04:48 +0200 Subject: [PATCH 04/83] check() for CookieComponent and Configure (similar to `CakeSession::check()`) --- .../Controller/Component/CookieComponent.php | 14 +++++ lib/Cake/Core/Configure.php | 14 +++++ .../Component/CookieComponentTest.php | 54 +++++++++++++++++++ lib/Cake/Test/Case/Core/ConfigureTest.php | 54 +++++++++++++++++++ .../Case/Model/Datasource/CakeSessionTest.php | 2 +- 5 files changed, 137 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index 45551a8af..bdf344a5b 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -281,6 +281,20 @@ class CookieComponent extends Component { return $this->_values[$this->name][$key]; } +/** + * Returns true if given variable is set in cookie. + * + * @param string $var Variable name to check for + * @return boolean True if variable is there + */ + public function check($key = null) { + if (empty($key)) { + return false; + } + $result = $this->read($key); + return isset($result); + } + /** * Delete a cookie value * diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 09615825c..f2101f795 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -170,6 +170,20 @@ class Configure { return Hash::get(self::$_values, $var); } +/** + * Returns true if given variable is set in Configure. + * + * @param string $var Variable name to check for + * @return boolean True if variable is there + */ + public static function check($var = null) { + if (empty($var)) { + return false; + } + $result = Hash::get(self::$_values, $var); + return isset($result); + } + /** * Used to delete a variable from Configure. * diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index 6ed65a673..7609b89ae 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -536,6 +536,60 @@ class CookieComponentTest extends CakeTestCase { $this->assertNull($this->Cookie->read('value')); } +/** + * testCheck method + * + * @return void + */ + public function testCheck() { + $this->Cookie->write('CookieComponentTestCase', 'value'); + $this->assertTrue($this->Cookie->check('CookieComponentTestCase')); + + $this->assertFalse($this->Cookie->check('NotExistingCookieComponentTestCase')); + } + +/** + * testCheckingSavedEmpty method + * + * @return void + */ + public function testCheckingSavedEmpty() { + $this->Cookie->write('CookieComponentTestCase', 0); + $this->assertTrue($this->Cookie->check('CookieComponentTestCase')); + + $this->Cookie->write('CookieComponentTestCase', '0'); + $this->assertTrue($this->Cookie->check('CookieComponentTestCase')); + + $this->Cookie->write('CookieComponentTestCase', false); + $this->assertTrue($this->Cookie->check('CookieComponentTestCase')); + + $this->Cookie->write('CookieComponentTestCase', null); + $this->assertFalse($this->Cookie->check('CookieComponentTestCase')); + } + +/** + * testCheckKeyWithSpaces method + * + * @return void + */ + public function testCheckKeyWithSpaces() { + $this->Cookie->write('CookieComponent Test', "test"); + $this->assertTrue($this->Cookie->check('CookieComponent Test')); + $this->Cookie->delete('CookieComponent Test'); + + $this->Cookie->write('CookieComponent Test.Test Case', "test"); + $this->assertTrue($this->Cookie->check('CookieComponent Test.Test Case')); + } + +/** + * testCheckEmpty + * + * @return void + */ + public function testCheckEmpty() { + $this->assertFalse($this->Cookie->check()); + } + /** * test that deleting a top level keys kills the child elements too. * diff --git a/lib/Cake/Test/Case/Core/ConfigureTest.php b/lib/Cake/Test/Case/Core/ConfigureTest.php index 7351f83f1..5dd1fe0b6 100644 --- a/lib/Cake/Test/Case/Core/ConfigureTest.php +++ b/lib/Cake/Test/Case/Core/ConfigureTest.php @@ -177,6 +177,60 @@ class ConfigureTest extends CakeTestCase { $this->assertTrue($result === null); } +/** + * testCheck method + * + * @return void + */ + public function testCheck() { + Configure::write('ConfigureTestCase', 'value'); + $this->assertTrue(Configure::check('ConfigureTestCase')); + + $this->assertFalse(Configure::check('NotExistingConfigureTestCase')); + } + +/** + * testCheckingSavedEmpty method + * + * @return void + */ + public function testCheckingSavedEmpty() { + $this->assertTrue(Configure::write('ConfigureTestCase', 0)); + $this->assertTrue(Configure::check('ConfigureTestCase')); + + $this->assertTrue(Configure::write('ConfigureTestCase', '0')); + $this->assertTrue(Configure::check('ConfigureTestCase')); + + $this->assertTrue(Configure::write('ConfigureTestCase', false)); + $this->assertTrue(Configure::check('ConfigureTestCase')); + + $this->assertTrue(Configure::write('ConfigureTestCase', null)); + $this->assertFalse(Configure::check('ConfigureTestCase')); + } + +/** + * testCheckKeyWithSpaces method + * + * @return void + */ + public function testCheckKeyWithSpaces() { + $this->assertTrue(Configure::write('Configure Test', "test")); + $this->assertTrue(Configure::check('Configure Test')); + Configure::delete('Configure Test'); + + $this->assertTrue(Configure::write('Configure Test.Test Case', "test")); + $this->assertTrue(Configure::check('Configure Test.Test Case')); + } + +/** + * testCheckEmpty + * + * @return void + */ + public function testCheckEmpty() { + $this->assertFalse(Configure::check()); + } + /** * testLoad method * diff --git a/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php b/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php index a2276972f..0c98febaa 100644 --- a/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php @@ -231,7 +231,7 @@ class CakeSessionTest extends CakeTestCase { TestCakeSession::write('SessionTestCase', 'value'); $this->assertTrue(TestCakeSession::check('SessionTestCase')); - $this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase'), false); + $this->assertFalse(TestCakeSession::check('NotExistingSessionTestCase')); } /** From bc40ac7d3f5c3f5448225bff3f368db7902e9107 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Wed, 5 Sep 2012 15:22:30 -0700 Subject: [PATCH 05/83] Remove unused variables and code --- lib/Cake/Controller/Component/Acl/PhpAcl.php | 2 -- lib/Cake/Controller/Controller.php | 1 - lib/Cake/Core/Configure.php | 1 - lib/Cake/Model/Behavior/TranslateBehavior.php | 1 - lib/Cake/Model/CakeSchema.php | 4 ++-- lib/Cake/Model/Datasource/CakeSession.php | 1 - lib/Cake/Model/Datasource/Database/Postgres.php | 2 +- lib/Cake/Model/Datasource/Database/Sqlite.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 12 ++++++------ lib/Cake/Model/Model.php | 6 +++--- lib/Cake/Network/CakeRequest.php | 2 +- lib/Cake/Utility/ClassRegistry.php | 2 +- lib/Cake/Utility/Debugger.php | 1 - lib/Cake/Utility/Folder.php | 2 +- lib/Cake/Utility/Hash.php | 1 - lib/Cake/View/Helper/FormHelper.php | 3 +-- lib/Cake/View/Helper/MootoolsEngineHelper.php | 1 - lib/Cake/View/Helper/PrototypeEngineHelper.php | 1 - lib/Cake/View/Helper/RssHelper.php | 2 +- lib/Cake/View/Helper/TimeHelper.php | 1 - lib/Cake/View/MediaView.php | 2 -- lib/Cake/View/View.php | 7 +------ 22 files changed, 19 insertions(+), 38 deletions(-) diff --git a/lib/Cake/Controller/Component/Acl/PhpAcl.php b/lib/Cake/Controller/Component/Acl/PhpAcl.php index 28b3b941f..d63217857 100644 --- a/lib/Cake/Controller/Component/Acl/PhpAcl.php +++ b/lib/Cake/Controller/Component/Acl/PhpAcl.php @@ -318,10 +318,8 @@ class PhpAco { * @return void */ public function build(array $allow, array $deny = array()) { - $stack = array(); $this->_tree = array(); $tree = array(); - $root = &$tree; foreach ($allow as $dotPath => $aros) { if (is_string($aros)) { diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index fa8b7dae9..978dade84 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -557,7 +557,6 @@ class Controller extends Object implements CakeEventListener { if ($mergeParent || !empty($pluginController)) { $appVars = get_class_vars($this->_mergeParent); - $uses = $appVars['uses']; $merge = array('components', 'helpers'); $this->_mergeVars($merge, $this->_mergeParent, true); } diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 09615825c..9896aa8de 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -185,7 +185,6 @@ class Configure { */ public static function delete($var = null) { $keys = explode('.', $var); - $last = array_pop($keys); self::$_values = Hash::remove(self::$_values, $var); } diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index f90615992..8adbd35c8 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -603,7 +603,6 @@ class TranslateBehavior extends ModelBehavior { if (is_string($fields)) { $fields = array($fields); } - $RuntimeModel = $this->translateModel($Model); $associations = array(); foreach ($fields as $key => $value) { diff --git a/lib/Cake/Model/CakeSchema.php b/lib/Cake/Model/CakeSchema.php index 60c3b7643..2fda5f75e 100644 --- a/lib/Cake/Model/CakeSchema.php +++ b/lib/Cake/Model/CakeSchema.php @@ -271,7 +271,7 @@ class CakeSchema extends Object { unset($currentTables[$key]); } if (!empty($Object->hasAndBelongsToMany)) { - foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) { + foreach ($Object->hasAndBelongsToMany as $assocData) { if (isset($assocData['with'])) { $class = $assocData['with']; } @@ -597,7 +597,7 @@ class CakeSchema extends Object { $db = $Obj->getDataSource(); $fields = $Obj->schema(true); - $columns = $props = array(); + $columns = array(); foreach ($fields as $name => $value) { if ($Obj->primaryKey == $name) { $value['key'] = 'primary'; diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 6baab1d5b..af457cdba 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -449,7 +449,6 @@ class CakeSession { */ protected static function _configureSession() { $sessionConfig = Configure::read('Session'); - $iniSet = function_exists('ini_set'); if (isset($sessionConfig['defaults'])) { $defaults = self::_defaultConfig($sessionConfig['defaults']); diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index cd7cffcac..2c7b8472e 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -438,7 +438,7 @@ class Postgres extends DboSource { ) AND c.oid = i.indrelid AND i.indexrelid = c2.oid ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", false); - foreach ($indexes as $i => $info) { + foreach ($indexes as $info) { $key = array_pop($info); if ($key['indisprimary']) { $key['relname'] = 'PRIMARY'; diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index e85504ed5..e267f5a65 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -474,7 +474,7 @@ class Sqlite extends DboSource { if (is_bool($indexes)) { return array(); } - foreach ($indexes as $i => $info) { + foreach ($indexes as $info) { $key = array_pop($info); $keyInfo = $this->query('PRAGMA index_info("' . $key['name'] . '")'); foreach ($keyInfo as $keyCol) { diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index e05763b0e..c8efb56fc 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1294,9 +1294,9 @@ class DboSource extends DataSource { } } if ($type === 'hasAndBelongsToMany') { - $uniqueIds = $merge = array(); + $merge = array(); - foreach ($fetch as $j => $data) { + foreach ($fetch as $data) { if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$modelAlias][$modelPK]) { if ($habtmFieldsCount <= 2) { unset($data[$with]); @@ -1445,7 +1445,7 @@ class DboSource extends DataSource { $data[$association] = array(); } } else { - foreach ($merge as $i => $row) { + foreach ($merge as $row) { $insert = array(); if (count($row) === 1) { $insert = $row[$association]; @@ -2413,7 +2413,7 @@ class DboSource extends DataSource { } $clauses = '/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i'; - if (preg_match($clauses, $conditions, $match)) { + if (preg_match($clauses, $conditions)) { $clause = ''; } $conditions = $this->_quoteFields($conditions); @@ -2908,7 +2908,7 @@ class DboSource extends DataSource { $columnMap[$key] = $pdoMap[$type]; } - foreach ($values as $row => $value) { + foreach ($values as $value) { $i = 1; foreach ($value as $col => $val) { $statement->bindValue($i, $val, $columnMap[$col]); @@ -3205,7 +3205,7 @@ class DboSource extends DataSource { $isAllFloat = $isAllInt = true; $containsFloat = $containsInt = $containsString = false; - foreach ($value as $key => $valElement) { + foreach ($value as $valElement) { $valElement = trim($valElement); if (!is_float($valElement) && !preg_match('/^[\d]+\.[\d]+$/', $valElement)) { $isAllFloat = false; diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 515f2e5b3..1e6dc56a5 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2363,7 +2363,7 @@ class Model extends Object implements CakeEventListener { $updateCounterCache = false; if (!empty($this->belongsTo)) { - foreach ($this->belongsTo as $parent => $assoc) { + foreach ($this->belongsTo as $assoc) { if (!empty($assoc['counterCache'])) { $updateCounterCache = true; break; @@ -2449,7 +2449,7 @@ class Model extends Object implements CakeEventListener { * @return void */ protected function _deleteLinks($id) { - foreach ($this->hasAndBelongsToMany as $assoc => $data) { + foreach ($this->hasAndBelongsToMany as $data) { list($plugin, $joinModel) = pluginSplit($data['with']); $records = $this->{$joinModel}->find('all', array( 'conditions' => array($this->{$joinModel}->escapeField($data['foreignKey']) => $id), @@ -3042,7 +3042,7 @@ class Model extends Object implements CakeEventListener { public function isForeignKey($field) { $foreignKeys = array(); if (!empty($this->belongsTo)) { - foreach ($this->belongsTo as $assoc => $data) { + foreach ($this->belongsTo as $data) { $foreignKeys[] = $data['foreignKey']; } } diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 1ac08cf8f..238793912 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -675,7 +675,7 @@ class CakeRequest implements ArrayAccess { public function accepts($type = null) { $raw = $this->parseAccept(); $accept = array(); - foreach ($raw as $value => $types) { + foreach ($raw as $types) { $accept = array_merge($accept, $types); } if ($type === null) { diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index da7b125a7..6dd757f30 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -175,7 +175,7 @@ class ClassRegistry { } if (!isset($instance)) { - trigger_error(__d('cake_dev', '(ClassRegistry::init() could not create instance of %1$s class %2$s ', $class, $type), E_USER_WARNING); + trigger_error(__d('cake_dev', '(ClassRegistry::init() could not create instance of %s', $class), E_USER_WARNING); return $false; } } diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 3a58cb326..0a0d746b4 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -213,7 +213,6 @@ class Debugger { if (empty($line)) { $line = '??'; } - $path = self::trimPath($file); $info = compact('code', 'description', 'file', 'line'); if (!in_array($info, $self->errors)) { diff --git a/lib/Cake/Utility/Folder.php b/lib/Cake/Utility/Folder.php index 08895bf2e..bda485869 100644 --- a/lib/Cake/Utility/Folder.php +++ b/lib/Cake/Utility/Folder.php @@ -367,7 +367,7 @@ class Folder { $paths = $this->tree($path); foreach ($paths as $type) { - foreach ($type as $key => $fullpath) { + foreach ($type as $fullpath) { $check = explode(DS, $fullpath); $count = count($check); diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 9514cccb9..fc133ff5f 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -432,7 +432,6 @@ class Hash { } $stack = array(); - $i = 1; while (!empty($needle)) { $key = key($needle); $val = $needle[$key]; diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d24bb997e..3cf95a59e 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -194,7 +194,7 @@ class FormHelper extends AppHelper { if ($key === 'fields') { if (!isset($this->fieldset[$model]['fields'])) { - $fields = $this->fieldset[$model]['fields'] = $object->schema(); + $this->fieldset[$model]['fields'] = $object->schema(); foreach ($object->hasAndBelongsToMany as $alias => $assocData) { $this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple'); } @@ -320,7 +320,6 @@ class FormHelper extends AppHelper { $key = null; if ($model !== false) { - $object = $this->_getModel($model); $key = $this->_introspectModel($model, 'key'); $this->setEntity($model, true); } diff --git a/lib/Cake/View/Helper/MootoolsEngineHelper.php b/lib/Cake/View/Helper/MootoolsEngineHelper.php index 3919754fe..cc0340b6e 100644 --- a/lib/Cake/View/Helper/MootoolsEngineHelper.php +++ b/lib/Cake/View/Helper/MootoolsEngineHelper.php @@ -254,7 +254,6 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $options['url'] = $url; $options = $this->_prepareCallbacks('request', $options); if (!empty($options['dataExpression'])) { - $callbacks[] = 'data'; unset($options['dataExpression']); } elseif (!empty($data)) { $data = $this->object($data); diff --git a/lib/Cake/View/Helper/PrototypeEngineHelper.php b/lib/Cake/View/Helper/PrototypeEngineHelper.php index c1feb6d41..6c483aa13 100644 --- a/lib/Cake/View/Helper/PrototypeEngineHelper.php +++ b/lib/Cake/View/Helper/PrototypeEngineHelper.php @@ -237,7 +237,6 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { $url = '"' . $this->url($url) . '"'; $options = $this->_mapOptions('request', $options); $type = '.Request'; - $data = null; if (isset($options['type']) && strtolower($options['type']) == 'json') { unset($options['type']); } diff --git a/lib/Cake/View/Helper/RssHelper.php b/lib/Cake/View/Helper/RssHelper.php index 26160f055..6e9db7cb3 100644 --- a/lib/Cake/View/Helper/RssHelper.php +++ b/lib/Cake/View/Helper/RssHelper.php @@ -341,7 +341,7 @@ class RssHelper extends AppHelper { $nodes->item(0)->setAttribute($key, $value); } } - foreach ($children as $k => $child) { + foreach ($children as $child) { $child = $elem->createElement($name, $child); $nodes->item(0)->appendChild($child); } diff --git a/lib/Cake/View/Helper/TimeHelper.php b/lib/Cake/View/Helper/TimeHelper.php index 284917971..630952817 100644 --- a/lib/Cake/View/Helper/TimeHelper.php +++ b/lib/Cake/View/Helper/TimeHelper.php @@ -358,7 +358,6 @@ class TimeHelper extends AppHelper { */ public function timeAgoInWords($dateTime, $options = array()) { $element = null; - $stringDate = ''; if (is_array($options) && !empty($options['element'])) { $element = array( diff --git a/lib/Cake/View/MediaView.php b/lib/Cake/View/MediaView.php index 49a3140a8..9dec162f0 100644 --- a/lib/Cake/View/MediaView.php +++ b/lib/Cake/View/MediaView.php @@ -101,8 +101,6 @@ class MediaView extends View { if ($this->_isActive()) { $extension = strtolower($extension); - $chunkSize = 8192; - $buffer = ''; $fileSize = @filesize($path); $handle = fopen($path, 'rb'); diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index b65a8fa52..9fa93d01c 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -289,11 +289,6 @@ class View extends Object { */ protected $_eventManager = null; -/** - * The view file to be rendered, only used inside _execute() - */ - private $__viewFileName = null; - /** * Whether the event manager was already configured for this object * @@ -856,7 +851,7 @@ class View extends Object { */ public function loadHelpers() { $helpers = HelperCollection::normalizeObjectArray($this->helpers); - foreach ($helpers as $name => $properties) { + foreach ($helpers as $properties) { list($plugin, $class) = pluginSplit($properties['class']); $this->{$class} = $this->Helpers->load($properties['class'], $properties['settings']); } From 0b0d83f261d3d1dd9068841a2e6161a2b10e3633 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 7 Sep 2012 00:04:03 +0200 Subject: [PATCH 06/83] remove cookie reading in startup --- lib/Cake/Controller/Component/CookieComponent.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index 9f0879f92..f314c42fa 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -191,9 +191,6 @@ class CookieComponent extends Component { $this->_expire($this->time); $this->_values[$this->name] = array(); - if (isset($_COOKIE[$this->name])) { - $this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]); - } } /** From 9ac5cbed3669a0af6faa6e8130ce2994213e8177 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 9 Sep 2012 15:32:50 +0200 Subject: [PATCH 07/83] Added MailTransport test class refs #2824 --- lib/Cake/Network/Email/MailTransport.php | 29 +++++-- .../Case/Network/Email/MailTransportTest.php | 84 +++++++++++++++++++ 2 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 lib/Cake/Test/Case/Network/Email/MailTransportTest.php diff --git a/lib/Cake/Network/Email/MailTransport.php b/lib/Cake/Network/Email/MailTransport.php index ae63b7612..2b849772a 100644 --- a/lib/Cake/Network/Email/MailTransport.php +++ b/lib/Cake/Network/Email/MailTransport.php @@ -41,14 +41,31 @@ class MailTransport extends AbstractTransport { unset($headers['To']); $headers = $this->_headersToString($headers, $eol); $message = implode($eol, $email->message()); - if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) { - if (!@mail($to, $email->subject(), $message, $headers)) { - throw new SocketException(__d('cake_dev', 'Could not send email.')); - } - } elseif (!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) { - throw new SocketException(__d('cake_dev', 'Could not send email.')); + + $params = null; + if (!ini_get('safe_mode')) { + $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null; } + + $this->_mail($to, $email->subject(), $message, $headers, $params); return array('headers' => $headers, 'message' => $message); } +/** + * Wraps internal function mail() and throws exception instead of errors if anything goes wrong + * + * @param string $to email's recipient + * @param string $subject email's subject + * @param string $message email's body + * @param string $headers email's custom headers + * @param string $params additional params for sending email + * @throws SocketException if mail could not be sent + * @return void + */ + protected function _mail($to, $subject, $message, $headers, $params = null) { + if (!@mail($to, $subject, $message, $headers, $params)) { + throw new SocketException(__d('cake_dev', 'Could not send email.')); + } + } + } diff --git a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php new file mode 100644 index 000000000..2d1741b44 --- /dev/null +++ b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php @@ -0,0 +1,84 @@ + + * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.Test.Case.Network.Email + * @since CakePHP(tm) v 2.0.0 + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + */ +App::uses('CakeEmail', 'Network/Email'); +App::uses('AbstractTransport', 'Network/Email'); +App::uses('MailTransport', 'Network/Email'); + + +/** + * Test case + * + */ +class MailTransportTest extends CakeTestCase { + +/** + * Setup + * + * @return void + */ + public function setUp() { + $this->MailTransport = $this->getMock('MailTransport', array('_mail')); + $this->MailTransport->config(array('additionalParameters' => '-f')); + } + +/** + * testSend method + * + * @return void + */ + public function testSendData() { + $email = $this->getMock('CakeEmail', array('message'), array()); + $email->from('noreply@cakephp.org', 'CakePHP Test'); + $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return'); + $email->to('cake@cakephp.org', 'CakePHP'); + $email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); + $email->bcc('phpnut@cakephp.org'); + $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); + $email->subject('Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz'); + $date = date(DATE_RFC2822); + $email->setHeaders(array('X-Mailer' => 'CakePHP Email', 'Date' => $date)); + $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); + + $data = "From: CakePHP Test " . PHP_EOL; + $data .= "Return-Path: CakePHP Return " . PHP_EOL; + $data .= "Cc: Mark Story , Juan Basso " . PHP_EOL; + $data .= "Bcc: phpnut@cakephp.org" . PHP_EOL; + $data .= "X-Mailer: CakePHP Email" . PHP_EOL; + $data .= "Date: " . $date . PHP_EOL; + $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL; + $data .= "MIME-Version: 1.0" . PHP_EOL; + $data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL; + $data .= "Content-Transfer-Encoding: 8bit"; + + $subject = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?='; + $subject .= "\r\n" . ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?='; + $this->MailTransport->expects($this->once())->method('_mail') + ->with( + 'CakePHP ', + $subject, + implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')), + $data, + '-f' + ); + + $this->MailTransport->send($email); + } + +} + From a934f700f1cf4b11580c98f360bbca3236bb62ac Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Sep 2012 20:56:40 -0400 Subject: [PATCH 08/83] Fix parsing '0' as a url. Fixes #3198 --- lib/Cake/Routing/Router.php | 2 +- lib/Cake/Test/Case/Routing/RouterTest.php | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index cb28f6e9c..2c56c5290 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -518,7 +518,7 @@ class Router { $ext = null; $out = array(); - if ($url && strpos($url, '/') !== 0) { + if (strlen($url) && strpos($url, '/') !== 0) { $url = '/' . $url; } if (strpos($url, '?') !== false) { diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 44bf6aacd..b4c956de0 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -451,6 +451,30 @@ class RouterTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * Test that catch all routes work with a variety of falsey inputs. + * + * @return void + */ + public function testUrlCatchAllRoute() { + Router::connect('/*', array('controller' => 'categories', 'action' => 'index')); + $result = Router::url(array('controller' => 'categories', 'action' => 'index', '0')); + $this->assertEquals('/0', $result); + + $expected = array( + 'plugin' => null, + 'controller' => 'categories', + 'action' => 'index', + 'pass' => array('0'), + 'named' => array() + ); + $result = Router::parse('/0'); + $this->assertEquals($expected, $result); + + $result = Router::parse('0'); + $this->assertEquals($expected, $result); + } + /** * Tests using arrays in named parameters * From e8c1140fc8f5f54d16302151386bc12e2bbb0c83 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Sep 2012 21:08:21 -0400 Subject: [PATCH 09/83] Fix notice error. --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index e5817f87d..8040073c3 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -268,7 +268,7 @@ class DebuggerTest extends CakeTestCase { * Test method for testing addFormat with callbacks. */ public function customFormat($error, $strings) { - return $error['error'] . ': I eated an error ' . $error['path']; + return $error['error'] . ': I eated an error ' . $error['file']; } /** From d26040e3aa2173dfc3562ceb522287eb1083a5db Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Sep 2012 21:25:53 -0400 Subject: [PATCH 10/83] Fix failing tests in PHPUnit 3.7.0-RC2 --- .../Test/Case/Event/CakeEventManagerTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 04a358ab4..4211e8e86 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -241,11 +241,13 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); - $firstStep = clone $event; - $listener->expects($this->at(0))->method('listenerFunction') - ->with($firstStep) + $listener->expects($this->at(0)) + ->method('listenerFunction') + ->with($event) ->will($this->returnValue('something special')); - $anotherListener->expects($this->at(0))->method('listenerFunction')->with($event); + $anotherListener->expects($this->at(0)) + ->method('listenerFunction') + ->with($event); $manager->dispatch($event); $this->assertEquals('something special', $event->result); } @@ -263,11 +265,11 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); - $originalEvent = clone $event; $listener->expects($this->at(0))->method('listenerFunction') - ->with($originalEvent) + ->with($event) ->will($this->returnValue(false)); - $anotherListener->expects($this->never())->method('listenerFunction'); + $anotherListener->expects($this->never()) + ->method('listenerFunction'); $manager->dispatch($event); $this->assertTrue($event->isStopped()); } From 4f637ed4c4dc1b4c1f280bc0c3f16d2530e88de4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Sep 2012 21:36:33 -0400 Subject: [PATCH 11/83] Revert "Fix failing tests in PHPUnit 3.7.0-RC2" This reverts commit d26040e3aa2173dfc3562ceb522287eb1083a5db. This change causes tests to fail in PHPUnit 3.6, this will have to wait until 3.7.0 stable. --- .../Test/Case/Event/CakeEventManagerTest.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 4211e8e86..04a358ab4 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -241,13 +241,11 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); - $listener->expects($this->at(0)) - ->method('listenerFunction') - ->with($event) + $firstStep = clone $event; + $listener->expects($this->at(0))->method('listenerFunction') + ->with($firstStep) ->will($this->returnValue('something special')); - $anotherListener->expects($this->at(0)) - ->method('listenerFunction') - ->with($event); + $anotherListener->expects($this->at(0))->method('listenerFunction')->with($event); $manager->dispatch($event); $this->assertEquals('something special', $event->result); } @@ -265,11 +263,11 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); + $originalEvent = clone $event; $listener->expects($this->at(0))->method('listenerFunction') - ->with($event) + ->with($originalEvent) ->will($this->returnValue(false)); - $anotherListener->expects($this->never()) - ->method('listenerFunction'); + $anotherListener->expects($this->never())->method('listenerFunction'); $manager->dispatch($event); $this->assertTrue($event->isStopped()); } From ce1b387de298c10db8a37e95dca53ad88448955b Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 10 Sep 2012 09:17:29 +0200 Subject: [PATCH 12/83] fix incorrect docblock --- lib/Cake/Test/Case/Network/Email/MailTransportTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php index 2d1741b44..9e102c1be 100644 --- a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php @@ -1,6 +1,6 @@ Date: Tue, 11 Sep 2012 21:47:25 -0400 Subject: [PATCH 13/83] Forward model option to PaginatorHelper::link(). Fixes #3193 --- lib/Cake/View/Helper/PaginatorHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 05a9935b1..252aea8a4 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -471,7 +471,7 @@ class PaginatorHelper extends AppHelper { $url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url); if ($this->{$check}($model)) { - return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class')); + return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'model'))), compact('class')); } else { unset($options['rel']); return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class'))); From 99a9cc96693a62a8f64510fd7d312f760a40540b Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 11 Sep 2012 21:59:46 -0400 Subject: [PATCH 14/83] Fix required field detection. Fix required field detection to match documentation and behavior when validating. Having `allowEmpty` in the first validation rule, makes the field not 'required' as the field is allowed to be empty. Fixes #3194 --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 3 +-- lib/Cake/View/Helper/FormHelper.php | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 0b964cc20..0a4a5e78a 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -107,8 +107,7 @@ class Contact extends CakeTestModel { 'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')), 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')), 'imrequiredonboth' => array( - 'required' => array('rule' => 'alphaNumeric', 'allowEmpty' => true), - 'check' => array('rule' => 'alphaNumeric') + 'required' => array('rule' => 'alphaNumeric'), ), 'string_required' => 'notEmpty', 'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 3cf95a59e..d70e4d286 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -244,13 +244,16 @@ class FormHelper extends AppHelper { * @return boolean true if field is required to be filled, false otherwise */ protected function _isRequiredField($validationRules) { + if (empty($validationRules) || count($validationRules) === 0) { + return false; + } foreach ($validationRules as $rule) { $rule->isUpdate($this->requestType === 'put'); - if (!$rule->isEmptyAllowed()) { - return true; + if ($rule->isEmptyAllowed()) { + return false; } } - return false; + return true; } /** From fb9360767ea25281bc0d9761b80e068131a96beb Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Sep 2012 22:31:07 -0400 Subject: [PATCH 15/83] Make connection exceptions more helpful. Fixes #3204 --- lib/Cake/Model/Datasource/Database/Mysql.php | 5 ++++- lib/Cake/Model/Datasource/Database/Postgres.php | 5 ++++- lib/Cake/Model/Datasource/Database/Sqlite.php | 5 ++++- lib/Cake/Model/Datasource/Database/Sqlserver.php | 5 ++++- lib/Cake/Model/Datasource/DboSource.php | 1 + lib/Cake/Test/Case/Error/ExceptionRendererTest.php | 6 +++--- lib/Cake/View/Errors/missing_connection.ctp | 8 +++++++- 7 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index c26de45e7..f96dfa420 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -149,7 +149,10 @@ class Mysql extends DboSource { ); $this->connected = true; } catch (PDOException $e) { - throw new MissingConnectionException(array('class' => $e->getMessage())); + throw new MissingConnectionException(array( + 'class' => get_class($this), + 'message' => $e->getMessage() + )); } $this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">="); diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 2c7b8472e..cca94a664 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -121,7 +121,10 @@ class Postgres extends DboSource { $this->_execute('SET search_path TO ' . $config['schema']); } } catch (PDOException $e) { - throw new MissingConnectionException(array('class' => $e->getMessage())); + throw new MissingConnectionException(array( + 'class' => get_class($this), + 'message' => $e->getMessage() + )); } return $this->connected; diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index e267f5a65..d30cc67df 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -113,7 +113,10 @@ class Sqlite extends DboSource { $this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags); $this->connected = true; } catch(PDOException $e) { - throw new MissingConnectionException(array('class' => $e->getMessage())); + throw new MissingConnectionException(array( + 'class' => get_class($this), + 'message' => $e->getMessage() + )); } return $this->connected; } diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index eaf93f433..46d565400 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -129,7 +129,10 @@ class Sqlserver extends DboSource { ); $this->connected = true; } catch (PDOException $e) { - throw new MissingConnectionException(array('class' => $e->getMessage())); + throw new MissingConnectionException(array( + 'class' => get_class($this), + 'message' => $e->getMessage() + )); } return $this->connected; diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index c8efb56fc..bae55cff9 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -253,6 +253,7 @@ class DboSource extends DataSource { if (!$this->enabled()) { throw new MissingConnectionException(array( 'class' => get_class($this), + 'message' => __d('cake_dev', 'Selected driver is not enabled'), 'enabled' => false )); } diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index 956acecc2..46745e89e 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -552,10 +552,10 @@ class ExceptionRendererTest extends CakeTestCase { 500 ), array( - new MissingConnectionException(array('class' => 'Article')), + new MissingConnectionException(array('class' => 'Mysql')), array( '/

Missing Database Connection<\/h2>/', - '/Article requires a database connection/' + '/A Database connection using "Mysql" was missing or unable to connect./', ), 500 ), @@ -563,7 +563,7 @@ class ExceptionRendererTest extends CakeTestCase { new MissingConnectionException(array('class' => 'Mysql', 'enabled' => false)), array( '/

Missing Database Connection<\/h2>/', - '/Mysql requires a database connection/', + '/A Database connection using "Mysql" was missing or unable to connect./', '/Mysql driver is NOT enabled/' ), 500 diff --git a/lib/Cake/View/Errors/missing_connection.ctp b/lib/Cake/View/Errors/missing_connection.ctp index b29fb9fc3..27d00a8ba 100644 --- a/lib/Cake/View/Errors/missing_connection.ctp +++ b/lib/Cake/View/Errors/missing_connection.ctp @@ -19,7 +19,13 @@

: - + +
+

From cf4a9f420f6f88e9761e59aa38bcd403f6c4f21e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Sep 2012 22:56:46 -0400 Subject: [PATCH 16/83] Tidy doc block. --- lib/Cake/View/Helper/FormHelper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d70e4d286..0c3cef835 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -168,14 +168,14 @@ class FormHelper extends AppHelper { * * The $key parameter accepts the following list of values: * - * - key: Returns the name of the primary key for the model - * - fields: Returns the model schema - * - validates: returns the list of fields that are required - * - errors: returns the list of validation errors + * - key: Returns the name of the primary key for the model + * - fields: Returns the model schema + * - validates: returns the list of fields that are required + * - errors: returns the list of validation errors * * If the $field parameter is passed if will return the information for that sole field. * - * `$this->_introspectModel('Post', 'fields', 'title');` will return the schema information for title column + * `$this->_introspectModel('Post', 'fields', 'title');` will return the schema information for title column * * @param string $model name of the model to extract information from * @param string $key name of the special information key to obtain (key, fields, validates, errors) From 82a8400deff6fe56f3ea2b3bc8c59556419d1075 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 13 Sep 2012 22:11:46 -0400 Subject: [PATCH 17/83] Fix null not stopping model callbacks. Add a compatibility shim into CakeEventManager to fix `null` not breaking model callbacks. This was a regression created when model callbacks were re-factored to use the event manager. This code should be removed in 3.x as its inconsistent with events used everywhere else in the framework. Fixes #3123 --- lib/Cake/Event/CakeEventManager.php | 4 +++ lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 39 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Event/CakeEventManager.php b/lib/Cake/Event/CakeEventManager.php index 252364d4c..1fecacd45 100644 --- a/lib/Cake/Event/CakeEventManager.php +++ b/lib/Cake/Event/CakeEventManager.php @@ -248,6 +248,10 @@ class CakeEventManager { if ($result === false) { $event->stopPropagation(); } + // TODO remove this in 3.0 as its a compatibility shim for model callbacks. + if (isset($event->break, $event->breakOn) && in_array($result, (array)$event->breakOn)) { + $event->stopPropagation(); + } if ($result !== null) { $event->result = $result; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 1e6dc56a5..f799948e7 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1667,7 +1667,7 @@ class Model extends Object implements CakeEventListener { $event = new CakeEvent('Model.beforeSave', $this, array($options)); list($event->break, $event->breakOn) = array(true, array(false, null)); $this->getEventManager()->dispatch($event); - if (!$event->result) { + if ($event->isStopped()) { $this->whitelist = $_whitelist; return false; } diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7de..576afdf39 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -539,6 +539,25 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); } +/** + * test that beforeValidate returning false can abort saves. + * + * @return void + */ + public function testBeforeValidateNullSaveAbortion() { + $this->loadFixtures('Post'); + $Model = new CallbackPostTestModel(); + $Model->beforeValidateReturn = null; + + $data = array( + 'title' => 'new article', + 'body' => 'this is some text.' + ); + $Model->create(); + $result = $Model->save($data); + $this->assertFalse($result); + } + /** * test that beforeSave returning false can abort saves. * @@ -558,6 +577,26 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); } +/** + * Test that beforeSave returnning null can abort saves. + * + * @return void + */ + public function testBeforeSaveNullAbort() { + $this->loadFixtures('Post'); + $Model = new CallbackPostTestModel(); + $Model->beforeSaveReturn = null; + + $data = array( + 'title' => 'new article', + 'body' => 'this is some text.' + ); + $Model->create(); + $result = $Model->save($data); + $this->assertFalse($result); + + } + /** * testSaveField method * From 7d2cbec79d8f966085c55ca30fa984158cb40153 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 13 Sep 2012 22:49:17 -0400 Subject: [PATCH 18/83] Revert "Fix null not stopping model callbacks." This reverts commit 82a8400deff6fe56f3ea2b3bc8c59556419d1075. The previous change broke a number of tests as existing tests expect that a return value of null will not stop events. --- lib/Cake/Event/CakeEventManager.php | 4 --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 39 --------------------- 3 files changed, 1 insertion(+), 44 deletions(-) diff --git a/lib/Cake/Event/CakeEventManager.php b/lib/Cake/Event/CakeEventManager.php index 1fecacd45..252364d4c 100644 --- a/lib/Cake/Event/CakeEventManager.php +++ b/lib/Cake/Event/CakeEventManager.php @@ -248,10 +248,6 @@ class CakeEventManager { if ($result === false) { $event->stopPropagation(); } - // TODO remove this in 3.0 as its a compatibility shim for model callbacks. - if (isset($event->break, $event->breakOn) && in_array($result, (array)$event->breakOn)) { - $event->stopPropagation(); - } if ($result !== null) { $event->result = $result; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index f799948e7..1e6dc56a5 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1667,7 +1667,7 @@ class Model extends Object implements CakeEventListener { $event = new CakeEvent('Model.beforeSave', $this, array($options)); list($event->break, $event->breakOn) = array(true, array(false, null)); $this->getEventManager()->dispatch($event); - if ($event->isStopped()) { + if (!$event->result) { $this->whitelist = $_whitelist; return false; } diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 576afdf39..31327e7de 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -539,25 +539,6 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); } -/** - * test that beforeValidate returning false can abort saves. - * - * @return void - */ - public function testBeforeValidateNullSaveAbortion() { - $this->loadFixtures('Post'); - $Model = new CallbackPostTestModel(); - $Model->beforeValidateReturn = null; - - $data = array( - 'title' => 'new article', - 'body' => 'this is some text.' - ); - $Model->create(); - $result = $Model->save($data); - $this->assertFalse($result); - } - /** * test that beforeSave returning false can abort saves. * @@ -577,26 +558,6 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); } -/** - * Test that beforeSave returnning null can abort saves. - * - * @return void - */ - public function testBeforeSaveNullAbort() { - $this->loadFixtures('Post'); - $Model = new CallbackPostTestModel(); - $Model->beforeSaveReturn = null; - - $data = array( - 'title' => 'new article', - 'body' => 'this is some text.' - ); - $Model->create(); - $result = $Model->save($data); - $this->assertFalse($result); - - } - /** * testSaveField method * From d33f676ddd72b798fba3aff6fdf58ba1a7bdf445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Fri, 14 Sep 2012 14:17:07 +0200 Subject: [PATCH 19/83] Handling a fatal error on console should call Shell::_stop(1). Just like we do on web, any exception or fatal error will result into a InternalErrorException/FatalErrorException. --- lib/Cake/Console/ConsoleErrorHandler.php | 4 ++++ .../Case/Console/ConsoleErrorHandlerTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Cake/Console/ConsoleErrorHandler.php b/lib/Cake/Console/ConsoleErrorHandler.php index 043c62125..e7409e891 100644 --- a/lib/Cake/Console/ConsoleErrorHandler.php +++ b/lib/Cake/Console/ConsoleErrorHandler.php @@ -84,6 +84,10 @@ class ConsoleErrorHandler { if (Configure::read('debug') == 0) { CakeLog::write($log, $message); } + + if ($log === LOG_ERR) { + $this->_stop(1); + } } /** diff --git a/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php b/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php index ef24dcbcf..32cddd4b0 100644 --- a/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php @@ -60,6 +60,23 @@ class ConsoleErrorHandlerTest extends CakeTestCase { $this->Error->handleError(E_NOTICE, 'This is a notice error', '/some/file', 275); } +/** + * test that the console error handler can deal with fatal errors. + * + * @return void + */ + public function testHandleFatalError() { + $content = "Fatal Error Error: This is a fatal error in [/some/file, line 275]\n"; + ConsoleErrorHandler::$stderr->expects($this->once())->method('write') + ->with($content); + + $this->Error->expects($this->once()) + ->method('_stop') + ->with(1); + + $this->Error->handleError(E_USER_ERROR, 'This is a fatal error', '/some/file', 275); + } + /** * test that the console error handler can deal with CakeExceptions. * From 0282194c205816309dacbbd8fe562ebc10eaf143 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Sep 2012 09:39:45 -0400 Subject: [PATCH 20/83] Make permission denied redirects host relative. This helps fix infinite redirect loops when HTTP_X_FORWARDED_HOST is set, and fixes redirects back to external domains on authentication errors. Fixes #3207 --- lib/Cake/Controller/Component/AuthComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index c0869571f..3ce93c999 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -332,7 +332,7 @@ class AuthComponent extends Component { if (!empty($this->loginRedirect)) { $default = $this->loginRedirect; } - $controller->redirect($controller->referer($default), null, true); + $controller->redirect($controller->referer($default, true), null, true); return false; } From 6f3e6c10a146ee431bf6deeed33b590a036ee6f2 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 14:54:10 +0100 Subject: [PATCH 21/83] Adding a check to the object before use For some reason that I have not been able to figure out yet the object is returned as null. This is causing some exceptions when trying to access properties that dont exist. FatalErrorException: "Call to a member function getAssociated() on a non-object" Test still pass with the added check. --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a1066a15d..4ff2d9a20 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -146,7 +146,7 @@ class FormHelper extends AppHelper { )); } elseif (ClassRegistry::isKeySet($this->defaultModel)) { $defaultObject = ClassRegistry::getObject($this->defaultModel); - if (in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) { + if ($defaultObject && in_array($model, array_keys($defaultObject->getAssociated()), true) && isset($defaultObject->{$model})) { $object = $defaultObject->{$model}; } } else { From c7faad9f78569e56580a4d0ee9edd3af4d4ce3ac Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 15:29:48 +0100 Subject: [PATCH 22/83] You cant pass func_get_args() in PHP < 5.3 --- .../Controller/Component/SecurityComponent.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index f6e407935..c89bb48cc 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -246,7 +246,8 @@ class SecurityComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requirePost */ public function requirePost() { - $this->_requireMethod('Post', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Post', $args); } /** @@ -255,7 +256,8 @@ class SecurityComponent extends Component { * @return void */ public function requireGet() { - $this->_requireMethod('Get', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Get', $args); } /** @@ -264,7 +266,8 @@ class SecurityComponent extends Component { * @return void */ public function requirePut() { - $this->_requireMethod('Put', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Put', $args); } /** @@ -273,7 +276,8 @@ class SecurityComponent extends Component { * @return void */ public function requireDelete() { - $this->_requireMethod('Delete', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Delete', $args); } /** @@ -283,7 +287,8 @@ class SecurityComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireSecure */ public function requireSecure() { - $this->_requireMethod('Secure', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Secure', $args); } /** @@ -293,7 +298,8 @@ class SecurityComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::requireAuth */ public function requireAuth() { - $this->_requireMethod('Auth', func_get_args()); + $args = func_get_args(); + $this->_requireMethod('Auth', $args); } /** From e09bf024673b9785ed304422ebdfc5bef0fc6ab4 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 01:17:28 +0100 Subject: [PATCH 23/83] Cleaning up the RequestHandlerCompoent removing redundant code and shifting a few things around so there are less nested ifs and making things easier to follow. Removing some variable setting, returning function calls instead. --- .../Component/RequestHandlerComponent.php | 114 +++++++++--------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index d3147af00..f46ad5571 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -107,8 +107,7 @@ class RequestHandlerComponent extends Component { * @param array $settings Array of settings. */ public function __construct(ComponentCollection $collection, $settings = array()) { - $default = array('checkHttpCache' => true); - parent::__construct($collection, $settings + $default); + parent::__construct($collection, $settings + array('checkHttpCache' => true)); $this->addInputType('xml', array(array($this, 'convertXml'))); $Controller = $collection->getController(); @@ -158,9 +157,11 @@ class RequestHandlerComponent extends Component { $extensions = Router::extensions(); $preferred = array_shift($accept); $preferredTypes = $this->response->mapType($preferred); - $similarTypes = array_intersect($extensions, $preferredTypes); - if (count($similarTypes) === 1 && !in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) { - $this->ext = array_shift($similarTypes); + if (!in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) { + $similarTypes = array_intersect($extensions, $preferredTypes); + if (count($similarTypes) === 1) { + $this->ext = array_shift($similarTypes); + } } } @@ -269,8 +270,7 @@ class RequestHandlerComponent extends Component { * @return boolean false if the render process should be aborted **/ public function beforeRender(Controller $controller) { - $shouldCheck = $this->settings['checkHttpCache']; - if ($shouldCheck && $this->response->checkNotModified($this->request)) { + if ($this->settings['checkHttpCache'] && $this->response->checkNotModified($this->request)) { return false; } } @@ -395,13 +395,11 @@ class RequestHandlerComponent extends Component { * Gets Prototype version if call is Ajax, otherwise empty string. * The Prototype library sets a special "Prototype version" HTTP header. * - * @return string Prototype version of component making Ajax call + * @return string|boolean When Ajax the prototype version of component making the call otherwise false */ public function getAjaxVersion() { - if (env('HTTP_X_PROTOTYPE_VERSION') != null) { - return env('HTTP_X_PROTOTYPE_VERSION'); - } - return false; + $httpX = env('HTTP_X_PROTOTYPE_VERSION'); + return ($httpX === null) ? false : $httpX; } /** @@ -467,9 +465,10 @@ class RequestHandlerComponent extends Component { public function accepts($type = null) { $accepted = $this->request->accepts(); - if ($type == null) { + if (!$type) { return $this->mapType($accepted); - } elseif (is_array($type)) { + } + if (is_array($type)) { foreach ($type as $t) { $t = $this->mapAlias($t); if (in_array($t, $accepted)) { @@ -477,9 +476,9 @@ class RequestHandlerComponent extends Component { } } return false; - } elseif (is_string($type)) { - $type = $this->mapAlias($type); - return in_array($type, $accepted); + } + if (is_string($type)) { + return in_array($this->mapAlias($type), $accepted); } return false; } @@ -496,18 +495,20 @@ class RequestHandlerComponent extends Component { if (!$this->request->is('post') && !$this->request->is('put')) { return null; } - - list($contentType) = explode(';', env('CONTENT_TYPE')); - if ($type == null) { - return $this->mapType($contentType); - } elseif (is_array($type)) { + if (is_array($type)) { foreach ($type as $t) { if ($this->requestedWith($t)) { return $t; } } return false; - } elseif (is_string($type)) { + } + + list($contentType) = explode(';', env('CONTENT_TYPE')); + if (!$type) { + return $this->mapType($contentType); + } + if (is_string($type)) { return ($type == $this->mapType($contentType)); } } @@ -535,10 +536,9 @@ class RequestHandlerComponent extends Component { if (empty($acceptRaw)) { return $this->ext; } - $accepts = array_shift($acceptRaw); - $accepts = $this->mapType($accepts); + $accepts = $this->mapType(array_shift($acceptRaw)); - if ($type == null) { + if (!$type) { if (empty($this->ext) && !empty($accepts)) { return $accepts[0]; } @@ -611,8 +611,11 @@ class RequestHandlerComponent extends Component { } elseif (empty($this->_renderType)) { $controller->viewPath .= DS . $type; } else { - $remove = preg_replace("/([\/\\\\]{$this->_renderType})$/", DS . $type, $controller->viewPath); - $controller->viewPath = $remove; + $controller->viewPath = preg_replace( + "/([\/\\\\]{$this->_renderType})$/", + DS . $type, + $controller->viewPath + ); } $this->_renderType = $type; $controller->layoutPath = $type; @@ -622,12 +625,8 @@ class RequestHandlerComponent extends Component { } $helper = ucfirst($type); - $isAdded = ( - in_array($helper, $controller->helpers) || - array_key_exists($helper, $controller->helpers) - ); - if (!$isAdded) { + if (!in_array($helper, $controller->helpers) && empty($controller->helpers[$helper])) { App::uses('AppHelper', 'View/Helper'); App::uses($helper . 'Helper', 'View/Helper'); if (class_exists($helper . 'Helper')) { @@ -653,39 +652,35 @@ class RequestHandlerComponent extends Component { $defaults = array('index' => null, 'charset' => null, 'attachment' => false); $options = $options + $defaults; + $cType = $type; if (strpos($type, '/') === false) { $cType = $this->response->getMimeType($type); - if ($cType === false) { - return false; - } - if (is_array($cType) && isset($cType[$options['index']])) { + } + if (is_array($cType)) { + if (isset($cType[$options['index']])) { $cType = $cType[$options['index']]; } - if (is_array($cType)) { - if ($this->prefers($cType)) { - $cType = $this->prefers($cType); - } else { - $cType = $cType[0]; - } + + if ($this->prefers($cType)) { + $cType = $this->prefers($cType); + } else { + $cType = $cType[0]; } - } else { - $cType = $type; } - if ($cType != null) { - if (empty($this->request->params['requested'])) { - $this->response->type($cType); - } - - if (!empty($options['charset'])) { - $this->response->charset($options['charset']); - } - if (!empty($options['attachment'])) { - $this->response->download($options['attachment']); - } - return true; + if (!$type) { + return false; } - return false; + if (empty($this->request->params['requested'])) { + $this->response->type($cType); + } + if (!empty($options['charset'])) { + $this->response->charset($options['charset']); + } + if (!empty($options['attachment'])) { + $this->response->download($options['attachment']); + } + return true; } /** @@ -758,7 +753,8 @@ class RequestHandlerComponent extends Component { public function viewClassMap($type = null, $viewClass = null) { if (!$viewClass && is_string($type) && isset($this->_viewClassMap[$type])) { return $this->_viewClassMap[$type]; - } elseif (is_string($type)) { + } + if (is_string($type)) { $this->_viewClassMap[$type] = $viewClass; } elseif (is_array($type)) { foreach ($type as $key => $value) { From 6d3e0a25b29eb16f5cbeac30481cc1dc2410008f Mon Sep 17 00:00:00 2001 From: euromark Date: Sat, 15 Sep 2012 02:33:05 +0200 Subject: [PATCH 24/83] save some memory usage (PHP < 5.4) in case of huge content and cut off the isset call --- lib/Cake/Controller/Component/CookieComponent.php | 3 +-- lib/Cake/Core/Configure.php | 3 +-- lib/Cake/Model/Datasource/CakeSession.php | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index bdf344a5b..e105bc9ec 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -291,8 +291,7 @@ class CookieComponent extends Component { if (empty($key)) { return false; } - $result = $this->read($key); - return isset($result); + return $this->read($key) !== null; } /** diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index f2101f795..0d1b27478 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -180,8 +180,7 @@ class Configure { if (empty($var)) { return false; } - $result = Hash::get(self::$_values, $var); - return isset($result); + return Hash::get(self::$_values, $var) !== null; } /** diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 6baab1d5b..ff13c0ca6 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -218,8 +218,7 @@ class CakeSession { if (empty($name)) { return false; } - $result = Hash::get($_SESSION, $name); - return isset($result); + return Hash::get($_SESSION, $name) !== null; } /** @@ -283,9 +282,8 @@ class CakeSession { protected static function _error($errorNumber) { if (!is_array(self::$error) || !array_key_exists($errorNumber, self::$error)) { return false; - } else { - return self::$error[$errorNumber]; } + return self::$error[$errorNumber]; } /** From d6e2b6f83e0080a52ee3472c5f99c5be22386493 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Sep 2012 22:06:41 -0400 Subject: [PATCH 25/83] Re-format long lines. --- lib/Cake/Model/Behavior/TranslateBehavior.php | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 8adbd35c8..37eb5c426 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -139,7 +139,10 @@ class TranslateBehavior extends ModelBehavior { return $query; } - $fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']); + $fields = array_merge( + $this->settings[$Model->alias], + $this->runtime[$Model->alias]['fields'] + ); $addFields = array(); if (empty($query['fields'])) { $addFields = $fields; @@ -147,7 +150,11 @@ class TranslateBehavior extends ModelBehavior { foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; - if (in_array($Model->escapeField('*'), $query['fields']) || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields'])) { + if ( + in_array($Model->escapeField('*'), $query['fields']) || + in_array($Model->alias . '.' . $field, $query['fields']) || + in_array($field, $query['fields']) + ) { $addFields[] = $field; } } @@ -395,7 +402,10 @@ class TranslateBehavior extends ModelBehavior { $conditions = array('model' => $Model->alias, 'foreign_key' => $Model->id); $RuntimeModel = $this->translateModel($Model); - $fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']); + $fields = array_merge( + $this->settings[$Model->alias], + $this->runtime[$Model->alias]['fields'] + ); if ($created) { // set each field value to an empty string foreach ($fields as $key => $field) { @@ -421,13 +431,20 @@ class TranslateBehavior extends ModelBehavior { $value = array($locale => $value); } } - $translations = $RuntimeModel->find('list', array('conditions' => $conditions, 'fields' => array($RuntimeModel->alias . '.locale', $RuntimeModel->alias . '.id'))); + $translations = $RuntimeModel->find('list', array( + 'conditions' => $conditions, + 'fields' => array($RuntimeModel->alias . '.locale', $RuntimeModel->alias . '.id') + )); foreach ($value as $_locale => $_value) { $RuntimeModel->create(); $conditions['locale'] = $_locale; $conditions['content'] = $_value; if (array_key_exists($_locale, $translations)) { - $RuntimeModel->save(array($RuntimeModel->alias => array_merge($conditions, array('id' => $translations[$_locale])))); + $RuntimeModel->save(array( + $RuntimeModel->alias => array_merge( + $conditions, array('id' => $translations[$_locale]) + ) + )); } else { $RuntimeModel->save(array($RuntimeModel->alias => $conditions)); } @@ -443,7 +460,10 @@ class TranslateBehavior extends ModelBehavior { */ public function afterDelete(Model $Model) { $RuntimeModel = $this->translateModel($Model); - $conditions = array('model' => $Model->alias, 'foreign_key' => $Model->id); + $conditions = array( + 'model' => $Model->alias, + 'foreign_key' => $Model->id + ); $RuntimeModel->deleteAll($conditions); } @@ -511,7 +531,10 @@ class TranslateBehavior extends ModelBehavior { } $associations = array(); $RuntimeModel = $this->translateModel($Model); - $default = array('className' => $RuntimeModel->alias, 'foreignKey' => 'foreign_key'); + $default = array( + 'className' => $RuntimeModel->alias, + 'foreignKey' => 'foreign_key' + ); foreach ($fields as $key => $value) { if (is_numeric($key)) { From ccd33782dac71ddf4a758cae68282eadb3c0c0a3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Sep 2012 22:37:39 -0400 Subject: [PATCH 26/83] Fix whitespace errors. --- lib/Cake/Test/Case/Utility/FolderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/FolderTest.php b/lib/Cake/Test/Case/Utility/FolderTest.php index f5e8c65b6..a6801db4c 100644 --- a/lib/Cake/Test/Case/Utility/FolderTest.php +++ b/lib/Cake/Test/Case/Utility/FolderTest.php @@ -918,7 +918,7 @@ class FolderTest extends CakeTestCase { * * @return void */ - function testCopyWithOverwrite() { + public function testCopyWithOverwrite() { extract($this->_setupFilesystem()); $Folder = new Folder($folderOne); @@ -1050,7 +1050,7 @@ class FolderTest extends CakeTestCase { $this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); $this->assertEquals('', file_get_contents($folderTwoB . DS . 'fileB.php')); $this->assertFalse(file_exists($fileOne)); - $this->assertFalse(file_exists($folderOneA)); + $this->assertFalse(file_exists($folderOneA)); $this->assertFalse(file_exists($fileOneA)); $Folder = new Folder($path); From a38a616cba8786f851cac31d973131db046295c4 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 15 Sep 2012 11:06:02 +0100 Subject: [PATCH 27/83] changing join() to implode() for consistency --- lib/Cake/Configure/IniReader.php | 2 +- lib/Cake/I18n/I18n.php | 8 ++++---- lib/Cake/Model/CakeSchema.php | 10 +++++----- lib/Cake/Model/Datasource/Database/Sqlite.php | 6 +++--- lib/Cake/Model/Datasource/DboSource.php | 2 +- .../Test/Case/Model/Datasource/Database/MysqlTest.php | 2 +- lib/Cake/Utility/Debugger.php | 6 +++--- lib/Cake/Utility/Inflector.php | 4 ++-- lib/Cake/View/Helper.php | 2 +- lib/Cake/View/Helper/FormHelper.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 6 +++--- lib/Cake/View/Helper/JsBaseEngineHelper.php | 2 +- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Cake/Configure/IniReader.php b/lib/Cake/Configure/IniReader.php index 900d65489..323a9c642 100644 --- a/lib/Cake/Configure/IniReader.php +++ b/lib/Cake/Configure/IniReader.php @@ -180,7 +180,7 @@ class IniReader implements ConfigReaderInterface { } } } - $contents = join("\n", $result); + $contents = implode("\n", $result); if (substr($filename, -4) !== '.ini') { $filename .= '.ini'; diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 7678ba6ae..9343d349d 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -592,19 +592,19 @@ class I18n { $string = $string[1]; if (substr($string, 0, 2) === $this->_escape . 'x') { $delimiter = $this->_escape . 'x'; - return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string))))); + return implode('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string))))); } if (substr($string, 0, 2) === $this->_escape . 'd') { $delimiter = $this->_escape . 'd'; - return join('', array_map('chr', array_filter(explode($delimiter, $string)))); + return implode('', array_map('chr', array_filter(explode($delimiter, $string)))); } if ($string[0] === $this->_escape && isset($string[1]) && is_numeric($string[1])) { $delimiter = $this->_escape; - return join('', array_map('chr', array_filter(explode($delimiter, $string)))); + return implode('', array_map('chr', array_filter(explode($delimiter, $string)))); } if (substr($string, 0, 3) === 'U00') { $delimiter = 'U00'; - return join('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string))))); + return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string))))); } if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) { return Multibyte::ascii(array(hexdec($match[1]))); diff --git a/lib/Cake/Model/CakeSchema.php b/lib/Cake/Model/CakeSchema.php index 75339e608..70430e6c2 100644 --- a/lib/Cake/Model/CakeSchema.php +++ b/lib/Cake/Model/CakeSchema.php @@ -418,26 +418,26 @@ class CakeSchema extends Object { } $col = "\t\t'{$field}' => array('type' => '" . $value['type'] . "', "; unset($value['type']); - $col .= join(', ', $this->_values($value)); + $col .= implode(', ', $this->_values($value)); } elseif ($field == 'indexes') { $col = "\t\t'indexes' => array(\n\t\t\t"; $props = array(); foreach ((array)$value as $key => $index) { - $props[] = "'{$key}' => array(" . join(', ', $this->_values($index)) . ")"; + $props[] = "'{$key}' => array(" . implode(', ', $this->_values($index)) . ")"; } - $col .= join(",\n\t\t\t", $props) . "\n\t\t"; + $col .= implode(",\n\t\t\t", $props) . "\n\t\t"; } elseif ($field == 'tableParameters') { $col = "\t\t'tableParameters' => array("; $props = array(); foreach ((array)$value as $key => $param) { $props[] = "'{$key}' => '$param'"; } - $col .= join(', ', $props); + $col .= implode(', ', $props); } $col .= ")"; $cols[] = $col; } - $out .= join(",\n", $cols); + $out .= implode(",\n", $cols); } $out .= "\n\t);\n"; return $out; diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 0ca4bc2c3..891e2ce38 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -459,7 +459,7 @@ class Sqlite extends DboSource { $out .= 'UNIQUE '; } if (is_array($value['column'])) { - $value['column'] = join(', ', array_map(array(&$this, 'name'), $value['column'])); + $value['column'] = implode(', ', array_map(array(&$this, 'name'), $value['column'])); } else { $value['column'] = $this->name($value['column']); } @@ -524,10 +524,10 @@ class Sqlite extends DboSource { case 'schema': extract($data); if (is_array($columns)) { - $columns = "\t" . join(",\n\t", array_filter($columns)); + $columns = "\t" . implode(",\n\t", array_filter($columns)); } if (is_array($indexes)) { - $indexes = "\t" . join("\n\t", array_filter($indexes)); + $indexes = "\t" . implode("\n\t", array_filter($indexes)); } return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}"; default: diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index cac97e6c0..01c0cf5ba 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1766,7 +1766,7 @@ class DboSource extends DataSource { case 'schema': foreach (array('columns', 'indexes', 'tableParameters') as $var) { if (is_array(${$var})) { - ${$var} = "\t" . join(",\n\t", array_filter(${$var})); + ${$var} = "\t" . implode(",\n\t", array_filter(${$var})); } else { ${$var} = ''; } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index e60cd3aa5..4a633b417 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -3270,7 +3270,7 @@ class MysqlTest extends CakeTestCase { ); $conditions = array('comment_count >' => 2); - $query = 'SELECT ' . join(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) . + $query = 'SELECT ' . implode(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) . ' FROM ' . $this->Dbo->fullTableName($Article) . ' Article ' . $this->Dbo->conditions($conditions, true, true, $Article); $result = $this->Dbo->fetchAll($query); $expected = array(array( diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 71638f334..00fa060a5 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -318,7 +318,7 @@ class Debugger { foreach ($next['args'] as $arg) { $args[] = Debugger::exportVar($arg); } - $reference .= join(', ', $args); + $reference .= implode(', ', $args); } $reference .= ')'; } @@ -779,11 +779,11 @@ class Debugger { continue; } if (is_array($value)) { - $value = join("\n", $value); + $value = implode("\n", $value); } $info .= String::insert($tpl[$key], array($key => $value) + $data, $insertOpts); } - $links = join(' ', $links); + $links = implode(' ', $links); if (isset($tpl['callback']) && is_callable($tpl['callback'])) { return call_user_func($tpl['callback'], $data, compact('links', 'info')); diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 31829d621..f18323e5a 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -406,8 +406,8 @@ class Inflector { } if (!isset(self::$_singular['cacheUninflected']) || !isset(self::$_singular['cacheIrregular'])) { - self::$_singular['cacheUninflected'] = '(?:' . join('|', self::$_singular['merged']['uninflected']) . ')'; - self::$_singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$_singular['merged']['irregular'])) . ')'; + self::$_singular['cacheUninflected'] = '(?:' . implode('|', self::$_singular['merged']['uninflected']) . ')'; + self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')'; } if (preg_match('/(.*)\\b(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) { diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 1f5933353..6738d2ea4 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -607,7 +607,7 @@ class Helper extends Object { $entity = $this->entity(); $model = array_shift($entity); - $dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity)); + $dom = $model . implode('', array_map(array('Inflector', 'camelize'), $entity)); if (is_array($options) && !array_key_exists($id, $options)) { $options[$id] = $dom; diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 4ff2d9a20..5f3a03d49 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -274,7 +274,7 @@ class FormHelper extends AppHelper { if (empty($errors)) { return false; } - $errors = Hash::get($errors, join('.', $entity)); + $errors = Hash::get($errors, implode('.', $entity)); return $errors === null ? false : $errors; } diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 8cf545748..5582f58f6 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -637,7 +637,7 @@ class HtmlHelper extends AppHelper { $out[] = $key . ':' . $value . ';'; } if ($oneline) { - return join(' ', $out); + return implode(' ', $out); } return implode("\n", $out); } @@ -669,7 +669,7 @@ class HtmlHelper extends AppHelper { $out[] = $crumb[0]; } } - return join($separator, $out); + return implode($separator, $out); } else { return null; } @@ -805,7 +805,7 @@ class HtmlHelper extends AppHelper { $out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes(current($arg)), key($arg)); } } - return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out)); + return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), implode(' ', $out)); } /** diff --git a/lib/Cake/View/Helper/JsBaseEngineHelper.php b/lib/Cake/View/Helper/JsBaseEngineHelper.php index b3a293ac4..bd83c387d 100644 --- a/lib/Cake/View/Helper/JsBaseEngineHelper.php +++ b/lib/Cake/View/Helper/JsBaseEngineHelper.php @@ -494,7 +494,7 @@ abstract class JsBaseEngineHelper extends AppHelper { $out[] = $key . ':' . $value; } sort($out); - return join(', ', $out); + return implode(', ', $out); } /** From aa87791432b153ab2fe958e3a3b1e9fe7ab52e5f Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 15 Sep 2012 11:15:01 +0100 Subject: [PATCH 28/83] replacing is_integer() with is_int() --- lib/Cake/Cache/Cache.php | 4 ++-- lib/Cake/Controller/Component/CookieComponent.php | 2 +- lib/Cake/Network/CakeResponse.php | 4 ++-- lib/Cake/Routing/Route/CakeRoute.php | 2 +- lib/Cake/Utility/CakeTime.php | 4 ++-- lib/Cake/Utility/Xml.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Cache/Cache.php b/lib/Cake/Cache/Cache.php index cb705f6f8..f7ac61122 100644 --- a/lib/Cake/Cache/Cache.php +++ b/lib/Cake/Cache/Cache.php @@ -366,7 +366,7 @@ class Cache { } $key = self::$_engines[$config]->key($key); - if (!$key || !is_integer($offset) || $offset < 0) { + if (!$key || !is_int($offset) || $offset < 0) { return false; } $success = self::$_engines[$config]->increment($settings['prefix'] . $key, $offset); @@ -394,7 +394,7 @@ class Cache { } $key = self::$_engines[$config]->key($key); - if (!$key || !is_integer($offset) || $offset < 0) { + if (!$key || !is_int($offset) || $offset < 0) { return false; } $success = self::$_engines[$config]->decrement($settings['prefix'] . $key, $offset); diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index e105bc9ec..fdf434458 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -398,7 +398,7 @@ class CookieComponent extends Component { return $this->_expires = 0; } - if (is_integer($expires) || is_numeric($expires)) { + if (is_int($expires) || is_numeric($expires)) { return $this->_expires = $now + intval($expires); } return $this->_expires = strtotime($expires, $now); diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 7d49fdff6..15c1892b6 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -746,7 +746,7 @@ class CakeResponse { * @return void */ public function cache($since, $time = '+1 day') { - if (!is_integer($time)) { + if (!is_int($time)) { $time = strtotime($time); } $this->header(array( @@ -1008,7 +1008,7 @@ class CakeResponse { protected function _getUTCDate($time = null) { if ($time instanceof DateTime) { $result = clone $time; - } elseif (is_integer($time)) { + } elseif (is_int($time)) { $result = new DateTime(date('Y-m-d H:i:s', $time)); } else { $result = new DateTime($time); diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 8fab212cf..e76dc2bfb 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -219,7 +219,7 @@ class CakeRoute { if (isset($route[$key])) { continue; } - if (is_integer($key)) { + if (is_int($key)) { $route['pass'][] = $value; continue; } diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 53db5688d..be3e83afb 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -310,7 +310,7 @@ class CakeTime { return false; } - if (is_integer($dateString) || is_numeric($dateString)) { + if (is_int($dateString) || is_numeric($dateString)) { $date = intval($dateString); } elseif (is_object($dateString) && $dateString instanceof DateTime) { $clone = clone $dateString; @@ -589,7 +589,7 @@ class CakeTime { if ($dateString instanceof DateTime) { $date = $dateString; - } elseif (is_integer($dateString) || is_numeric($dateString)) { + } elseif (is_int($dateString) || is_numeric($dateString)) { $dateString = (int)$dateString; $date = new DateTime('@' . $dateString); diff --git a/lib/Cake/Utility/Xml.php b/lib/Cake/Utility/Xml.php index f8662b282..f58a01989 100644 --- a/lib/Cake/Utility/Xml.php +++ b/lib/Cake/Utility/Xml.php @@ -174,7 +174,7 @@ class Xml { throw new XmlException(__d('cake_dev', 'Invalid input.')); } $key = key($input); - if (is_integer($key)) { + if (is_int($key)) { throw new XmlException(__d('cake_dev', 'The key of input must be alphanumeric')); } From 4899b5b91b76b8b9b524e098d1fde14437c6b543 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 15 Sep 2012 11:17:35 +0100 Subject: [PATCH 29/83] changing is_writeable() to is_writable() --- lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php | 4 ++-- lib/Cake/Test/Case/Utility/FolderTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php index 9a25b4939..78617881e 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php @@ -61,7 +61,7 @@ class CakeTestSuiteTest extends CakeTestCase { * @return void */ public function testAddTestDirectoryRecursiveWithHidden() { - $this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.'); + $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'MyTestFolder', true, 0777); mkdir($Folder->path . DS . '.svn', 0777, true); @@ -85,7 +85,7 @@ class CakeTestSuiteTest extends CakeTestCase { * @return void */ public function testAddTestDirectoryRecursiveWithNonPhp() { - $this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.'); + $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'MyTestFolder', true, 0777); touch($Folder->path . DS . 'BackupTest.php~'); diff --git a/lib/Cake/Test/Case/Utility/FolderTest.php b/lib/Cake/Test/Case/Utility/FolderTest.php index a6801db4c..65739bf84 100644 --- a/lib/Cake/Test/Case/Utility/FolderTest.php +++ b/lib/Cake/Test/Case/Utility/FolderTest.php @@ -374,7 +374,7 @@ class FolderTest extends CakeTestCase { * @return void */ public function testFolderReadWithHiddenFiles() { - $this->skipIf(!is_writeable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.'); + $this->skipIf(!is_writable(TMP), 'Cant test Folder::read with hidden files unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777); mkdir($Folder->path . DS . '.svn'); @@ -457,7 +457,7 @@ class FolderTest extends CakeTestCase { * @return void */ public function testFolderTreeWithHiddenFiles() { - $this->skipIf(!is_writeable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.'); + $this->skipIf(!is_writable(TMP), 'Can\'t test Folder::tree with hidden files unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'folder_tree_hidden', true, 0777); mkdir($Folder->path . DS . '.svn', 0777, true); From d0bb8a94b4d0ee85ebb1322b9c3106f38dd50c7e Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 15 Sep 2012 11:20:51 +0100 Subject: [PATCH 30/83] die() to exit() --- lib/Cake/Console/Templates/skel/webroot/test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Console/Templates/skel/webroot/test.php b/lib/Cake/Console/Templates/skel/webroot/test.php index 37b7f2528..da7088fd8 100644 --- a/lib/Cake/Console/Templates/skel/webroot/test.php +++ b/lib/Cake/Console/Templates/skel/webroot/test.php @@ -86,7 +86,7 @@ if (!empty($failed)) { } if (Configure::read('debug') < 1) { - die(__d('cake_dev', 'Debug setting does not allow access to this url.')); + exit(__d('cake_dev', 'Debug setting does not allow access to this url.')); } require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php'; From 26934236b1a3d71f53b76115ebaeb9de32b577fe Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 15 Sep 2012 11:43:39 +0100 Subject: [PATCH 31/83] skipping the rijndael test if mcrypt_encrypt() is not available --- lib/Cake/Test/Case/Utility/SecurityTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/Utility/SecurityTest.php b/lib/Cake/Test/Case/Utility/SecurityTest.php index 153d1ad57..ea7d6fa29 100644 --- a/lib/Cake/Test/Case/Utility/SecurityTest.php +++ b/lib/Cake/Test/Case/Utility/SecurityTest.php @@ -215,6 +215,7 @@ class SecurityTest extends CakeTestCase { * @return void */ public function testRijndael() { + $this->skipIf(!function_exists('mcrypt_encrypt')); $txt = 'The quick brown fox jumped over the lazy dog.'; $key = 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi'; From 9530e68ae62dc9cb49b00e61814165c46009f56e Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 17 Sep 2012 11:29:13 +0200 Subject: [PATCH 32/83] add default return value as parameter to use when size can not be determined --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 23 ++++++++++--------- lib/Cake/Utility/CakeNumber.php | 6 ++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 25737679f..c1bf0188c 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -529,8 +529,8 @@ class CakeNumberTest extends CakeTestCase { * @dataProvider filesizes * @return void */ - public function testFromReadableSize($size, $expected) { - $result = $this->Number->fromReadableSize($size); + public function testFromReadableSize($params, $expected) { + $result = $this->Number->fromReadableSize($params['size'], $params['default']); $this->assertEquals($expected, $result); } @@ -541,7 +541,7 @@ class CakeNumberTest extends CakeTestCase { * @return void */ public function testFromReadableSizeException() { - $result = $this->Number->fromReadableSize('bogus'); + $result = $this->Number->fromReadableSize('bogus', false); } /** @@ -551,14 +551,15 @@ class CakeNumberTest extends CakeTestCase { */ public function filesizes() { return array( - array('512B', 512), - array('1KB', 1024), - array('1.5KB', 1536), - array('1MB', 1048576), - array('1.5MB', 1572864), - array('1GB', 1073741824), - array('1.5GB', 1610612736), - array('512', 512), + array(array('size' => '512B', 'default' => false), 512), + array(array('size' => '1KB', 'default' => false), 1024), + array(array('size' => '1.5KB', 'default' => false), 1536), + array(array('size' => '1MB', 'default' => false), 1048576), + array(array('size' => '1.5MB', 'default' => false), 1572864), + array(array('size' => '1GB', 'default' => false), 1073741824), + array(array('size' => '1.5GB', 'default' => false), 1610612736), + array(array('size' => '512', 'default' => 'Unknown type'), 512), + array(array('size' => '2VB', 'default' => 'Unknown type'), 'Unknown type') ); } diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index d12b4f90a..db3f51a70 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -105,9 +105,10 @@ class CakeNumber { * Converts filesize from human readable string to bytes * * @param string $size Size in human readable string like '5MB' + * @param mixed $default Value to be returned when invalid size was used, for example 'Unknown type' * @return integer Bytes */ - public static function fromReadableSize($size) { + public static function fromReadableSize($size, $default = false) { if (ctype_digit($size)) { return $size * 1; } @@ -120,6 +121,9 @@ class CakeNumber { if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) { return $size * 1; } + if ($default !== false) { + return $default; + } throw new CakeException(__d('cake_dev', 'No unit type.')); } From 55dcb9c3b3913edac06a9befaeef89f627d190df Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 17 Sep 2012 20:50:05 -0400 Subject: [PATCH 33/83] Implement resetSequence() This is an optional method in DboSource that allows datasources to resetSequence values in tables. This is useful for datasources like Postgres, and makes using fixtures much easier. Fixes #3026 --- .../Model/Datasource/Database/Postgres.php | 16 ++++++++++++++ lib/Cake/Model/Datasource/DboSource.php | 14 ++++++++++++ .../Datasource/Database/PostgresTest.php | 22 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 9b1fbcf3d..5b79ea57d 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -291,6 +291,22 @@ class Postgres extends DboSource { } } +/** + * Reset a sequence based on the MAX() value of $column. Useful + * for resetting sequences after using insertMulti(). + * + * @param string $table The name of the table to update. + * @param string $column The column to use when reseting the sequence value, the + * sequence name will be fetched using Postgres::getSequence(); + * @return boolean success. + */ + public function resetSequence($table, $column) { + $sequence = $this->value($this->getSequence($table, $column)); + $table = $this->fullTableName($table); + $this->execute("SELECT setval($sequence, (SELECT MAX(id) FROM $table))"); + return true; + } + /** * Deletes all the records in a table and drops all associated auto-increment sequences * diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 01c0cf5ba..4d4843b42 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2920,6 +2920,20 @@ class DboSource extends DataSource { return $this->commit(); } +/** + * Reset a sequence based on the MAX() value of $column. Useful + * for resetting sequences after using insertMulti(). + * + * This method should be implmented by datasources that require sequences to be used. + * + * @param string $table The name of the table to update. + * @param string $column The column to use when reseting the sequence value. + * @return boolean success. + */ + public function resetSequence($table, $column) { + + } + /** * Returns an array of the indexes in given datasource name. * diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 154920262..7015750d3 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -950,4 +950,26 @@ class PostgresTest extends CakeTestCase { $this->assertNotEmpty($model->read(null, 1)); } + public function testResetSequence() { + $model = new Article(); + + $table = $this->Dbo->fullTableName($model, false); + $fields = array( + 'id', 'user_id', 'title', 'body', 'published', + ); + $values = array( + array(1, 1, 'test', 'first post', false), + array(2, 1, 'test 2', 'second post post', false), + ); + $this->Dbo->insertMulti($table, $fields, $values); + $sequence = $this->Dbo->getSequence($table); + $result = $this->Dbo->rawQuery("SELECT nextval('$sequence')"); + $original = $result->fetch(PDO::FETCH_ASSOC); + + $this->assertTrue($this->Dbo->resetSequence($table, 'id')); + $result = $this->Dbo->rawQuery("SELECT currval('$sequence')"); + $new = $result->fetch(PDO::FETCH_ASSOC); + $this->assertTrue($new['currval'] > $original['nextval'], 'Sequence did not update'); + } + } From 90c32add9cea115ca7c6ffc4acc6f792565898a3 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 18 Sep 2012 09:34:05 +0200 Subject: [PATCH 34/83] opmitisation of fromReadableSize --- lib/Cake/Utility/CakeNumber.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index db3f51a70..b84670aa6 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -112,15 +112,16 @@ class CakeNumber { if (ctype_digit($size)) { return $size * 1; } - $units = array('KB', 'MB', 'GB', 'TB', 'PB'); - foreach ($units as $i => $unit) { - if ($unit == substr($size, -2)) { - return $size * pow(1024, $i + 1); - } + + $i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB')); + if ($i !== false) { + return $size * pow(1024, $i + 1); } + if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) { return $size * 1; } + if ($default !== false) { return $default; } From 6d98069f1349b6173ebb1b2476bf3417c05715e6 Mon Sep 17 00:00:00 2001 From: Tigran Gabrielyan Date: Thu, 13 Sep 2012 12:42:15 -0700 Subject: [PATCH 35/83] Added ability to set default view block content --- lib/Cake/View/View.php | 6 +++--- lib/Cake/View/ViewBlock.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 9e0bafb91..1b7243928 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -636,11 +636,11 @@ class View extends Object { * empty or undefined '' will be returned. * * @param string $name Name of the block - * @return The block content or '' if the block does not exist. + * @return string The block content or $default if the block does not exist. * @see ViewBlock::get() */ - public function fetch($name) { - return $this->Blocks->get($name); + public function fetch($name, $default = '') { + return $this->Blocks->get($name, $default); } /** diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index 98b16d7fe..baf08ad21 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -119,11 +119,11 @@ class ViewBlock { * Get the content for a block. * * @param string $name Name of the block - * @return The block content or '' if the block does not exist. + * @return string The block content or $default if the block does not exist. */ - public function get($name) { + public function get($name, $default = '') { if (!isset($this->_blocks[$name])) { - return ''; + return $default; } return $this->_blocks[$name]; } From f1a344eee4b8bcfdba69ecc87fe09c86f7c87bd9 Mon Sep 17 00:00:00 2001 From: Tigran Gabrielyan Date: Thu, 13 Sep 2012 15:35:11 -0700 Subject: [PATCH 36/83] Added test case for view block default value --- lib/Cake/Test/Case/View/ViewTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 3cb1f02e3..ef64b727d 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1445,4 +1445,20 @@ TEXT; $end = memory_get_usage(); $this->assertLessThanOrEqual($start + 5000, $end); } -} + +/** + * tests that a vew block uses default value when not assigned and uses assigned value when it is + * + * @return void + */ + public function testBlockDefaultValue() { + $default = 'Default'; + $result = $this->View->fetch('title', $default); + $this->assertEqual($result, $default); + + $expected = 'My Title'; + $this->View->assign('title', $expected); + $result = $this->View->fetch('title', $default); + $this->assertEqual($result, $expected); + } +} \ No newline at end of file From d30e092966c3349346629ade3ac633f389160f81 Mon Sep 17 00:00:00 2001 From: Tigran Gabrielyan Date: Tue, 18 Sep 2012 00:46:06 -0700 Subject: [PATCH 37/83] Fixed test case --- lib/Cake/Test/Case/View/ViewTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index ef64b727d..59c504c21 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1454,11 +1454,11 @@ TEXT; public function testBlockDefaultValue() { $default = 'Default'; $result = $this->View->fetch('title', $default); - $this->assertEqual($result, $default); + $this->assertEquals($default, $result); $expected = 'My Title'; $this->View->assign('title', $expected); $result = $this->View->fetch('title', $default); - $this->assertEqual($result, $expected); + $this->assertEquals($expected, $result); } } \ No newline at end of file From 990d5f89f0933945994782e785094d12ae90c568 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 18 Sep 2012 10:51:24 -0300 Subject: [PATCH 38/83] Update lib/Cake/View/Helper/FormHelper.php --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 0c3cef835..ee01b60fa 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -260,7 +260,7 @@ class FormHelper extends AppHelper { * Returns false if given form field described by the current entity has no errors. * Otherwise it returns the validation message * - * @return mixed Either false when there or no errors, or an array of error + * @return mixed Either false when there are no errors, or an array of error * strings. An error string could be ''. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::tagIsInvalid */ From 46035cfd737c8cbbe1b06ab0c6d33c8b615648a9 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 18 Sep 2012 10:56:36 -0300 Subject: [PATCH 39/83] Update lib/Cake/View/Helper/FormHelper.php --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index ee01b60fa..92ee6c372 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -719,7 +719,7 @@ class FormHelper extends AppHelper { /** * Returns a formatted LABEL element for HTML FORMs. Will automatically generate - * a for attribute if one is not provided. + * a `for` attribute if one is not provided. * * ### Options * From ff676b5ea4a2c19d2bf3205d72bde81d61a5db97 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 18 Sep 2012 17:15:33 +0200 Subject: [PATCH 40/83] allow for lowercase as well, also strip the unit part off before pow() --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 1 + lib/Cake/Utility/CakeNumber.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index c1bf0188c..314fba99c 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -555,6 +555,7 @@ class CakeNumberTest extends CakeTestCase { array(array('size' => '1KB', 'default' => false), 1024), array(array('size' => '1.5KB', 'default' => false), 1536), array(array('size' => '1MB', 'default' => false), 1048576), + array(array('size' => '1mb', 'default' => false), 1048576), array(array('size' => '1.5MB', 'default' => false), 1572864), array(array('size' => '1GB', 'default' => false), 1073741824), array(array('size' => '1.5GB', 'default' => false), 1610612736), diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index b84670aa6..347114441 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -112,13 +112,16 @@ class CakeNumber { if (ctype_digit($size)) { return $size * 1; } + $size = strtoupper($size); $i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB')); if ($i !== false) { + $size = substr($size, 0, strlen($size) -2); return $size * pow(1024, $i + 1); } if (substr($size, -1) == 'B' && ctype_digit(substr($size, 0, strlen($size) - 1))) { + $size = substr($size, 0, strlen($size) - 1); return $size * 1; } From e8cfac0eecd5323b0382d36b72b131902b9261c5 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 18 Sep 2012 19:38:53 +0200 Subject: [PATCH 41/83] adding query() for CakeRequest --- lib/Cake/Network/CakeRequest.php | 10 ++++++++++ lib/Cake/Test/Case/Network/CakeRequestTest.php | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 919e380a3..b1c80372a 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -758,6 +758,16 @@ class CakeRequest implements ArrayAccess { return $accept; } +/** + * Provides a read accessor for `$this->query`. Allows you + * to use a syntax similar to `CakeSession` for reading url query data. + * + * @return mixed The value being read + */ + public function query($name) { + return Hash::get($this->query, $name); + } + /** * Provides a read/write accessor for `$this->data`. Allows you * to use a syntax similar to `CakeSession` for reading post data. diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index ae64aad6e..ae33d00b7 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1678,6 +1678,24 @@ class CakeRequestTest extends CakeTestCase { } } +/** + * test the query() method + * + * @return void + */ + public function testQuery() { + $_GET = array(); + $_GET['foo'] = 'bar'; + + $request = new CakeRequest(); + + $result = $request->query('foo'); + $this->assertEquals('bar', $result); + + $result = $request->query('imaginary'); + $this->assertNull($result); + } + /** * test the data() method reading * From a1838a0c856ad8357275b7bf5a82cec271e9ef21 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Sep 2012 14:11:51 -0400 Subject: [PATCH 42/83] Implement missing bits for automatic sequence resetting. Refs #3206 --- .../Model/Datasource/Database/Postgres.php | 8 ++-- .../TestSuite/Fixture/CakeTestFixture.php | 39 ++++++++++++++++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 5b79ea57d..e4f85b6aa 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -301,9 +301,11 @@ class Postgres extends DboSource { * @return boolean success. */ public function resetSequence($table, $column) { - $sequence = $this->value($this->getSequence($table, $column)); - $table = $this->fullTableName($table); - $this->execute("SELECT setval($sequence, (SELECT MAX(id) FROM $table))"); + $tableName = $this->fullTableName($table, false, false); + $fullTable = $this->fullTableName($table); + + $sequence = $this->value($this->getSequence($tableName, $column)); + $this->execute("SELECT setval($sequence, (SELECT MAX(id) FROM $fullTable))"); return true; } diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index b25a37ea9..58c3ef888 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -58,6 +58,28 @@ class CakeTestFixture { */ public $created = array(); +/** + * Fields / Schema for the fixture. + * This array should match the output of Model::schema() + * + * @var array + */ + public $fields = array(); + +/** + * Fixture records to be inserted. + * + * @var array + */ + public $records = array(); + +/** + * The primary key for the table this fixture represents. + * + * @var string + */ + public $primaryKey = null; + /** * Instantiate the fixture. * @@ -110,6 +132,7 @@ class CakeTestFixture { $this->fields = $model->schema(true); $this->fields[$model->primaryKey]['key'] = 'primary'; $this->table = $db->fullTableName($model, false, false); + $this->primaryKey = $model->primaryKey; ClassRegistry::config(array('ds' => 'test')); ClassRegistry::flush(); } elseif (isset($import['table'])) { @@ -121,6 +144,7 @@ class CakeTestFixture { $model->table = $import['table']; $model->tablePrefix = $db->config['prefix']; $this->fields = $model->schema(true); + $this->primaryKey = $model->primaryKey; ClassRegistry::flush(); } @@ -159,7 +183,7 @@ class CakeTestFixture { /** * Run before all tests execute, should return SQL statement to create table for this fixture could be executed successfully. * - * @param object $db An instance of the database object used to create the fixture table + * @param DboSource $db An instance of the database object used to create the fixture table * @return boolean True on success, false on failure */ public function create($db) { @@ -210,7 +234,7 @@ class CakeTestFixture { /** * Run after all tests executed, should return SQL statement to drop table for this fixture. * - * @param object $db An instance of the database object used to create the fixture table + * @param DboSource $db An instance of the database object used to create the fixture table * @return boolean True on success, false on failure */ public function drop($db) { @@ -232,7 +256,7 @@ class CakeTestFixture { * Run before each tests is executed, should return a set of SQL statements to insert records for the table * of this fixture could be executed successfully. * - * @param object $db An instance of the database into which the records will be inserted + * @param DboSource $db An instance of the database into which the records will be inserted * @return boolean on success or if there are no records to insert, or false on failure */ public function insert($db) { @@ -252,6 +276,9 @@ class CakeTestFixture { $nested = $db->useNestedTransactions; $db->useNestedTransactions = false; $result = $db->insertMulti($this->table, $fields, $values); + if ($this->primaryKey && in_array($this->fields[$this->primaryKey]['type'], array('integer', 'biginteger'))) { + $db->resetSequence($this->table, $this->primaryKey); + } $db->useNestedTransactions = $nested; return $result; } @@ -260,10 +287,10 @@ class CakeTestFixture { } /** - * Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after - * truncate. + * Truncates the current fixture. Can be overwritten by classes extending + * CakeFixture to trigger other events before / after truncate. * - * @param object $db A reference to a db instance + * @param DboSource $db A reference to a db instance * @return boolean */ public function truncate($db) { From 5d830d7adb449becfd4aae45a7e623d576e141ea Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Sep 2012 14:41:51 -0400 Subject: [PATCH 43/83] Fix multiple selects always failing post validation. Fixes #3218 --- .../Test/Case/View/Helper/FormHelperTest.php | 17 +++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 0a4a5e78a..de5747b3f 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -4255,6 +4255,23 @@ class FormHelperTest extends CakeTestCase { $this->assertRegExp('/"' . $key . '"/', $result); } +/** + * Multiple select elements should always be secured as they always participate + * in the POST data. + * + * @return void + */ + public function testSelectMultipleSecureWithNoOptions() { + $this->Form->request['_Token'] = array('key' => 'testkey'); + $this->assertEquals(array(), $this->Form->fields); + + $result = $this->Form->select( + 'Model.select', + array(), + array('multiple' => true) + ); + $this->assertEquals(array('Model.select'), $this->Form->fields); + } /** * When a select box has no options it should not be added to the fields list * as it always fail post validation. diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 92ee6c372..ab24d38c3 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1850,10 +1850,12 @@ class FormHelper extends AppHelper { if (!empty($tag) || isset($template)) { $hasOptions = (count($options) > 0 || $showEmpty); + // Secure the field if there are options, or its a multi select. + // Single selects with no options don't submit, but multiselects do. if ( (!isset($secure) || $secure == true) && empty($attributes['disabled']) && - $hasOptions + (!empty($attributes['multiple']) || $hasOptions) ) { $this->_secure(true); } From da6d49e5549ecb48d43728cac7777d3a174f7ef8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Sep 2012 14:50:03 -0400 Subject: [PATCH 44/83] Fix code conventions. --- lib/Cake/Test/Case/Network/Email/MailTransportTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php index 9e102c1be..43f0cc5e6 100644 --- a/lib/Cake/Test/Case/Network/Email/MailTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/MailTransportTest.php @@ -60,7 +60,7 @@ class MailTransportTest extends CakeTestCase { $data .= "Cc: Mark Story , Juan Basso " . PHP_EOL; $data .= "Bcc: phpnut@cakephp.org" . PHP_EOL; $data .= "X-Mailer: CakePHP Email" . PHP_EOL; - $data .= "Date: " . $date . PHP_EOL; + $data .= "Date: " . $date . PHP_EOL; $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL; $data .= "MIME-Version: 1.0" . PHP_EOL; $data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL; From 99cbd22969bb73692d017f5fd962ee7f8b497117 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Sep 2012 14:52:46 -0400 Subject: [PATCH 45/83] Fix coding standards. --- lib/Cake/Model/Datasource/DboSource.php | 1 - lib/Cake/Utility/CakeNumber.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 4d4843b42..387c5e82f 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2931,7 +2931,6 @@ class DboSource extends DataSource { * @return boolean success. */ public function resetSequence($table, $column) { - } /** diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 347114441..687504607 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -107,6 +107,7 @@ class CakeNumber { * @param string $size Size in human readable string like '5MB' * @param mixed $default Value to be returned when invalid size was used, for example 'Unknown type' * @return integer Bytes + * @throws CakeException On invalid Unit type. */ public static function fromReadableSize($size, $default = false) { if (ctype_digit($size)) { From 60385d1d2837485bae88541a104d5ebbb4b94147 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 19 Sep 2012 03:14:55 +0200 Subject: [PATCH 46/83] test the query() method with arrays passed via $_GET --- .../Test/Case/Network/CakeRequestTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index ae33d00b7..981a2c044 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1696,6 +1696,27 @@ class CakeRequestTest extends CakeTestCase { $this->assertNull($result); } +/** + * test the query() method with arrays passed via $_GET + * + * @return void + */ + public function testQueryWithArray() { + $_GET = array(); + $_GET['test'] = array('foo', 'bar'); + + $request = new CakeRequest(); + + $result = $request->query('test'); + $this->assertEquals(array('foo', 'bar'), $result); + + $result = $request->query('test.1'); + $this->assertEquals('bar', $result); + + $result = $request->query('test.2'); + $this->assertNull($result); + } + /** * test the data() method reading * From 0f0b5e7668e9cf8160efea26b9f0e84b35fa3262 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 19 Sep 2012 10:14:29 -0400 Subject: [PATCH 47/83] Fix incorrect radio selection with falsey values. Use strval() to work around 0 == '' type issues. Cleanup some tests. Fixes #3221 --- .../Test/Case/View/Helper/FormHelperTest.php | 133 ++++++++---------- lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 57 insertions(+), 78 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index de5747b3f..5e822c7a0 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -3183,80 +3183,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1')); - $expected = array( - 'fieldset' => array(), - 'legend' => array(), - 'Field', - '/legend', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')), - array('label' => array('for' => 'ModelField1')), - 'Yes', - '/label', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), - array('label' => array('for' => 'ModelField0')), - 'No', - '/label', - '/fieldset' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); - $expected = array( - 'fieldset' => array(), - 'legend' => array(), - 'Field', - '/legend', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), - array('label' => array('for' => 'ModelField1')), - 'Yes', - '/label', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')), - array('label' => array('for' => 'ModelField0')), - 'No', - '/label', - '/fieldset' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null)); - $expected = array( - 'fieldset' => array(), - 'legend' => array(), - 'Field', - '/legend', - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), - array('label' => array('for' => 'ModelField1')), - 'Yes', - '/label', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), - array('label' => array('for' => 'ModelField0')), - 'No', - '/label', - '/fieldset' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); - $expected = array( - 'fieldset' => array(), - 'legend' => array(), - 'Field', - '/legend', - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), - array('label' => array('for' => 'ModelField1')), - 'Yes', - '/label', - array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), - array('label' => array('for' => 'ModelField0')), - 'No', - '/label', - '/fieldset' - ); - $this->assertTags($result, $expected); - $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), @@ -3445,6 +3371,59 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that radios with a 0 value are selected under the correct conditions. + * + * @return void + */ + public function testRadioOptionWithZeroValue() { + $expected = array( + 'fieldset' => array(), + 'legend' => array(), + 'Field', + '/legend', + array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), + array('label' => array('for' => 'ModelField1')), + 'Yes', + '/label', + array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')), + array('label' => array('for' => 'ModelField0')), + 'No', + '/label', + '/fieldset' + ); + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); + $this->assertTags($result, $expected); + + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 0)); + $this->assertTags($result, $expected); + + $expected = array( + 'fieldset' => array(), + 'legend' => array(), + 'Field', + '/legend', + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), + array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), + array('label' => array('for' => 'ModelField1')), + 'Yes', + '/label', + array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), + array('label' => array('for' => 'ModelField0')), + 'No', + '/label', + '/fieldset' + ); + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null)); + $this->assertTags($result, $expected); + + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '')); + $this->assertTags($result, $expected); + + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); + $this->assertTags($result, $expected); + } + /** * test disabled radio options * @@ -3454,7 +3433,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->radio( 'Model.field', array('option A', 'option B'), - array('disabled' => array('option A'), 'value' => 'option A') + array('disabled' => array('option A'), 'value' => '0') ); $expected = array( 'fieldset' => array(), @@ -3476,7 +3455,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->radio( 'Model.field', array('option A', 'option B'), - array('disabled' => true, 'value' => 'option A') + array('disabled' => true, 'value' => '0') ); $expected = array( 'fieldset' => array(), @@ -3498,7 +3477,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->radio( 'Model.field', array('option A', 'option B'), - array('disabled' => 'disabled', 'value' => 'option A') + array('disabled' => 'disabled', 'value' => '0') ); $expected = array( 'fieldset' => array(), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index ab24d38c3..ad6bf80a0 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1377,7 +1377,7 @@ class FormHelper extends AppHelper { foreach ($options as $optValue => $optTitle) { $optionsHere = array('value' => $optValue); - if (isset($value) && $optValue == $value) { + if (isset($value) && strval($optValue) === strval($value)) { $optionsHere['checked'] = 'checked'; } if ($disabled && (!is_array($disabled) || in_array($optValue, $disabled))) { From d12f50a2b660d1cf1f763e0ab3001f16c21eef9a Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 20 Sep 2012 02:40:54 +0530 Subject: [PATCH 48/83] Removing unneeded App::uses() calls --- lib/Cake/Model/Validator/CakeValidationRule.php | 5 ++--- lib/Cake/Model/Validator/CakeValidationSet.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Validator/CakeValidationRule.php b/lib/Cake/Model/Validator/CakeValidationRule.php index a59a01c7b..6380376bf 100644 --- a/lib/Cake/Model/Validator/CakeValidationRule.php +++ b/lib/Cake/Model/Validator/CakeValidationRule.php @@ -18,8 +18,7 @@ * @since CakePHP(tm) v 2.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('ModelValidator', 'Model'); -App::uses('CakeValidationSet', 'Model/Validator'); + App::uses('Validation', 'Utility'); /** @@ -246,7 +245,7 @@ class CakeValidationRule { * If called with no parameters it will return whether this rule * is configured for update operations or not. * - * @return boolean + * @return boolean **/ public function isUpdate($exists = null) { if ($exists === null) { diff --git a/lib/Cake/Model/Validator/CakeValidationSet.php b/lib/Cake/Model/Validator/CakeValidationSet.php index 1cd32c617..3451f8103 100644 --- a/lib/Cake/Model/Validator/CakeValidationSet.php +++ b/lib/Cake/Model/Validator/CakeValidationSet.php @@ -18,7 +18,7 @@ * @since CakePHP(tm) v 2.2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('ModelValidator', 'Model'); + App::uses('CakeValidationRule', 'Model/Validator'); /** From 3fa6b96ad0ff02f1af67b55e25af08b5156696f0 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 20 Sep 2012 01:41:41 +0200 Subject: [PATCH 49/83] adding CakeNumber::formatDelta() and fixing issue with near-zero values and format() --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 46 +++++++++++ lib/Cake/Utility/CakeNumber.php | 78 ++++++++++++------- 2 files changed, 96 insertions(+), 28 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 314fba99c..961be31b2 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -70,6 +70,52 @@ class CakeNumberTest extends CakeTestCase { $result = $this->Number->format($value, '-'); $expected = '100-100-100'; $this->assertEquals($expected, $result); + + $value = 0.00001; + $result = $this->Number->format($value, array('places' => 1)); + $expected = '$0.0'; + $this->assertEquals($expected, $result); + + $value = -0.00001; + $result = $this->Number->format($value, array('places' => 1)); + $expected = '$0.0'; + $this->assertEquals($expected, $result); + } + +/** + * testFormatDelta method + * + * @return void + */ + public function testFormatDelta() { + $value = '100100100'; + + $result = $this->Number->formatDelta($value, array('before' => '', 'after' => '')); + $expected = '+100,100,100.00'; + $this->assertEquals($expected, $result); + + $result = $this->Number->formatDelta($value, array('before' => '[', 'after' => ']')); + $expected = '[+100,100,100.00]'; + $this->assertEquals($expected, $result); + + $result = $this->Number->formatDelta(-$value, array('before' => '[', 'after' => ']')); + $expected = '[-100,100,100.00]'; + $this->assertEquals($expected, $result); + + $value = 0; + $result = $this->Number->formatDelta($value, array('places' => 1, 'before' => '[', 'after' => ']')); + $expected = '[0.0]'; + $this->assertEquals($expected, $result); + + $value = 0.0001; + $result = $this->Number->formatDelta($value, array('places' => 1, 'before' => '[', 'after' => ']')); + $expected = '[0.0]'; + $this->assertEquals($expected, $result); + + $value = 9876.1234; + $result = $this->Number->formatDelta($value, array('places' => 1, 'decimals' => ',', 'thousands' => '.')); + $expected = '+9.876,1'; + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 687504607..4cdd946fe 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -70,13 +70,13 @@ class CakeNumber { /** * Formats a number with a level of precision. * - * @param float $number A floating point number. + * @param float $value A floating point number. * @param integer $precision The precision of the returned number. * @return float Formatted float. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision */ - public static function precision($number, $precision = 3) { - return sprintf("%01.{$precision}F", $number); + public static function precision($value, $precision = 3) { + return sprintf("%01.{$precision}F", $value); } /** @@ -135,25 +135,25 @@ class CakeNumber { /** * Formats a number into a percentage string. * - * @param float $number A floating point number + * @param float $value A floating point number * @param integer $precision The precision of the returned number * @return string Percentage string * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage */ - public static function toPercentage($number, $precision = 2) { - return self::precision($number, $precision) . '%'; + public static function toPercentage($value, $precision = 2) { + return self::precision($value, $precision) . '%'; } /** * Formats a number into a currency format. * - * @param float $number A floating point number + * @param float $value A floating point number * @param integer $options if int then places, if string then before, if (,.-) then use it * or array with places and before keys * @return string formatted number * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format */ - public static function format($number, $options = false) { + public static function format($value, $options = false) { $places = 0; if (is_int($options)) { $places = $options; @@ -180,7 +180,8 @@ class CakeNumber { extract($options); } - $out = $before . self::_numberFormat($number, $places, $decimals, $thousands) . $after; + $value = self::_numberFormat($value, $places, '.', ''); + $out = $before . self::_numberFormat($value, $places, $decimals, $thousands) . $after; if ($escape) { return h($out); @@ -188,34 +189,55 @@ class CakeNumber { return $out; } +/** + * Formats a number into a currency format to show deltas (signed differences in value). + * + * - `places` - Number of decimal places to use. ie. 2 + * - `before` - The string to place before whole numbers. ie. '[' + * - `after` - The string to place after decimal numbers. ie. ']' + * - `thousands` - Thousands separator ie. ',' + * - `decimals` - Decimal separator symbol ie. '.' + * + * @param float $value A floating point number + * @param array $options + * @return string formatted delta + */ + public static function formatDelta($value, $options = array()) { + $places = isset($options['places']) ? $options['places'] : 0; + $value = self::_numberFormat($value, $places, '.', ''); + $sign = $value > 0 ? '+' : ''; + $options['before'] = isset($options['before']) ? $options['before'] . $sign : $sign; + return self::format($value, $options); + } + /** * Alternative number_format() to accommodate multibyte decimals and thousands < PHP 5.4 * - * @param float $number + * @param float $value * @param integer $places * @param string $decimals * @param string $thousands * @return string */ - protected static function _numberFormat($number, $places = 0, $decimals = '.', $thousands = ',') { + protected static function _numberFormat($value, $places = 0, $decimals = '.', $thousands = ',') { if (!isset(self::$_numberFormatSupport)) { self::$_numberFormatSupport = version_compare(PHP_VERSION, '5.4.0', '>='); } if (self::$_numberFormatSupport) { - return number_format($number, $places, $decimals, $thousands); + return number_format($value, $places, $decimals, $thousands); } - $number = number_format($number, $places, '.', ''); + $value = number_format($value, $places, '.', ''); $after = ''; - $foundDecimal = strpos($number, '.'); + $foundDecimal = strpos($value, '.'); if ($foundDecimal !== false) { - $after = substr($number, $foundDecimal); - $number = substr($number, 0, $foundDecimal); + $after = substr($value, $foundDecimal); + $value = substr($value, 0, $foundDecimal); } - while (($foundThousand = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $number)) != $number) { - $number = $foundThousand; + while (($foundThousand = preg_replace('/(\d+)(\d\d\d)/', '\1 \2', $value)) != $value) { + $value = $foundThousand; } - $number .= $after; - return strtr($number, array(' ' => $thousands, '.' => $decimals)); + $value .= $after; + return strtr($value, array(' ' => $thousands, '.' => $decimals)); } /** @@ -244,14 +266,14 @@ class CakeNumber { * the number will be wrapped with ( and ) * - `escape` - Should the output be htmlentity escaped? Defaults to true * - * @param float $number + * @param float $value * @param string $currency Shortcut to default options. Valid values are * 'USD', 'EUR', 'GBP', otherwise set at least 'before' and 'after' options. * @param array $options * @return string Number formatted as a currency. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency */ - public static function currency($number, $currency = 'USD', $options = array()) { + public static function currency($value, $currency = 'USD', $options = array()) { $default = self::$_currencyDefaults; if (isset(self::$_currencies[$currency])) { @@ -272,14 +294,14 @@ class CakeNumber { $result = $options['before'] = $options['after'] = null; $symbolKey = 'whole'; - if ($number == 0 ) { - if ($options['zero'] !== 0 ) { + if ($value == 0) { + if ($options['zero'] !== 0) { return $options['zero']; } - } elseif ($number < 1 && $number > -1 ) { + } elseif ($value < 1 && $value > -1) { if ($options['fractionSymbol'] !== false) { $multiply = intval('1' . str_pad('', $options['places'], '0')); - $number = $number * $multiply; + $value = $value * $multiply; $options['places'] = null; $symbolKey = 'fraction'; } @@ -288,10 +310,10 @@ class CakeNumber { $position = $options[$symbolKey . 'Position'] != 'after' ? 'before' : 'after'; $options[$position] = $options[$symbolKey . 'Symbol']; - $abs = abs($number); + $abs = abs($value); $result = self::format($abs, $options); - if ($number < 0 ) { + if ($value < 0) { if ($options['negative'] == '()') { $result = '(' . $result . ')'; } else { From 8a070ca3dd1e75a6f6ad780474157fc3bfebc1a3 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 20 Sep 2012 01:45:05 +0200 Subject: [PATCH 50/83] doc block --- lib/Cake/Utility/CakeNumber.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 4cdd946fe..9470f910f 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -192,6 +192,8 @@ class CakeNumber { /** * Formats a number into a currency format to show deltas (signed differences in value). * + * ### Options + * * - `places` - Number of decimal places to use. ie. 2 * - `before` - The string to place before whole numbers. ie. '[' * - `after` - The string to place after decimal numbers. ie. ']' From 213d4caa852fb22b0c2d0d12e3f200c93485e8e9 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 20 Sep 2012 01:50:15 +0200 Subject: [PATCH 51/83] coding standards --- lib/Cake/Console/Command/Task/ExtractTask.php | 2 +- lib/Cake/Console/Templates/skel/View/Errors/error400.ctp | 2 +- lib/Cake/Console/Templates/skel/View/Errors/error500.ctp | 2 +- lib/Cake/Controller/Component/SecurityComponent.php | 2 +- lib/Cake/I18n/Multibyte.php | 2 +- lib/Cake/Model/Behavior/TranslateBehavior.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 2 +- lib/Cake/Network/CakeResponse.php | 2 +- lib/Cake/Test/test_app/View/Errors/error400.ctp | 2 +- lib/Cake/Test/test_app/View/Errors/error500.ctp | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 8d0777be9..ab35612db 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -245,7 +245,7 @@ class ExtractTask extends AppShell { if (empty($this->_translations[$domain][$msgid])) { $this->_translations[$domain][$msgid] = array( 'msgid_plural' => false - ); + ); } if (isset($details['msgid_plural'])) { diff --git a/lib/Cake/Console/Templates/skel/View/Errors/error400.ctp b/lib/Cake/Console/Templates/skel/View/Errors/error400.ctp index 6d508604c..cfaff40a1 100644 --- a/lib/Cake/Console/Templates/skel/View/Errors/error400.ctp +++ b/lib/Cake/Console/Templates/skel/View/Errors/error400.ctp @@ -25,7 +25,7 @@ ); ?>

0 ): +if (Configure::read('debug') > 0): echo $this->element('exception_stack_trace'); endif; ?> diff --git a/lib/Cake/Console/Templates/skel/View/Errors/error500.ctp b/lib/Cake/Console/Templates/skel/View/Errors/error500.ctp index 4e1f36ece..54d3774df 100644 --- a/lib/Cake/Console/Templates/skel/View/Errors/error500.ctp +++ b/lib/Cake/Console/Templates/skel/View/Errors/error500.ctp @@ -22,7 +22,7 @@

0 ): +if (Configure::read('debug') > 0): echo $this->element('exception_stack_trace'); endif; ?> diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index c89bb48cc..cda99d7e7 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -389,7 +389,7 @@ class SecurityComponent extends Component { $requireAuth = $this->requireAuth; if (in_array($this->request->params['action'], $requireAuth) || $this->requireAuth == array('*')) { - if (!isset($controller->request->data['_Token'] )) { + if (!isset($controller->request->data['_Token'])) { if (!$this->blackHole($controller, 'auth')) { return null; } diff --git a/lib/Cake/I18n/Multibyte.php b/lib/Cake/I18n/Multibyte.php index b741ef4d6..f69d11683 100644 --- a/lib/Cake/I18n/Multibyte.php +++ b/lib/Cake/I18n/Multibyte.php @@ -1122,7 +1122,7 @@ class Multibyte { public static function checkMultibyte($string) { $length = strlen($string); - for ($i = 0; $i < $length; $i++ ) { + for ($i = 0; $i < $length; $i++) { $value = ord(($string[$i])); if ($value > 128) { return true; diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 3eccf6269..001c355d9 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -184,7 +184,7 @@ class TranslateBehavior extends ModelBehavior { */ protected function _checkConditions(Model $Model, $query) { $conditionFields = array(); - if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions'])) ) { + if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions']))) { return $conditionFields; } foreach ($query['conditions'] as $col => $val) { diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 387c5e82f..73087c3f0 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -599,7 +599,7 @@ class DboSource extends DataSource { } else { if (isset($args[1]) && $args[1] === true) { return $this->fetchAll($args[0], true); - } elseif (isset($args[1]) && !is_array($args[1]) ) { + } elseif (isset($args[1]) && !is_array($args[1])) { return $this->fetchAll($args[0], false); } elseif (isset($args[1]) && is_array($args[1])) { if (isset($args[2])) { diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 15c1892b6..2740e0a4f 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1070,7 +1070,7 @@ class CakeResponse { * @return int */ public function length($bytes = null) { - if ($bytes !== null ) { + if ($bytes !== null) { $this->_headers['Content-Length'] = $bytes; } if (isset($this->_headers['Content-Length'])) { diff --git a/lib/Cake/Test/test_app/View/Errors/error400.ctp b/lib/Cake/Test/test_app/View/Errors/error400.ctp index 6d508604c..cfaff40a1 100644 --- a/lib/Cake/Test/test_app/View/Errors/error400.ctp +++ b/lib/Cake/Test/test_app/View/Errors/error400.ctp @@ -25,7 +25,7 @@ ); ?>

0 ): +if (Configure::read('debug') > 0): echo $this->element('exception_stack_trace'); endif; ?> diff --git a/lib/Cake/Test/test_app/View/Errors/error500.ctp b/lib/Cake/Test/test_app/View/Errors/error500.ctp index 4e1f36ece..54d3774df 100644 --- a/lib/Cake/Test/test_app/View/Errors/error500.ctp +++ b/lib/Cake/Test/test_app/View/Errors/error500.ctp @@ -22,7 +22,7 @@

0 ): +if (Configure::read('debug') > 0): echo $this->element('exception_stack_trace'); endif; ?> From 0be1943bcdae7808b02ac6b6796dbd971b7ecb37 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 20 Sep 2012 01:56:52 +0200 Subject: [PATCH 52/83] adding basic test --- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 961be31b2..978e69080 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -90,6 +90,10 @@ class CakeNumberTest extends CakeTestCase { public function testFormatDelta() { $value = '100100100'; + $result = $this->Number->formatDelta($value); + $expected = '+100,100,100.00'; + $this->assertEquals($expected, $result); + $result = $this->Number->formatDelta($value, array('before' => '', 'after' => '')); $expected = '+100,100,100.00'; $this->assertEquals($expected, $result); From 3dd82e6d88abb88f931103b9732504b761702ea4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 19 Sep 2012 20:55:39 -0400 Subject: [PATCH 53/83] Fix Database/ from always being appended to the driver name. Fixes #3223 --- lib/Cake/Console/Command/Task/DbConfigTask.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index b9778a558..596ad817d 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -315,8 +315,11 @@ class DbConfigTask extends AppShell { $config = array_merge($this->_defaultConfig, $config); extract($config); + if (strpos($datasource, 'Database/') === false) { + $datasource = "Database/{$datasource}"; + } $out .= "\tpublic \${$name} = array(\n"; - $out .= "\t\t'datasource' => 'Database/{$datasource}',\n"; + $out .= "\t\t'datasource' => '{$datasource}',\n"; $out .= "\t\t'persistent' => {$persistent},\n"; $out .= "\t\t'host' => '{$host}',\n"; From 36c99a358f19381f874185c8613c3748fae30dd9 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Thu, 20 Sep 2012 00:21:26 -0300 Subject: [PATCH 54/83] Add MySQL FULLTEXT support. Minor optimizations and testing added. --- lib/Cake/Model/Datasource/Database/Mysql.php | 35 ++++++--------- lib/Cake/Model/Datasource/DboSource.php | 4 +- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 17 +++++++ .../Model/Datasource/Database/MysqlTest.php | 45 +++++++++++++------ 4 files changed, 64 insertions(+), 37 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 9506a8a94..3036f3368 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -422,17 +422,21 @@ class Mysql extends DboSource { $table = $this->fullTableName($model); $old = version_compare($this->getVersion(), '4.1', '<='); if ($table) { - $indices = $this->_execute('SHOW INDEX FROM ' . $table); + $indexes = $this->_execute('SHOW INDEX FROM ' . $table); // @codingStandardsIgnoreStart // MySQL columns don't match the cakephp conventions. - while ($idx = $indices->fetch(PDO::FETCH_OBJ)) { + while ($idx = $indexes->fetch(PDO::FETCH_OBJ)) { if ($old) { $idx = (object)current((array)$idx); } if (!isset($index[$idx->Key_name]['column'])) { $col = array(); $index[$idx->Key_name]['column'] = $idx->Column_name; - $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); + if ($idx->Index_type === 'FULLTEXT') { + $index[$idx->Key_name]['type'] = strtolower($idx->Index_type); + } else { + $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); + } } else { if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { $col[] = $index[$idx->Key_name]['column']; @@ -442,7 +446,7 @@ class Mysql extends DboSource { } } // @codingStandardsIgnoreEnd - $indices->closeCursor(); + $indexes->closeCursor(); } return $index; } @@ -553,31 +557,18 @@ class Mysql extends DboSource { if (isset($indexes['drop'])) { foreach ($indexes['drop'] as $name => $value) { $out = 'DROP '; - if ($name == 'PRIMARY') { + if ($name === 'PRIMARY') { $out .= 'PRIMARY KEY'; } else { - $out .= 'KEY ' . $name; + $out .= 'KEY ' . $this->startQuote . $name . $this->endQuote; } $alter[] = $out; } } if (isset($indexes['add'])) { - foreach ($indexes['add'] as $name => $value) { - $out = 'ADD '; - if ($name == 'PRIMARY') { - $out .= 'PRIMARY '; - $name = null; - } else { - if (!empty($value['unique'])) { - $out .= 'UNIQUE '; - } - } - if (is_array($value['column'])) { - $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; - } else { - $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')'; - } - $alter[] = $out; + $add = $this->buildIndex($indexes['add']); + foreach ($add as $index) { + $alter[] = 'ADD ' . $index; } } return $alter; diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 64536c610..7cdf22e73 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3114,7 +3114,7 @@ class DboSource extends DataSource { } /** - * Format indexes for create table + * Format indexes for create table. * * @param array $indexes * @param string $table @@ -3130,6 +3130,8 @@ class DboSource extends DataSource { } else { if (!empty($value['unique'])) { $out .= 'UNIQUE '; + } elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') { + $out .= 'FULLTEXT '; } $name = $this->startQuote . $name . $this->endQuote; } diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index 47effcc14..e403d3a57 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -762,6 +762,23 @@ class CakeSchemaTest extends CakeTestCase { ); $result = $this->Schema->generateTable('posts', $posts); $this->assertRegExp('/public \$posts/', $result); + + $posts = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), + 'author_id' => array('type' => 'integer', 'null' => false), + 'title' => array('type' => 'string', 'null' => false), + 'body' => array('type' => 'text', 'null' => true, 'default' => null), + 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => true), + 'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext') + ) + ); + $result = $this->Schema->generateTable('fields', $posts); + $this->assertRegExp('/public \$fields/', $result); + $this->assertPattern('/\'type\' \=\> \'fulltext\'/', $result); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index c6645a3c5..c3a0bc986 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -313,6 +313,16 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->index('with_multiple_compound_keys', false); $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEquals($expected, $result); + + $name = $this->Dbo->fullTableName('with_fulltext'); + $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, name varchar(255), description text, primary key(id), FULLTEXT KEY `MyFtIndex` ( `name`, `description` )) ENGINE=MyISAM;'); + $expected = array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') + ); + $result = $this->Dbo->index('with_fulltext', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); + $this->assertEquals($expected, $result); } /** @@ -548,9 +558,9 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaB->compare($schemaA)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('ADD KEY name_idx (`name`),', $result); - $this->assertContains('ADD KEY group_idx (`group1`),', $result); - $this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result); + $this->assertContains('ADD KEY `name_idx` (`name`),', $result); + $this->assertContains('ADD KEY `group_idx` (`group1`),', $result); + $this->assertContains('ADD KEY `compound_idx` (`group1`, `group2`),', $result); $this->assertContains('ADD PRIMARY KEY (`id`);', $result); //Test that the string is syntactically correct @@ -576,13 +586,13 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaC->compare($schemaB)); $this->assertContains("ALTER TABLE $table", $result); $this->assertContains('DROP PRIMARY KEY,', $result); - $this->assertContains('DROP KEY name_idx,', $result); - $this->assertContains('DROP KEY group_idx,', $result); - $this->assertContains('DROP KEY compound_idx,', $result); - $this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result); - $this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result); - $this->assertContains('ADD KEY group_idx (`group2`),', $result); - $this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result); + $this->assertContains('DROP KEY `name_idx`,', $result); + $this->assertContains('DROP KEY `group_idx`,', $result); + $this->assertContains('DROP KEY `compound_idx`,', $result); + $this->assertContains('ADD KEY `id_name_idx` (`id`, `name`),', $result); + $this->assertContains('ADD UNIQUE KEY `name_idx` (`name`),', $result); + $this->assertContains('ADD KEY `group_idx` (`group2`),', $result); + $this->assertContains('ADD KEY `compound_idx` (`group2`, `group1`);', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -594,10 +604,10 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaA->compare($schemaC)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('DROP KEY name_idx,', $result); - $this->assertContains('DROP KEY group_idx,', $result); - $this->assertContains('DROP KEY compound_idx,', $result); - $this->assertContains('DROP KEY id_name_idx;', $result); + $this->assertContains('DROP KEY `name_idx`,', $result); + $this->assertContains('DROP KEY `group_idx`,', $result); + $this->assertContains('DROP KEY `compound_idx`,', $result); + $this->assertContains('DROP KEY `id_name_idx`;', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -2837,6 +2847,13 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->buildIndex($data); $expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)'); $this->assertEquals($expected, $result); + + $data = array( + 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') + ); + $result = $this->Dbo->buildIndex($data); + $expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)'); + $this->assertEquals($expected, $result); } /** From a9750264e452a3491ec94c210f403bc44a337847 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 Sep 2012 20:39:02 -0400 Subject: [PATCH 55/83] Revert "Add MySQL FULLTEXT support." This reverts commit 36c99a358f19381f874185c8613c3748fae30dd9. --- lib/Cake/Model/Datasource/Database/Mysql.php | 35 +++++++++------ lib/Cake/Model/Datasource/DboSource.php | 4 +- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 17 ------- .../Model/Datasource/Database/MysqlTest.php | 45 ++++++------------- 4 files changed, 37 insertions(+), 64 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index fe7139649..f96dfa420 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -425,21 +425,17 @@ class Mysql extends DboSource { $table = $this->fullTableName($model); $old = version_compare($this->getVersion(), '4.1', '<='); if ($table) { - $indexes = $this->_execute('SHOW INDEX FROM ' . $table); + $indices = $this->_execute('SHOW INDEX FROM ' . $table); // @codingStandardsIgnoreStart // MySQL columns don't match the cakephp conventions. - while ($idx = $indexes->fetch(PDO::FETCH_OBJ)) { + while ($idx = $indices->fetch(PDO::FETCH_OBJ)) { if ($old) { $idx = (object)current((array)$idx); } if (!isset($index[$idx->Key_name]['column'])) { $col = array(); $index[$idx->Key_name]['column'] = $idx->Column_name; - if ($idx->Index_type === 'FULLTEXT') { - $index[$idx->Key_name]['type'] = strtolower($idx->Index_type); - } else { - $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); - } + $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); } else { if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { $col[] = $index[$idx->Key_name]['column']; @@ -449,7 +445,7 @@ class Mysql extends DboSource { } } // @codingStandardsIgnoreEnd - $indexes->closeCursor(); + $indices->closeCursor(); } return $index; } @@ -559,18 +555,31 @@ class Mysql extends DboSource { if (isset($indexes['drop'])) { foreach ($indexes['drop'] as $name => $value) { $out = 'DROP '; - if ($name === 'PRIMARY') { + if ($name == 'PRIMARY') { $out .= 'PRIMARY KEY'; } else { - $out .= 'KEY ' . $this->startQuote . $name . $this->endQuote; + $out .= 'KEY ' . $name; } $alter[] = $out; } } if (isset($indexes['add'])) { - $add = $this->buildIndex($indexes['add']); - foreach ($add as $index) { - $alter[] = 'ADD ' . $index; + foreach ($indexes['add'] as $name => $value) { + $out = 'ADD '; + if ($name == 'PRIMARY') { + $out .= 'PRIMARY '; + $name = null; + } else { + if (!empty($value['unique'])) { + $out .= 'UNIQUE '; + } + } + if (is_array($value['column'])) { + $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; + } else { + $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')'; + } + $alter[] = $out; } } return $alter; diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 5c1aa97e1..bae55cff9 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3113,7 +3113,7 @@ class DboSource extends DataSource { } /** - * Format indexes for create table. + * Format indexes for create table * * @param array $indexes * @param string $table @@ -3129,8 +3129,6 @@ class DboSource extends DataSource { } else { if (!empty($value['unique'])) { $out .= 'UNIQUE '; - } elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') { - $out .= 'FULLTEXT '; } $name = $this->startQuote . $name . $this->endQuote; } diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index e403d3a57..47effcc14 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -762,23 +762,6 @@ class CakeSchemaTest extends CakeTestCase { ); $result = $this->Schema->generateTable('posts', $posts); $this->assertRegExp('/public \$posts/', $result); - - $posts = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), - 'author_id' => array('type' => 'integer', 'null' => false), - 'title' => array('type' => 'string', 'null' => false), - 'body' => array('type' => 'text', 'null' => true, 'default' => null), - 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => true), - 'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext') - ) - ); - $result = $this->Schema->generateTable('fields', $posts); - $this->assertRegExp('/public \$fields/', $result); - $this->assertPattern('/\'type\' \=\> \'fulltext\'/', $result); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 340ea1e12..f14bf6116 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -313,16 +313,6 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->index('with_multiple_compound_keys', false); $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEquals($expected, $result); - - $name = $this->Dbo->fullTableName('with_fulltext'); - $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, name varchar(255), description text, primary key(id), FULLTEXT KEY `MyFtIndex` ( `name`, `description` )) ENGINE=MyISAM;'); - $expected = array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') - ); - $result = $this->Dbo->index('with_fulltext', false); - $this->Dbo->rawQuery('DROP TABLE ' . $name); - $this->assertEquals($expected, $result); } /** @@ -558,9 +548,9 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaB->compare($schemaA)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('ADD KEY `name_idx` (`name`),', $result); - $this->assertContains('ADD KEY `group_idx` (`group1`),', $result); - $this->assertContains('ADD KEY `compound_idx` (`group1`, `group2`),', $result); + $this->assertContains('ADD KEY name_idx (`name`),', $result); + $this->assertContains('ADD KEY group_idx (`group1`),', $result); + $this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result); $this->assertContains('ADD PRIMARY KEY (`id`);', $result); //Test that the string is syntactically correct @@ -586,13 +576,13 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaC->compare($schemaB)); $this->assertContains("ALTER TABLE $table", $result); $this->assertContains('DROP PRIMARY KEY,', $result); - $this->assertContains('DROP KEY `name_idx`,', $result); - $this->assertContains('DROP KEY `group_idx`,', $result); - $this->assertContains('DROP KEY `compound_idx`,', $result); - $this->assertContains('ADD KEY `id_name_idx` (`id`, `name`),', $result); - $this->assertContains('ADD UNIQUE KEY `name_idx` (`name`),', $result); - $this->assertContains('ADD KEY `group_idx` (`group2`),', $result); - $this->assertContains('ADD KEY `compound_idx` (`group2`, `group1`);', $result); + $this->assertContains('DROP KEY name_idx,', $result); + $this->assertContains('DROP KEY group_idx,', $result); + $this->assertContains('DROP KEY compound_idx,', $result); + $this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result); + $this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result); + $this->assertContains('ADD KEY group_idx (`group2`),', $result); + $this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -604,10 +594,10 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaA->compare($schemaC)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('DROP KEY `name_idx`,', $result); - $this->assertContains('DROP KEY `group_idx`,', $result); - $this->assertContains('DROP KEY `compound_idx`,', $result); - $this->assertContains('DROP KEY `id_name_idx`;', $result); + $this->assertContains('DROP KEY name_idx,', $result); + $this->assertContains('DROP KEY group_idx,', $result); + $this->assertContains('DROP KEY compound_idx,', $result); + $this->assertContains('DROP KEY id_name_idx;', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -2866,13 +2856,6 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->buildIndex($data); $expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)'); $this->assertEquals($expected, $result); - - $data = array( - 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') - ); - $result = $this->Dbo->buildIndex($data); - $expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)'); - $this->assertEquals($expected, $result); } /** From aaefbf1c2f927b0a7f7a2a1c487c2cffa6bc795f Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Thu, 20 Sep 2012 00:21:26 -0300 Subject: [PATCH 56/83] Add MySQL FULLTEXT support. Minor optimizations and testing added. Merge pull request #862 from bar/mysql-fulltext Fixes #262 --- lib/Cake/Model/Datasource/Database/Mysql.php | 35 ++++++--------- lib/Cake/Model/Datasource/DboSource.php | 4 +- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 17 +++++++ .../Model/Datasource/Database/MysqlTest.php | 45 +++++++++++++------ 4 files changed, 64 insertions(+), 37 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index f75c5330b..bdbaaa6c9 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -423,17 +423,21 @@ class Mysql extends DboSource { $table = $this->fullTableName($model); $old = version_compare($this->getVersion(), '4.1', '<='); if ($table) { - $indices = $this->_execute('SHOW INDEX FROM ' . $table); + $indexes = $this->_execute('SHOW INDEX FROM ' . $table); // @codingStandardsIgnoreStart // MySQL columns don't match the cakephp conventions. - while ($idx = $indices->fetch(PDO::FETCH_OBJ)) { + while ($idx = $indexes->fetch(PDO::FETCH_OBJ)) { if ($old) { $idx = (object)current((array)$idx); } if (!isset($index[$idx->Key_name]['column'])) { $col = array(); $index[$idx->Key_name]['column'] = $idx->Column_name; - $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); + if ($idx->Index_type === 'FULLTEXT') { + $index[$idx->Key_name]['type'] = strtolower($idx->Index_type); + } else { + $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); + } } else { if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { $col[] = $index[$idx->Key_name]['column']; @@ -443,7 +447,7 @@ class Mysql extends DboSource { } } // @codingStandardsIgnoreEnd - $indices->closeCursor(); + $indexes->closeCursor(); } return $index; } @@ -553,31 +557,18 @@ class Mysql extends DboSource { if (isset($indexes['drop'])) { foreach ($indexes['drop'] as $name => $value) { $out = 'DROP '; - if ($name == 'PRIMARY') { + if ($name === 'PRIMARY') { $out .= 'PRIMARY KEY'; } else { - $out .= 'KEY ' . $name; + $out .= 'KEY ' . $this->startQuote . $name . $this->endQuote; } $alter[] = $out; } } if (isset($indexes['add'])) { - foreach ($indexes['add'] as $name => $value) { - $out = 'ADD '; - if ($name == 'PRIMARY') { - $out .= 'PRIMARY '; - $name = null; - } else { - if (!empty($value['unique'])) { - $out .= 'UNIQUE '; - } - } - if (is_array($value['column'])) { - $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; - } else { - $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')'; - } - $alter[] = $out; + $add = $this->buildIndex($indexes['add']); + foreach ($add as $index) { + $alter[] = 'ADD ' . $index; } } return $alter; diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 387c5e82f..34f1ff75b 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3125,7 +3125,7 @@ class DboSource extends DataSource { } /** - * Format indexes for create table + * Format indexes for create table. * * @param array $indexes * @param string $table @@ -3141,6 +3141,8 @@ class DboSource extends DataSource { } else { if (!empty($value['unique'])) { $out .= 'UNIQUE '; + } elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') { + $out .= 'FULLTEXT '; } $name = $this->startQuote . $name . $this->endQuote; } diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index 34c782e58..7863af19a 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -763,6 +763,23 @@ class CakeSchemaTest extends CakeTestCase { ); $result = $this->Schema->generateTable('posts', $posts); $this->assertRegExp('/public \$posts/', $result); + + $posts = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'), + 'author_id' => array('type' => 'integer', 'null' => false), + 'title' => array('type' => 'string', 'null' => false), + 'body' => array('type' => 'text', 'null' => true, 'default' => null), + 'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'updated' => array('type' => 'datetime', 'null' => true, 'default' => null), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => true), + 'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext') + ) + ); + $result = $this->Schema->generateTable('fields', $posts); + $this->assertRegExp('/public \$fields/', $result); + $this->assertPattern('/\'type\' \=\> \'fulltext\'/', $result); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 4a633b417..caddc5b7a 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -320,6 +320,16 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->index('with_multiple_compound_keys', false); $this->Dbo->rawQuery('DROP TABLE ' . $name); $this->assertEquals($expected, $result); + + $name = $this->Dbo->fullTableName('with_fulltext'); + $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, name varchar(255), description text, primary key(id), FULLTEXT KEY `MyFtIndex` ( `name`, `description` )) ENGINE=MyISAM;'); + $expected = array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') + ); + $result = $this->Dbo->index('with_fulltext', false); + $this->Dbo->rawQuery('DROP TABLE ' . $name); + $this->assertEquals($expected, $result); } /** @@ -559,9 +569,9 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaB->compare($schemaA)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('ADD KEY name_idx (`name`),', $result); - $this->assertContains('ADD KEY group_idx (`group1`),', $result); - $this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result); + $this->assertContains('ADD KEY `name_idx` (`name`),', $result); + $this->assertContains('ADD KEY `group_idx` (`group1`),', $result); + $this->assertContains('ADD KEY `compound_idx` (`group1`, `group2`),', $result); $this->assertContains('ADD PRIMARY KEY (`id`);', $result); //Test that the string is syntactically correct @@ -587,13 +597,13 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaC->compare($schemaB)); $this->assertContains("ALTER TABLE $table", $result); $this->assertContains('DROP PRIMARY KEY,', $result); - $this->assertContains('DROP KEY name_idx,', $result); - $this->assertContains('DROP KEY group_idx,', $result); - $this->assertContains('DROP KEY compound_idx,', $result); - $this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result); - $this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result); - $this->assertContains('ADD KEY group_idx (`group2`),', $result); - $this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result); + $this->assertContains('DROP KEY `name_idx`,', $result); + $this->assertContains('DROP KEY `group_idx`,', $result); + $this->assertContains('DROP KEY `compound_idx`,', $result); + $this->assertContains('ADD KEY `id_name_idx` (`id`, `name`),', $result); + $this->assertContains('ADD UNIQUE KEY `name_idx` (`name`),', $result); + $this->assertContains('ADD KEY `group_idx` (`group2`),', $result); + $this->assertContains('ADD KEY `compound_idx` (`group2`, `group1`);', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -605,10 +615,10 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->alterSchema($schemaA->compare($schemaC)); $this->assertContains("ALTER TABLE $table", $result); - $this->assertContains('DROP KEY name_idx,', $result); - $this->assertContains('DROP KEY group_idx,', $result); - $this->assertContains('DROP KEY compound_idx,', $result); - $this->assertContains('DROP KEY id_name_idx;', $result); + $this->assertContains('DROP KEY `name_idx`,', $result); + $this->assertContains('DROP KEY `group_idx`,', $result); + $this->assertContains('DROP KEY `compound_idx`,', $result); + $this->assertContains('DROP KEY `id_name_idx`;', $result); $query = $this->Dbo->getConnection()->prepare($result); $this->assertEquals($query->queryString, $result); @@ -2867,6 +2877,13 @@ class MysqlTest extends CakeTestCase { $result = $this->Dbo->buildIndex($data); $expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)'); $this->assertEquals($expected, $result); + + $data = array( + 'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext') + ); + $result = $this->Dbo->buildIndex($data); + $expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)'); + $this->assertEquals($expected, $result); } /** From d3ba9703a5602caaca4dd039f8065727e8579788 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 Sep 2012 21:07:14 -0400 Subject: [PATCH 57/83] Try to make some time related test failures go away. --- .../Case/Controller/Component/CookieComponentTest.php | 4 +++- lib/Cake/Test/Case/Utility/FileTest.php | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index 6ed65a673..380c29099 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -271,12 +271,14 @@ class CookieComponentTest extends CakeTestCase { $expected = array( 'name' => $this->Cookie->name . '[Testing]', 'value' => '[1,2,3]', - 'expire' => time() + 10, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false); $result = $this->Controller->response->cookie($this->Cookie->name . '[Testing]'); + + $this->assertWithinMargin($result['expire'], time() + 10, 1); + unset($result['expire']); $this->assertEquals($expected, $result); } diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index 93c7227be..01799519d 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -362,11 +362,10 @@ class FileTest extends CakeTestCase { * @return void */ public function testLastAccess() { - $ts = time(); $someFile = new File(TMP . 'some_file.txt', false); $this->assertFalse($someFile->lastAccess()); $this->assertTrue($someFile->open()); - $this->assertTrue($someFile->lastAccess() >= $ts); + $this->assertWithinMargin($someFile->lastAccess(), time(), 2); $someFile->close(); $someFile->delete(); } @@ -377,13 +376,14 @@ class FileTest extends CakeTestCase { * @return void */ public function testLastChange() { - $ts = time(); $someFile = new File(TMP . 'some_file.txt', false); $this->assertFalse($someFile->lastChange()); $this->assertTrue($someFile->open('r+')); - $this->assertTrue($someFile->lastChange() >= $ts); + $this->assertWithinMargin($someFile->lastChange(), time(), 2); + $someFile->write('something'); - $this->assertTrue($someFile->lastChange() >= $ts); + $this->assertWithinMargin($someFile->lastChange(), time(), 2); + $someFile->close(); $someFile->delete(); } From 268e58956d6fd14067f9e7665d9fafce36173fa6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 20 Sep 2012 21:28:29 -0400 Subject: [PATCH 58/83] Attempt to make tests pass when OpenSSL is not enabled. --- lib/Cake/Test/Case/Network/CakeSocketTest.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/Network/CakeSocketTest.php b/lib/Cake/Test/Case/Network/CakeSocketTest.php index 0cee94c38..d4211e590 100644 --- a/lib/Cake/Test/Case/Network/CakeSocketTest.php +++ b/lib/Cake/Test/Case/Network/CakeSocketTest.php @@ -204,11 +204,11 @@ class CakeSocketTest extends CakeTestCase { */ public function testReset() { $config = array( - 'persistent' => true, - 'host' => '127.0.0.1', - 'protocol' => 'udp', - 'port' => 80, - 'timeout' => 20 + 'persistent' => true, + 'host' => '127.0.0.1', + 'protocol' => 'udp', + 'port' => 80, + 'timeout' => 20 ); $anotherSocket = new CakeSocket($config); $anotherSocket->reset(); @@ -222,6 +222,7 @@ class CakeSocketTest extends CakeTestCase { * @return void */ public function testEnableCryptoSocketExceptionNoSsl() { + $this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); $configNoSslOrTls = array('host' => 'localhost', 'port' => 80, 'timeout' => 0.1); // testing exception on no ssl socket server for ssl and tls methods @@ -251,6 +252,7 @@ class CakeSocketTest extends CakeTestCase { * @return void */ protected function _connectSocketToSslTls() { + $this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); $configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5); $this->Socket = new CakeSocket($configSslTls); $this->Socket->connect(); From 6d4f4b57d76cd733ed0ecc39f4b97f343a14642e Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Tue, 19 Jun 2012 22:46:34 +0100 Subject: [PATCH 59/83] adding a plugin propery to models wwith tests for ticket #85 Merge pull request #696 --- lib/Cake/Model/Model.php | 13 ++++++++++++- lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 8 ++++++++ lib/Cake/Utility/ClassRegistry.php | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 515f2e5b3..b4db4a7af 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -235,6 +235,13 @@ class Model extends Object implements CakeEventListener { */ public $tablePrefix = null; +/** + * Plugin model belongs to. + * + * @var string + */ + public $plugin = null; + /** * Name of the model. * @@ -665,12 +672,16 @@ class Model extends Object implements CakeEventListener { extract(array_merge( array( 'id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig, - 'name' => $this->name, 'alias' => $this->alias + 'name' => $this->name, 'alias' => $this->alias, 'plugin' => $this->plugin ), $id )); } + if ($this->plugin === null) { + $this->plugin = (isset($plugin) ? $plugin : $this->plugin); + } + if ($this->name === null) { $this->name = (isset($name) ? $name : get_class($this)); } diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index a7063c0fd..4eec3151f 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1667,6 +1667,14 @@ class ModelIntegrationTest extends BaseModelTest { $result = $TestModel->alias; $expected = 'AnotherTest'; $this->assertEquals($expected, $result); + + $TestModel = ClassRegistry::init('Test'); + $expected = null; + $this->assertEquals($expected, $TestModel->plugin); + + $TestModel = ClassRegistry::init('TestPlugin.TestPluginComment'); + $expected = 'TestPlugin'; + $this->assertEquals($expected, $TestModel->plugin); } /** diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index b74f8b486..30c84faf6 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -124,6 +124,7 @@ class ClassRegistry { list($plugin, $class) = pluginSplit($class); if ($plugin) { $pluginPath = $plugin . '.'; + $settings['plugin'] = $plugin; } if (empty($settings['alias'])) { From 3665a9599670037b52e205e741d916c0d33ff634 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 24 Sep 2012 10:06:45 +0200 Subject: [PATCH 60/83] refactoring asset dispatcher filter --- lib/Cake/Routing/Filter/AssetDispatcher.php | 78 ++++++++++++--------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/lib/Cake/Routing/Filter/AssetDispatcher.php b/lib/Cake/Routing/Filter/AssetDispatcher.php index 11840ba8b..35445670b 100644 --- a/lib/Cake/Routing/Filter/AssetDispatcher.php +++ b/lib/Cake/Routing/Filter/AssetDispatcher.php @@ -42,8 +42,6 @@ class AssetDispatcher extends DispatcherFilter { */ public function beforeDispatch($event) { $url = $event->data['request']->url; - $response = $event->data['response']; - if (strpos($url, '..') !== false || strpos($url, '.') === false) { return; } @@ -53,43 +51,26 @@ class AssetDispatcher extends DispatcherFilter { return $result; } - $pathSegments = explode('.', $url); - $ext = array_pop($pathSegments); - $parts = explode('/', $url); - $assetFile = null; - - if ($parts[0] === 'theme') { - $themeName = $parts[1]; - unset($parts[0], $parts[1]); - $fileFragment = urldecode(implode(DS, $parts)); - $path = App::themePath($themeName) . 'webroot' . DS; - if (file_exists($path . $fileFragment)) { - $assetFile = $path . $fileFragment; - } - } else { - $plugin = Inflector::camelize($parts[0]); - if (CakePlugin::loaded($plugin)) { - unset($parts[0]); - $fileFragment = urldecode(implode(DS, $parts)); - $pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS; - if (file_exists($pluginWebroot . $fileFragment)) { - $assetFile = $pluginWebroot . $fileFragment; - } - } + $assetFile = $this->_getAssetFile($url); + if ($assetFile === null || !file_exists($assetFile)) { + return null; } - if ($assetFile !== null) { - $event->stopPropagation(); - $response->modified(filemtime($assetFile)); - if (!$response->checkNotModified($event->data['request'])) { - $this->_deliverAsset($response, $assetFile, $ext); - } + $response = $event->data['response']; + $event->stopPropagation(); + + $response->modified(filemtime($assetFile)); + if ($response->checkNotModified($event->data['request'])) { return $response; } + + $ext = array_pop(explode('.', $url)); + $this->_deliverAsset($response, $assetFile, $ext); + return $response; } /** - * Checks if the client is requeting a filtered asset and runs the corresponding + * Checks if the client is requesting a filtered asset and runs the corresponding * filter if any is configured * * @param CakeEvent $event containing the request and response object @@ -111,15 +92,44 @@ class AssetDispatcher extends DispatcherFilter { if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) { $response->statusCode(404); return $response; - } elseif ($isCss) { + } + + if ($isCss) { include WWW_ROOT . DS . $filters['css']; return $response; - } elseif ($isJs) { + } + + if ($isJs) { include WWW_ROOT . DS . $filters['js']; return $response; } } +/** + * Builds asset file path based off url + * + * @param string $url + * @return string Absolute path for asset file + */ + protected function _getAssetFile($url) { + $parts = explode('/', $url); + if ($parts[0] === 'theme') { + $themeName = $parts[1]; + unset($parts[0], $parts[1]); + $fileFragment = urldecode(implode(DS, $parts)); + $path = App::themePath($themeName) . 'webroot' . DS; + return $path . $fileFragment; + } + + $plugin = Inflector::camelize($parts[0]); + if (CakePlugin::loaded($plugin)) { + unset($parts[0]); + $fileFragment = urldecode(implode(DS, $parts)); + $pluginWebroot = CakePlugin::path($plugin) . 'webroot' . DS; + return $pluginWebroot . $fileFragment; + } + } + /** * Sends an asset file to the client * From fe5b49e6eba930867adade4ac88125d8bf319d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Mon, 24 Sep 2012 13:41:56 +0200 Subject: [PATCH 61/83] Fixing variable name used to set error handlers. --- lib/Cake/Console/ShellDispatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 40c27cc15..6eb0e1624 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -160,11 +160,11 @@ class ShellDispatcher { $errorHandler = new ConsoleErrorHandler(); if (empty($error['consoleHandler'])) { $error['consoleHandler'] = array($errorHandler, 'handleError'); - Configure::write('error', $error); + Configure::write('Error', $error); } if (empty($exception['consoleHandler'])) { $exception['consoleHandler'] = array($errorHandler, 'handleException'); - Configure::write('exception', $exception); + Configure::write('Exception', $exception); } set_exception_handler($exception['consoleHandler']); set_error_handler($error['consoleHandler'], Configure::read('Error.level')); From e4542827c85c6558833bb8ce1c8b63ef2cd12c76 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 24 Sep 2012 18:26:25 +0200 Subject: [PATCH 62/83] avoid pass by reference error on 5.4 --- lib/Cake/Routing/Filter/AssetDispatcher.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Filter/AssetDispatcher.php b/lib/Cake/Routing/Filter/AssetDispatcher.php index 35445670b..24aff7cd0 100644 --- a/lib/Cake/Routing/Filter/AssetDispatcher.php +++ b/lib/Cake/Routing/Filter/AssetDispatcher.php @@ -64,7 +64,8 @@ class AssetDispatcher extends DispatcherFilter { return $response; } - $ext = array_pop(explode('.', $url)); + $pathSegments = explode('.', $url); + $ext = array_pop($pathSegments); $this->_deliverAsset($response, $assetFile, $ext); return $response; } From b0822d2246b6bad7dfb0c52b996dd8d5ea3ee036 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 25 Sep 2012 15:23:19 +0200 Subject: [PATCH 63/83] Introducing failing test case to prove issue in CakeTime --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 13bf89ddc..04b1b3cde 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -1049,4 +1049,19 @@ class CakeTimeTest extends CakeTestCase { } } +/** + * Tests that using CakeTime::format() with the correct sytax actually converts + * from one timezone to the other correctly + * + * @return void + **/ + public function testCorrectTimezoneConversion() { + date_default_timezone_set('UTC'); + $date = '2012-01-01 10:00:00'; + $converted = CakeTime::format($date, '%Y-%m-%d %H:%M:%S', '', 'Europe/Copenhagen'); + $expected = new DateTime($date); + $expected->setTimezone(new DateTimeZone('Europe/Copenhagen')); + $this->assertEquals($expected->format('Y-m-d H:i:s'), $converted); + } + } From 6818d69fc344c8c44b72c1701380a43fba1ba155 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 25 Sep 2012 15:23:46 +0200 Subject: [PATCH 64/83] Fixed issue in CakeTime that it would apply userOffset twice when using the format() function --- lib/Cake/Utility/CakeTime.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index f5e343fc6..35c7241d0 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -941,15 +941,11 @@ class CakeTime { * @see CakeTime::i18nFormat() */ public static function format($date, $format = null, $default = false, $timezone = null) { - //Backwards compatible params order + //Backwards compatible params re-order test $time = self::fromString($format, $timezone); - $_time = is_numeric($time) ? false : self::fromString($date, $timezone); - if (is_numeric($_time) && $time === false) { - return self::i18nFormat($_time, $format, $default, $timezone); - } - if ($time === false && $default !== false) { - return $default; + if ($time === false) { + return self::i18nFormat($date, $format, $default, $timezone); } return date($date, $time); } From 047ffd15300eb58d1856fec1e4c5c90f5e9c9586 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 25 Sep 2012 17:01:06 +0200 Subject: [PATCH 65/83] Removing variable from dump test as it does not exist anymore --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index d9e82fed8..155cd1c2d 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -357,7 +357,6 @@ TEXT; [protected] _stack => array() [protected] _eventManager => object(CakeEventManager) {} [protected] _eventManagerConfigured => false - [private] __viewFileName => null TEXT; } From c8700442628e444e904db83b031393b8100c76b6 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 25 Sep 2012 17:05:41 +0200 Subject: [PATCH 66/83] Fixed typo --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index b201e3018..3bc1495eb 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2925,7 +2925,7 @@ class DboSource extends DataSource { * Reset a sequence based on the MAX() value of $column. Useful * for resetting sequences after using insertMulti(). * - * This method should be implmented by datasources that require sequences to be used. + * This method should be implemented by datasources that require sequences to be used. * * @param string $table The name of the table to update. * @param string $column The column to use when reseting the sequence value. From 0fc9a2c29c489177afeecaccf4eb7ddb7ab153a7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 25 Sep 2012 21:01:19 -0400 Subject: [PATCH 67/83] Update query building in TranslateBehavior. * Reduce duplicate checks for Alias.*. * Allow both the quoted and non quoted version of Alias.* Fixes #3210 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 37eb5c426..dd1243b91 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -147,11 +147,14 @@ class TranslateBehavior extends ModelBehavior { if (empty($query['fields'])) { $addFields = $fields; } elseif (is_array($query['fields'])) { + $isAllFields = ( + in_array($Model->alias . '.' . '*', $query['fields']) || + in_array($Model->escapeField('*'), $query['fields']) + ); foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; - if ( - in_array($Model->escapeField('*'), $query['fields']) || + $isAllFields || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields']) ) { From 61d6f716bc718c0cefb6b0ef7cfdf8c18a37bac6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 26 Sep 2012 21:48:05 -0400 Subject: [PATCH 68/83] Attempting to get passing builds on travisci Currently the 5.2 builds fail due to the length checks on blowfish hashes. Try a shorter wall to see if those builds will pass. --- lib/Cake/Utility/Security.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Utility/Security.php b/lib/Cake/Utility/Security.php index 84369e04d..c884d2662 100644 --- a/lib/Cake/Utility/Security.php +++ b/lib/Cake/Utility/Security.php @@ -272,7 +272,8 @@ class Security { $salt, ); $salt = vsprintf($saltFormat[$hashType], $vspArgs); - } elseif ($salt === true || strpos($salt, '$2a$') !== 0 || strlen($salt) < 29) { + } + if ($salt === true || strpos($salt, '$2a$') !== 0 || strlen($salt) < 12) { trigger_error(__d( 'cake_dev', 'Invalid salt: %s for %s Please visit http://www.php.net/crypt and read the appropriate section for building %s salts.', From 8bbb1f166c1e974796bccffeddf0701a8551a88e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 26 Sep 2012 21:58:14 -0400 Subject: [PATCH 69/83] Revert "Attempting to get passing builds on travisci" This reverts commit 61d6f716bc718c0cefb6b0ef7cfdf8c18a37bac6. --- lib/Cake/Utility/Security.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Utility/Security.php b/lib/Cake/Utility/Security.php index c884d2662..84369e04d 100644 --- a/lib/Cake/Utility/Security.php +++ b/lib/Cake/Utility/Security.php @@ -272,8 +272,7 @@ class Security { $salt, ); $salt = vsprintf($saltFormat[$hashType], $vspArgs); - } - if ($salt === true || strpos($salt, '$2a$') !== 0 || strlen($salt) < 12) { + } elseif ($salt === true || strpos($salt, '$2a$') !== 0 || strlen($salt) < 29) { trigger_error(__d( 'cake_dev', 'Invalid salt: %s for %s Please visit http://www.php.net/crypt and read the appropriate section for building %s salts.', From ea784f68dc2275153186fc2cbd4cf5b0df364e2a Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 26 Sep 2012 22:00:52 -0400 Subject: [PATCH 70/83] Try skipping blowfish tests if hashes are wrong. Another attempt at fixing failing tests on travisci. --- .../Controller/Component/Auth/BlowfishAuthenticateTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Test/Case/Controller/Component/Auth/BlowfishAuthenticateTest.php b/lib/Cake/Test/Case/Controller/Component/Auth/BlowfishAuthenticateTest.php index 59238199e..d36379e89 100644 --- a/lib/Cake/Test/Case/Controller/Component/Auth/BlowfishAuthenticateTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Auth/BlowfishAuthenticateTest.php @@ -51,6 +51,9 @@ class BlowfishAuthenticateTest extends CakeTestCase { $User = ClassRegistry::init('User'); $User->updateAll(array('password' => $User->getDataSource()->value($password))); $this->response = $this->getMock('CakeResponse'); + + $hash = Security::hash('password', 'blowfish'); + $this->skipIf(strpos($hash, '$2a$') === false, 'Skipping blowfish tests as hashing is not working'); } /** From 76d21c6d565e5b829d28783b60417d3005773e46 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 26 Sep 2012 22:23:01 -0400 Subject: [PATCH 71/83] Try to fix another test failure caused by blowfish. travis ci seems to have wonky hashing with blowfish on the 5.2 boxes. Skip tests when we know blowfish is messed up. --- lib/Cake/Test/Case/Utility/SecurityTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/SecurityTest.php b/lib/Cake/Test/Case/Utility/SecurityTest.php index ea7d6fa29..c6c017df6 100644 --- a/lib/Cake/Test/Case/Utility/SecurityTest.php +++ b/lib/Cake/Test/Case/Utility/SecurityTest.php @@ -147,9 +147,25 @@ class SecurityTest extends CakeTestCase { $this->assertSame(strlen(Security::hash($key, 'sha256', true)), 64); } + Security::setHash($_hashType); + } + +/** + * Test that hash() works with blowfish. + * + * @return void + */ + public function testHashBlowfish() { + Security::setCost(10); + $test = Security::hash('password', 'blowfish'); + $this->skipIf(strpos($test, '$2a$') === false, 'Blowfish hashes are incorrect.'); + + $_hashType = Security::$hashType; + + $key = 'someKey'; $hashType = 'blowfish'; Security::setHash($hashType); - Security::setCost(10); // ensure default cost + $this->assertSame(Security::$hashType, $hashType); $this->assertSame(strlen(Security::hash($key, null, false)), 60); From c87b53a7d851fb1b6ecc098663c9479a7f79aab3 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 27 Sep 2012 10:10:40 +0200 Subject: [PATCH 72/83] correcting iso standard for nld (dutch) - making dut the alias --- lib/Cake/I18n/L10n.php | 8 ++++---- lib/Cake/Test/Case/I18n/L10nTest.php | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Cake/I18n/L10n.php b/lib/Cake/I18n/L10n.php index 275cb4c5f..6e432c726 100644 --- a/lib/Cake/I18n/L10n.php +++ b/lib/Cake/I18n/L10n.php @@ -105,8 +105,8 @@ class L10n { /* Czech */ 'cze' => 'cs', /* Czech */ 'ces' => 'cs', /* Danish */ 'dan' => 'da', - /* Dutch (Standard) */ 'dut' => 'nl', /* Dutch (Standard) */ 'nld' => 'nl', + /* Dutch (Standard) */ 'dut' => 'nl', /* English */ 'eng' => 'en', /* Estonian */ 'est' => 'et', /* Faeroese */ 'fao' => 'fo', @@ -280,10 +280,10 @@ class L10n { 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr'), 'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'n' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), 'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), 'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'), 'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'), 'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8', 'direction' => 'ltr'), diff --git a/lib/Cake/Test/Case/I18n/L10nTest.php b/lib/Cake/Test/Case/I18n/L10nTest.php index d52c3a60d..e34e97ab4 100644 --- a/lib/Cake/Test/Case/I18n/L10nTest.php +++ b/lib/Cake/Test/Case/I18n/L10nTest.php @@ -186,17 +186,21 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('dut', 'nl')); - $expected = array('dut' => 'nl', 'nl' => 'dut'); + $expected = array('dut' => 'nl', 'nl' => 'nld'); $this->assertEquals($expected, $result); $result = $localize->map(array('nld', 'nl')); - $expected = array('nld' => 'nl', 'nl' => 'dut'); + $expected = array('nld' => 'nl', 'nl' => 'nld'); $this->assertEquals($expected, $result); $result = $localize->map(array('nld')); $expected = array('nld' => 'nl'); $this->assertEquals($expected, $result); + $result = $localize->map(array('dut')); + $expected = array('dut' => 'nl'); + $this->assertEquals($expected, $result); + $result = $localize->map(array('eng', 'en')); $expected = array('eng' => 'en', 'en' => 'eng'); $this->assertEquals($expected, $result); @@ -740,22 +744,22 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('n', 'nl', 'nl-be')); $expected = array( - 'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr') + 'n' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); $result = $localize->catalog('nl'); - $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog('nld'); - $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog('dut'); - $expected = array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8', 'direction' => 'ltr'); + $expected = array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'); $this->assertEquals($expected, $result); $result = $localize->catalog(array('nb')); From b47e3a7d92d8b79ec69fd292165209d5d50748a3 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 27 Sep 2012 20:28:19 +0200 Subject: [PATCH 73/83] move charset/App.encoding into CakeResponse --- app/webroot/index.php | 2 +- lib/Cake/Console/Templates/skel/webroot/index.php | 2 +- lib/Cake/Controller/Component/CookieComponent.php | 2 +- lib/Cake/Error/ExceptionRenderer.php | 2 +- lib/Cake/Network/CakeResponse.php | 5 +++-- lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php | 2 +- lib/Cake/View/Helper/CacheHelper.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 2 +- lib/Cake/View/View.php | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/webroot/index.php b/app/webroot/index.php index b06dda684..9ef8225db 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -94,4 +94,4 @@ if (!empty($failed)) { App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); -$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding')))); +$Dispatcher->dispatch(new CakeRequest(), new CakeResponse()); diff --git a/lib/Cake/Console/Templates/skel/webroot/index.php b/lib/Cake/Console/Templates/skel/webroot/index.php index 205c4b6e0..3b6e141ce 100644 --- a/lib/Cake/Console/Templates/skel/webroot/index.php +++ b/lib/Cake/Console/Templates/skel/webroot/index.php @@ -98,5 +98,5 @@ App::uses('Dispatcher', 'Routing'); $Dispatcher = new Dispatcher(); $Dispatcher->dispatch( new CakeRequest(), - new CakeResponse(array('charset' => Configure::read('App.encoding'))) + new CakeResponse() ); diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index d57b65804..d059fc336 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -177,7 +177,7 @@ class CookieComponent extends Component { if ($controller && isset($controller->response)) { $this->_response = $controller->response; } else { - $this->_response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); + $this->_response = new CakeResponse(); } } diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index fb55b3ad6..6d7670b1f 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -146,7 +146,7 @@ class ExceptionRenderer { if (!$request = Router::getRequest(true)) { $request = new CakeRequest(); } - $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); + $response = new CakeResponse(); if (method_exists($exception, 'responseHeader')) { $response->header($exception->responseHeader()); diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 2740e0a4f..68e70e85c 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -384,9 +384,10 @@ class CakeResponse { if (isset($options['type'])) { $this->type($options['type']); } - if (isset($options['charset'])) { - $this->charset($options['charset']); + if (!isset($options['charset'])) { + $options['charset'] = Configure::read('App.encoding'); } + $this->charset($options['charset']); } /** diff --git a/lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php b/lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php index e104a01c2..efd92b26f 100644 --- a/lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php +++ b/lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php @@ -7,7 +7,7 @@ class TestAppsExceptionRenderer extends ExceptionRenderer { if (!$request = Router::getRequest(true)) { $request = new CakeRequest(); } - $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); + $response = new CakeResponse(); try { $controller = new TestAppsErrorController($request, $response); $controller->layout = 'banana'; diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index 2f85cd50b..043c4a3f2 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -302,7 +302,7 @@ class CacheHelper extends AppHelper { $file .= ' $request = unserialize(base64_decode(\'' . base64_encode(serialize($this->request)) . '\')); - $response = new CakeResponse(array("charset" => Configure::read("App.encoding"))); + $response = new CakeResponse(); $controller = new ' . $this->_View->name . 'Controller($request, $response); $controller->plugin = $this->plugin = \'' . $this->_View->plugin . '\'; $controller->helpers = $this->helpers = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->helpers)) . '\')); diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 5582f58f6..b5b68b06a 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -160,7 +160,7 @@ class HtmlHelper extends AppHelper { if (is_object($this->_View->response)) { $this->response = $this->_View->response; } else { - $this->response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); + $this->response = new CakeResponse(); } if (!empty($settings['configFile'])) { $this->loadConfig($settings['configFile']); diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 861f6f6a7..3e7137bca 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -330,7 +330,7 @@ class View extends Object { if (is_object($controller) && isset($controller->response)) { $this->response = $controller->response; } else { - $this->response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); + $this->response = new CakeResponse(); } $this->Helpers = new HelperCollection($this); $this->Blocks = new ViewBlock(); From 99edef0abc3332cd833d11cd29470f6850dc73d8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 20:34:22 -0400 Subject: [PATCH 74/83] Re-order assertions. Group the true/false assertions. --- lib/Cake/Test/Case/Utility/ValidationTest.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 73bc5e635..22afee2c9 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -1826,32 +1826,32 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake')); $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake')); $this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake')); - $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); - $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start')); $this->assertTrue(Validation::url('www.domain.tld')); + $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com')); + $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2')); + $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php')); + $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params')); + $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor')); + $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing')); + $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)')); + $this->assertTrue(Validation::url('http://www.cakephp.org', true)); + $this->assertTrue(Validation::url('http://example.com/~userdir/')); + $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); + $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); + $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); + $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); $this->assertFalse(Validation::url('http://w_w.domain.co_m')); $this->assertFalse(Validation::url('http://www.domain.12com')); $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed')); $this->assertFalse(Validation::url('http://www.-invaliddomain.tld')); $this->assertFalse(Validation::url('http://www.domain.-invalidtld')); - $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com')); $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com')); - $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2')); - $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php')); - $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params')); - $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor')); - $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); - $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing')); - $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)')); - $this->assertFalse(Validation::url('http://en.(wikipedia).org/')); - $this->assertFalse(Validation::url('www.cakephp.org', true)); - $this->assertTrue(Validation::url('http://www.cakephp.org', true)); - $this->assertTrue(Validation::url('http://example.com/~userdir/')); - $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); - $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); $this->assertFalse(Validation::url('http://www.underscore_domain.org')); $this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com')); + $this->assertFalse(Validation::url('http://en.(wikipedia).org/')); + $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); + $this->assertFalse(Validation::url('www.cakephp.org', true)); $this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html')); $this->assertTrue(Validation::url('http://www.zwischenraume.de')); From 393849a9bac3bae94cc91be73e1cb8df7e9d9276 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 21:38:20 -0400 Subject: [PATCH 75/83] Make exception rendererer more resiliant Exceptions in beforeRender() should render correct error pages. Fixes #3235 --- lib/Cake/Error/ExceptionRenderer.php | 4 +- .../Test/Case/Error/ExceptionRendererTest.php | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 8c69e4d0e..a404d3be8 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -290,11 +290,11 @@ class ExceptionRenderer { $this->controller->layoutPath = null; $this->controller->subDir = null; $this->controller->viewPath = 'Errors/'; - $this->controller->viewClass = 'View'; $this->controller->layout = 'error'; $this->controller->helpers = array('Form', 'Html', 'Session'); - $this->controller->render($template); + $view = new View($this->controller); + $this->controller->response->body($view->render($template, 'error')); $this->controller->response->type('html'); $this->controller->response->send(); } diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index 46745e89e..a5704433b 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -670,25 +670,49 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new MissingHelperException(array('class' => 'Fail')); $ExceptionRenderer = new ExceptionRenderer($exception); - $ExceptionRenderer->controller = $this->getMock('Controller'); + $ExceptionRenderer->controller = $this->getMock('Controller', array('render')); $ExceptionRenderer->controller->helpers = array('Fail', 'Boom'); $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); - $ExceptionRenderer->controller->expects($this->at(2)) + $ExceptionRenderer->controller->expects($this->at(0)) ->method('render') ->with('missingHelper') ->will($this->throwException($exception)); - $ExceptionRenderer->controller->expects($this->at(4)) - ->method('render') - ->with('error500') - ->will($this->returnValue(true)); + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Helper class Fail')); - $ExceptionRenderer->controller->response = $this->getMock('CakeResponse'); + $ExceptionRenderer->controller->response = $response; $ExceptionRenderer->render(); sort($ExceptionRenderer->controller->helpers); $this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers); } +/** + * Test that exceptions in beforeRender() are handled by outputMessageSafe + * + * @return void + */ + public function testRenderExceptionInBeforeRender() { + $exception = new NotFoundException('Not there, sorry'); + $ExceptionRenderer = new ExceptionRenderer($exception); + + $ExceptionRenderer->controller = $this->getMock('Controller', array('beforeRender')); + $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); + $ExceptionRenderer->controller->expects($this->any()) + ->method('beforeRender') + ->will($this->throwException($exception)); + + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Not there, sorry')); + + $ExceptionRenderer->controller->response = $response; + $ExceptionRenderer->render(); + } + /** * Test that missing subDir/layoutPath don't cause other fatal errors. * @@ -698,32 +722,31 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new NotFoundException(); $ExceptionRenderer = new ExceptionRenderer($exception); - $ExceptionRenderer->controller = $this->getMock('Controller'); + $ExceptionRenderer->controller = $this->getMock('Controller', array('render')); $ExceptionRenderer->controller->helpers = array('Fail', 'Boom'); $ExceptionRenderer->controller->layoutPath = 'json'; $ExceptionRenderer->controller->subDir = 'json'; $ExceptionRenderer->controller->viewClass = 'Json'; $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); - $ExceptionRenderer->controller->expects($this->at(1)) + $ExceptionRenderer->controller->expects($this->once()) ->method('render') ->with('error400') ->will($this->throwException($exception)); - $ExceptionRenderer->controller->expects($this->at(3)) - ->method('render') - ->with('error500') - ->will($this->returnValue(true)); - - $ExceptionRenderer->controller->response = $this->getMock('CakeResponse'); - $ExceptionRenderer->controller->response->expects($this->once()) + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Not Found')); + $response->expects($this->once()) ->method('type') ->with('html'); + $ExceptionRenderer->controller->response = $response; + $ExceptionRenderer->render(); $this->assertEquals('', $ExceptionRenderer->controller->layoutPath); $this->assertEquals('', $ExceptionRenderer->controller->subDir); - $this->assertEquals('View', $ExceptionRenderer->controller->viewClass); $this->assertEquals('Errors/', $ExceptionRenderer->controller->viewPath); } From eed59a95ad81aad6c80c30054eda0399b5e5d9ec Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 21:42:15 -0400 Subject: [PATCH 76/83] Fix whitespace. --- lib/Cake/Test/Case/Utility/SecurityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/SecurityTest.php b/lib/Cake/Test/Case/Utility/SecurityTest.php index c6c017df6..cc07b0a32 100644 --- a/lib/Cake/Test/Case/Utility/SecurityTest.php +++ b/lib/Cake/Test/Case/Utility/SecurityTest.php @@ -161,7 +161,7 @@ class SecurityTest extends CakeTestCase { $this->skipIf(strpos($test, '$2a$') === false, 'Blowfish hashes are incorrect.'); $_hashType = Security::$hashType; - + $key = 'someKey'; $hashType = 'blowfish'; Security::setHash($hashType); From e5503326ac4acbc8e230ffef2848bc963c97758b Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 21:44:19 -0400 Subject: [PATCH 77/83] Fix coding standard error. --- lib/Cake/Utility/CakeNumber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 9470f910f..166bda187 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -117,7 +117,7 @@ class CakeNumber { $i = array_search(substr($size, -2), array('KB', 'MB', 'GB', 'TB', 'PB')); if ($i !== false) { - $size = substr($size, 0, strlen($size) -2); + $size = substr($size, 0, strlen($size) - 2); return $size * pow(1024, $i + 1); } From b7f1740d2bc1aaff2ee6a014a0600238a396b877 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 28 Sep 2012 13:49:51 +0200 Subject: [PATCH 78/83] correcting coding-standards --- .../Console/Command/Task/ControllerTask.php | 2 +- lib/Cake/Console/Command/Task/ModelTask.php | 10 +- lib/Cake/Model/Model.php | 4 +- .../Console/Command/Task/TestTaskTest.php | 2 +- .../Controller/Component/Acl/PhpAclTest.php | 2 +- lib/Cake/Test/Case/I18n/I18nTest.php | 4 +- .../Model/Behavior/TreeBehaviorNumberTest.php | 116 +++++++++--------- 7 files changed, 70 insertions(+), 70 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 8feecc1a5..4da40184e 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -432,7 +432,7 @@ class ControllerTask extends BakeTask { } } - if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers) ) { + if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers)) { $controllerName = $controllers[intval($enteredController) - 1]; } else { $controllerName = Inflector::camelize($enteredController); diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index df2725d1f..038d4cd91 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -688,7 +688,7 @@ class ModelTask extends BakeTask { $prompt = __d('cake_console', 'Would you like to define some additional model associations?'); $wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n'); $possibleKeys = $this->_generatePossibleKeys(); - while (strtolower($wannaDoMoreAssoc) == 'y') { + while (strtolower($wannaDoMoreAssoc) === 'y') { $assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $this->out(__d('cake_console', 'What is the association type?')); $assocType = intval($this->inOptions($assocs, __d('cake_console', 'Enter a number'))); @@ -698,9 +698,9 @@ class ModelTask extends BakeTask { $this->hr(); $alias = $this->in(__d('cake_console', 'What is the alias for this association?')); - $className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias ); + $className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias); - if ($assocType == 0) { + if ($assocType === 0) { if (!empty($possibleKeys[$model->table])) { $showKeys = $possibleKeys[$model->table]; } else { @@ -733,7 +733,7 @@ class ModelTask extends BakeTask { if (!isset($foreignKey)) { $foreignKey = $this->in(__d('cake_console', 'What is the foreignKey? Specify your own.'), null, $suggestedForeignKey); } - if ($assocType == 3) { + if ($assocType === 3) { $associationForeignKey = $this->in(__d('cake_console', 'What is the associationForeignKey?'), null, $this->_modelKey($model->name)); $joinTable = $this->in(__d('cake_console', 'What is the joinTable?')); } @@ -743,7 +743,7 @@ class ModelTask extends BakeTask { $associations[$assocs[$assocType]][$i]['alias'] = $alias; $associations[$assocs[$assocType]][$i]['className'] = $className; $associations[$assocs[$assocType]][$i]['foreignKey'] = $foreignKey; - if ($assocType == 3) { + if ($assocType === 3) { $associations[$assocs[$assocType]][$i]['associationForeignKey'] = $associationForeignKey; $associations[$assocs[$assocType]][$i]['joinTable'] = $joinTable; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index a9a3aa2a6..940c64a02 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1881,7 +1881,7 @@ class Model extends Object implements CakeEventListener { if ($keepExisting && !empty($links)) { foreach ($links as $link) { $oldJoin = $link[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']]; - if (! in_array($oldJoin, $newJoins) ) { + if (!in_array($oldJoin, $newJoins)) { $conditions[$associationForeignKey] = $oldJoin; $db->delete($this->{$join}, $conditions); } else { @@ -2735,7 +2735,7 @@ class Model extends Object implements CakeEventListener { */ protected function _findCount($state, $query, $results = array()) { if ($state === 'before') { - if (!empty($query['type']) && isset($this->findMethods[$query['type']]) && $query['type'] !== 'count' ) { + if (!empty($query['type']) && isset($this->findMethods[$query['type']]) && $query['type'] !== 'count') { $query['operation'] = 'count'; $query = $this->{'_find' . ucfirst($query['type'])}('before', $query); } diff --git a/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php index 7eb5fa8b4..6fad8069e 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php @@ -694,7 +694,7 @@ class TestTaskTest extends CakeTestCase { public function testTestCaseFileNamePlugin() { $this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS; - CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS )); + CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS)); $this->Task->plugin = 'TestTest'; $result = $this->Task->testCaseFileName('Model', 'Post'); $expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php'; diff --git a/lib/Cake/Test/Case/Controller/Component/Acl/PhpAclTest.php b/lib/Cake/Test/Case/Controller/Component/Acl/PhpAclTest.php index 92543b396..00f74bcf5 100644 --- a/lib/Cake/Test/Case/Controller/Component/Acl/PhpAclTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Acl/PhpAclTest.php @@ -118,7 +118,7 @@ class PhpAclTest extends CakeTestCase { $this->Acl->Aro->addAlias(array('Role/25' => 'Role/IT')); $this->Acl->allow('Role/IT', '/rules/debugging/*'); - $this->assertEquals(array(array('Role/IT', )), $this->Acl->Aro->roles($user)); + $this->assertEquals(array(array('Role/IT')), $this->Acl->Aro->roles($user)); $this->assertTrue($this->Acl->check($user, '/rules/debugging/stats/pageload')); $this->assertTrue($this->Acl->check($user, '/rules/debugging/sql/queries')); // Role/default is allowed users dashboard, but not Role/IT diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index 637494012..a6a65533f 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -1893,7 +1893,7 @@ class I18nTest extends CakeTestCase { private function __domainPlural($domain = 'test_plugin') { $plurals = array(); for ($number = 0; $number <= 25; $number++) { - $plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number), (float)$number ); + $plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number), (float)$number); } return $plurals; } @@ -1949,7 +1949,7 @@ class I18nTest extends CakeTestCase { private function __pluralFromCore() { $plurals = array(); for ($number = 0; $number <= 25; $number++) { - $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number ); + $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number); } return $plurals; } diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index d93c6334e..f71378a14 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -636,8 +636,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { $parent = $this->Tree->findByName('1. Root', array('id')); $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); - $expected = array(array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.1', ))); + $expected = array(array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.1'))); $this->assertSame($expected, $result); } @@ -658,8 +658,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { $parent = $this->Tree->findByName('1. Root', array('id')); $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); - $expected = array(array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', ))); + $expected = array(array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2'))); $this->assertSame($expected, $result); } @@ -680,16 +680,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); $expected = array( - array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.5', )), - array($modelClass => array('name' => '1.3', )), - array($modelClass => array('name' => '1.4', )), - array($modelClass => array('name' => '1.6', )), - array($modelClass => array('name' => '1.7', )), - array($modelClass => array('name' => '1.8', )), - array($modelClass => array('name' => '1.9', )), - array($modelClass => array('name' => '1.10', ))); + array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.5')), + array($modelClass => array('name' => '1.3')), + array($modelClass => array('name' => '1.4')), + array($modelClass => array('name' => '1.6')), + array($modelClass => array('name' => '1.7')), + array($modelClass => array('name' => '1.8')), + array($modelClass => array('name' => '1.9')), + array($modelClass => array('name' => '1.10'))); $this->assertSame($expected, $result); } @@ -710,16 +710,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); $expected = array( - array($modelClass => array('name' => '1.5', )), - array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.3', )), - array($modelClass => array('name' => '1.4', )), - array($modelClass => array('name' => '1.6', )), - array($modelClass => array('name' => '1.7', )), - array($modelClass => array('name' => '1.8', )), - array($modelClass => array('name' => '1.9', )), - array($modelClass => array('name' => '1.10', ))); + array($modelClass => array('name' => '1.5')), + array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.3')), + array($modelClass => array('name' => '1.4')), + array($modelClass => array('name' => '1.6')), + array($modelClass => array('name' => '1.7')), + array($modelClass => array('name' => '1.8')), + array($modelClass => array('name' => '1.9')), + array($modelClass => array('name' => '1.10'))); $this->assertSame($expected, $result); } @@ -739,8 +739,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { $parent = $this->Tree->findByName('1. Root', array('id')); $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); - $expected = array(array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.1', ))); + $expected = array(array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.1'))); $this->assertSame($expected, $result); } @@ -760,8 +760,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { $parent = $this->Tree->findByName('1. Root', array('id')); $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); - $expected = array(array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', ))); + $expected = array(array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2'))); $this->assertSame($expected, $result); } @@ -782,16 +782,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); $expected = array( - array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.3', )), - array($modelClass => array('name' => '1.4', )), - array($modelClass => array('name' => '1.6', )), - array($modelClass => array('name' => '1.7', )), - array($modelClass => array('name' => '1.8', )), - array($modelClass => array('name' => '1.9', )), - array($modelClass => array('name' => '1.10', )), - array($modelClass => array('name' => '1.5', ))); + array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.3')), + array($modelClass => array('name' => '1.4')), + array($modelClass => array('name' => '1.6')), + array($modelClass => array('name' => '1.7')), + array($modelClass => array('name' => '1.8')), + array($modelClass => array('name' => '1.9')), + array($modelClass => array('name' => '1.10')), + array($modelClass => array('name' => '1.5'))); $this->assertSame($expected, $result); } @@ -812,16 +812,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); $expected = array( - array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.3', )), - array($modelClass => array('name' => '1.4', )), - array($modelClass => array('name' => '1.6', )), - array($modelClass => array('name' => '1.7', )), - array($modelClass => array('name' => '1.5', )), - array($modelClass => array('name' => '1.8', )), - array($modelClass => array('name' => '1.9', )), - array($modelClass => array('name' => '1.10', ))); + array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.3')), + array($modelClass => array('name' => '1.4')), + array($modelClass => array('name' => '1.6')), + array($modelClass => array('name' => '1.7')), + array($modelClass => array('name' => '1.5')), + array($modelClass => array('name' => '1.8')), + array($modelClass => array('name' => '1.9')), + array($modelClass => array('name' => '1.10'))); $this->assertSame($expected, $result); } @@ -842,16 +842,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $parent[$modelClass]['id']; $result = $this->Tree->children(null, true, array('name')); $expected = array( - array($modelClass => array('name' => '1.1', )), - array($modelClass => array('name' => '1.2', )), - array($modelClass => array('name' => '1.3', )), - array($modelClass => array('name' => '1.4', )), - array($modelClass => array('name' => 'renamed', )), - array($modelClass => array('name' => '1.6', )), - array($modelClass => array('name' => '1.7', )), - array($modelClass => array('name' => '1.8', )), - array($modelClass => array('name' => '1.9', )), - array($modelClass => array('name' => '1.10', ))); + array($modelClass => array('name' => '1.1')), + array($modelClass => array('name' => '1.2')), + array($modelClass => array('name' => '1.3')), + array($modelClass => array('name' => '1.4')), + array($modelClass => array('name' => 'renamed')), + array($modelClass => array('name' => '1.6')), + array($modelClass => array('name' => '1.7')), + array($modelClass => array('name' => '1.8')), + array($modelClass => array('name' => '1.9')), + array($modelClass => array('name' => '1.10'))); $this->assertSame($expected, $result); } From 032704346a99c0daf31e4a95ed6d5bdcb36187e2 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 28 Sep 2012 14:46:29 +0200 Subject: [PATCH 79/83] after correcting nld the iso standard should be enforced for all languages --- lib/Cake/I18n/L10n.php | 79 +++++++++++---------- lib/Cake/Test/Case/I18n/L10nTest.php | 100 +++++++++++++-------------- 2 files changed, 92 insertions(+), 87 deletions(-) diff --git a/lib/Cake/I18n/L10n.php b/lib/Cake/I18n/L10n.php index 6e432c726..08e99dae7 100644 --- a/lib/Cake/I18n/L10n.php +++ b/lib/Cake/I18n/L10n.php @@ -85,47 +85,52 @@ class L10n { /** * Maps ISO 639-3 to I10n::_l10nCatalog + * The terminological codes (first one per language) should be used if possible. + * The bibliographic codes are aliases and work as well, though. * * @var array */ protected $_l10nMap = array( /* Afrikaans */ 'afr' => 'af', - /* Albanian */ 'alb' => 'sq', + /* Albanian */ 'sqi' => 'sq', + /* Albanian - bibliographic */ 'alb' => 'sq', /* Arabic */ 'ara' => 'ar', - /* Armenian - Armenia */ 'hye' => 'hy', + /* Armenian/Armenia */ 'hye' => 'hy', + /* Basque */ 'eus' => 'eu', /* Basque */ 'baq' => 'eu', /* Tibetan */ 'bod' => 'bo', + /* Tibetan - bibliographic */ 'tib' => 'bo', /* Bosnian */ 'bos' => 'bs', /* Bulgarian */ 'bul' => 'bg', /* Byelorussian */ 'bel' => 'be', /* Catalan */ 'cat' => 'ca', - /* Chinese */ 'chi' => 'zh', /* Chinese */ 'zho' => 'zh', + /* Chinese - bibliographic */ 'chi' => 'zh', /* Croatian */ 'hrv' => 'hr', - /* Czech */ 'cze' => 'cs', /* Czech */ 'ces' => 'cs', + /* Czech - bibliographic */ 'cze' => 'cs', /* Danish */ 'dan' => 'da', /* Dutch (Standard) */ 'nld' => 'nl', - /* Dutch (Standard) */ 'dut' => 'nl', + /* Dutch (Standard) - bibliographic */ 'dut' => 'nl', /* English */ 'eng' => 'en', /* Estonian */ 'est' => 'et', /* Faeroese */ 'fao' => 'fo', - /* Farsi */ 'fas' => 'fa', - /* Farsi */ 'per' => 'fa', + /* Farsi/Persian */ 'fas' => 'fa', + /* Farsi/Persian - bibliographic */ 'per' => 'fa', /* Finnish */ 'fin' => 'fi', - /* French (Standard) */ 'fre' => 'fr', /* French (Standard) */ 'fra' => 'fr', + /* French (Standard) - bibliographic */ 'fre' => 'fr', /* Gaelic (Scots) */ 'gla' => 'gd', /* Galician */ 'glg' => 'gl', /* German (Standard) */ 'deu' => 'de', - /* German (Standard) */ 'ger' => 'de', + /* German (Standard) - bibliographic */ 'ger' => 'de', /* Greek */ 'gre' => 'el', /* Greek */ 'ell' => 'el', /* Hebrew */ 'heb' => 'he', /* Hindi */ 'hin' => 'hi', /* Hungarian */ 'hun' => 'hu', - /* Icelandic */ 'ice' => 'is', /* Icelandic */ 'isl' => 'is', + /* Icelandic - bibliographic */ 'ice' => 'is', /* Indonesian */ 'ind' => 'id', /* Irish */ 'gle' => 'ga', /* Italian */ 'ita' => 'it', @@ -133,10 +138,10 @@ class L10n { /* Korean */ 'kor' => 'ko', /* Latvian */ 'lav' => 'lv', /* Lithuanian */ 'lit' => 'lt', - /* Macedonian */ 'mac' => 'mk', /* Macedonian */ 'mkd' => 'mk', - /* Malaysian */ 'may' => 'ms', + /* Macedonian - bibliographic */ 'mac' => 'mk', /* Malaysian */ 'msa' => 'ms', + /* Malaysian - bibliographic */ 'may' => 'ms', /* Maltese */ 'mlt' => 'mt', /* Norwegian */ 'nor' => 'no', /* Norwegian Bokmal */ 'nob' => 'nb', @@ -144,14 +149,13 @@ class L10n { /* Polish */ 'pol' => 'pl', /* Portuguese (Portugal) */ 'por' => 'pt', /* Rhaeto-Romanic */ 'roh' => 'rm', - /* Romanian */ 'rum' => 'ro', /* Romanian */ 'ron' => 'ro', + /* Romanian - bibliographic */ 'rum' => 'ro', /* Russian */ 'rus' => 'ru', /* Sami (Lappish) */ 'smi' => 'sz', - /* Serbian */ 'scc' => 'sr', /* Serbian */ 'srp' => 'sr', - /* Slovak */ 'slo' => 'sk', /* Slovak */ 'slk' => 'sk', + /* Slovak - bibliographic */ 'slo' => 'sk', /* Slovenian */ 'slv' => 'sl', /* Sorbian */ 'wen' => 'sb', /* Spanish (Spain - Traditional) */ 'spa' => 'es', @@ -165,6 +169,7 @@ class L10n { /* Venda */ 'ven' => 've', /* Vietnamese */ 'vie' => 'vi', /* Welsh */ 'cym' => 'cy', + /* Welsh - bibliographic */ 'wel' => 'cy', /* Xhosa */ 'xho' => 'xh', /* Yiddish */ 'yid' => 'yi', /* Zulu */ 'zul' => 'zu' @@ -203,7 +208,7 @@ class L10n { 'bo-in' => array('language' => 'Tibetan (India)', 'locale' => 'bo_in', 'localeFallback' => 'bod', 'charset' => 'utf-8', 'direction' => 'ltr'), 'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr'), 'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), 'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), @@ -245,16 +250,16 @@ class L10n { 'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8', 'direction' => 'rtl'), 'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8', 'direction' => 'ltr'), 'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8', 'direction' => 'ltr'), 'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'), 'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8', 'direction' => 'ltr'), @@ -266,7 +271,7 @@ class L10n { 'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8', 'direction' => 'ltr'), 'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'), 'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr'), 'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'), 'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8', 'direction' => 'ltr'), @@ -276,9 +281,9 @@ class L10n { 'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'), 'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'), 'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8', 'direction' => 'ltr'), 'n' => array('language' => 'Dutch (Standard)', 'locale' => 'nld', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'), 'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8', 'direction' => 'ltr'), @@ -291,15 +296,15 @@ class L10n { 'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'), 'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr'), 'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8', 'direction' => 'ltr'), @@ -315,11 +320,11 @@ class L10n { 'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8', 'direction' => 'ltr'), 'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'), - 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'), + 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr') ); diff --git a/lib/Cake/Test/Case/I18n/L10nTest.php b/lib/Cake/Test/Case/I18n/L10nTest.php index e34e97ab4..a80c270a9 100644 --- a/lib/Cake/Test/Case/I18n/L10nTest.php +++ b/lib/Cake/Test/Case/I18n/L10nTest.php @@ -125,8 +125,12 @@ class L10nTest extends CakeTestCase { $expected = array('afr' => 'af', 'af' => 'afr'); $this->assertEquals($expected, $result); + $result = $localize->map(array('sqi', 'sq')); + $expected = array('sqi' => 'sq', 'sq' => 'sqi'); + $this->assertEquals($expected, $result); + $result = $localize->map(array('alb', 'sq')); - $expected = array('alb' => 'sq', 'sq' => 'alb'); + $expected = array('alb' => 'sq', 'sq' => 'sqi'); $this->assertEquals($expected, $result); $result = $localize->map(array('ara', 'ar')); @@ -137,12 +141,12 @@ class L10nTest extends CakeTestCase { $expected = array('hye' => 'hy', 'hy' => 'hye'); $this->assertEquals($expected, $result); - $result = $localize->map(array('baq', 'eu')); - $expected = array('baq' => 'eu', 'eu' => 'baq'); + $result = $localize->map(array('eus', 'eu')); + $expected = array('eus' => 'eu', 'eu' => 'eus'); $this->assertEquals($expected, $result); $result = $localize->map(array('baq', 'eu')); - $expected = array('baq' => 'eu', 'eu' => 'baq'); + $expected = array('baq' => 'eu', 'eu' => 'eus'); $this->assertEquals($expected, $result); $result = $localize->map(array('bos', 'bs')); @@ -162,11 +166,11 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('chi', 'zh')); - $expected = array('chi' => 'zh', 'zh' => 'chi'); + $expected = array('chi' => 'zh', 'zh' => 'zho'); $this->assertEquals($expected, $result); $result = $localize->map(array('zho', 'zh')); - $expected = array('zho' => 'zh', 'zh' => 'chi'); + $expected = array('zho' => 'zh', 'zh' => 'zho'); $this->assertEquals($expected, $result); $result = $localize->map(array('hrv', 'hr')); @@ -174,11 +178,11 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('ces', 'cs')); - $expected = array('ces' => 'cs', 'cs' => 'cze'); + $expected = array('ces' => 'cs', 'cs' => 'ces'); $this->assertEquals($expected, $result); $result = $localize->map(array('cze', 'cs')); - $expected = array('cze' => 'cs', 'cs' => 'cze'); + $expected = array('cze' => 'cs', 'cs' => 'ces'); $this->assertEquals($expected, $result); $result = $localize->map(array('dan', 'da')); @@ -226,11 +230,11 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('fra', 'fr')); - $expected = array('fra' => 'fr', 'fr' => 'fre'); + $expected = array('fra' => 'fr', 'fr' => 'fra'); $this->assertEquals($expected, $result); $result = $localize->map(array('fre', 'fr')); - $expected = array('fre' => 'fr', 'fr' => 'fre'); + $expected = array('fre' => 'fr', 'fr' => 'fra'); $this->assertEquals($expected, $result); $result = $localize->map(array('gla', 'gd')); @@ -270,11 +274,11 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('ice', 'is')); - $expected = array('ice' => 'is', 'is' => 'ice'); + $expected = array('ice' => 'is', 'is' => 'isl'); $this->assertEquals($expected, $result); $result = $localize->map(array('isl', 'is')); - $expected = array('isl' => 'is', 'is' => 'ice'); + $expected = array('isl' => 'is', 'is' => 'isl'); $this->assertEquals($expected, $result); $result = $localize->map(array('ind', 'id')); @@ -306,19 +310,19 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('mac', 'mk')); - $expected = array('mac' => 'mk', 'mk' => 'mac'); + $expected = array('mac' => 'mk', 'mk' => 'mkd'); $this->assertEquals($expected, $result); $result = $localize->map(array('mkd', 'mk')); - $expected = array('mkd' => 'mk', 'mk' => 'mac'); + $expected = array('mkd' => 'mk', 'mk' => 'mkd'); $this->assertEquals($expected, $result); $result = $localize->map(array('may', 'ms')); - $expected = array('may' => 'ms', 'ms' => 'may'); + $expected = array('may' => 'ms', 'ms' => 'msa'); $this->assertEquals($expected, $result); $result = $localize->map(array('msa', 'ms')); - $expected = array('msa' => 'ms', 'ms' => 'may'); + $expected = array('msa' => 'ms', 'ms' => 'msa'); $this->assertEquals($expected, $result); $result = $localize->map(array('mlt', 'mt')); @@ -350,11 +354,11 @@ class L10nTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $localize->map(array('ron', 'ro')); - $expected = array('ron' => 'ro', 'ro' => 'rum'); + $expected = array('ron' => 'ro', 'ro' => 'ron'); $this->assertEquals($expected, $result); $result = $localize->map(array('rum', 'ro')); - $expected = array('rum' => 'ro', 'ro' => 'rum'); + $expected = array('rum' => 'ro', 'ro' => 'ron'); $this->assertEquals($expected, $result); $result = $localize->map(array('rus', 'ru')); @@ -365,20 +369,16 @@ class L10nTest extends CakeTestCase { $expected = array('smi' => 'sz', 'sz' => 'smi'); $this->assertEquals($expected, $result); - $result = $localize->map(array('scc', 'sr')); - $expected = array('scc' => 'sr', 'sr' => 'scc'); - $this->assertEquals($expected, $result); - $result = $localize->map(array('srp', 'sr')); - $expected = array('srp' => 'sr', 'sr' => 'scc'); + $expected = array('srp' => 'sr', 'sr' => 'srp'); $this->assertEquals($expected, $result); $result = $localize->map(array('slk', 'sk')); - $expected = array('slk' => 'sk', 'sk' => 'slo'); + $expected = array('slk' => 'sk', 'sk' => 'slk'); $this->assertEquals($expected, $result); $result = $localize->map(array('slo', 'sk')); - $expected = array('slo' => 'sk', 'sk' => 'slo'); + $expected = array('slo' => 'sk', 'sk' => 'slk'); $this->assertEquals($expected, $result); $result = $localize->map(array('slv', 'sl')); @@ -509,7 +509,7 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('cs')); $expected = array( - 'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8', 'direction' => 'ltr') + 'cs' => array('language' => 'Czech', 'locale' => 'ces', 'localeFallback' => 'ces', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -587,7 +587,7 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('eu')); $expected = array( - 'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8', 'direction' => 'ltr') + 'eu' => array('language' => 'Basque', 'locale' => 'eus', 'localeFallback' => 'eus', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -611,12 +611,12 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('fr', 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'fr-lu')); $expected = array( - 'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8', 'direction' => 'ltr') + 'fr' => array('language' => 'French (Standard)', 'locale' => 'fra', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fra', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -678,7 +678,7 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('is')); $expected = array( - 'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8', 'direction' => 'ltr') + 'is' => array('language' => 'Icelandic', 'locale' => 'isl', 'localeFallback' => 'isl', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -725,14 +725,14 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('mk', 'mk-mk')); $expected = array( - 'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8', 'direction' => 'ltr') + 'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mkd', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); $result = $localize->catalog(array('ms')); $expected = array( - 'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8', 'direction' => 'ltr') + 'ms' => array('language' => 'Malaysian', 'locale' => 'msa', 'localeFallback' => 'msa', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -797,8 +797,8 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('ro', 'ro-mo')); $expected = array( - 'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr') + 'ro' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -810,7 +810,7 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('sk')); $expected = array( - 'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8', 'direction' => 'ltr') + 'sk' => array('language' => 'Slovak', 'locale' => 'slk', 'localeFallback' => 'slk', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -822,13 +822,13 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('sq')); $expected = array( - 'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8', 'direction' => 'ltr') + 'sq' => array('language' => 'Albanian', 'locale' => 'sqi', 'localeFallback' => 'sqi', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); $result = $localize->catalog(array('sr')); $expected = array( - 'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8', 'direction' => 'ltr') + 'sr' => array('language' => 'Serbian', 'locale' => 'srp', 'localeFallback' => 'srp', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -920,11 +920,11 @@ class L10nTest extends CakeTestCase { $result = $localize->catalog(array('zh', 'zh-cn', 'zh-hk', 'zh-sg', 'zh-tw')); $expected = array( - 'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312', 'direction' => 'ltr'), - 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr') + 'zh' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'zho', 'charset' => 'GB2312', 'direction' => 'ltr'), + 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -940,7 +940,7 @@ class L10nTest extends CakeTestCase { 'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8', 'direction' => 'ltr'), 'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8', 'direction' => 'ltr'), 'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8', 'direction' => 'rtl'), - 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), 'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8', 'direction' => 'ltr') ); $this->assertEquals($expected, $result); @@ -949,8 +949,8 @@ class L10nTest extends CakeTestCase { $expected = array( 'eng' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8', 'direction' => 'ltr'), 'deu' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'zho' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8', 'direction' => 'ltr'), - 'rum' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'zho' => array('language' => 'Chinese', 'locale' => 'zho', 'localeFallback' => 'zho', 'charset' => 'utf-8', 'direction' => 'ltr'), + 'rum' => array('language' => 'Romanian', 'locale' => 'ron', 'localeFallback' => 'ron', 'charset' => 'utf-8', 'direction' => 'ltr'), 'zul' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8', 'direction' => 'ltr'), 'yid' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8', 'direction' => 'ltr') ); From a33b187a0938296699214eb36b10dfb7f7a47556 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 28 Sep 2012 14:51:51 +0200 Subject: [PATCH 80/83] doc block correction --- lib/Cake/I18n/L10n.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/I18n/L10n.php b/lib/Cake/I18n/L10n.php index 08e99dae7..bf105d637 100644 --- a/lib/Cake/I18n/L10n.php +++ b/lib/Cake/I18n/L10n.php @@ -86,7 +86,8 @@ class L10n { /** * Maps ISO 639-3 to I10n::_l10nCatalog * The terminological codes (first one per language) should be used if possible. - * The bibliographic codes are aliases and work as well, though. + * They are the ones building the path in `/APP/Locale/[code]/` + * The bibliographic codes are aliases. * * @var array */ From 2d46fc60bef5d2f11bb745c0d2f8078ee99344f8 Mon Sep 17 00:00:00 2001 From: James Michael DuPont Date: Fri, 28 Sep 2012 06:57:31 +0200 Subject: [PATCH 81/83] Fixing undefined variable usage Squash of pull request #872 --- lib/Cake/Cache/Engine/WincacheEngine.php | 1 + lib/Cake/Console/ShellDispatcher.php | 3 ++- lib/Cake/Model/Model.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Cache/Engine/WincacheEngine.php b/lib/Cake/Cache/Engine/WincacheEngine.php index 542172c0c..8e81312ab 100644 --- a/lib/Cake/Cache/Engine/WincacheEngine.php +++ b/lib/Cake/Cache/Engine/WincacheEngine.php @@ -183,6 +183,7 @@ class WincacheEngine extends CacheEngine { * @return boolean success **/ public function clearGroup($group) { + $success = null; wincache_ucache_inc($this->settings['prefix'] . $group, 1, $success); return $success; } diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 6eb0e1624..162e8f508 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -215,7 +215,8 @@ class ShellDispatcher { return $Shell->main(); } } - throw new MissingShellMethodException(array('shell' => $shell, 'method' => $arg)); + + throw new MissingShellMethodException(array('shell' => $shell, 'method' => $command)); } /** diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 1e6dc56a5..b597ae297 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -3250,7 +3250,7 @@ class Model extends Object implements CakeEventListener { return array($with, array_unique(array_merge($assoc[$with], $keys))); } trigger_error( - __d('cake_dev', 'Invalid join model settings in %s', $model->alias), + __d('cake_dev', 'Invalid join model settings in %s. The association parameter has the wrong type, expecting a string or array, but was passed type: %s', $this->alias, gettype($assoc)), E_USER_WARNING ); } From 853d866c3567da6a832f4617d07ef3796110af01 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 28 Sep 2012 21:20:14 -0400 Subject: [PATCH 82/83] Remove port numbers from Message-id domains. Fixes #3244 --- lib/Cake/Network/Email/CakeEmail.php | 2 +- lib/Cake/Test/Case/Network/Email/CakeEmailTest.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 9e5ed09b8..b812dac97 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -325,7 +325,7 @@ class CakeEmail { if ($this->_appCharset !== null) { $this->charset = $this->_appCharset; } - $this->_domain = env('HTTP_HOST'); + $this->_domain = preg_replace('/\:\d+$/', '', env('HTTP_HOST')); if (empty($this->_domain)) { $this->_domain = php_uname('n'); } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 94b5f373f..27e593f66 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -411,14 +411,18 @@ class CakeEmailTest extends CakeTestCase { * @return void */ public function testMessageIdWithDomain() { - $result = $this->CakeEmail->getHeaders(); - $expected = '@' . (env('HTTP_HOST') ? env('HTTP_HOST') : php_uname('n')) . '>'; - $this->assertTextContains($expected, $result['Message-ID']); - $this->CakeEmail->domain('example.org'); $result = $this->CakeEmail->getHeaders(); $expected = '@example.org>'; $this->assertTextContains($expected, $result['Message-ID']); + + $_SERVER['HTTP_HOST'] = 'example.org'; + $result = $this->CakeEmail->getHeaders(); + $this->assertTextContains('example.org', $result['Message-ID']); + + $_SERVER['HTTP_HOST'] = 'example.org:81'; + $result = $this->CakeEmail->getHeaders(); + $this->assertTextNotContains(':81', $result['Message-ID']); } /** From 035f727686883d6201207fff43e22c5d7c99cb85 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 30 Sep 2012 13:08:57 +0530 Subject: [PATCH 83/83] Replace Model::read() with Model::find('first') in baked controller Removed references to Ajax and Javascript helpers --- .../Console/Command/Task/ControllerTask.php | 2 +- .../default/actions/controller_actions.ctp | 12 +++++------ .../Command/Task/ControllerTaskTest.php | 21 ++++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 4da40184e..11ba8a61a 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -349,7 +349,7 @@ class ControllerTask extends BakeTask { public function doHelpers() { return $this->_doPropertyChoices( __d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"), - __d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'") + __d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Text, Js, Time'") ); } diff --git a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp index 21b6ab8ea..88f20c6f0 100644 --- a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp +++ b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp @@ -36,11 +36,11 @@ * @return void */ public function view($id = null) { - $this->->id = $id; - if (!$this->->exists()) { + if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } - $this->set('', $this->->read(null, $id)); + $options = array('conditions' => array('.' . $this->->primaryKey => $id)); + $this->set('', $this->->find('first', $options)); } @@ -91,8 +91,7 @@ * @return void */ public function edit($id = null) { - $this->->id = $id; - if (!$this->->exists()) { + if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } if ($this->request->is('post') || $this->request->is('put')) { @@ -109,7 +108,8 @@ } } else { - $this->request->data = $this->->read(null, $id); + $options = array('conditions' => array('.' . $this->->primaryKey => $id)); + $this->request->data = $this->->find('first', $options); } Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); - $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne ')); + $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne ')); $result = $this->Task->doHelpers(); - $expected = array('Javascript', 'Ajax', 'CustomOne'); + $expected = array('Text', 'Number', 'CustomOne'); $this->assertEquals($expected, $result); } @@ -204,9 +204,9 @@ class ControllerTaskTest extends CakeTestCase { */ public function testDoHelpersTrailingCommas() { $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); - $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , ')); + $this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , ')); $result = $this->Task->doHelpers(); - $expected = array('Javascript', 'Ajax', 'CustomOne'); + $expected = array('Text', 'Number', 'CustomOne'); $this->assertEquals($expected, $result); } @@ -257,11 +257,11 @@ class ControllerTaskTest extends CakeTestCase { public function testConfirmController() { $controller = 'Posts'; $scaffold = false; - $helpers = array('Ajax', 'Time'); + $helpers = array('Js', 'Time'); $components = array('Acl', 'Auth'); $this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller"); - $this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time"); + $this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time"); $this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth"); $this->Task->confirmController($controller, $scaffold, $helpers, $components); } @@ -272,7 +272,7 @@ class ControllerTaskTest extends CakeTestCase { * @return void */ public function testBake() { - $helpers = array('Ajax', 'Time'); + $helpers = array('Js', 'Time'); $components = array('Acl', 'Auth'); $this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true)); @@ -282,7 +282,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains(' * @property AuthComponent $Auth', $result); $this->assertContains('class ArticlesController extends AppController', $result); $this->assertContains("public \$components = array('Acl', 'Auth')", $result); - $this->assertContains("public \$helpers = array('Ajax', 'Time')", $result); + $this->assertContains("public \$helpers = array('Js', 'Time')", $result); $this->assertContains("--actions--", $result); $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components); @@ -350,7 +350,8 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains('function view($id = null)', $result); $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); - $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); + $this->assertContains("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result); + $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result); $this->assertContains('function add()', $result); $this->assertContains("if (\$this->request->is('post'))", $result); @@ -389,7 +390,7 @@ class ControllerTaskTest extends CakeTestCase { $this->assertContains('function view($id = null)', $result); $this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result); - $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result); + $this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result); $this->assertContains('function add()', $result); $this->assertContains("if (\$this->request->is('post'))", $result);