From 8581350d24e5c4af3a5b1ba6d6ed336d5fef0b16 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 30 Jun 2010 22:51:21 -0400 Subject: [PATCH 01/31] Fixing failing tests. --- .../tests/cases/libs/controller/components/session.test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index 2241afa5c..5a5ec4d3a 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -356,7 +356,7 @@ class SessionComponentTest extends CakeTestCase { $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, mktime() + (300 * Configure::read('Session.timeout'))); - $this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins()); + $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); @@ -366,7 +366,7 @@ class SessionComponentTest extends CakeTestCase { $Session =& new SessionComponent(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, mktime() + (100 * Configure::read('Session.timeout'))); - $this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins()); + $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); @@ -377,7 +377,7 @@ class SessionComponentTest extends CakeTestCase { $Session =& new SessionComponent(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, mktime() + (10 * Configure::read('Session.timeout'))); - $this->assertEqual($_SESSION['Config']['timeout'], Security::inactiveMins()); + $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); From 17a7a96ba2768b7ea0bc44fd06ef13048609ae29 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 1 Jul 2010 12:39:50 -0400 Subject: [PATCH 02/31] Fixing issue where non-reset associations would get reset by resetAssociations if __backAssociations existed. Test cases from 'real34' added. Fixes #868 --- cake/libs/model/model.php | 13 ++++--- .../cases/libs/model/model_read.test.php | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 8b2dcd650..747dcc0ae 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -532,7 +532,6 @@ class Model extends Overloadable { if ($reset === true) { $this->__backAssociation[$assoc] = $this->{$assoc}; } - foreach ($model as $key => $value) { $assocName = $key; @@ -542,6 +541,10 @@ class Model extends Overloadable { } $modelName = $assocName; $this->{$assoc}[$assocName] = $value; + + if ($reset === false && isset($this->__backAssociation[$assoc])) { + $this->__backAssociation[$assoc][$assocName] = $value; + } } } $this->__createLinks(); @@ -575,8 +578,8 @@ class Model extends Overloadable { foreach ($models as $model) { $this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc}); - unset ($this->__backAssociation[$model]); - unset ($this->{$assoc}[$model]); + unset($this->__backAssociation[$model]); + unset($this->{$assoc}[$model]); } } return true; @@ -2341,9 +2344,9 @@ class Model extends Overloadable { } /** - * Called only when bindTo() is used. * This resets the association arrays for the model back - * to those originally defined in the model. + * to those originally defined in the model. Normally called at the end + * of each call to Model::find() * * @return boolean Success * @access public diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 621bd6dfc..bdfe97abf 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -4720,6 +4720,41 @@ class ModelReadTest extends BaseModelTest { $this->assertEqual($result, $expected); } +/** + * testBindMultipleTimes method with different reset settings + * + * @access public + * @return void + */ + function testBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel =& new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array( + 'hasMany' => array('Comment') + )); + $this->assertTrue($result); + $result = $TestModel->bindModel( + array('hasMany' => array('Article')), + false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->hasMany); + $expected = array('Comment', 'Article'); + $this->assertEqual($result, $expected); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->hasMany); + $expected = array('Article'); + $this->assertEqual($result, $expected); + } + /** * test that bindModel behaves with Custom primary Key associations * From f9de88d6cfdb42ca0541daafd4c9ebbc59212659 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jul 2010 17:21:02 -0400 Subject: [PATCH 03/31] Reverted regression with ob_clean() called even when ob_start() was not executed, introduced in cb3100f71f430146343d8f3eb055c015e317cd58 Refs #864. Fixes #882 --- cake/dispatcher.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 6351793e1..38ab04511 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -615,7 +615,8 @@ class Dispatcher extends Object { */ function _deliverAsset($assetFile, $ext) { $ob = @ini_get("zlib.output_compression") !== '1' && extension_loaded("zlib") && (strpos(env('HTTP_ACCEPT_ENCODING'), 'gzip') !== false); - if ($ob && Configure::read('Asset.compress')) { + $compressionEnabled = $ob && Configure::read('Asset.compress'); + if ($compressionEnabled) { ob_start(); ob_start('ob_gzhandler'); } @@ -642,11 +643,13 @@ class Dispatcher extends Object { if ($ext === 'css' || $ext === 'js') { include($assetFile); } else { - ob_clean(); + if ($compressionEnabled) { + ob_clean(); + } readfile($assetFile); } - if (Configure::read('Asset.compress')) { + if ($compressionEnabled) { ob_end_flush(); } } From 4cd43553b4da5163dabc0219000466e946117b41 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jul 2010 18:05:14 -0400 Subject: [PATCH 04/31] Fixing issues where multiple reset bindModel() calls would cause incorrect associations to be restored. Also fixing issues where multiple calls to unbindModel() would cause incorrect associations to be restored. Tests added. Fixes #889 --- cake/libs/model/model.php | 10 +-- .../cases/libs/model/model_read.test.php | 68 +++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 747dcc0ae..07bb37e4f 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -529,7 +529,7 @@ class Model extends Overloadable { */ function bindModel($params, $reset = true) { foreach ($params as $assoc => $model) { - if ($reset === true) { + if ($reset === true && !isset($this->__backAssociation[$assoc])) { $this->__backAssociation[$assoc] = $this->{$assoc}; } foreach ($model as $key => $value) { @@ -572,13 +572,13 @@ class Model extends Overloadable { */ function unbindModel($params, $reset = true) { foreach ($params as $assoc => $models) { - if ($reset === true) { + if ($reset === true && !isset($this->__backAssociation[$assoc])) { $this->__backAssociation[$assoc] = $this->{$assoc}; } - foreach ($models as $model) { - $this->__backAssociation = array_merge($this->__backAssociation, $this->{$assoc}); - unset($this->__backAssociation[$model]); + if ($reset === false && isset($this->__backAssociation[$assoc][$model])) { + unset($this->__backAssociation[$assoc][$model]); + } unset($this->{$assoc}[$model]); } } diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index bdfe97abf..75f22ed46 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -4720,6 +4720,22 @@ class ModelReadTest extends BaseModelTest { $this->assertEqual($result, $expected); } +/** + * test that multiple reset = true calls to bindModel() result in the original associations. + * + * @return void + */ + function testBindModelMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel =& new User(); + + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); + } + /** * testBindMultipleTimes method with different reset settings * @@ -4774,6 +4790,58 @@ class ModelReadTest extends BaseModelTest { $this->assertFalse(empty($result)); } +/** + * test that calling unbindModel() with reset == true multiple times + * leaves associations in the correct state. + * + * @return void + */ + function testUnbindMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel =& new Article10(); + + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); + } + +/** + * testBindMultipleTimes method with different reset settings + * + * @access public + * @return void + */ + function testUnBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel =& new Comment(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('Article', 'User'); + $this->assertEqual($result, $expected); + + $result = $TestModel->unbindModel(array( + 'belongsTo' => array('User') + )); + $this->assertTrue($result); + $result = $TestModel->unbindModel( + array('belongsTo' => array('Article')), + false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->belongsTo); + $expected = array(); + $this->assertEqual($result, $expected); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('User'); + $this->assertEqual($result, $expected); + } + /** * testAssociationAfterFind method * From 60ab9800e2d951e32ebe0d6226dda17bc9bad68c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jul 2010 18:34:02 -0400 Subject: [PATCH 05/31] Fixes issue where CakeSession::destroy() would fail to properly restart the session. Tests added. Fixes #787 --- cake/libs/cake_session.php | 2 +- cake/tests/cases/libs/cake_session.test.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index e0bcb6b48..bf599bf8a 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -227,7 +227,7 @@ class CakeSession extends Object { * @return boolean True if session has been started. */ function started() { - if (isset($_SESSION) && session_id()) { + if (!empty($_SESSION) && session_id()) { return true; } return false; diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index c80eb3c26..2c4019d1e 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -255,6 +255,10 @@ class CakeSessionTest extends CakeTestCase { $this->Session->destroy(); $this->assertFalse($this->Session->check('bulletProof')); $this->assertNotEqual($id, $this->Session->id()); + + $this->Session->cookieLifeTime = 'test'; + $this->Session->destroy(); + $this->assertNotEqual('test', $this->Session->cookieLifeTime); } /** From 103346155fe2730f52171f96fd9bf778c205f803 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 6 Jul 2010 22:30:48 -0400 Subject: [PATCH 06/31] Fixing HttpSocket losing auth credentials when multiple requests are made with the same object. Fixes #893 --- cake/libs/http_socket.php | 12 +++++++---- cake/tests/cases/libs/http_socket.test.php | 25 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 6686ebbce..5d1198f38 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -196,7 +196,10 @@ class HttpSocket extends CakeSocket { $request['uri'] = null; } $uri = $this->_parseUri($request['uri']); - + $hadAuth = false; + if (is_array($uri) && array_key_exists('user', $uri)) { + $hadAuth = true; + } if (!isset($uri['host'])) { $host = $this->config['host']; } @@ -204,11 +207,14 @@ class HttpSocket extends CakeSocket { $host = $request['host']; unset($request['host']); } - $request['uri'] = $this->url($request['uri']); $request['uri'] = $this->_parseUri($request['uri'], true); $this->request = Set::merge($this->request, $this->config['request'], $request); + if (!$hadAuth && !empty($this->config['request']['auth']['user'])) { + $this->request['uri']['user'] = $this->config['request']['auth']['user']; + $this->request['uri']['pass'] = $this->config['request']['auth']['pass']; + } $this->_configUri($this->request['uri']); if (isset($host)) { @@ -605,7 +611,6 @@ class HttpSocket extends CakeSocket { if (!isset($uri['host'])) { return false; } - $config = array( 'request' => array( 'uri' => array_intersect_key($uri, $this->config['request']['uri']), @@ -1049,7 +1054,6 @@ class HttpSocket extends CakeSocket { if (empty($initalState)) { $initalState = get_class_vars(__CLASS__); } - if ($full == false) { $this->request = $initalState['request']; $this->response = $initalState['response']; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index d61d654f5..a49222235 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -638,6 +638,31 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->get('http://www.google.com/', null, array('auth' => array('user' => 'foo', 'pass' => 'bar'))); } +/** + * test that two consecutive get() calls reset the authentication credentials. + * + * @return void + */ + function testConsecutiveGetResetsAuthCredentials() { + $socket = new MockHttpSocket(); + $socket->config['request']['auth'] = array( + 'method' => 'Basic', + 'user' => 'mark', + 'pass' => 'secret' + ); + $socket->get('http://mark:secret@example.com/test'); + $this->assertEqual($socket->request['uri']['user'], 'mark'); + $this->assertEqual($socket->request['uri']['pass'], 'secret'); + + $socket->get('/test2'); + $this->assertEqual($socket->request['auth']['user'], 'mark'); + $this->assertEqual($socket->request['auth']['pass'], 'secret'); + + $socket->get('/test3'); + $this->assertEqual($socket->request['auth']['user'], 'mark'); + $this->assertEqual($socket->request['auth']['pass'], 'secret'); + } + /** * testPostPutDelete method * From 65efd675c1a471d644add491cb96565ed74b3e36 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 11 Jul 2010 13:06:33 -0400 Subject: [PATCH 07/31] Fixing fatal error caused by associated models using a datasource that is not a subclass of dbo_source. Test added. Fixes #873 --- cake/libs/model/datasources/dbo_source.php | 2 +- .../libs/model/datasources/dbo_source.test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index b717ee00a..35be891be 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -841,7 +841,7 @@ class DboSource extends DataSource { $db =& $this; } - if (isset($db)) { + if (isset($db) && method_exists($db, 'queryAssociation')) { $stack = array($assoc); $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack); unset($db); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 8dda31f00..5ef6d396f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1339,6 +1339,7 @@ class DboSourceTest extends CakeTestCase { function endTest() { unset($this->Model); Configure::write('debug', $this->debug); + ClassRegistry::flush(); unset($this->debug); } @@ -4441,4 +4442,19 @@ class DboSourceTest extends CakeTestCase { $result = $this->testDb->fullTableName($Article, false); $this->assertEqual($result, 'tbl_articles'); } + +/** + * test that read() only calls queryAssociation on db objects when the method is defined. + * + * @return void + */ + function testReadOnlyCallingQueryAssociationWhenDefined() { + ConnectionManager::create('test_no_queryAssociation', array( + 'datasource' => 'data' + )); + $Article =& ClassRegistry::init('Article'); + $Article->Comment->useDbConfig = 'test_no_queryAssociation'; + $result = $Article->find('all'); + $this->assertTrue(is_array($result)); + } } From 6d8724097e675ec5e4fc9ac1a10abc52a96410f9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 11 Jul 2010 13:47:40 -0400 Subject: [PATCH 08/31] Changing check in AjaxHelper::link() so lazy users don't get type errors. Fixes #902 --- cake/libs/view/helpers/ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index e2cba1277..9c153c3a2 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -218,7 +218,7 @@ class AjaxHelper extends AppHelper { $options['url'] = $url; } - if (isset($confirm)) { + if (!empty($confirm)) { $options['confirm'] = $confirm; unset($confirm); } From e382a1c63cd54277d2eee0d44a48f9dcd6ecf545 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 11 Jul 2010 18:38:27 -0400 Subject: [PATCH 09/31] Adding test case for find(list) with recursive. --- cake/tests/cases/libs/model/model_read.test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cake/tests/cases/libs/model/model_read.test.php b/cake/tests/cases/libs/model/model_read.test.php index 75f22ed46..d59af8988 100755 --- a/cake/tests/cases/libs/model/model_read.test.php +++ b/cake/tests/cases/libs/model/model_read.test.php @@ -6408,6 +6408,18 @@ class ModelReadTest extends BaseModelTest { 4 => 'garrett (CakePHP)' ); $this->assertEqual($result, $expected); + + $TestModel =& new Article(); + $TestModel->displayField = 'title'; + $result = $TestModel->find('list', array( + 'conditions' => array('User.user' => 'mariano'), + 'recursive' => 0 + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article' + ); + $this->assertEqual($result, $expected); } /** From 15435e9d6fc0806337e651b1172f48be01a91344 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Tue, 13 Jul 2010 19:53:50 -0700 Subject: [PATCH 10/31] FormHelper::create should use domId to determine the default ID of the form tag. Signed-off-by: mark_story --- cake/libs/view/helpers/form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 cake/libs/view/helpers/form.php diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php old mode 100755 new mode 100644 index 6f8899c53..51a6b979d --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -260,7 +260,7 @@ class FormHelper extends AppHelper { 0 => $id ); if (!empty($options['action']) && !isset($options['id'])) { - $options['id'] = $model . Inflector::camelize($options['action']) . 'Form'; + $options['id'] = $this->domId(Inflector::camelize($options['action']) . 'Form'); } $options['action'] = array_merge($actionDefaults, (array)$options['url']); } elseif (is_string($options['url'])) { From 21f359bff9457f00c4e650e91cd6a7176ab3db7f Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Jul 2010 22:07:41 -0400 Subject: [PATCH 11/31] Removing additional call to camelize(). Fixes #913 --- cake/libs/view/helpers/form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 51a6b979d..adf7abb38 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -260,7 +260,7 @@ class FormHelper extends AppHelper { 0 => $id ); if (!empty($options['action']) && !isset($options['id'])) { - $options['id'] = $this->domId(Inflector::camelize($options['action']) . 'Form'); + $options['id'] = $this->domId($options['action'] . 'Form'); } $options['action'] = array_merge($actionDefaults, (array)$options['url']); } elseif (is_string($options['url'])) { From 0e184c66f4cf871fc7a7722f1e84aed50371f66a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 15 Jul 2010 21:52:24 -0400 Subject: [PATCH 12/31] Adding failing test for #917 --- .../cases/libs/controller/controller.test.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index a517092ea..f588b82a1 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -391,6 +391,16 @@ class TestComponent extends Object { */ function shutdown(&$controller) { } +/** + * beforeRender callback + * + * @return void + */ + function beforeRender(&$controller) { + if ($this->viewclass) { + $controller->view = $this->viewclass; + } + } } /** @@ -894,6 +904,27 @@ class ControllerTest extends CakeTestCase { App::build(); } +/** + * test that a component beforeRender can change the controller view class. + * + * @return void + */ + function testComponentBeforeRenderChangingViewClass() { + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + ), true); + $Controller =& new Controller(); + $Controller->uses = array(); + $Controller->components = array('Test'); + $Controller->constructClasses(); + $Controller->Test->viewclass = 'Theme'; + $Controller->viewPath = 'posts'; + $Controller->theme = 'test_theme'; + $result = $Controller->render('index'); + $this->assertPattern('/posts index themed view/', $result); + App::build(); + } + /** * testToBeInheritedGuardmethods method * @@ -1411,4 +1442,4 @@ class ControllerTest extends CakeTestCase { $MockedController->MockTest->expectCallCount('shutdown', 1); $MockedController->shutdownProcess(); } -} +} \ No newline at end of file From 32ea6d24cf7e88ab7261ee6bbd85f0b415c9a788 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Thu, 15 Jul 2010 14:59:29 +0200 Subject: [PATCH 13/31] Moving Component::beforeRender triggering to allow components to modify the view class to use for the render() call. Fixes #917 Signed-off-by: mark_story --- cake/libs/controller/controller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 7308418a0..5c8871dcf 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -865,6 +865,7 @@ class Controller extends Object { */ function render($action = null, $layout = null, $file = null) { $this->beforeRender(); + $this->Component->triggerCallback('beforeRender', $this); $viewClass = $this->view; if ($this->view != 'View') { @@ -873,8 +874,6 @@ class Controller extends Object { App::import('View', $this->view); } - $this->Component->triggerCallback('beforeRender', $this); - $this->params['models'] = $this->modelNames; if (Configure::read() > 2) { From 4c27c24a72bad9b25a5986a80fd9176535aa0b8e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 15 Jul 2010 23:17:38 -0400 Subject: [PATCH 14/31] Fixing issue in DboSource where COUNT() was hardcoded, omitting any other aggregate functions. Replaced with a regexp that accepts only letters. Test case added. Fixes #878 --- cake/libs/model/datasources/dbo_source.php | 4 ++-- .../model/datasources/dbo_source.test.php | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 35be891be..940a909df 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1216,10 +1216,10 @@ class DboSource extends DataSource { } elseif (!empty($model->hasMany) && $model->recursive > -1) { $assocFields = $this->fields($model, $model->alias, array("{$model->alias}.{$model->primaryKey}")); $passedFields = $this->fields($model, $model->alias, $queryData['fields']); - if (count($passedFields) === 1) { $match = strpos($passedFields[0], $assocFields[0]); - $match1 = strpos($passedFields[0], 'COUNT('); + $match1 = (bool)preg_match('/^[a-z]+\(/i', $passedFields[0]); + if ($match === false && $match1 === false) { $queryData['fields'] = array_merge($passedFields, $assocFields); } else { diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 5ef6d396f..6a71591bd 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2044,6 +2044,28 @@ class DboSourceTest extends CakeTestCase { unset($this->Model->hasMany['TestModel6']['fields']); } +/** + * test generateAssociationQuery with a hasMany and an aggregate function. + * + * @return void + */ + function testGenerateAssociationQueryHasManyAndAggregateFunction() { + $this->Model =& new TestModel5(); + $this->Model->schema(); + $this->_buildRelatedModels($this->Model); + + $binding = array('type' => 'hasMany', 'model' => 'TestModel6'); + $queryData = array('fields' => array('MIN(TestModel5.test_model4_id)')); + $resultSet = null; + $null = null; + + $params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding); + $this->Model->recursive = 0; + + $result = $this->testDb->generateAssociationQuery($this->Model, $null, $params['type'], $params['assoc'], $params['assocData'], $queryData, false, $resultSet); + $this->assertPattern('/^SELECT\s+MIN\(`TestModel5`\.`test_model4_id`\)\s+FROM/', $result); + } + /** * testGenerateAssociationQueryHasAndBelongsToMany method * From 41997b06e19eb7c7572d0b9d926bac4037af3849 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 18 Jul 2010 20:48:15 -0400 Subject: [PATCH 15/31] Fixing issues where mb_internal_encoding() might not be correctly set, causing email subjects to be incorrectly encoded. Tests added. Fixes #904 --- cake/libs/controller/components/email.php | 11 ++++++- .../libs/controller/components/email.test.php | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index b341f3965..aae446593 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -723,7 +723,16 @@ class EmailComponent extends Object{ if ($this->delivery == 'mail') { $nl = ''; } - return mb_encode_mimeheader($subject, $this->charset, 'B', $nl); + $internalEncoding = function_exists('mb_internal_encoding'); + if ($internalEncoding) { + $restore = mb_internal_encoding(); + mb_internal_encoding($this->charset); + } + $return = mb_encode_mimeheader($subject, $this->charset, 'B', $nl); + if ($internalEncoding) { + mb_internal_encoding($restore); + } + return $return; } /** diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 521a3fbb9..6d19c77f0 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -857,7 +857,38 @@ HTMLBLOC; $result = $this->Controller->EmailTest->strip($content, true); $expected = $content; $this->assertEqual($result, $expected); + } +/** + * test that the _encode() will set mb_internal_encoding. + * + * @return void + */ + function test_encodeSettingInternalCharset() { + $skip = !function_exists('mb_internal_encoding'); + if ($this->skipIf($skip, 'Missing mb_* functions, cannot run test.')) { + return; + } + mb_internal_encoding('ISO-8859-1'); + + $this->Controller->charset = 'UTF-8'; + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + $this->Controller->EmailTest->delivery = 'debug'; + + $this->Controller->EmailTest->sendAs = 'text'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); + + $subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?='; + + preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches); + $this->assertEqual(trim($matches[1]), $subject); + + $result = mb_internal_encoding(); + $this->assertEqual($result, 'ISO-8859-1'); } /** @@ -867,6 +898,7 @@ HTMLBLOC; * @return void */ function testMultibyte() { + $this->Controller->charset = 'UTF-8'; $this->Controller->EmailTest->to = 'postmaster@localhost'; $this->Controller->EmailTest->from = 'noreply@example.com'; $this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم'; From a78bb20bdabed0a7cdfe41e9cb9ac1570ea0e607 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 18 Jul 2010 21:28:52 -0400 Subject: [PATCH 16/31] Fixing failing test in ControllerTest caused by ThemeView not being correctly found if it was not in the mapped files. --- cake/tests/cases/libs/controller/controller.test.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index f588b82a1..4110f8065 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -910,8 +910,12 @@ class ControllerTest extends CakeTestCase { * @return void */ function testComponentBeforeRenderChangingViewClass() { + $core = App::core('views'); App::build(array( - 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + 'views' => array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, + $core[0] + ) ), true); $Controller =& new Controller(); $Controller->uses = array(); @@ -921,7 +925,7 @@ class ControllerTest extends CakeTestCase { $Controller->viewPath = 'posts'; $Controller->theme = 'test_theme'; $result = $Controller->render('index'); - $this->assertPattern('/posts index themed view/', $result); + $this->assertPattern('/default test_theme layout/', $result); App::build(); } From ca1c8f1f8038a701f1b6edf0bf0b96fc218b38b4 Mon Sep 17 00:00:00 2001 From: predominant Date: Mon, 19 Jul 2010 12:14:44 +1000 Subject: [PATCH 17/31] Remvoed session destruction from tests. --- .../tests/cases/libs/controller/components/session.test.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index 5a5ec4d3a..8bce838e8 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -349,8 +349,6 @@ class SessionComponentTest extends CakeTestCase { * @return void */ function testSessionTimeout() { - - session_destroy(); Configure::write('Security.level', 'low'); $Session =& new SessionComponent(); $Session->write('Test', 'some value'); @@ -361,7 +359,6 @@ class SessionComponentTest extends CakeTestCase { $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); - session_destroy(); Configure::write('Security.level', 'medium'); $Session =& new SessionComponent(); $Session->write('Test', 'some value'); @@ -371,8 +368,6 @@ class SessionComponentTest extends CakeTestCase { $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); - - session_destroy(); Configure::write('Security.level', 'high'); $Session =& new SessionComponent(); $Session->write('Test', 'some value'); @@ -381,6 +376,5 @@ class SessionComponentTest extends CakeTestCase { $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); $this->assertEqual($Session->time, mktime()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); - } } From 0c312e3d779e5509bf6dcf23870c1fa22cc91c2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 18 Jul 2010 22:56:57 -0400 Subject: [PATCH 18/31] Adding some destroy() calls to cause the timestamps to refresh. --- .../controller/components/session.test.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index 8bce838e8..78fe1ad10 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -349,32 +349,37 @@ class SessionComponentTest extends CakeTestCase { * @return void */ function testSessionTimeout() { + Configure::write('debug', 2); Configure::write('Security.level', 'low'); - $Session =& new SessionComponent(); - $Session->write('Test', 'some value'); - $this->assertEqual($Session->sessionTime, mktime() + (300 * Configure::read('Session.timeout'))); + session_destroy(); + $Session =& new SessionComponent(); + $Session->destroy(); + $Session->write('Test', 'some value'); + $this->assertEqual($Session->sessionTime, time() + (300 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); - $this->assertEqual($Session->time, mktime()); - $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); + $this->assertEqual($Session->time, time()); + $this->assertEqual($_SESSION['Config']['time'], $Session->time + (300 * Configure::read('Session.timeout'))); Configure::write('Security.level', 'medium'); $Session =& new SessionComponent(); + $Session->destroy(); $Session->write('Test', 'some value'); $this->assertEqual($Session->sessionTime, mktime() + (100 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); - $this->assertEqual($Session->time, mktime()); + $this->assertEqual($Session->time, time()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); Configure::write('Security.level', 'high'); $Session =& new SessionComponent(); + $Session->destroy(); $Session->write('Test', 'some value'); - $this->assertEqual($Session->sessionTime, mktime() + (10 * Configure::read('Session.timeout'))); + $this->assertEqual($Session->sessionTime, time() + (10 * Configure::read('Session.timeout'))); $this->assertEqual($_SESSION['Config']['timeout'], 10); $this->assertEqual($_SESSION['Config']['time'], $Session->sessionTime); - $this->assertEqual($Session->time, mktime()); + $this->assertEqual($Session->time, time()); $this->assertEqual($_SESSION['Config']['time'], $Session->time + (Security::inactiveMins() * Configure::read('Session.timeout'))); } } From f01b4ae13b9cd24091264f10ad19b326e329ae7c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 18 Jul 2010 23:00:24 -0400 Subject: [PATCH 19/31] Updating version numbers to 1.3.3 --- cake/VERSION.txt | 2 +- cake/config/config.php | 2 +- cake/libs/view/pages/home.ctp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/VERSION.txt b/cake/VERSION.txt index 5f08ec3dc..458264c68 100644 --- a/cake/VERSION.txt +++ b/cake/VERSION.txt @@ -18,5 +18,5 @@ // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -1.3.2 +1.3.3 diff --git a/cake/config/config.php b/cake/config/config.php index 65dd5a77c..52a713037 100644 --- a/cake/config/config.php +++ b/cake/config/config.php @@ -17,4 +17,4 @@ * @since CakePHP(tm) v 1.1.11.4062 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -return $config['Cake.version'] = '1.3.2'; +return $config['Cake.version'] = '1.3.3'; diff --git a/cake/libs/view/pages/home.ctp b/cake/libs/view/pages/home.ctp index f5a774fa3..82d3b8bf6 100644 --- a/cake/libs/view/pages/home.ctp +++ b/cake/libs/view/pages/home.ctp @@ -21,7 +21,7 @@ if (Configure::read() == 0): endif; ?>

