From 8d15ba503771c13f11901fa946ba1d76533afcfa Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Sun, 9 Jan 2011 17:43:41 -0300 Subject: [PATCH 01/18] Fixing env('HTTP_BASE') for site domain names that have the form xxx.yyy.zzz and use second level TLDs. --- cake/basics.php | 23 +++++++++++++++-------- cake/tests/cases/basics.test.php | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 2bfabd743..53b717d7e 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -446,7 +446,7 @@ if (!function_exists('array_combine')) { if (defined('SERVER_IIS') && SERVER_IIS === true) { return str_replace('\\\\', '\\', env('PATH_TRANSLATED')); } - break; + break; case 'DOCUMENT_ROOT': $name = env('SCRIPT_NAME'); $filename = env('SCRIPT_FILENAME'); @@ -455,20 +455,27 @@ if (!function_exists('array_combine')) { $offset = 4; } return substr($filename, 0, strlen($filename) - (strlen($name) + $offset)); - break; + break; case 'PHP_SELF': return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME')); - break; + break; case 'CGI_MODE': return (PHP_SAPI === 'cgi'); - break; + break; case 'HTTP_BASE': $host = env('HTTP_HOST'); - if (substr_count($host, '.') !== 1) { - return preg_replace('/^([^.])*/i', null, env('HTTP_HOST')); + $count = substr_count($host, '.'); + if ($count <= 1) { + return '.' . $host; + } elseif ($count === 2) { + $gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx'); + $domainName = explode('.', $host); + if (in_array($domainName[1], $gTLD)) { + $host = '.' . $host; + } } - return '.' . $host; - break; + return preg_replace('/^([^.])*/i', null, $host); + break; } return null; } diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 07455d0f8..6ba22e6b8 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -96,7 +96,13 @@ class BasicsTest extends CakeTestCase { $__ENV = $_ENV; $_SERVER['HTTP_HOST'] = 'localhost'; - $this->assertEqual(env('HTTP_BASE'), ''); + $this->assertEqual(env('HTTP_BASE'), '.localhost'); + + $_SERVER['HTTP_HOST'] = 'com.ar'; + $this->assertEqual(env('HTTP_BASE'), '.com.ar'); + + $_SERVER['HTTP_HOST'] = 'example.ar'; + $this->assertEqual(env('HTTP_BASE'), '.example.ar'); $_SERVER['HTTP_HOST'] = 'example.com'; $this->assertEqual(env('HTTP_BASE'), '.example.com'); @@ -107,9 +113,21 @@ class BasicsTest extends CakeTestCase { $_SERVER['HTTP_HOST'] = 'subdomain.example.com'; $this->assertEqual(env('HTTP_BASE'), '.example.com'); + $_SERVER['HTTP_HOST'] = 'example.com.ar'; + $this->assertEqual(env('HTTP_BASE'), '.example.com.ar'); + + $_SERVER['HTTP_HOST'] = 'www.example.com.ar'; + $this->assertEqual(env('HTTP_BASE'), '.example.com.ar'); + + $_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar'; + $this->assertEqual(env('HTTP_BASE'), '.example.com.ar'); + $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com'; $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com'); + $_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar'; + $this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar'); + $_SERVER = $_ENV = array(); $_SERVER['SCRIPT_NAME'] = '/a/test/test.php'; From 4f94b715ecf893e2ce415ba312f4448a05c19a94 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 9 Jan 2011 22:29:10 -0500 Subject: [PATCH 02/18] Revert "Fixing Set::filter() not predictably filtering in a recursive fashion. While a minor change in behavior, more predictable and uniform behavior is worth it." Refs #1431 This reverts commit 6e2ffafe54862710d3ae27e726de058b70b83a27. --- cake/libs/set.php | 16 ++-------------- cake/tests/cases/libs/set.test.php | 14 +------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index 289c5af59..3d4e89f02 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -68,22 +68,10 @@ class Set { * @static */ function filter($var, $isArray = false) { - foreach ((array)$var as $k => $v) { - if (!empty($v) && is_array($v)) { - $var[$k] = array_filter($v, array('Set', '_filter')); - } + if (is_array($var) && (!empty($var) || $isArray)) { + return array_filter($var, array('Set', 'filter')); } - return array_filter($var, array('Set', '_filter')); - } -/** - * Set::filter callback function - * - * @param array $var Array to filter. - * @return boolean - * @access protected - */ - function _filter($var) { if ($var === 0 || $var === '0' || !empty($var)) { return true; } diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 9f0d9a596..3018c351a 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -88,20 +88,8 @@ class SetTest extends CakeTestCase { */ function testFilter() { $result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false))); - $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be')); + $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be', false)); $this->assertIdentical($result, $expected); - - $result = Set::filter(array(1, array(false))); - $expected = array(1); - $this->assertEqual($expected, $result); - - $result = Set::filter(array(1, array(false, false))); - $expected = array(1); - $this->assertEqual($expected, $result); - - $result = Set::filter(array(1, array('empty', false))); - $expected = array(1, array('empty')); - $this->assertEqual($expected, $result); } /** From f893e3b63b86761366334bcba71ea4b02b0d5a61 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 11 Jan 2011 20:16:42 -0500 Subject: [PATCH 03/18] Applying patch from 'ryandesign' fixing incorrect datetime formats. Fixes #1441 --- cake/console/templates/default/classes/fixture.ctp | 2 +- cake/console/templates/default/classes/test.ctp | 2 +- cake/libs/model/cake_schema.php | 2 +- cake/tests/cases/libs/model/model_write.test.php | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cake/console/templates/default/classes/fixture.ctp b/cake/console/templates/default/classes/fixture.ctp index d3283795f..6d158052c 100644 --- a/cake/console/templates/default/classes/fixture.ctp +++ b/cake/console/templates/default/classes/fixture.ctp @@ -21,7 +21,7 @@ */ ?> -/* Fixture generated on: */ +/* Fixture generated on: */ class Fixture extends CakeTestFixture { var $name = ''; diff --git a/cake/console/templates/default/classes/test.ctp b/cake/console/templates/default/classes/test.ctp index db6dffc62..1207e468c 100644 --- a/cake/console/templates/default/classes/test.ctp +++ b/cake/console/templates/default/classes/test.ctp @@ -19,7 +19,7 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ echo " App::import('', ''); diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 541cc943f..fefc41f7f 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -379,7 +379,7 @@ class CakeSchema extends Object { $File =& new File($path . DS . $file, true); $header = '$Id'; - $content = ""; + $content = ""; $content = $File->prepare($content); if ($File->write($content)) { return $content; diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 34133d31f..44f863908 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -1586,7 +1586,6 @@ class ModelWriteTest extends BaseModelTest { ); $TestModel->save($data); $result = $TestModel->read(null, 1); - $time = date('Y-M-D H:i:s'); $expected = array(4, 5); $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/id', $result), $expected); $expected = array('new record', 'new record'); From 0f4c90588d6e4b43c41ee2ce883303fe32ff14b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 12 Jan 2011 20:43:41 -0500 Subject: [PATCH 04/18] Fixing issue where elements did not get .ctp as a fallback extension unlike view and layout files. Adding a protected method to get extensions, as it would be in 3 places now. Added tests. Fixes #1438 --- cake/libs/view/view.php | 39 +++++++++++++++--------- cake/tests/cases/libs/view/view.test.php | 15 +++++++++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index dbf7b5f9b..0224ce4c9 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -372,11 +372,13 @@ class View extends Object { } } $paths = $this->_paths($plugin); - - foreach ($paths as $path) { - if (file_exists($path . 'elements' . DS . $name . $this->ext)) { - $file = $path . 'elements' . DS . $name . $this->ext; - break; + $exts = $this->_getExtensions(); + foreach ($exts as $ext) { + foreach ($paths as $path) { + if (file_exists($path . 'elements' . DS . $name . $ext)) { + $file = $path . 'elements' . DS . $name . $ext; + break; + } } } @@ -862,10 +864,7 @@ class View extends Object { } $paths = $this->_paths(Inflector::underscore($this->plugin)); - $exts = array($this->ext); - if ($this->ext !== '.ctp') { - array_push($exts, '.ctp'); - } + $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { if (file_exists($path . $name . $ext)) { @@ -905,11 +904,8 @@ class View extends Object { } $paths = $this->_paths(Inflector::underscore($this->plugin)); $file = 'layouts' . DS . $subDir . $name; - - $exts = array($this->ext); - if ($this->ext !== '.ctp') { - array_push($exts, '.ctp'); - } + + $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { if (file_exists($path . $file . $ext)) { @@ -920,6 +916,21 @@ class View extends Object { return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout'); } + +/** + * Get the extensions that view files can use. + * + * @return array Array of extensions view files use. + * @access protected + */ + function _getExtensions() { + $exts = array($this->ext); + if ($this->ext !== '.ctp') { + array_push($exts, '.ctp'); + } + return $exts; + } + /** * Return a misssing view error message * diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 8ffb0837a..938b1aac4 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -573,6 +573,21 @@ class ViewTest extends CakeTestCase { } +/** + * test that ctp is used as a fallback file extension for elements + * + * @return void + */ + function testElementCtpFallback() { + $View = new TestView($this->PostsController); + $View->ext = '.missing'; + $element = 'test_element'; + $expected = 'this is the test element'; + $result = $View->element($element); + + $this->assertEqual($expected, $result); + } + /** * testLoadHelpers method * From 5f612b78336547b921237da6018ba80db303d188 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 13 Jan 2011 20:27:10 -0500 Subject: [PATCH 05/18] Making memcache cache adapter, set the expiry time of any value greater than 30 days to never expire. This works around the 30 day limitation of the PHP extension. Test case added. Fixes #1451 --- cake/libs/cache/memcache.php | 6 +++-- cake/tests/cases/libs/cache/memcache.test.php | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 32df6f0ab..c9616ea7a 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -119,8 +119,7 @@ class MemcacheEngine extends CacheEngine { /** * Write data for key into cache. When using memcache as your cache engine * remember that the Memcache pecl extension does not support cache expiry times greater - * than 30 days in the future. If you wish to create cache entries that do not expire, set the duration - * to `0` in your cache configuration. + * than 30 days in the future. Any duration greater than 30 days will be treated as never expiring. * * @param string $key Identifier for the data * @param mixed $value Data to be cached @@ -130,6 +129,9 @@ class MemcacheEngine extends CacheEngine { * @access public */ function write($key, &$value, $duration) { + if ($duration > 30 * DAY) { + $duration = 0; + } return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration); } diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 9c566c1a1..8f7715c3c 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -33,8 +33,14 @@ class TestMemcacheEngine extends MemcacheEngine { function parseServerString($server) { return $this->_parseServerString($server); } + + function setMemcache(&$memcache) { + $this->__Memcache = $memcache; + } } +Mock::generate('Memcache', 'MemcacheMockMemcache'); + /** * MemcacheEngineTest class * @@ -361,7 +367,23 @@ class MemcacheEngineTest extends CakeTestCase { $this->assertTrue($result, 'Could not write with duration 0'); $result = Cache::read('test_key', 'memcache'); $this->assertEqual($result, 'written!'); - + } + +/** + * test that durations greater than 30 days never expire + * + * @return void + */ + function testLongDurationEqualToZero() { + $memcache =& new TestMemcacheEngine(); + $memcache->settings['compress'] = false; + + $mock = new MemcacheMockMemcache(); + $memcache->setMemcache($mock); + $mock->expectAt(0, 'set', array('key', 'value', false, 0)); + + $value = 'value'; + $memcache->write('key', $value, 50 * DAY); } } From 75483791f4af2ce19443d7ff0fdaf151e75e9005 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Jan 2011 17:14:22 -0500 Subject: [PATCH 06/18] Small refactor for how HTTP_BASE is generated. Removing non-obvious regular expression. Fixes #1436 --- cake/basics.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 53b717d7e..ac3f02ae0 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -464,17 +464,21 @@ if (!function_exists('array_combine')) { break; case 'HTTP_BASE': $host = env('HTTP_HOST'); - $count = substr_count($host, '.'); - if ($count <= 1) { + $parts = explode('.', $host); + $count = count($parts); + + if ($count === 1) { return '.' . $host; } elseif ($count === 2) { + return '.' . $host; + } elseif ($count === 3) { $gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx'); - $domainName = explode('.', $host); - if (in_array($domainName[1], $gTLD)) { - $host = '.' . $host; + if (in_array($parts[1], $gTLD)) { + return '.' . $host; } } - return preg_replace('/^([^.])*/i', null, $host); + array_shift($parts); + return '.' . implode('.', $parts); break; } return null; From b8780586ec9f04ff245c5772d4f36919ec6148bf Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 14 Jan 2011 21:48:23 -0500 Subject: [PATCH 07/18] Fixing issue where FormHelper::checkbox() would ignore an explicit checked = false, and use the post data instead. Test case added. Fixes #1437 --- cake/libs/view/helpers/form.php | 5 +- .../cases/libs/view/helpers/form.test.php | 64 +++++++++++++------ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 5ee8a6c2c..b62092ed4 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1007,7 +1007,10 @@ class FormHelper extends AppHelper { if (empty($options['value'])) { $options['value'] = 1; - } elseif (!empty($value) && $value === $options['value']) { + } elseif ( + (!isset($options['checked']) && !empty($value) && $value === $options['value']) || + !empty($options['checked']) + ) { $options['checked'] = 'checked'; } if ($options['hiddenField']) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 3a9868c77..3c4cea940 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -3773,27 +3773,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->checkbox('Model.field', array('checked' => 'checked')); - $expected = array( - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), - array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) - ); - $this->assertTags($result, $expected); - - $result = $this->Form->checkbox('Model.field', array('checked' => 1)); - $expected = array( - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), - array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) - ); - $this->assertTags($result, $expected); - - $result = $this->Form->checkbox('Model.field', array('checked' => true)); - $expected = array( - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), - array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) - ); - $this->assertTags($result, $expected); - $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; $result = $this->Form->checkbox('Contact.published', array('id' => 'theID')); @@ -3834,6 +3813,49 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test the checked option for checkboxes. + * + * @return void + */ + function testCheckboxCheckedOption() { + $result = $this->Form->checkbox('Model.field', array('checked' => 'checked')); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) + ); + $this->assertTags($result, $expected); + + $result = $this->Form->checkbox('Model.field', array('checked' => 1)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) + ); + $this->assertTags($result, $expected); + + $result = $this->Form->checkbox('Model.field', array('checked' => true)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) + ); + $this->assertTags($result, $expected); + + $result = $this->Form->checkbox('Model.field', array('checked' => false)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) + ); + $this->assertTags($result, $expected); + + $this->Form->data['Model']['field'] = 1; + $result = $this->Form->checkbox('Model.field', array('checked' => false)); + $expected = array( + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) + ); + $this->assertTags($result, $expected); + } + /** * Test that disabling a checkbox also disables the hidden input so no value is submitted * From ca299a097cf0b6195722862ce1a2253bb244a7f2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 15 Jan 2011 14:39:24 -0500 Subject: [PATCH 08/18] Fixing issue where get forms created with model = false would create inputs with name = ''. Tests added. Fixes #1455 --- cake/libs/view/helpers/form.php | 2 +- .../cases/libs/view/helpers/form.test.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index b62092ed4..5c4435f97 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1960,7 +1960,7 @@ class FormHelper extends AppHelper { } $view = ClassRegistry::getObject('view'); - $name = $view->field; + $name = !empty($view->field) ? $view->field : $view->model; if (!empty($view->fieldSuffix)) { $name .= '[' . $view->fieldSuffix . ']'; } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 3c4cea940..ba979092f 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5729,6 +5729,28 @@ class FormHelperTest extends CakeTestCase { ))); } +/** + * test get form, and inputs when the model param is false + * + * @return void + */ + function testGetFormWithFalseModel() { + $encoding = strtolower(Configure::read('App.encoding')); + $result = $this->Form->create(false, array('type' => 'get')); + + $expected = array('form' => array( + 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add', + 'accept-charset' => $encoding + )); + $this->assertTags($result, $expected); + + $result = $this->Form->text('reason'); + $expected = array( + 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason') + ); + $this->assertTags($result, $expected); + } + /** * test that datetime() works with GET style forms. * From b0d495118482914161e48ec7d0932d0a366973fe Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 17 Jan 2011 11:11:30 -0500 Subject: [PATCH 09/18] Fixing TextHelper::autoLinkEmails() not linking email addresses that contain '. Test added. Fixes #1457 --- cake/libs/view/helpers/text.php | 6 ++++-- cake/tests/cases/libs/view/helpers/text.test.php | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 04e80a812..7d25ea349 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -142,9 +142,11 @@ class TextHelper extends AppHelper { $linkOptions .= "'$option' => $value, "; } $linkOptions .= ')'; + $atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]'; - return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#', - create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); + return preg_replace_callback( + '/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i', + create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); } /** diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index f4c18d628..295d9ce39 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -298,6 +298,11 @@ class TextHelperTest extends CakeTestCase { $expected = 'Text with email@example.com address'; $result = $this->Text->autoLinkEmails($text); $this->assertPattern('#^' . $expected . '$#', $result); + + $text = "Text with o'hare._-bob@example.com address"; + $expected = 'Text with o'hare._-bob@example.com address'; + $result = $this->Text->autoLinkEmails($text); + $this->assertEqual($expected, $result); $text = 'Text with email@example.com address'; $expected = 'Text with email@example.com address'; From cfce0e45d3f51471571241a32241f5da08d4c583 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 08:14:47 -0500 Subject: [PATCH 10/18] Fixing issue where empty session id's would cause duplicate key errors. Empty session id sessions are no longer saved. Fixes #1450 --- cake/libs/cake_session.php | 3 ++ cake/tests/cases/libs/cake_session.test.php | 31 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 0ad09de2c..395f68536 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -751,6 +751,9 @@ class CakeSession extends Object { * @access private */ function __write($id, $data) { + if (!$id) { + return false; + } $expires = time() + Configure::read('Session.timeout') * Security::inactiveMins(); $model =& ClassRegistry::getObject('Session'); $return = $model->save(array($model->primaryKey => $id) + compact('data', 'expires')); diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index 1ef143f67..b6bc12248 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -474,4 +474,35 @@ class CakeSessionTest extends CakeTestCase { $this->setUp(); } +/** + * testReadAndWriteWithDatabaseStorage method + * + * @access public + * @return void + */ + function testDatabaseStorageEmptySessionId() { + unset($_SESSION); + session_destroy(); + Configure::write('Session.table', 'sessions'); + Configure::write('Session.model', 'Session'); + Configure::write('Session.database', 'test_suite'); + Configure::write('Session.save', 'database'); + $this->setUp(); + $id = $this->Session->id(); + + $this->Session->id = ''; + session_id(''); + + $this->Session->write('SessionTestCase', 'This is a Test'); + $this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test'); + + session_write_close(); + + unset($_SESSION); + ini_set('session.save_handler', 'files'); + Configure::write('Session.save', 'php'); + session_id($id); + $this->setUp(); + } + } From 932533c5c8ec3ce9a019431b4ad0b358da2411c1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 08:28:16 -0500 Subject: [PATCH 11/18] Fixing incorrect content type headers from being set, when an action contains a requestAction to an action with a different Content-Type. Also populating RequestHandler->params as it was always empty. Fixes #1445 --- cake/libs/controller/components/request_handler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index c60d48b70..ae33ab27d 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -202,6 +202,7 @@ class RequestHandlerComponent extends Object { if (isset($controller->params['url']['ext'])) { $this->ext = $controller->params['url']['ext']; } + $this->params = $controller->params; $this->_set($settings); } @@ -738,7 +739,7 @@ class RequestHandlerComponent extends Object { if (!empty($options['attachment'])) { $this->_header("Content-Disposition: attachment; filename=\"{$options['attachment']}\""); } - if (Configure::read() < 2 && !defined('CAKEPHP_SHELL')) { + if (Configure::read() < 2 && !defined('CAKEPHP_SHELL') && empty($this->params['requested'])) { $this->_header($header); } $this->__responseTypeSet = $cType; From d4e495756301d89b0bb74580b0682a90cbc526e0 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 19 Jan 2011 02:25:39 +0530 Subject: [PATCH 12/18] Adding test case for FormHelper::input() for generation multiple checkboxes with space in option values. Refs #1465 --- .../cases/libs/view/helpers/form.test.php | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index ba979092f..103a33d02 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2173,6 +2173,35 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $this->Form->data = array(); + $result = $this->Form->input('Publisher.id', array( + 'label' => 'Publisher', + 'type' => 'select', + 'multiple' => 'checkbox', + 'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2') + )); + $expected = array( + array('div' => array('class' => 'input select')), + array('label' => array('for' => 'PublisherId')), + 'Publisher', + '/label', + 'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'), + array('div' => array('class' => 'checkbox')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')), + array('label' => array('for' => 'PublisherIdValue1')), + 'Label 1', + '/label', + '/div', + array('div' => array('class' => 'checkbox')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')), + array('label' => array('for' => 'PublisherIdValue2')), + 'Label 2', + '/label', + '/div', + '/div' + ); + $this->assertTags($result, $expected); } /** @@ -3132,7 +3161,7 @@ class FormHelperTest extends CakeTestCase { '/select' ); $this->assertTags($result, $expected); - + $options = array( '>< Key' => array( 1 => 'One', @@ -3510,7 +3539,7 @@ class FormHelperTest extends CakeTestCase { */ function testSelectMultipleCheckboxDiv() { $result = $this->Form->select( - 'Model.tags', + 'Model.tags', array('first', 'second'), null, array('multiple' => 'checkbox', 'class' => 'my-class') @@ -3539,7 +3568,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->input('Model.tags', array( 'options' => array('first', 'second'), - 'multiple' => 'checkbox', + 'multiple' => 'checkbox', 'class' => 'my-class', 'div' => false, 'label' => false @@ -5743,7 +5772,7 @@ class FormHelperTest extends CakeTestCase { 'accept-charset' => $encoding )); $this->assertTags($result, $expected); - + $result = $this->Form->text('reason'); $expected = array( 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason') From 607178847850d66cfeddd668dca37423185bf31a Mon Sep 17 00:00:00 2001 From: Miah Gregory Date: Tue, 18 Jan 2011 14:23:12 -0800 Subject: [PATCH 13/18] Updated documentation for Router::connect. Fixed a few spelling issues as well. Signed-off-by: mark_story --- cake/libs/router.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index cd4c27999..622dae829 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -161,7 +161,7 @@ class Router { } /** - * Sets the Routing prefixes. Includes compatibilty for existing Routing.admin + * Sets the Routing prefixes. Includes compatibility for existing Routing.admin * configurations. * * @return void @@ -236,21 +236,25 @@ class Router { * Shows connecting a route with custom route parameters as well as providing patterns for those parameters. * Patterns for routing parameters do not need capturing groups, as one will be added for each route params. * - * $options offers two 'special' keys. `pass` and `persist` have special meaning in the $options array. + * $options offers three 'special' keys. `pass`, `persist` and `routeClass` have special meaning in the $options array. * * `pass` is used to define which of the routed parameters should be shifted into the pass array. Adding a * parameter to pass will remove it from the regular route array. Ex. `'pass' => array('slug')` * * `persist` is used to define which route parameters should be automatically included when generating - * new urls. You can override peristent parameters by redifining them in a url or remove them by + * new urls. You can override persistent parameters by redefining them in a url or remove them by * setting the parameter to `false`. Ex. `'persist' => array('lang')` * + * `routeClass` is used to extend and change how individual routes parse requests and handle reverse routing, + * via a custom routing class. Ex. `'routeClass' => 'SlugRoute'` + * * @param string $route A string describing the template of the route * @param array $defaults An array describing the default route parameters. These parameters will be used by default * and can supply routing parameters that are not dynamic. See above. * @param array $options An array matching the named elements in the route to regular expressions which that * element should match. Also contains additional parameters such as which routed parameters should be - * shifted into the passed arguments. As well as supplying patterns for routing parameters. + * shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a + * custom routing class. * @see routes * @return array Array of routes * @access public @@ -708,7 +712,7 @@ class Router { * * @param $which A zero-based array index representing the route to move. For example, * if 3 routes have been added, the last route would be 2. - * @return boolean Retuns false if no route exists at the position specified by $which. + * @return boolean Returns false if no route exists at the position specified by $which. * @access public * @static */ @@ -732,7 +736,7 @@ class Router { * Returns an URL pointing to a combination of controller and action. Param * $url can be: * - * - Empty - the method will find address to actuall controller/action. + * - Empty - the method will find address to actual controller/action. * - '/' - the method will find base URL of application. * - A combination of controller/action - the method will find url for it. * @@ -1044,7 +1048,7 @@ class Router { } /** - * Reverses a parsed parameter array into a string. Works similarily to Router::url(), but + * Reverses a parsed parameter array into a string. Works similarly to Router::url(), but * Since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys. * Those keys need to be specially handled in order to reverse a params array into a string url. * @@ -1177,7 +1181,7 @@ class Router { } /** - * Takes an passed params and converts it to args + * Takes a passed params and converts it to args * * @param array $params * @return array Array containing passed and named parameters @@ -1393,7 +1397,7 @@ class CakeRoute { /** * Checks to see if the given URL can be parsed by this route. - * If the route can be parsed an array of parameters will be returned if not + * If the route can be parsed an array of parameters will be returned; if not, * false will be returned. String urls are parsed if they match a routes regular expression. * * @param string $url The url to attempt to parse. @@ -1470,8 +1474,8 @@ class CakeRoute { } /** - * Attempt to match a url array. If the url matches the route parameters + settings, then - * return a generated string url. If the url doesn't match the route parameters false will be returned. + * Attempt to match a url array. If the url matches the route parameters and settings, then + * return a generated string url. If the url doesn't match the route parameters, false will be returned. * This method handles the reverse routing or conversion of url arrays into string urls. * * @param array $url An array of parameters to check matching with. From ab337e2e8a3ad7f2291f5db6cc4cedd6a9cfdb9c Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 18:56:35 -0500 Subject: [PATCH 14/18] Adding tests for TextHelper::autolinkurl(). Closes #1466 --- cake/tests/cases/libs/view/helpers/text.test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 295d9ce39..249f96749 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -280,6 +280,16 @@ class TextHelperTest extends CakeTestCase { $expected = 'Text with a url www.cot.ag/cuIb2Q and more'; $result = $this->Text->autoLinkUrls($text); $this->assertEqual($expected, $result); + + $text = 'Text with a url http://www.does--not--work.com and more'; + $expected = 'Text with a url http://www.does--not--work.com and more'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEqual($expected, $result); + + $text = 'Text with a url http://www.not--work.com and more'; + $expected = 'Text with a url http://www.not--work.com and more'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEqual($expected, $result); } /** From b94edefb2cce6ee7a9ba9a0697e80dd6c78302b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 19:33:05 -0500 Subject: [PATCH 15/18] Removing the last vestiges of the enable parameter. Fixing issue where isset() stupidly plods along when doing a string index of a string. Updating DbAcl to use proper settings array. Fixes #1467 --- cake/console/libs/task_collection.php | 4 ++-- cake/libs/controller/component_collection.php | 2 +- cake/libs/model/behavior_collection.php | 2 +- cake/libs/model/db_acl.php | 2 +- cake/libs/view/helper_collection.php | 2 +- cake/libs/view/view.php | 2 +- cake/tests/cases/console/libs/task_collection.test.php | 2 +- cake/tests/cases/libs/object_collection.test.php | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/task_collection.php b/cake/console/libs/task_collection.php index 32f0b31a4..df29d3d26 100644 --- a/cake/console/libs/task_collection.php +++ b/cake/console/libs/task_collection.php @@ -48,11 +48,10 @@ class TaskCollection extends ObjectCollection { * * @param string $task Task name to load * @param array $settings Settings for the task. - * @param boolean $enable Whether or not this task should be enabled by default * @return Task A task object, Either the existing loaded task or a new one. * @throws MissingTaskFileException, MissingTaskClassException when the task could not be found */ - public function load($task, $settings = array(), $enable = true) { + public function load($task, $settings = array()) { list($plugin, $name) = pluginSplit($task, true); if (isset($this->_loaded[$name])) { @@ -72,6 +71,7 @@ class TaskCollection extends ObjectCollection { $this->_loaded[$name] = new $taskClass( $this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin ); + $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { $this->_enabled[] = $name; } diff --git a/cake/libs/controller/component_collection.php b/cake/libs/controller/component_collection.php index 5efb7c888..2a483cc21 100644 --- a/cake/libs/controller/component_collection.php +++ b/cake/libs/controller/component_collection.php @@ -74,7 +74,7 @@ class ComponentCollection extends ObjectCollection { * @throws MissingComponentFileException, MissingComponentClassException when the component could not be found */ public function load($component, $settings = array()) { - if (isset($settings['className'])) { + if (is_array($settings) && isset($settings['className'])) { $alias = $component; $component = $settings['className']; } diff --git a/cake/libs/model/behavior_collection.php b/cake/libs/model/behavior_collection.php index 2035a77a0..30c9c1469 100644 --- a/cake/libs/model/behavior_collection.php +++ b/cake/libs/model/behavior_collection.php @@ -99,7 +99,7 @@ class BehaviorCollection extends ObjectCollection { * @throws MissingBehaviorFileException or MissingBehaviorClassException when a behavior could not be found. */ public function load($behavior, $config = array()) { - if (isset($config['className'])) { + if (is_array($config) && isset($config['className'])) { $alias = $behavior; $behavior = $config['className']; } diff --git a/cake/libs/model/db_acl.php b/cake/libs/model/db_acl.php index e8a31cef7..4782cfc91 100644 --- a/cake/libs/model/db_acl.php +++ b/cake/libs/model/db_acl.php @@ -46,7 +46,7 @@ class AclNode extends AppModel { * @var array * @access public */ - public $actsAs = array('Tree' => 'nested'); + public $actsAs = array('Tree' => array('nested')); /** * Constructor diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 35e6e0dd4..d90289e21 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -57,7 +57,7 @@ class HelperCollection extends ObjectCollection { * @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found */ public function load($helper, $settings = array()) { - if (isset($settings['className'])) { + if (is_array($settings) && isset($settings['className'])) { $alias = $helper; $helper = $settings['className']; } diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index ef1d46b9f..7318a829d 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -623,7 +623,7 @@ class View extends Object { public function loadHelpers() { $helpers = HelperCollection::normalizeObjectArray($this->helpers); foreach ($helpers as $name => $properties) { - $this->Helpers->load($properties['class'], $properties['settings'], true); + $this->Helpers->load($properties['class'], $properties['settings']); } $this->_helpersLoaded = true; } diff --git a/cake/tests/cases/console/libs/task_collection.test.php b/cake/tests/cases/console/libs/task_collection.test.php index 27a43e619..74c0c61f2 100644 --- a/cake/tests/cases/console/libs/task_collection.test.php +++ b/cake/tests/cases/console/libs/task_collection.test.php @@ -63,7 +63,7 @@ class TaskCollectionTest extends CakeTestCase { * @return void */ function testLoadWithEnableFalse() { - $result = $this->Tasks->load('DbConfig', array(), false); + $result = $this->Tasks->load('DbConfig', array('enabled' => false)); $this->assertInstanceOf('DbConfigTask', $result); $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); diff --git a/cake/tests/cases/libs/object_collection.test.php b/cake/tests/cases/libs/object_collection.test.php index b01a93627..e3a0f82ca 100644 --- a/cake/tests/cases/libs/object_collection.test.php +++ b/cake/tests/cases/libs/object_collection.test.php @@ -54,16 +54,16 @@ class GenericObjectCollection extends ObjectCollection { * * @param string $object Object name * @param array $settings Settings array - * @param boolean $enable Start object as enabled * @return array List of loaded objects */ - public function load($object, $settings = array(), $enable = true) { + public function load($object, $settings = array()) { list($plugin, $name) = pluginSplit($object); if (isset($this->_loaded[$name])) { return $this->_loaded[$name]; } $objectClass = $name . 'GenericObject'; $this->_loaded[$name] = new $objectClass($this, $settings); + $enable = isset($settings['enabled']) ? $settings['enabled'] : true; if ($enable === true) { $this->_enabled[] = $name; } From a0a87ade5ad308c36baf9ede9cf7d96e666acb95 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 19:40:31 -0500 Subject: [PATCH 16/18] Adding non-zero exit codes to ErrorHandler in the console. Fixes #1468 --- cake/console/error.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cake/console/error.php b/cake/console/error.php index 5494efcf6..e837d1b8d 100644 --- a/cake/console/error.php +++ b/cake/console/error.php @@ -63,7 +63,7 @@ class ErrorHandler extends Object { function error($params) { extract($params, EXTR_OVERWRITE); $this->stderr($code . $name . $message."\n"); - $this->_stop(); + $this->_stop(1); } /** @@ -79,7 +79,7 @@ class ErrorHandler extends Object { 'name' => 'Not found', 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message) )); - $this->_stop(); + $this->_stop(1); } /** @@ -92,7 +92,7 @@ class ErrorHandler extends Object { extract($params, EXTR_OVERWRITE); $controllerName = str_replace('Controller', '', $className); $this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName)); - $this->_stop(); + $this->_stop(1); } /** @@ -104,7 +104,7 @@ class ErrorHandler extends Object { function missingAction($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className)); - $this->_stop(); + $this->_stop(1); } /** @@ -116,7 +116,7 @@ class ErrorHandler extends Object { function privateAction($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className)); - $this->_stop(); + $this->_stop(1); } /** @@ -128,7 +128,7 @@ class ErrorHandler extends Object { function missingTable($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className)); - $this->_stop(); + $this->_stop(1); } /** @@ -139,7 +139,7 @@ class ErrorHandler extends Object { */ function missingDatabase($params = array()) { $this->stderr(__("Missing Database", true)); - $this->_stop(); + $this->_stop(1); } /** @@ -151,7 +151,7 @@ class ErrorHandler extends Object { function missingView($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className)); - $this->_stop(); + $this->_stop(1); } /** @@ -163,7 +163,7 @@ class ErrorHandler extends Object { function missingLayout($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Layout '%s'", true), $file)); - $this->_stop(); + $this->_stop(1); } /** @@ -175,7 +175,7 @@ class ErrorHandler extends Object { function missingConnection($params) { extract($params, EXTR_OVERWRITE); $this->stderr(__("Missing Database Connection. Try 'cake bake'", true)); - $this->_stop(); + $this->_stop(1); } /** @@ -187,7 +187,7 @@ class ErrorHandler extends Object { function missingHelperFile($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper))); - $this->_stop(); + $this->_stop(1); } /** @@ -199,7 +199,7 @@ class ErrorHandler extends Object { function missingHelperClass($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file)); - $this->_stop(); + $this->_stop(1); } /** @@ -211,7 +211,7 @@ class ErrorHandler extends Object { function missingComponentFile($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component))); - $this->_stop(); + $this->_stop(1); } /** @@ -223,7 +223,7 @@ class ErrorHandler extends Object { function missingComponentClass($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file)); - $this->_stop(); + $this->_stop(1); } /** @@ -235,7 +235,7 @@ class ErrorHandler extends Object { function missingModel($params) { extract($params, EXTR_OVERWRITE); $this->stderr(sprintf(__("Missing model '%s'", true), $className)); - $this->_stop(); + $this->_stop(1); } /** From 23dce83836c6864c2291b1cc709208d03302a9b3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Jan 2011 20:20:49 -0500 Subject: [PATCH 17/18] Fixing test cases and code from merge with 1.3 Making MemcacheEngine::__Memcache protected, so mocking is possible. --- cake/libs/cache/memcache.php | 24 +++++++------- cake/libs/view/view.php | 4 +-- cake/tests/cases/libs/cache/memcache.test.php | 12 +++---- cake/tests/cases/libs/cake_session.test.php | 31 ------------------- .../libs/session/database_session.test.php | 10 ++++++ 5 files changed, 30 insertions(+), 51 deletions(-) diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index 8db15b131..012eceba0 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine { * @var Memcache * @access private */ - private $__Memcache = null; + protected $_Memcache = null; /** * Settings @@ -74,12 +74,12 @@ class MemcacheEngine extends CacheEngine { if (!is_array($this->settings['servers'])) { $this->settings['servers'] = array($this->settings['servers']); } - if (!isset($this->__Memcache)) { + if (!isset($this->_Memcache)) { $return = false; - $this->__Memcache = new Memcache(); + $this->_Memcache = new Memcache(); foreach ($this->settings['servers'] as $server) { list($host, $port) = $this->_parseServerString($server); - if ($this->__Memcache->addServer($host, $port)) { + if ($this->_Memcache->addServer($host, $port)) { $return = true; } } @@ -128,7 +128,7 @@ class MemcacheEngine extends CacheEngine { if ($duration > 30 * DAY) { $duration = 0; } - return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration); + return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration); } /** @@ -138,7 +138,7 @@ class MemcacheEngine extends CacheEngine { * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it */ public function read($key) { - return $this->__Memcache->get($key); + return $this->_Memcache->get($key); } /** @@ -156,7 +156,7 @@ class MemcacheEngine extends CacheEngine { __('Method increment() not implemented for compressed cache in %s', __CLASS__) ); } - return $this->__Memcache->increment($key, $offset); + return $this->_Memcache->increment($key, $offset); } /** @@ -174,7 +174,7 @@ class MemcacheEngine extends CacheEngine { __('Method decrement() not implemented for compressed cache in %s', __CLASS__) ); } - return $this->__Memcache->decrement($key, $offset); + return $this->_Memcache->decrement($key, $offset); } /** @@ -184,7 +184,7 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed */ public function delete($key) { - return $this->__Memcache->delete($key); + return $this->_Memcache->delete($key); } /** @@ -193,7 +193,7 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if the cache was succesfully cleared, false otherwise */ public function clear($check) { - return $this->__Memcache->flush(); + return $this->_Memcache->flush(); } /** @@ -204,8 +204,8 @@ class MemcacheEngine extends CacheEngine { * @return boolean True if memcache server was connected */ public function connect($host, $port = 11211) { - if ($this->__Memcache->getServerStatus($host, $port) === 0) { - if ($this->__Memcache->connect($host, $port)) { + if ($this->_Memcache->getServerStatus($host, $port) === 0) { + if ($this->_Memcache->connect($host, $port)) { return true; } return false; diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 9702874c1..7ff7ed9fa 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -778,8 +778,8 @@ class View extends Object { $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { - if (file_exists($path . 'elements' . DS . $name . $this->ext)) { - return $path . 'elements' . DS . $name . $this->ext; + if (file_exists($path . 'elements' . DS . $name . $ext)) { + return $path . 'elements' . DS . $name . $ext; } } } diff --git a/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index aea370cc0..61bcec550 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -32,13 +32,11 @@ class TestMemcacheEngine extends MemcacheEngine { return $this->_parseServerString($server); } - function setMemcache(&$memcache) { - $this->__Memcache = $memcache; + function setMemcache($memcache) { + $this->_Memcache = $memcache; } } -Mock::generate('Memcache', 'MemcacheMockMemcache'); - /** * MemcacheEngineTest class * @@ -374,9 +372,11 @@ class MemcacheEngineTest extends CakeTestCase { $memcache =& new TestMemcacheEngine(); $memcache->settings['compress'] = false; - $mock = new MemcacheMockMemcache(); + $mock = $this->getMock('Memcache'); $memcache->setMemcache($mock); - $mock->expectAt(0, 'set', array('key', 'value', false, 0)); + $mock->expects($this->once()) + ->method('set') + ->with('key', 'value', false, 0); $value = 'value'; $memcache->write('key', $value, 50 * DAY); diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index e88a01aec..3673121fd 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -702,35 +702,4 @@ class CakeSessionTest extends CakeTestCase { $this->assertEquals(CakeSession::$time + $timeoutSeconds, $_SESSION['Config']['time']); } -/** - * testReadAndWriteWithDatabaseStorage method - * - * @access public - * @return void - */ - function testDatabaseStorageEmptySessionId() { - unset($_SESSION); - session_destroy(); - Configure::write('Session.table', 'sessions'); - Configure::write('Session.model', 'Session'); - Configure::write('Session.database', 'test_suite'); - Configure::write('Session.save', 'database'); - $this->setUp(); - $id = $this->Session->id(); - - $this->Session->id = ''; - session_id(''); - - $this->Session->write('SessionTestCase', 'This is a Test'); - $this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test'); - - session_write_close(); - - unset($_SESSION); - ini_set('session.save_handler', 'files'); - Configure::write('Session.save', 'php'); - session_id($id); - $this->setUp(); - } - } diff --git a/cake/tests/cases/libs/session/database_session.test.php b/cake/tests/cases/libs/session/database_session.test.php index b3c457c2d..657ce8159 100644 --- a/cake/tests/cases/libs/session/database_session.test.php +++ b/cake/tests/cases/libs/session/database_session.test.php @@ -126,6 +126,16 @@ class DatabaseSessionTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * testReadAndWriteWithDatabaseStorage method + * + * @access public + * @return void + */ + function testWriteEmptySessionId() { + $result = $this->storage->write('', 'This is a Test'); + $this->assertFalse($result); + } /** * test read() * From f73c4f38d525116f2b644712fee65d1d31c497d0 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 18 Jan 2011 23:39:05 -0200 Subject: [PATCH 18/18] Fixing the postLink url when the application is not in root path. --- cake/libs/view/helpers/form.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index ab56d4e3a..f397c670d 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1325,7 +1325,6 @@ class FormHelper extends AppHelper { unset($options['confirm']); } - $url = $this->url($url); $formName = uniqid('post_'); $out = $this->create(false, array('url' => $url, 'name' => $formName, 'id' => $formName, 'style' => 'display:none;')); if (isset($options['data']) && is_array($options['data'])) {