- + 0): Debugger::checkSecurityKeys(); From 742bb29118ad8e9d931e9119ecd41573fcbdcfe3 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:17:02 -0700 Subject: [PATCH 20/31] Fixing typo in variable description for logoutRedirect. Signed-off-by: mark_story --- cake/libs/controller/components/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index fb736e8e5..053514d19 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -164,7 +164,7 @@ class AuthComponent extends Object { var $loginRedirect = null; /** - * The the default action to redirect to after the user is logged out. While AuthComponent does + * The default action to redirect to after the user is logged out. While AuthComponent does * not handle post-logout redirection, a redirect URL will be returned from AuthComponent::logout(). * Defaults to AuthComponent::$loginAction. * From 1774530222ecc4f8f41cb19e7d7a51d6435baeee Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:22:50 -0700 Subject: [PATCH 21/31] Fixing typo in method description. Signed-off-by: mark_story --- cake/console/libs/shell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 65333f01d..529f1c527 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -181,7 +181,7 @@ class Shell extends Object { } /** - * Starts up the the Shell + * Starts up the Shell * allows for checking and configuring prior to command or main execution * can be overriden in subclasses * From 037a7628c402177351480329d5282116140c33bd Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:25:42 -0700 Subject: [PATCH 22/31] Fixing typo in parameter description. Signed-off-by: mark_story --- cake/libs/cake_session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index bf599bf8a..f961836e6 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -743,7 +743,7 @@ class CakeSession extends Object { * Helper function called on write for database sessions. * * @param integer $id ID that uniquely identifies session in database - * @param mixed $data The value of the the data to be saved. + * @param mixed $data The value of the data to be saved. * @return boolean True for successful write, false otherwise. * @access private */ From ba59c931879a48722e5e465f62a434e2418aa9b8 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:27:06 -0700 Subject: [PATCH 23/31] Fixing typo in method description. Signed-off-by: mark_story --- cake/libs/controller/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 5c8871dcf..0d1dd6bcd 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -473,7 +473,7 @@ class Controller extends Object { } /** - * Loads Model classes based on the the uses property + * Loads Model classes based on the uses property * see Controller::loadModel(); for more info. * Loads Components and prepares them for initialization. * From b717abe1aa2ea8548185cf44625651b7422bc9c3 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:29:18 -0700 Subject: [PATCH 24/31] Fixing typo in Constructor description. Signed-off-by: mark_story --- cake/libs/model/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 07bb37e4f..d2b6d94d1 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -387,7 +387,7 @@ class Model extends Overloadable { * * ### Dynamically creating models * - * You can dynamically create model instances using the the $id array syntax. + * You can dynamically create model instances using the $id array syntax. * * {{{ * $Post = new Model(array('table' => 'posts', 'name' => 'Post', 'ds' => 'connection2')); From ba9fc949779fdae78266b5dfba2d46a2f6c401f8 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:30:34 -0700 Subject: [PATCH 25/31] Fix typo in variable description. Signed-off-by: mark_story --- cake/libs/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 10d2db5d6..51572e75e 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -30,7 +30,7 @@ if (!class_exists('Multibyte')) { class Validation extends Object { /** - * Set the the value of methods $check param. + * Set the value of methods $check param. * * @var string * @access public From f44911f6dc4dccae90b1c0981d976897718849e0 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:32:32 -0700 Subject: [PATCH 26/31] Fixing typo in parameter description. Signed-off-by: mark_story --- cake/libs/view/helpers/form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index adf7abb38..9e0480ee6 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -2165,7 +2165,7 @@ class FormHelper extends AppHelper { * * Options * - * - `secure` - boolean whether or not the the field should be added to the security fields. + * - `secure` - boolean whether or not the field should be added to the security fields. * * @param string $field Name of the field to initialize options for. * @param array $options Array of options to append options into. From 88e32b3ceeb1e7be48350cf8a1f0d5e4bee1a939 Mon Sep 17 00:00:00 2001 From: Scott Reeves Date: Mon, 19 Jul 2010 15:34:08 -0700 Subject: [PATCH 27/31] Fixing typo Signed-off-by: mark_story --- cake/tests/cases/libs/model/model_write.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index ba7b4383f..8d3564dc5 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -1645,7 +1645,7 @@ class ModelWriteTest extends BaseModelTest { } /** - * test that saving habtm records respects conditions set in the the 'conditions' key + * test that saving habtm records respects conditions set in the 'conditions' key * for the association. * * @return void From f6c7be9d2283824233ef8b1f891a0bc68cc4ff5a Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 19 Jul 2010 23:18:42 -0400 Subject: [PATCH 28/31] Adding omitted import for Multibyte to i18n. Fixes #929 --- cake/libs/i18n.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index b775223bd..b2cc52e3f 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -21,7 +21,7 @@ /** * Included libraries. */ -App::import('Core', 'l10n'); +App::import('Core', array('l10n', 'Multibyte')); /** * I18n handles translation of Text and time format strings. From fbb54e6a45b05c10ce3acaf325d4533df1a2549e Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 21 Jul 2010 23:37:14 -0400 Subject: [PATCH 29/31] Adding a test case for nested array data and clean(). --- cake/tests/cases/libs/sanitize.test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cake/tests/cases/libs/sanitize.test.php b/cake/tests/cases/libs/sanitize.test.php index f564ac1e2..34bb5f497 100644 --- a/cake/tests/cases/libs/sanitize.test.php +++ b/cake/tests/cases/libs/sanitize.test.php @@ -193,6 +193,29 @@ class SanitizeTest extends CakeTestCase { $expected = ''; $result = Sanitize::clean($string); $this->assertEqual($string, $expected); + + $data = array( + 'Grant' => array( + 'title' => '2 o clock grant', + 'grant_peer_review_id' => 3, + 'institution_id' => 5, + 'created_by' => 1, + 'modified_by' => 1, + 'created' => '2010-07-15 14:11:00', + 'modified' => '2010-07-19 10:45:41' + ), + 'GrantsMember' => array( + 0 => array( + 'id' => 68, + 'grant_id' => 120, + 'member_id' => 16, + 'program_id' => 29, + 'pi_percent_commitment' => 1 + ) + ) + ); + $result = Sanitize::clean($data); + $this->assertEqual($result, $data); } /** From 5b7b2d074eb7ad909ec76d86c0d5bdd810f26f7d Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Fri, 23 Jul 2010 00:13:19 -0300 Subject: [PATCH 30/31] Putting the port in header Host, following RFC 2616 item 14.23. Fixes #947. --- cake/libs/http_socket.php | 18 +++++++++++++++++- cake/tests/cases/libs/http_socket.test.php | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 5d1198f38..de7114a9f 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -227,7 +227,23 @@ class HttpSocket extends CakeSocket { if (!empty($this->request['cookies'])) { $cookies = $this->buildCookies($this->request['cookies']); } - $this->request['header'] = array_merge(array('Host' => $this->request['uri']['host']), $this->request['header']); + $Host = $this->request['uri']['host']; + $schema = ''; + $port = 0; + if (isset($this->request['uri']['schema'])) { + $schema = $this->request['uri']['schema']; + } + if (isset($this->request['uri']['port'])) { + $port = $this->request['uri']['port']; + } + if ( + ($schema === 'http' && $port != 80) || + ($schema === 'https' && $port != 443) || + ($port != 80 && $port != 443) + ) { + $Host .= ':' . $port; + } + $this->request['header'] = array_merge(compact('Host'), $this->request['header']); } if (isset($this->request['auth']['user']) && isset($this->request['auth']['pass'])) { diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index a49222235..ec024bc76 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -455,6 +455,25 @@ class HttpSocketTest extends CakeTestCase { ) ) , 9 => array( + 'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')) + , 'expectation' => array( + 'config' => array( + 'port' => 8080 + , 'request' => array( + 'uri' => array( + 'port' => 8080 + ) + ) + ) + , 'request' => array( + 'uri' => array( + 'port' => 8080 + ) + , 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" + ) + ) + ) + , 10 => array( 'request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')) , 'expectation' => array( 'config' => array( @@ -471,10 +490,11 @@ class HttpSocketTest extends CakeTestCase { 'scheme' => 'https' , 'port' => 443 ) + , 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n" ) ) ) - , 10 => array( + , 11 => array( 'request' => array( 'method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', From b5d7f6447f986d0f2905f69ecbab887f60b416fb Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 23 Jul 2010 21:46:06 -0400 Subject: [PATCH 31/31] Applying patch from 'asavoy'. Changing schema shell so that schema files generated for plugins have the classname of PluginSchema instead of AppSchema. Tests updated. Fixes #922 --- cake/console/libs/schema.php | 3 +++ cake/tests/cases/console/libs/schema.test.php | 1 + 2 files changed, 4 insertions(+) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 3629f59ad..889f85453 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -90,6 +90,9 @@ class SchemaShell extends Shell { } if (!empty($this->params['plugin'])) { $plugin = $this->params['plugin']; + if (empty($name)) { + $name = $plugin; + } } $this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin')); } diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 83bd25906..0f97950d6 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -368,6 +368,7 @@ class SchemaShellTest extends CakeTestCase { $file =& new File(TMP . 'tests' . DS . 'schema.php'); $contents = $file->read(); + $this->assertPattern('/class TestPluginSchema/', $contents); $this->assertPattern('/var \$posts/', $contents); $this->assertPattern('/var \$auth_users/', $contents); $this->assertPattern('/var \$authors/', $contents);